From 69a6631742c2c2b464c5beca289619dca5760e45 Mon Sep 17 00:00:00 2001 From: ForklessAnon Date: Sat, 1 Nov 2014 16:49:34 -0500 Subject: [PATCH] Added option to disable/ignore keybinds. --- js/comment-toolbar.js | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/js/comment-toolbar.js b/js/comment-toolbar.js index 2c8b9ca8..74654868 100644 --- a/js/comment-toolbar.js +++ b/js/comment-toolbar.js @@ -226,7 +226,6 @@ if (active_page == 'thread' || active_page == 'index') { self.save_rules = function(){ var newrules = {}, rules = $('.format_rule'); for (var index=0;rules[index];index++) { - console.log(rules[index]); newrules[$(rules[index]).attr('name')] = { text: $(rules[index]).find('[name="text"]').val(), key: $(rules[index]).find('[name="key"]').val(), @@ -236,7 +235,6 @@ if (active_page == 'thread' || active_page == 'index') { exclusiveline: $(rules[index]).find('[name="exclusiveline"]').is(':checked') }; } - console.log(newrules); localStorage.formatText_rules = JSON.stringify(newrules); self.build_toolbars(); }; @@ -250,12 +248,19 @@ if (active_page == 'thread' || active_page == 'index') { // Add settings to Options panel general tab if (window.Options && Options.get_tab('general')) { - var s1 = '#formatText_enable>input', s2 = '#formatText_toolbar>input', e = 'change'; - Options.extend_tab('general', ''); - Options.extend_tab('general', ''); + var s1 = '#formatText_enable>input', s2 = '#formatText_keybinds>input', s3 = '#formatText_toolbar>input', e = 'change'; + Options.extend_tab('general', '\ +
\ + Formatting Options\ + \ + \ + \ +
\ + '); } else { - var s1 = '#formatText_enable', s2 = '#formatText_toolbar', e = 'click'; + var s1 = '#formatText_enable', s2 = '#formatText_keybinds', s3 = '#formatText_toolbar', e = 'click'; $('hr:first').before('
'+ _('Enable post formatting') +'
'); + $('hr:first').before('
'+ _('Enable formatting keybinds') +'
'); $('hr:first').before('
'+ _('Show formatting toolbar') +'
'); } @@ -270,8 +275,19 @@ if (active_page == 'thread' || active_page == 'index') { } }); - // setting for toolbar injection + // setting for enableing formatting keybinds $(s2).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 + $(s3).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; @@ -287,8 +303,10 @@ if (active_page == 'thread' || active_page == 'index') { if (window.Options && Options.get_tab('general')) { if (localStorage.formatText_enable == 'true') $(s1)[0].checked = true; else $(s1)[0].checked = false; - if (localStorage.formatText_toolbar == 'true') $(s2)[0].checked = true; + if (localStorage.formatText_keybinds == 'true') $(s2)[0].checked = true; else $(s2)[0].checked = false; + if (localStorage.formatText_toolbar == 'true') $(s2)[0].checked = true; + else $(s3)[0].checked = false; } // add the tab for customizing the format settings @@ -309,6 +327,9 @@ if (active_page == 'thread' || active_page == 'index') { .format_option:last-child{\ margin-right:0;\ }\ + fieldset{\ + margin-top:5px;\ + }\ \ '); @@ -346,6 +367,7 @@ if (active_page == 'thread' || active_page == 'index') { //attach listeners to so it also works on quick-reply box $('body').on('keydown', '#body, #quick-reply #body', function(e) { if (!localStorage.formatText_enable || localStorage.formatText_enable == 'false') return; + 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) { @@ -361,4 +383,4 @@ if (active_page == 'thread' || active_page == 'index') { } }); $(document).trigger('formatText'); -} +} \ No newline at end of file