From 6a663ba07f442d30c6730bbf3a76c8dd9046662d Mon Sep 17 00:00:00 2001 From: El RIDO Date: Mon, 11 Jul 2016 11:09:41 +0200 Subject: [PATCH] adding preview feature, resolves #4 --- css/bootstrap/zerobin.css | 4 ++ i18n/de.json | 4 +- i18n/fr.json | 4 +- i18n/pl.json | 4 +- i18n/sl.json | 4 +- i18n/zh.json | 4 +- js/zerobin.js | 85 ++++++++++++++++++++++++++++-------- tpl/bootstrap-compact.html | 4 ++ tpl/bootstrap-dark-page.html | 4 ++ tpl/bootstrap-dark.html | 4 ++ tpl/bootstrap-page.html | 4 ++ tpl/bootstrap.html | 4 ++ tpl/page.html | 4 ++ 13 files changed, 110 insertions(+), 23 deletions(-) diff --git a/css/bootstrap/zerobin.css b/css/bootstrap/zerobin.css index 817eebc..863baec 100644 --- a/css/bootstrap/zerobin.css +++ b/css/bootstrap/zerobin.css @@ -62,6 +62,10 @@ body.navbar-spacing { word-wrap: break-word; } +#preview { + margin-bottom: 10px; +} + #message { font-family: monospace; } diff --git a/i18n/de.json b/i18n/de.json index 191c69f..5c398eb 100644 --- a/i18n/de.json +++ b/i18n/de.json @@ -136,5 +136,7 @@ "Dein Browser unterstützt das hochladen von verschlüsselten Dateien nicht. Bitte verwende einen neueren Browser.", "Invalid attachment.": "Ungültiger Datei-Anhang.", "Options": "Optionen", - "Shorten URL": "URL verkürzen" + "Shorten URL": "URL verkürzen", + "Editor": "Bearbeiten", + "Preview": "Vorschau" } diff --git a/i18n/fr.json b/i18n/fr.json index 8736314..6fe650c 100644 --- a/i18n/fr.json +++ b/i18n/fr.json @@ -145,5 +145,7 @@ "Votre navigateur ne supporte pas l'envoi de fichiers chiffrés. Merci d'utiliser un navigateur plus récent.", "Invalid attachment.": "Attachement invalide.", "Options": "Options", - "Shorten URL": "Raccourcir URL" + "Shorten URL": "Raccourcir URL", + "Editor": "éditer", + "Preview": "avant-première" } diff --git a/i18n/pl.json b/i18n/pl.json index 5e7db74..b86cc2a 100644 --- a/i18n/pl.json +++ b/i18n/pl.json @@ -136,5 +136,7 @@ "Twoja przeglądarka nie wspiera wysyłania zaszyfrowanych plików. Użyj nowszej przeglądarki.", "Invalid attachment.": "Nieprawidłowy załącznik.", "Options": "Opcje", - "Shorten URL": "Skróć adres URL" + "Shorten URL": "Skróć adres URL", + "Editor": "Edytować", + "Preview": "Zapowiedź" } diff --git a/i18n/sl.json b/i18n/sl.json index a7e9542..baff6ca 100644 --- a/i18n/sl.json +++ b/i18n/sl.json @@ -145,5 +145,7 @@ "Tvoj brskalnik ne omogoča nalaganje zakodiranih datotek. Prosim uporabi novejši brskalnik.", "Invalid attachment.": "Neveljavna priponka.", "Options": "Možnosti", - "Shorten URL": "Skrajšajte URL" + "Shorten URL": "Skrajšajte URL", + "Editor": "Uredi", + "Preview": "Predogled" } diff --git a/i18n/zh.json b/i18n/zh.json index d736eb4..e8b476c 100644 --- a/i18n/zh.json +++ b/i18n/zh.json @@ -136,5 +136,7 @@ "您的浏览器不支持上传加密的文件,请使用更新的浏览器。", "Invalid attachment.": "无效的附件", "Options": "选项", - "Shorten URL": "缩短链接" + "Shorten URL": "缩短链接", + "Editor": "編輯", + "Preview": "預習" } diff --git a/js/zerobin.js b/js/zerobin.js index 4c50c69..a50e1f1 100644 --- a/js/zerobin.js +++ b/js/zerobin.js @@ -583,7 +583,13 @@ $(function() { this.prettyMessage.addClass('hidden'); break; case 'syntaxhighlighting': - if (typeof prettyPrint == 'function') prettyPrint(); + if (typeof prettyPrintOne == 'function') + { + if (typeof prettyPrint == 'function') prettyPrint(); + this.prettyPrint.html( + prettyPrintOne(text, null, true) + ); + }; default: // Convert URLs to clickable links. helper.urls2links(this.clearText); @@ -1055,33 +1061,42 @@ $(function() { this.password.removeClass('hidden'); this.attach.removeClass('hidden'); this.message.removeClass('hidden'); + this.preview.removeClass('hidden'); this.message.focus(); }, /** * Put the screen in "Existing paste" mode. + * + * @param boolean preview (optional) : tell if the preview tabs should be displayed, defaults to false. */ - stateExistingPaste: function() + stateExistingPaste: function(preview) { - this.sendButton.addClass('hidden'); + preview = preview || false; - // No "clone" for IE<10. - if ($('#oldienotice').is(":visible")) + if (!preview) { - this.cloneButton.addClass('hidden'); - } - else - { - this.cloneButton.removeClass('hidden'); - } - this.rawTextButton.removeClass('hidden'); + // No "clone" for IE<10. + if ($('#oldienotice').is(":visible")) + { + this.cloneButton.addClass('hidden'); + } + else + { + this.cloneButton.removeClass('hidden'); + } + + this.rawTextButton.removeClass('hidden'); + this.sendButton.addClass('hidden'); + this.attach.addClass('hidden'); + this.expiration.addClass('hidden'); + this.formatter.addClass('hidden'); + this.burnAfterReadingOption.addClass('hidden'); + this.openDisc.addClass('hidden'); + this.newButton.removeClass('hidden'); + this.preview.addClass('hidden'); + } - this.attach.addClass('hidden'); - this.expiration.addClass('hidden'); - this.formatter.addClass('hidden'); - this.burnAfterReadingOption.addClass('hidden'); - this.openDisc.addClass('hidden'); - this.newButton.removeClass('hidden'); this.pasteResult.addClass('hidden'); this.message.addClass('hidden'); this.clearText.addClass('hidden'); @@ -1177,6 +1192,35 @@ $(function() { } }, + /** + * View the editor tab. + * + * @param Event event + */ + viewEditor: function(event) + { + event.preventDefault(); + this.messagePreview.parent().removeClass('active'); + this.messageEdit.parent().addClass('active'); + this.message.focus(); + this.stateNewPaste(); + }, + + /** + * View the preview tab. + * + * @param Event event + */ + viewPreview: function(event) + { + event.preventDefault(); + this.messageEdit.parent().removeClass('active'); + this.messagePreview.parent().addClass('active'); + this.message.focus(); + this.stateExistingPaste(true); + this.formatPaste($('#pasteFormatter').val(), this.message.val()); + }, + /** * Create a new paste. */ @@ -1261,6 +1305,8 @@ $(function() { this.fileRemoveButton.click($.proxy(this.removeAttachment, this)); $('.reloadlink').click($.proxy(this.reloadPage, this)); this.message.keydown(this.supportTabs); + this.messageEdit.click($.proxy(this.viewEditor, this)); + this.messagePreview.click($.proxy(this.viewPreview, this)); }, /** @@ -1290,6 +1336,8 @@ $(function() { this.formatter = $('#formatter'); this.image = $('#image'); this.message = $('#message'); + this.messageEdit = $('#messageedit'); + this.messagePreview = $('#messagepreview'); this.newButton = $('#newbutton'); this.openDisc = $('#opendisc'); this.openDiscussion = $('#opendiscussion'); @@ -1298,6 +1346,7 @@ $(function() { this.pasteResult = $('#pasteresult'); this.prettyMessage = $('#prettymessage'); this.prettyPrint = $('#prettyprint'); + this.preview = $('#preview'); this.rawTextButton = $('#rawtextbutton'); this.remainingTime = $('#remainingtime'); this.replyStatus = $('#replystatus'); diff --git a/tpl/bootstrap-compact.html b/tpl/bootstrap-compact.html index 68d6b7e..b95ea3c 100644 --- a/tpl/bootstrap-compact.html +++ b/tpl/bootstrap-compact.html @@ -175,6 +175,10 @@ {/if} +
diff --git a/tpl/bootstrap-dark-page.html b/tpl/bootstrap-dark-page.html index 1c387c1..4143f13 100644 --- a/tpl/bootstrap-dark-page.html +++ b/tpl/bootstrap-dark-page.html @@ -171,6 +171,10 @@ {/if} +
diff --git a/tpl/bootstrap-dark.html b/tpl/bootstrap-dark.html index 5004754..58a50ff 100644 --- a/tpl/bootstrap-dark.html +++ b/tpl/bootstrap-dark.html @@ -171,6 +171,10 @@ {/if} +
diff --git a/tpl/bootstrap-page.html b/tpl/bootstrap-page.html index a27029e..12c5195 100644 --- a/tpl/bootstrap-page.html +++ b/tpl/bootstrap-page.html @@ -171,6 +171,10 @@ {/if} +
diff --git a/tpl/bootstrap.html b/tpl/bootstrap.html index 4fe353c..4d6ce4e 100644 --- a/tpl/bootstrap.html +++ b/tpl/bootstrap.html @@ -171,6 +171,10 @@ {/if} +
diff --git a/tpl/page.html b/tpl/page.html index 747fc02..f4f7163 100644 --- a/tpl/page.html +++ b/tpl/page.html @@ -94,6 +94,10 @@ {function="t('Attach a file')"}: {/if} +