فهرست منبع

make it work(1): paste input can be shown

rugk 9 سال پیش
والد
کامیت
8a07a0b157
2فایلهای تغییر یافته به همراه201 افزوده شده و 119 حذف شده
  1. 201 117
      js/privatebin.js
  2. 0 2
      tpl/bootstrap.php

+ 201 - 117
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
          * get value of cookie, if it was set, empty string otherwise
          *
          *
@@ -512,10 +534,8 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
     })(window, document);
     })(window, document);
 
 
     /**
     /**
-     * cryptTool methods
+     * handles everything related to en/decryption
      *
      *
-     * @param  {object} window
-     * @param  {object} document
      * @class
      * @class
      */
      */
     var cryptTool = (function () {
     var cryptTool = (function () {
@@ -552,7 +572,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
         /**
         /**
          * compress, then encrypt message with given key and password
          * compress, then encrypt message with given key and password
          *
          *
-         * @name   cryptToolcipher
+         * @name   cryptTool.cipher
          * @function
          * @function
          * @param  {string} key
          * @param  {string} key
          * @param  {string} password
          * @param  {string} password
@@ -573,7 +593,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
         /**
         /**
          * decrypt message with key, then decompress
          * decrypt message with key, then decompress
          *
          *
-         * @name   cryptTooldecipher
+         * @name   cryptTool.decipher
          * @function
          * @function
          * @param  {string} key
          * @param  {string} key
          * @param  {string} password
          * @param  {string} password
@@ -606,6 +626,58 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
         return me;
         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
      * User interface manager
      *
      *
@@ -617,8 +689,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
         var me = {};
         var me = {};
 
 
         // jQuery pre-loaded objects
         // jQuery pre-loaded objects
-        var $cipherData,
-            $clearText,
+        var $clearText,
             $clonedFile,
             $clonedFile,
             $comments,
             $comments,
             $discussion,
             $discussion,
@@ -709,7 +780,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
          */
          */
         me.displayMessages = function(paste)
         me.displayMessages = function(paste)
         {
         {
-            paste = paste || $.parseJSON($cipherData.text());
+            paste = paste || $.parseJSON(modal.getCipherData());
             var key = helper.pageKey(),
             var key = helper.pageKey(),
                 password = $passwordInput.val();
                 password = $passwordInput.val();
             if (!$prettyPrint.hasClass('prettyprinted')) {
             if (!$prettyPrint.hasClass('prettyprinted')) {
@@ -718,7 +789,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
                 {
                 {
                     if (paste.attachment)
                     if (paste.attachment)
                     {
                     {
-                        var attachment = cryptTooldecipher(key, password, paste.attachment);
+                        var attachment = cryptTool.decipher(key, password, paste.attachment);
                         if (attachment.length === 0)
                         if (attachment.length === 0)
                         {
                         {
                             if (password.length === 0)
                             if (password.length === 0)
@@ -726,7 +797,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
                                 me.requestPassword();
                                 me.requestPassword();
                                 return;
                                 return;
                             }
                             }
-                            attachment = cryptTooldecipher(key, password, paste.attachment);
+                            attachment = cryptTool.decipher(key, password, paste.attachment);
                         }
                         }
                         if (attachment.length === 0)
                         if (attachment.length === 0)
                         {
                         {
@@ -735,7 +806,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
 
 
                         if (paste.attachmentname)
                         if (paste.attachmentname)
                         {
                         {
-                            var attachmentname = cryptTooldecipher(key, password, paste.attachmentname);
+                            var attachmentname = cryptTool.decipher(key, password, paste.attachmentname);
                             if (attachmentname.length > 0)
                             if (attachmentname.length > 0)
                             {
                             {
                                 $attachmentLink.attr('download', attachmentname);
                                 $attachmentLink.attr('download', attachmentname);
@@ -756,7 +827,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
                             $image.removeClass('hidden');
                             $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)
                     if (cleartext.length === 0 && password.length === 0 && !paste.attachment)
                     {
                     {
                         me.requestPassword();
                         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] + '.',
                         'This document will expire in %d ' + expiration[1] + 's.'
                         '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')
                 $remainingTime.removeClass('foryoureyesonly')
                                   .removeClass('hidden');
                                   .removeClass('hidden');
             }
             }
@@ -807,7 +878,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
                 .fail(function() {
                 .fail(function() {
                     controller.showError(i18n._('Could not delete the paste, it was not stored in burn after reading mode.'));
                     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.'
                     'FOR YOUR EYES ONLY. Don\'t close this window, this message can\'t be displayed again.'
                 ));
                 ));
                 $remainingTime.addClass('foryoureyesonly')
                 $remainingTime.addClass('foryoureyesonly')
@@ -828,7 +899,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
                 {
                 {
                     var $place = $comments,
                     var $place = $comments,
                         comment = paste.comments[i],
                         comment = paste.comments[i],
-                        commentText = cryptTooldecipher(key, password, comment.data),
+                        commentText = cryptTool.decipher(key, password, comment.data),
                         $parentComment = $('#comment_' + comment.parentid);
                         $parentComment = $('#comment_' + comment.parentid);
 
 
                     $divComment = $('<article><div class="comment" id="comment_' + comment.id
                     $divComment = $('<article><div class="comment" id="comment_' + comment.id
@@ -850,7 +921,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
                     helper.urls2links($divCommentData);
                     helper.urls2links($divCommentData);
 
 
                     // try to get optional nickname
                     // try to get optional nickname
-                    var nick = cryptTooldecipher(key, password, comment.meta.nickname);
+                    var nick = cryptTool.decipher(key, password, comment.meta.nickname);
                     if (nick.length > 0)
                     if (nick.length > 0)
                     {
                     {
                         $divComment.find('span.nickname').text(nick);
                         $divComment.find('span.nickname').text(nick);
@@ -914,28 +985,6 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
             $('#replymessage').focus();
             $('#replymessage').focus();
         };
         };
 
 
-        /**
-         * replace last child of element with message
-         *
-         * @name   me.appendMessage
-         * @function
-         * @param  {jQuery} $element - a jQuery wrapped DOM element
-         * @param  {string} message - the message to append
-         * @TODO: make private if possible
-         */
-        me.appendMessage = function($element, message)
-        {
-            var content = $element.contents();
-            if (content.length > 0)
-            {
-                content[content.length - 1].nodeValue = ' ' + message;
-            }
-            else
-            {
-                me.setElementText($element, message);
-            }
-        };
-
         /**
         /**
          * handle history (pop) state changes
          * handle history (pop) state changes
          *
          *
@@ -1003,19 +1052,16 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
             $('#noscript').hide();
             $('#noscript').hide();
 
 
             // preload jQuery elements
             // preload jQuery elements
-            $cipherData = $('#cipherdata');
             $clearText = $('#cleartext');
             $clearText = $('#cleartext');
             $clonedFile = $('#clonedfile');
             $clonedFile = $('#clonedfile');
             $comments = $('#comments');
             $comments = $('#comments');
             $discussion = $('#discussion');
             $discussion = $('#discussion');
-            $errorMessage = $('#errormessage');
             $image = $('#image');
             $image = $('#image');
             $pasteResult = $('#pasteresult');
             $pasteResult = $('#pasteresult');
             // $pasteUrl is saved in sendDataContinue() if/after it is
             // $pasteUrl is saved in sendDataContinue() if/after it is
             // actually created
             // actually created
             $prettyMessage = $('#prettymessage');
             $prettyMessage = $('#prettymessage');
             $prettyPrint = $('#prettyprint');
             $prettyPrint = $('#prettyprint');
-            $preview = $('#preview');
             $remainingTime = $('#remainingtime');
             $remainingTime = $('#remainingtime');
 
 
             // bind events
             // bind events
@@ -1137,8 +1183,6 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
             $status.text(message);
             $status.text(message);
         };
         };
 
 
-        // @TODO: add showLoading()
-
         /**
         /**
          * display a status message for replying to comments
          * display a status message for replying to comments
          *
          *
@@ -1169,20 +1213,20 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
         /**
         /**
          * display an error message
          * display an error message
          *
          *
-         * @name   controller.showError
+         * @name   status.showError
          * @function
          * @function
          * @param  {string} message - text to display
          * @param  {string} message - text to display
          */
          */
         me.showError = function(message)
         me.showError = function(message)
         {
         {
             $errorMessage.removeClass('hidden');
             $errorMessage.removeClass('hidden');
-            me.appendMessage($errorMessage, message);
+            helper.appendMessage($errorMessage, message);
         };
         };
 
 
         /**
         /**
          * display an error message
          * display an error message
          *
          *
-         * @name   controller.showError
+         * @name   status.showError
          * @function
          * @function
          * @param  {string} message - text to display
          * @param  {string} message - text to display
          */
          */
@@ -1199,7 +1243,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
          *
          *
          * preloads jQuery elements
          * preloads jQuery elements
          *
          *
-         * @name   controller.init
+         * @name   status.init
          * @function
          * @function
          */
          */
         me.init = function()
         me.init = function()
@@ -1222,24 +1266,27 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
 
 
             // keep line height even if content empty
             // keep line height even if content empty
             $status.html(' '); // @TODO what? remove?
             $status.html(' '); // @TODO what? remove?
+
+            // display error message from php code
+            if ($errorMessage.text().length > 1) {
+                me.showError($errorMessage.text());
+            }
         };
         };
 
 
         return me;
         return me;
     })(window, document);
     })(window, document);
 
 
     /**
     /**
-     * Passwort modal manager
+     * Passwort prompt
      *
      *
      * @param  {object} window
      * @param  {object} window
      * @param  {object} document
      * @param  {object} document
-     * @name modal
      * @class
      * @class
      */
      */
-    var modal = (function (window, document) {
+    var prompt = (function (window, document) {
         var me = {};
         var me = {};
 
 
-        var $password,
-            $passwordInput,
+        var $passwordInput,
             $passwordModal,
             $passwordModal,
             $passwordForm,
             $passwordForm,
             $passwordDecrypt;
             $passwordDecrypt;
@@ -1307,7 +1354,6 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
          */
          */
         me.init = function()
         me.init = function()
         {
         {
-            $password = $('#password');
             $passwordInput = $('#passwordinput');
             $passwordInput = $('#passwordinput');
             $passwordModal = $('#passwordmodal');
             $passwordModal = $('#passwordmodal');
             $passwordForm = $('#passwordform');
             $passwordForm = $('#passwordform');
@@ -1339,7 +1385,8 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
 
 
         var $message,
         var $message,
             $messageEdit,
             $messageEdit,
-            $messagePreview;
+            $messagePreview,
+            $preview;
 
 
         /**
         /**
          * support input of tab character
          * support input of tab character
@@ -1407,13 +1454,13 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
         /**
         /**
          * reset the editor view
          * reset the editor view
          *
          *
-         * @name   editor.reset
+         * @name   editor.resetInput
          * @function
          * @function
          */
          */
-        me.reset = function()
+        me.resetInput = function()
         {
         {
             // clear content
             // clear content
-            $message.text('');
+            $message.val('');
         };
         };
 
 
         /**
         /**
@@ -1424,12 +1471,13 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
          */
          */
         me.show = function()
         me.show = function()
         {
         {
-            $attachment.removeClass('hidden');
-            $clearText.removeClass('hidden');
-            $discussion.removeClass('hidden');
-            $pasteResult.removeClass('hidden'); //??
+            $message.removeClass('hidden');
+            $preview.removeClass('hidden');
+            // $clearText ??
+            // $discussion.removeClass('hidden');
+            // $pasteResult.removeClass('hidden'); //??
             // $prettyMessage.removeClass('hidden');
             // $prettyMessage.removeClass('hidden');
-            $remainingTime.removeClass('hidden');
+            // $remainingTime.removeClass('hidden');
         };
         };
 
 
         /**
         /**
@@ -1440,21 +1488,21 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
          */
          */
         me.hide = function()
         me.hide = function()
         {
         {
-            $attachment.addClass('hidden');
-            $clearText.addClass('hidden');
-            $discussion.addClass('hidden');
-            $pasteResult.addClass('hidden');
-            $prettyMessage.addClass('hidden');
-            $remainingTime.addClass('hidden');
+            $message.addClass('hidden');
+            $preview.addClass('hidden');
+            // $discussion.addClass('hidden');
+            // $pasteResult.addClass('hidden');
+            // $prettyMessage.addClass('hidden');
+            // $remainingTime.addClass('hidden');
         };
         };
 
 
         /**
         /**
          * focuses the message input
          * focuses the message input
          *
          *
-         * @name   editor.focus
+         * @name   editor.focusInput
          * @function
          * @function
          */
          */
-        me.focus = function()
+        me.focusInput = function()
         {
         {
             $message.focus();
             $message.focus();
         };
         };
@@ -1472,6 +1520,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
             $message = $('#message');
             $message = $('#message');
             $messageEdit = $('#messageedit');
             $messageEdit = $('#messageedit');
             $messagePreview = $('#messagepreview');
             $messagePreview = $('#messagepreview');
+            $preview = $('#preview');
 
 
             // bind events
             // bind events
             $message.keydown(supportTabs);
             $message.keydown(supportTabs);
@@ -1493,6 +1542,9 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
     var topNav = (function (window, document) {
     var topNav = (function (window, document) {
         var me = {};
         var me = {};
 
 
+        var createButtonsDisplayed = false;
+        var viewButtonsDisplayed = false;
+
         var $attach,
         var $attach,
             $attachment,
             $attachment,
             $attachmentLink,
             $attachmentLink,
@@ -1506,6 +1558,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
             $newButton,
             $newButton,
             $openDisc, // @TODO: rename - too similar to openDiscussion, difference unclear
             $openDisc, // @TODO: rename - too similar to openDiscussion, difference unclear
             $openDiscussion,
             $openDiscussion,
+            $password,
             $rawTextButton,
             $rawTextButton,
             $sendButton;
             $sendButton;
 
 
@@ -1644,8 +1697,15 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
          */
          */
         me.showViewButtons = function()
         me.showViewButtons = function()
         {
         {
+            if (viewButtonsDisplayed) {
+                console.log('showViewButtons: view buttons are already displayed');
+                return;
+            }
+
             $cloneButton.removeClass('hidden');
             $cloneButton.removeClass('hidden');
             $rawTextButton.removeClass('hidden');
             $rawTextButton.removeClass('hidden');
+
+            viewButtonsDisplayed = true;
         };
         };
 
 
         /**
         /**
@@ -1656,8 +1716,15 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
          */
          */
         me.hideViewButtons = function()
         me.hideViewButtons = function()
         {
         {
+            if (!viewButtonsDisplayed) {
+                console.log('hideViewButtons: view buttons are already hidden');
+                return;
+            }
+
             $cloneButton.addClass('hidden');
             $cloneButton.addClass('hidden');
             $rawTextButton.addClass('hidden');
             $rawTextButton.addClass('hidden');
+
+            viewButtonsDisplayed = false;
         };
         };
 
 
         /**
         /**
@@ -1668,6 +1735,12 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
          */
          */
         me.showCreateButtons = function()
         me.showCreateButtons = function()
         {
         {
+            if (createButtonsDisplayed) {
+                console.log('showCreateButtons: create buttons are already displayed');
+                return;
+            }
+
+            $attachment.removeClass('hidden');
             $sendButton.removeClass('hidden');
             $sendButton.removeClass('hidden');
             $expiration.removeClass('hidden');
             $expiration.removeClass('hidden');
             $formatter.removeClass('hidden');
             $formatter.removeClass('hidden');
@@ -1676,8 +1749,8 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
             $newButton.removeClass('hidden');
             $newButton.removeClass('hidden');
             $password.removeClass('hidden');
             $password.removeClass('hidden');
             $attach.removeClass('hidden');
             $attach.removeClass('hidden');
-            $message.removeClass('hidden');
-            $preview.removeClass('hidden');
+
+            createButtonsDisplayed = true;
         };
         };
 
 
         /**
         /**
@@ -1688,6 +1761,12 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
          */
          */
         me.hideCreateButtons = function()
         me.hideCreateButtons = function()
         {
         {
+            if (!createButtonsDisplayed) {
+                console.log('hideCreateButtons: create buttons are already hidden');
+                return;
+            }
+
+            $attachment.addClass('hidden');
             $sendButton.addClass('hidden');
             $sendButton.addClass('hidden');
             $expiration.addClass('hidden');
             $expiration.addClass('hidden');
             $formatter.addClass('hidden');
             $formatter.addClass('hidden');
@@ -1696,8 +1775,8 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
             $newButton.addClass('hidden');
             $newButton.addClass('hidden');
             $password.addClass('hidden');
             $password.addClass('hidden');
             $attach.addClass('hidden');
             $attach.addClass('hidden');
-            $message.addClass('hidden');
-            $preview.addClass('hidden');
+
+            createButtonsDisplayed = false;
         };
         };
 
 
         /**
         /**
@@ -1759,6 +1838,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
             $newButton = $('#newbutton');
             $newButton = $('#newbutton');
             $openDisc = $('#opendisc');
             $openDisc = $('#opendisc');
             $openDiscussion = $('#opendiscussion');
             $openDiscussion = $('#opendiscussion');
+            $password = $('#password');
             $rawTextButton = $('#rawtextbutton');
             $rawTextButton = $('#rawtextbutton');
             $sendButton = $('#sendbutton');
             $sendButton = $('#sendbutton');
 
 
@@ -1770,9 +1850,10 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
             // bind events
             // bind events
             $burnAfterReading.change(changeBurnAfterReading);
             $burnAfterReading.change(changeBurnAfterReading);
             $openDisc.change(changeOpenDisc);
             $openDisc.change(changeOpenDisc);
+            $newButton.click(controller.newPaste);
             $sendButton.click(controller.sendData);
             $sendButton.click(controller.sendData);
             $cloneButton.click(controller.clonePaste);
             $cloneButton.click(controller.clonePaste);
-            $rawTextButton.click(me.rawText);
+            $rawTextButton.click(rawText);
             $fileRemoveButton.click(me.removeAttachment);
             $fileRemoveButton.click(me.removeAttachment);
 
 
             // initiate default state of checkboxes
             // initiate default state of checkboxes
@@ -1839,12 +1920,12 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
             me.showStatus(i18n._('Sending comment...'), true);
             me.showStatus(i18n._('Sending comment...'), true);
             var parentid = event.data.parentid,
             var parentid = event.data.parentid,
                 key = helper.pageKey(),
                 key = helper.pageKey(),
-                cipherdata = cryptToolcipher(key, $passwordInput.val(), replyMessage.val()),
+                cipherdata = cryptTool.cipher(key, $passwordInput.val(), replyMessage.val()),
                 ciphernickname = '',
                 ciphernickname = '',
                 nick = $('#nickname').val();
                 nick = $('#nickname').val();
             if (nick.length > 0)
             if (nick.length > 0)
             {
             {
-                ciphernickname = cryptToolcipher(key, $passwordInput.val(), nick);
+                ciphernickname = cryptTool.cipher(key, $passwordInput.val(), nick);
             }
             }
             var data_to_send = {
             var data_to_send = {
                 data:     cipherdata,
                 data:     cipherdata,
@@ -1957,8 +2038,8 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
                     return function(e) {
                     return function(e) {
                         controller.sendDataContinue(
                         controller.sendDataContinue(
                             randomkey,
                             randomkey,
-                            cryptToolcipher(randomkey, password, e.target.result),
-                            cryptToolcipher(randomkey, password, theFile.name)
+                            cryptTool.cipher(randomkey, password, e.target.result),
+                            cryptTool.cipher(randomkey, password, theFile.name)
                         );
                         );
                     };
                     };
                 })(files[0]);
                 })(files[0]);
@@ -1968,7 +2049,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
             {
             {
                 me.sendDataContinue(
                 me.sendDataContinue(
                     randomkey,
                     randomkey,
-                    cryptToolcipher(randomkey, password, $attachmentLink.attr('href')),
+                    cryptTool.cipher(randomkey, password, $attachmentLink.attr('href')),
                     $attachmentLink.attr('download')
                     $attachmentLink.attr('download')
                 );
                 );
             }
             }
@@ -1989,7 +2070,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
          */
          */
         me.sendDataContinue = function(randomkey, cipherdata_attachment, cipherdata_attachment_name)
         me.sendDataContinue = function(randomkey, cipherdata_attachment, cipherdata_attachment_name)
         {
         {
-            var cipherdata = cryptToolcipher(randomkey, $passwordInput.val(), $message.val()),
+            var cipherdata = cryptTool.cipher(randomkey, $passwordInput.val(), $message.val()),
                 data_to_send = {
                 data_to_send = {
                     data:             cipherdata,
                     data:             cipherdata,
                     expire:           $('#pasteExpiration').val(),
                     expire:           $('#pasteExpiration').val(),
@@ -2098,6 +2179,21 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
             event.preventDefault();
             event.preventDefault();
         };
         };
 
 
+        /**
+         * creates a new paste
+         *
+         * @name   controller.newPaste
+         * @function
+         */
+        me.newPaste = function()
+        {
+            // topNav.hideViewButtons(); // should not be necessary as they are not yet shown
+            topNav.showCreateButtons();
+            editor.resetInput();
+            editor.show();
+            editor.focusInput();
+        };
+
         /**
         /**
          * clone the current paste
          * clone the current paste
          *
          *
@@ -2118,28 +2214,15 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
                 $clonedFile.removeClass('hidden');
                 $clonedFile.removeClass('hidden');
                 $fileWrap.addClass('hidden');
                 $fileWrap.addClass('hidden');
             }
             }
-            $message.text(
+            $message.val(
                 $('#pasteFormatter').val() === 'markdown' ?
                 $('#pasteFormatter').val() === 'markdown' ?
-                    $prettyPrint.text() : $clearText.text()
+                    $prettyPrint.val() : $clearText.val()
             );
             );
             $('.navbar-toggle').click();
             $('.navbar-toggle').click();
 
 
             event.preventDefault();
             event.preventDefault();
         };
         };
 
 
-        /**
-         * create a new paste
-         *
-         * @name   controller.newPaste
-         * @function
-         */
-        me.newPaste = function()
-        {
-            me.stateNewPaste();
-            me.hideStatus();
-            $message.text('');
-        };
-
         /**
         /**
          * application start
          * application start
          *
          *
@@ -2151,48 +2234,49 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
             // first load translations
             // first load translations
             i18n.loadTranslations();
             i18n.loadTranslations();
 
 
-            // init UI @TODO show loading
+            // initialize other modules/"classes"
+            status.init();
+            modal.init();
             uiMan.init();
             uiMan.init();
+            topNav.init();
+            editor.init();
+            prompt.init();
 
 
             // display an existing paste
             // display an existing paste
-            if ($cipherData.text().length > 1)
-            {
+            if (modal.hasCipherData()) {
                 // missing decryption key in URL?
                 // missing decryption key in URL?
                 if (window.location.hash.length === 0)
                 if (window.location.hash.length === 0)
                 {
                 {
-                    me.showError(i18n._('Cannot decrypt paste: Decryption key missing in URL (Did you use a redirector or an URL shortener which strips part of the URL?)'));
+                    status.showError(i18n._('Cannot decrypt paste: Decryption key missing in URL (Did you use a redirector or an URL shortener which strips part of the URL?)'));
                     return;
                     return;
                 }
                 }
 
 
                 // show proper elements on screen
                 // show proper elements on screen
-                me.stateExistingPaste();
+                // me.hideCreateButtons(); // they should not be visible in the first place
+                me.showViewButtons();
                 me.displayMessages();
                 me.displayMessages();
+                return;
             }
             }
-            // display error message from php code
-            else if ($errorMessage.text().length > 1)
-            {
-                me.showError($errorMessage.text());
-            }
-            // create a new paste
-            else
-            {
-                me.newPaste();
-            }
+
+            // otherwise create a new paste
+            me.newPaste();
         };
         };
 
 
         return me;
         return me;
     })(window, document);
     })(window, document);
 
 
-    /**
-     * main application start, called when DOM is fully loaded and
-     * runs controller initalization
-     */
-    $(controller.init);
+    jQuery(document).ready(function() {
+        /**
+         * main application start, called when DOM is fully loaded and
+         * runs controller initalization
+         */
+        $(controller.init);
+    });
 
 
     return {
     return {
         helper: helper,
         helper: helper,
         i18n: i18n,
         i18n: i18n,
-        filter: filter,
+        cryptTool: cryptTool,
         controller: controller
         controller: controller
     };
     };
 }(jQuery, sjcl, Base64, RawDeflate);
 }(jQuery, sjcl, Base64, RawDeflate);

+ 0 - 2
tpl/bootstrap.php

@@ -409,8 +409,6 @@ endif;
 				<span class="glyphicon glyphicon-ok" aria-hidden="true"></span>
 				<span class="glyphicon glyphicon-ok" aria-hidden="true"></span>
 				<?php echo htmlspecialchars($STATUS), PHP_EOL; ?>
 				<?php echo htmlspecialchars($STATUS), PHP_EOL; ?>
 			</div>
 			</div>
-<?php
-?>
 			<div id="errormessage" role="alert" class="<?php echo empty($ERROR) ? 'hidden' : '' ?> alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo htmlspecialchars($ERROR); ?></div>
 			<div id="errormessage" role="alert" class="<?php echo empty($ERROR) ? 'hidden' : '' ?> alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo htmlspecialchars($ERROR); ?></div>
 			<noscript><div id="noscript" role="alert" class="nonworking alert alert-<?php echo $isDark ? 'error' : 'warning'; ?>"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> <?php echo I18n::_('JavaScript is required for %s to work.<br />Sorry for the inconvenience.', I18n::_($NAME)); ?></div></noscript>
 			<noscript><div id="noscript" role="alert" class="nonworking alert alert-<?php echo $isDark ? 'error' : 'warning'; ?>"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> <?php echo I18n::_('JavaScript is required for %s to work.<br />Sorry for the inconvenience.', I18n::_($NAME)); ?></div></noscript>
 			<div id="oldienotice" role="alert" class="hidden nonworking alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo I18n::_('%s requires a modern browser to work.', I18n::_($NAME)); ?></div>
 			<div id="oldienotice" role="alert" class="hidden nonworking alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo I18n::_('%s requires a modern browser to work.', I18n::_($NAME)); ?></div>