summaryrefslogtreecommitdiff
path: root/js/comment-toolbar.js
diff options
context:
space:
mode:
authorForkless <REDACTED@gmail.com>2014-11-08 14:25:54 -0600
committerczaks <marcin@6irc.net>2016-05-05 12:45:07 +0200
commit81daf934fb4d1740583220694083b292bc697206 (patch)
treeece92b3b4e2efb3c62aaad8018d7c4aaf471c016 /js/comment-toolbar.js
parentf6b4b2ac182fa1e155eff5697d8f5352de3385ab (diff)
Fix for the js being shitty inside the compiled main.js.
Diffstat (limited to 'js/comment-toolbar.js')
-rw-r--r--js/comment-toolbar.js118
1 files 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', '\
<fieldset>\
<legend>Formatting Options</legend>\
- <label id="formatText_keybinds"><input type="checkbox" checked="checked" id="formatText_keybinds">' + _('Enable formatting keybinds') + '</label>\
- <label id="formatText_toolbar"><input type="checkbox" checked="checked" id="formatText_toolbar">' + _('Show formatting toolbar') + '</label>\
+ <label id="formatText_keybinds"><input type="checkbox">' + _('Enable formatting keybinds') + '</label>\
+ <label id="formatText_toolbar"><input type="checkbox">' + _('Show formatting toolbar') + '</label>\
</fieldset>\
');
} else {
@@ -267,39 +267,6 @@ if (active_page == 'thread' || active_page == 'index') {
$('hr:first').before('<div id="formatText_toolbar" style="text-align:right"><a class="unimportant" href="javascript:void(0)">'+ _('Show formatting toolbar') +'</a></div>');
}
-
- // 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 <body> 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 <body> 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