From 81b00dd42246078cdd88c60ee910fc0db4a7af33 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sun, 12 Mar 2017 14:16:08 +0100 Subject: [PATCH] fixing page template, removing error messages when markdown or source are disabled in configuration, re-removing unnecessary spans --- css/bootstrap/privatebin.css | 7 ----- js/privatebin.js | 50 ++++++++++++++++++++---------------- tpl/bootstrap.php | 42 ++++++++++++++++++++---------- tpl/page.php | 23 ++++++++++++++--- tst/PrivateBinTest.php | 18 ++++++------- tst/ViewTest.php | 2 +- 6 files changed, 86 insertions(+), 56 deletions(-) diff --git a/css/bootstrap/privatebin.css b/css/bootstrap/privatebin.css index 3e8cbb2..ded8259 100644 --- a/css/bootstrap/privatebin.css +++ b/css/bootstrap/privatebin.css @@ -102,15 +102,10 @@ body.loading { margin-bottom: 10px; } -.pl-1::before { - content: " "; -} - .comment { border-left: 1px solid #ccc; padding: 5px 0 5px 10px; white-space: pre-wrap; - transition: background-color 0.75s ease-out; } @@ -119,8 +114,6 @@ body.loading { transition: background-color 0.2s ease-in; } - - footer h4 { margin-top: 0; } diff --git a/js/privatebin.js b/js/privatebin.js index f43e334..8d41732 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -995,7 +995,8 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { var $errorMessage, $loadingIndicator, - $statusMessage; + $statusMessage, + $remainingTime; var currentIcon = [ 'glyphicon-time', // loading icon @@ -1036,7 +1037,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { args = [args]; } - // pass to custom handler if dfined + // pass to custom handler if defined if (typeof customHandler === 'function') { var handlerResult = customHandler(alertType[id], $element, args, icon); if (handlerResult === true) { @@ -1069,11 +1070,13 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { // show text if (args !== null) { - // add jQuery object to it as first parameter - args.unshift($element.find(':last')); - - // pass it to I18n - I18n._.apply(this, args); + // get last text node of element + var content = $element.contents(); + if (content.length > 1) { + content[content.length - 1].nodeValue = ' ' + I18n._(args); + } else { + $element.text(I18n._(args)); + } } // show notification @@ -1130,6 +1133,21 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { handleNotification(3, $errorMessage, message, icon); } + /** + * display remaining message + * + * This automatically passes the text to I18n for translation. + * + * @name Alert.showRemaining + * @function + * @param {string|array} message string, use an array for %s/%d options + */ + me.showRemaining = function(message) + { + console.error('remaining message shown: ', message); + handleNotification(1, $remainingTime, message); + } + /** * shows a loading message, optionally with a percentage * @@ -1230,18 +1248,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { $errorMessage = $('#errormessage'); $loadingIndicator = $('#loadingindicator'); $statusMessage = $('#status'); - - // display status returned by php code, if any (e.g. paste was properly deleted) - var serverStatus = $statusMessage.text(); - if (Helper.isValidText(serverStatus)) { - me.showStatus(); - } - - // display error message from php code - var serverError = $errorMessage.text(); - if (Helper.isValidText(serverError)) { - Alert.showError(); - } + $remainingTime = $('#remainingtime'); } return me; @@ -1339,7 +1346,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { // actually remove paste, before we claim it is deleted Controller.removePaste(Model.getPasteId(), 'burnafterreading'); - I18n._($remainingTime.find(':last'), "FOR YOUR EYES ONLY. Don't close this window, this message can't be displayed again."); + Alert.showRemaining("FOR YOUR EYES ONLY. Don't close this window, this message can't be displayed again."); $remainingTime.addClass('foryoureyesonly'); // discourage cloning (it cannot really be prevented) @@ -1353,7 +1360,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { 'This document will expire in %d ' + expiration[1] + 's.' ]; - I18n._($remainingTime.find(':last'), expirationLabel, expiration[0]); + Alert.showRemaining(expirationLabel, expiration[0]); $remainingTime.removeClass('foryoureyesonly') } else { // never expires @@ -1620,7 +1627,6 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { $message.addClass('hidden'); // show preview - $('#errormessage').find(':last') PasteViewer.setText($message.val()); PasteViewer.run(); diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index 4dd6389..683e234 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -69,7 +69,7 @@ if ($MARKDOWN): - + @@ -122,7 +122,7 @@ endif;