diff --git a/js/privatebin.js b/js/privatebin.js
index 5963592a..e8d8acb2 100644
--- a/js/privatebin.js
+++ b/js/privatebin.js
@@ -115,8 +115,8 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
{
// For IE<10: Doesn't support white-space:pre-wrap; so we have to do this...
if ($('#oldienotice').is(':visible')) {
- var html = this.htmlEntities(text).replace(/\n/ig,'\r\n ');
- element.html('
'+html+'
');
+ var html = this.htmlEntities(text).replace(/\n/ig, '\r\n ');
+ element.html('
' + html + '
');
}
// for other (sane) browsers:
else
@@ -230,11 +230,14 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
* @return {string}
*/
getCookie: function(cname) {
- var name = cname + '=';
- var ca = document.cookie.split(';');
+ var name = cname + '=',
+ ca = document.cookie.split(';');
for (var i = 0; i < ca.length; ++i) {
var c = ca[i];
- while (c.charAt(0) === ' ') c = c.substring(1);
+ while (c.charAt(0) === ' ')
+ {
+ c = c.substring(1);
+ }
if (c.indexOf(name) === 0)
{
return c.substring(name.length, c.length);
@@ -243,6 +246,77 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
return '';
},
+ /**
+ * get the current script location (without search or hash part of the URL),
+ * eg. http://example.com/path/?aaaa#bbbb --> http://example.com/path/
+ *
+ * @name helper.scriptLocation
+ * @function
+ * @return {string} current script location
+ */
+ scriptLocation: function()
+ {
+ var scriptLocation = window.location.href.substring(
+ 0,
+ window.location.href.length - window.location.search.length - window.location.hash.length
+ ), hashIndex = scriptLocation.indexOf('#');
+ if (hashIndex !== -1)
+ {
+ scriptLocation = scriptLocation.substring(0, hashIndex);
+ }
+ return scriptLocation;
+ },
+
+ /**
+ * get the pastes unique identifier from the URL,
+ * eg. http://example.com/path/?c05354954c49a487#c05354954c49a487 returns c05354954c49a487
+ *
+ * @name helper.pasteId
+ * @function
+ * @return {string} unique identifier
+ */
+ pasteId: function()
+ {
+ return window.location.search.substring(1);
+ },
+
+ /**
+ * return the deciphering key stored in anchor part of the URL
+ *
+ * @name helper.pageKey
+ * @function
+ * @return {string} key
+ */
+ pageKey: function()
+ {
+ // Some web 2.0 services and redirectors add data AFTER the anchor
+ // (such as &utm_source=...). We will strip any additional data.
+
+ var key = window.location.hash.substring(1), // Get key
+ i = key.indexOf('=');
+
+ // First, strip everything after the equal sign (=) which signals end of base64 string.
+ if (i > -1)
+ {
+ key = key.substring(0, i + 1);
+ }
+
+ // If the equal sign was not present, some parameters may remain:
+ i = key.indexOf('&');
+ if (i > -1)
+ {
+ key = key.substring(0, i);
+ }
+
+ // Then add trailing equal sign if it's missing
+ if (key.charAt(key.length - 1) !== '=')
+ {
+ key += '=';
+ }
+
+ return key;
+ },
+
/**
* convert all applicable characters to HTML entities
*
@@ -404,8 +478,11 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
*/
loadTranslations: function()
{
- var selectedLang = helper.getCookie('lang');
- var language = selectedLang.length > 0 ? selectedLang : (navigator.language || navigator.userLanguage).substring(0, 2);
+ var language = helper.getCookie('lang');
+ if (language.length === 0)
+ {
+ language = (navigator.language || navigator.userLanguage).substring(0, 2);
+ }
// note that 'en' is built in, so no translation is necessary
if (i18n.supportedLanguages.indexOf(language) === -1)
{
@@ -555,76 +632,6 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
*/
createdPasteUrl: '',
- /**
- * get the current script location (without search or hash part of the URL),
- * eg. http://example.com/zero/?aaaa#bbbb --> http://example.com/zero/
- *
- * @name controller.scriptLocation
- * @function
- * @return {string} current script location
- */
- scriptLocation: function()
- {
- var scriptLocation = window.location.href.substring(0,window.location.href.length
- - window.location.search.length - window.location.hash.length),
- hashIndex = scriptLocation.indexOf('#');
- if (hashIndex !== -1)
- {
- scriptLocation = scriptLocation.substring(0, hashIndex);
- }
- return scriptLocation;
- },
-
- /**
- * get the pastes unique identifier from the URL,
- * eg. http://example.com/zero/?c05354954c49a487#c05354954c49a487 returns c05354954c49a487
- *
- * @name controller.pasteID
- * @function
- * @return {string} unique identifier
- */
- pasteID: function()
- {
- return window.location.search.substring(1);
- },
-
- /**
- * return the deciphering key stored in anchor part of the URL
- *
- * @name controller.pageKey
- * @function
- * @return {string} key
- */
- pageKey: function()
- {
- // Some web 2.0 services and redirectors add data AFTER the anchor
- // (such as &utm_source=...). We will strip any additional data.
-
- var key = window.location.hash.substring(1), // Get key
- i = key.indexOf('=');
-
- // First, strip everything after the equal sign (=) which signals end of base64 string.
- if (i > -1)
- {
- key = key.substring(0, i + 1);
- }
-
- // If the equal sign was not present, some parameters may remain:
- i = key.indexOf('&');
- if (i > -1)
- {
- key = key.substring(0, i);
- }
-
- // Then add trailing equal sign if it's missing
- if (key.charAt(key.length - 1) !== '=')
- {
- key += '=';
- }
-
- return key;
- },
-
/**
* ask the user for the password and set it
*
@@ -722,8 +729,8 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
displayMessages: function(paste)
{
paste = paste || $.parseJSON(this.cipherData.text());
- var key = this.pageKey();
- var password = this.passwordInput.val();
+ var key = helper.pageKey(),
+ password = this.passwordInput.val();
if (!this.prettyPrint.hasClass('prettyprinted')) {
// Try to decrypt the paste.
try
@@ -813,7 +820,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
// unfortunately many web servers don't support DELETE (and PUT) out of the box
$.ajax({
type: 'POST',
- url: this.scriptLocation() + '?' + this.pasteID(),
+ url: helper.scriptLocation() + '?' + helper.pasteId(),
data: {deletetoken: 'burnafterreading'},
dataType: 'json',
headers: this.headers
@@ -838,24 +845,27 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
// iterate over comments
for (var i = 0; i < paste.comments.length; ++i)
{
- var place = this.comments;
- var comment = paste.comments[i];
- var commenttext = filter.decipher(key, password, comment.data);
- // if parent comment exists, display below (CSS will automatically shift it to the right)
- var cname = '#comment_' + comment.parentid;
+ var place = this.comments,
+ comment = paste.comments[i],
+ commenttext = filter.decipher(key, password, comment.data),
+ // if parent comment exists, display below (CSS will automatically shift it to the right)
+ cname = '#comment_' + comment.parentid,
+ divComment = $('
'
+ + '
'
+ + ''
+ + '
'),
+ divCommentData = divComment.find('div.commentdata');
// if the element exists in page
if ($(cname).length)
{
place = $(cname);
}
- var divComment = $('
'
- + '
'
- + ''
- + '
');
divComment.find('button').click({commentid: comment.id}, $.proxy(this.openReply, this));
- helper.setElementText(divComment.find('div.commentdata'), commenttext);
- helper.urls2links(divComment.find('div.commentdata'));
+ helper.setElementText(divCommentData, commenttext);
+ helper.urls2links(divCommentData);
// try to get optional nickname
var nick = filter.decipher(key, password, comment.meta.nickname);
@@ -887,7 +897,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
''
);
- divComment.find('button').click({commentid: this.pasteID()}, $.proxy(this.openReply, this));
+ divComment.find('button').click({commentid: helper.pasteId()}, $.proxy(this.openReply, this));
this.comments.append(divComment);
this.discussion.removeClass('hidden');
}
@@ -903,20 +913,26 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
openReply: function(event)
{
event.preventDefault();
- var source = $(event.target),
- commentid = event.data.commentid,
- hint = i18n._('Optional nickname...');
// remove any other reply area
$('div.reply').remove();
- var reply = $(
- '