diff --git a/js/privatebin.js b/js/privatebin.js index 0416a03..4589526 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -227,6 +227,28 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { }); }; + /** + * replace last child of element with message + * + * @name helper.appendMessage + * @function + * @param {jQuery} $element - a jQuery wrapped DOM element + * @param {string} message - the message to append + * @TODO: make private if possible & move to function + */ + me.appendMessage = function($element, message) + { + var content = $element.contents(); + if (content.length > 0) + { + content[content.length - 1].nodeValue = ' ' + message; + } + else + { + me.setElementText($element, message); + } + }; + /** * get value of cookie, if it was set, empty string otherwise * @@ -512,10 +534,8 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { })(window, document); /** - * cryptTool methods + * handles everything related to en/decryption * - * @param {object} window - * @param {object} document * @class */ var cryptTool = (function () { @@ -552,7 +572,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { /** * compress, then encrypt message with given key and password * - * @name cryptToolcipher + * @name cryptTool.cipher * @function * @param {string} key * @param {string} password @@ -573,7 +593,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { /** * decrypt message with key, then decompress * - * @name cryptTooldecipher + * @name cryptTool.decipher * @function * @param {string} key * @param {string} password @@ -606,6 +626,58 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { return me; })(); + /** + * Data source (aka MVC) + * + * @param {object} window + * @param {object} document + * @class + */ + var modal = (function (window, document) { + var me = {}; + + var $cipherData; + + /** + * check if cipher data was supplied + * + * @name modal.getCipherData + * @function + * @return boolean + */ + me.hasCipherData = function() + { + return (me.getCipherData().length > 0); + }; + + /** + * returns the cipher data + * + * @name modal.getCipherData + * @function + * @return string + */ + me.getCipherData = function() + { + return $cipherData.text(); + }; + + /** + * init navigation manager + * + * preloads jQuery elements + * + * @name modal.init + * @function + */ + me.init = function() + { + $cipherData = $('#cipherdata'); + }; + + return me; + })(window, document); + /** * User interface manager * @@ -617,8 +689,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { var me = {}; // jQuery pre-loaded objects - var $cipherData, - $clearText, + var $clearText, $clonedFile, $comments, $discussion, @@ -709,7 +780,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { */ me.displayMessages = function(paste) { - paste = paste || $.parseJSON($cipherData.text()); + paste = paste || $.parseJSON(modal.getCipherData()); var key = helper.pageKey(), password = $passwordInput.val(); if (!$prettyPrint.hasClass('prettyprinted')) { @@ -718,7 +789,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { { if (paste.attachment) { - var attachment = cryptTooldecipher(key, password, paste.attachment); + var attachment = cryptTool.decipher(key, password, paste.attachment); if (attachment.length === 0) { if (password.length === 0) @@ -726,7 +797,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { me.requestPassword(); return; } - attachment = cryptTooldecipher(key, password, paste.attachment); + attachment = cryptTool.decipher(key, password, paste.attachment); } if (attachment.length === 0) { @@ -735,7 +806,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { if (paste.attachmentname) { - var attachmentname = cryptTooldecipher(key, password, paste.attachmentname); + var attachmentname = cryptTool.decipher(key, password, paste.attachmentname); if (attachmentname.length > 0) { $attachmentLink.attr('download', attachmentname); @@ -756,7 +827,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { $image.removeClass('hidden'); } } - var cleartext = cryptTooldecipher(key, password, paste.data); + var cleartext = cryptTool.decipher(key, password, paste.data); if (cleartext.length === 0 && password.length === 0 && !paste.attachment) { me.requestPassword(); @@ -790,7 +861,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { 'This document will expire in %d ' + expiration[1] + '.', 'This document will expire in %d ' + expiration[1] + 's.' ]; - me.appendMessage($remainingTime, i18n._(expirationLabel, expiration[0])); + helper.appendMessage($remainingTime, i18n._(expirationLabel, expiration[0])); $remainingTime.removeClass('foryoureyesonly') .removeClass('hidden'); } @@ -807,7 +878,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { .fail(function() { controller.showError(i18n._('Could not delete the paste, it was not stored in burn after reading mode.')); }); - me.appendMessage($remainingTime, i18n._( + helper.appendMessage($remainingTime, i18n._( 'FOR YOUR EYES ONLY. Don\'t close this window, this message can\'t be displayed again.' )); $remainingTime.addClass('foryoureyesonly') @@ -828,7 +899,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { { var $place = $comments, comment = paste.comments[i], - commentText = cryptTooldecipher(key, password, comment.data), + commentText = cryptTool.decipher(key, password, comment.data), $parentComment = $('#comment_' + comment.parentid); $divComment = $('
-