From 81daf934fb4d1740583220694083b292bc697206 Mon Sep 17 00:00:00 2001 From: Forkless Date: Sat, 8 Nov 2014 14:25:54 -0600 Subject: [PATCH] Fix for the js being shitty inside the compiled main.js. --- js/comment-toolbar.js | 118 ++++++++++++++++++++++-------------------- 1 file changed, 62 insertions(+), 56 deletions(-) diff --git a/js/comment-toolbar.js b/js/comment-toolbar.js index ab9e3eb1..80993cb0 100644 --- a/js/comment-toolbar.js +++ b/js/comment-toolbar.js @@ -257,8 +257,8 @@ if (active_page == 'thread' || active_page == 'index') { Options.extend_tab('general', '\
\ Formatting Options\ - \ - \ + \ + \
\ '); } else { @@ -267,39 +267,6 @@ if (active_page == 'thread' || active_page == 'index') { $('hr:first').before('
'+ _('Show formatting toolbar') +'
'); } - - // setting for enableing formatting keybinds - $(s1).on(e, function(e) { - if (!localStorage.formatText_keybinds || localStorage.formatText_keybinds == 'false') { - localStorage.formatText_keybinds = 'true'; - if (window.Options && Options.get_tab('general')) e.target.checked = true; - } else { - localStorage.formatText_keybinds = 'false'; - if (window.Options && Options.get_tab('general')) e.target.checked = false; - } - }); - - // setting for toolbar injection - $(s2).on(e, function(e) { - if (!localStorage.formatText_toolbar || localStorage.formatText_toolbar == 'false') { - localStorage.formatText_toolbar = 'true'; - if (window.Options && Options.get_tab('general')) e.target.checked = true; - formatText.build_toolbars(); - } else { - localStorage.formatText_toolbar = 'false'; - if (window.Options && Options.get_tab('general')) e.target.checked = false; - $('.format-text').remove(); - } - }); - - // make sure the tab settings are switch properly at loadup - if (window.Options && Options.get_tab('general')) { - if (localStorage.formatText_keybinds == 'true') $(s1)[0].checked = true; - else $(s1)[0].checked = false; - if (localStorage.formatText_toolbar == 'true') $(s2)[0].checked = true; - else $(s2)[0].checked = false; - } - // add the tab for customizing the format settings if (window.Options && !Options.get_tab('formatting')) { Options.add_tab('formatting', 'angle-right', 'Customize Formatting'); @@ -350,28 +317,67 @@ if (active_page == 'thread' || active_page == 'index') { } } - return self; - })(jQuery); - - // run initial toolbar injection - formatText.build_toolbars(); - - //attach listeners to so it also works on quick-reply box - $('body').on('keydown', '#body, #quick-reply #body', function(e) { - if (!localStorage.formatText_keybinds || localStorage.formatText_keybinds == 'false') return; - var key = String.fromCharCode(e.which).toLowerCase(); - var rules = JSON.parse(localStorage.formatText_rules); - for (var index in rules) { - if (!rules.hasOwnProperty(index)) continue; - if (key === rules[index].key && e.ctrlKey) { - e.preventDefault(); - if (e.shiftKey) { - formatText.wrap(e.target, 'textarea[name="body"]', index, true); + // setup code to be ran when page is ready (work around for main.js compilation). + $(document).ready(function(){ + // setting for enabling formatting keybinds + $(s1).on(e, function(e) { + console.log('Keybind'); + if (!localStorage.formatText_keybinds || localStorage.formatText_keybinds == 'false') { + localStorage.formatText_keybinds = 'true'; + if (window.Options && Options.get_tab('general')) e.target.checked = true; } else { - formatText.wrap(e.target, 'textarea[name="body"]', index, false); + localStorage.formatText_keybinds = 'false'; + if (window.Options && Options.get_tab('general')) e.target.checked = false; } + }); + + // setting for toolbar injection + $(s2).on(e, function(e) { + console.log('Toolbar'); + if (!localStorage.formatText_toolbar || localStorage.formatText_toolbar == 'false') { + localStorage.formatText_toolbar = 'true'; + if (window.Options && Options.get_tab('general')) e.target.checked = true; + formatText.build_toolbars(); + } else { + localStorage.formatText_toolbar = 'false'; + if (window.Options && Options.get_tab('general')) e.target.checked = false; + $('.format-text').remove(); + } + }); + + // make sure the tab settings are switch properly at loadup + if (window.Options && Options.get_tab('general')) { + if (localStorage.formatText_keybinds == 'true') $(s1)[0].checked = true; + else $(s1)[0].checked = false; + if (localStorage.formatText_toolbar == 'true') $(s2)[0].checked = true; + else $(s2)[0].checked = false; } - } - }); - $(document).trigger('formatText'); + + // Initial toolbar injection + formatText.build_toolbars(); + + //attach listener to so it also works on quick-reply box + $('body').on('keydown', '[name="body"]', function(e) { + if (!localStorage.formatText_keybinds || localStorage.formatText_keybinds == 'false') return; + var key = String.fromCharCode(e.which).toLowerCase(); + var rules = JSON.parse(localStorage.formatText_rules); + for (var index in rules) { + if (!rules.hasOwnProperty(index)) continue; + if (key === rules[index].key && e.ctrlKey) { + e.preventDefault(); + if (e.shiftKey) { + formatText.wrap(e.target, 'textarea[name="body"]', index, true); + } else { + formatText.wrap(e.target, 'textarea[name="body"]', index, false); + } + } + } + }); + + // Signal that comment-toolbar loading has completed. + $(document).trigger('formatText'); + }); + + return self; + })(jQuery); } \ No newline at end of file