From 968064c7918a524f7e6d522883fd5d0114e58002 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 5 Dec 2014 17:41:59 +1100 Subject: [PATCH] shift code into server safe section --- plugins/emoji/assets/javascripts/emoji.js.erb | 79 ++++++++++--------- 1 file changed, 41 insertions(+), 38 deletions(-) diff --git a/plugins/emoji/assets/javascripts/emoji.js.erb b/plugins/emoji/assets/javascripts/emoji.js.erb index 1d881fe94..2133626cd 100644 --- a/plugins/emoji/assets/javascripts/emoji.js.erb +++ b/plugins/emoji/assets/javascripts/emoji.js.erb @@ -137,54 +137,57 @@ } }); - var renderPage = Handlebars.compile( - "" + - "{{#each this}}"+ - "{{#each this}}" + - "" + - "{{/each}}" + - "{{/each}}"+ - "
"); - var closeSelector = function(){ - $('.emoji-modal, .emoji-modal-wrapper').remove(); - }; + if(window.PagedownCustom) { + var renderPage = Handlebars.compile( + "" + + "{{#each this}}"+ + "{{#each this}}" + + "" + + "{{/each}}" + + "{{/each}}"+ + "
"); - var showSelector = function(){ + var closeSelector = function(){ + $('.emoji-modal, .emoji-modal-wrapper').remove(); + }; - $('body').append('
'); + var showSelector = function(){ - $('.emoji-modal-wrapper').click(function(){ - closeSelector(); - }); + $('body').append('
'); - var rows = []; - var row = []; - var icons = groups[0].icons; + $('.emoji-modal-wrapper').click(function(){ + closeSelector(); + }); - for(var i=0; i<50; i++){ - if(row.length === 10){ - rows.push(row); - row = []; + var rows = []; + var row = []; + var icons = groups[0].icons; + + for(var i=0; i<50; i++){ + if(row.length === 10){ + rows.push(row); + row = []; + } + row.push({src: urlFor(icons[i]), title: icons[i]}); } - row.push({src: urlFor(icons[i]), title: icons[i]}); - } - rows.push(row); + rows.push(row); - $('body').append('
' + renderPage(rows) + '
'); + $('body').append('
' + renderPage(rows) + '
'); - var composerController = Discourse.__container__.lookup('controller:composer'); - $('.emoji-page a').click(function(){ - composerController.appendText(":" + $(this).attr('title') + ":", {space: true}); - closeSelector(); + var composerController = Discourse.__container__.lookup('controller:composer'); + $('.emoji-page a').click(function(){ + composerController.appendText(":" + $(this).attr('title') + ":", {space: true}); + closeSelector(); + }); + }; + + window.PagedownCustom.appendButtons.push({ + id: 'wmd-emoji-button', + description: I18n.t("composer.emoji"), + execute: showSelector }); - }; - - window.PagedownCustom.appendButtons.push({ - id: 'wmd-emoji-button', - description: I18n.t("composer.emoji"), - execute: showSelector - }); + } // TODO: Make this a proper ES6 import var ComposerView = (Discourse && Discourse.ComposerView) || (typeof require !== "undefined" && require('discourse/views/composer').default);