forked from GithubBackups/vichan
Merge pull request #239 from forklessanon/comment-toolbar
Fix for the js being shitty inside the compiled main.js.
This commit is contained in:
commit
9b00491385
@ -251,127 +251,133 @@ if (active_page == 'thread' || active_page == 'index') {
|
|||||||
// setup default rules for customizing
|
// setup default rules for customizing
|
||||||
if (!localStorage.formatText_rules) localStorage.formatText_rules = JSON.stringify(self.rules);
|
if (!localStorage.formatText_rules) localStorage.formatText_rules = JSON.stringify(self.rules);
|
||||||
|
|
||||||
// Add settings to Options panel general tab
|
// setup code to be ran when page is ready (work around for main.js compilation).
|
||||||
if (window.Options && Options.get_tab('general')) {
|
$(document).ready(function(){
|
||||||
var s1 = '#formatText_keybinds>input', s2 = '#formatText_toolbar>input', e = 'change';
|
// Add settings to Options panel general tab
|
||||||
Options.extend_tab('general', '\
|
if (window.Options && Options.get_tab('general')) {
|
||||||
<fieldset>\
|
var s1 = '#formatText_keybinds>input', s2 = '#formatText_toolbar>input', e = 'change';
|
||||||
<legend>Formatting Options</legend>\
|
Options.extend_tab('general', '\
|
||||||
<label id="formatText_keybinds"><input type="checkbox" checked="checked" id="formatText_keybinds">' + _('Enable formatting keybinds') + '</label>\
|
<fieldset>\
|
||||||
<label id="formatText_toolbar"><input type="checkbox" checked="checked" id="formatText_toolbar">' + _('Show formatting toolbar') + '</label>\
|
<legend>Formatting Options</legend>\
|
||||||
</fieldset>\
|
<label id="formatText_keybinds"><input type="checkbox">' + _('Enable formatting keybinds') + '</label>\
|
||||||
');
|
<label id="formatText_toolbar"><input type="checkbox">' + _('Show formatting toolbar') + '</label>\
|
||||||
} else {
|
</fieldset>\
|
||||||
var s1 = '#formatText_keybinds', s2 = '#formatText_toolbar', e = 'click';
|
');
|
||||||
$('hr:first').before('<div id="formatText_keybinds" style="text-align:right"><a class="unimportant" href="javascript:void(0)">'+ _('Enable formatting keybinds') +'</a></div>');
|
|
||||||
$('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 {
|
} else {
|
||||||
localStorage.formatText_keybinds = 'false';
|
var s1 = '#formatText_keybinds', s2 = '#formatText_toolbar', e = 'click';
|
||||||
if (window.Options && Options.get_tab('general')) e.target.checked = false;
|
$('hr:first').before('<div id="formatText_keybinds" style="text-align:right"><a class="unimportant" href="javascript:void(0)">'+ _('Enable formatting keybinds') +'</a></div>');
|
||||||
|
$('hr:first').before('<div id="formatText_toolbar" style="text-align:right"><a class="unimportant" href="javascript:void(0)">'+ _('Show formatting toolbar') +'</a></div>');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add the tab for customizing the format settings
|
||||||
|
if (window.Options && !Options.get_tab('formatting')) {
|
||||||
|
Options.add_tab('formatting', 'angle-right', 'Customize Formatting');
|
||||||
|
Options.extend_tab('formatting', '\
|
||||||
|
<style>\
|
||||||
|
.format_option{\
|
||||||
|
margin-right:5px;\
|
||||||
|
overflow:initial;\
|
||||||
|
font-size:15px;\
|
||||||
|
}\
|
||||||
|
.format_option[type="text"]{\
|
||||||
|
text-align:center;\
|
||||||
|
padding-bottom: 2px;\
|
||||||
|
padding-top: 2px;\
|
||||||
|
}\
|
||||||
|
.format_option:last-child{\
|
||||||
|
margin-right:0;\
|
||||||
|
}\
|
||||||
|
fieldset{\
|
||||||
|
margin-top:5px;\
|
||||||
|
}\
|
||||||
|
</style>\
|
||||||
|
');
|
||||||
|
|
||||||
|
// Data control row
|
||||||
|
Options.extend_tab('formatting', '\
|
||||||
|
<button onclick="formatText.add_rule();">Add Rule</button>\
|
||||||
|
<button onclick="formatText.save_rules();">Save Rules</button>\
|
||||||
|
<button onclick="formatText.reset_rules(false);">Revert</button>\
|
||||||
|
<button onclick="formatText.reset_rules(true);">Reset to Default</button>\
|
||||||
|
');
|
||||||
|
|
||||||
|
// Descriptor row
|
||||||
|
Options.extend_tab('formatting', '\
|
||||||
|
<span class="format_option" style="margin-left:25px;">Name</span>\
|
||||||
|
<span class="format_option" style="margin-left:45px;" title="Multi-line: Allow formatted area to contain linebreaks.">ML</span>\
|
||||||
|
<span class="format_option" style="margin-left:0px;" title="Exclusive-line: Require formatted area to start after and end before a linebreak.">EL</span>\
|
||||||
|
<span class="format_option" style="margin-left:25px;" title="Text injected at the start of a format area.">Prefix</span>\
|
||||||
|
<span class="format_option" style="margin-left:60px;" title="Text injected at the end of a format area.">Suffix</span>\
|
||||||
|
<span class="format_option" style="margin-left:40px;" title="Optional keybind value to allow keyboard shortcut access.">Key</span>\
|
||||||
|
');
|
||||||
|
|
||||||
|
// Rule rows
|
||||||
|
var rules = JSON.parse(localStorage.formatText_rules);
|
||||||
|
for (var index in rules){
|
||||||
|
if (!rules.hasOwnProperty(index)) continue;
|
||||||
|
self.add_rule(rules[index], index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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');
|
||||||
});
|
});
|
||||||
|
|
||||||
// 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');
|
|
||||||
Options.extend_tab('formatting', '\
|
|
||||||
<style>\
|
|
||||||
.format_option{\
|
|
||||||
margin-right:5px;\
|
|
||||||
overflow:initial;\
|
|
||||||
font-size:15px;\
|
|
||||||
}\
|
|
||||||
.format_option[type="text"]{\
|
|
||||||
text-align:center;\
|
|
||||||
padding-bottom: 2px;\
|
|
||||||
padding-top: 2px;\
|
|
||||||
}\
|
|
||||||
.format_option:last-child{\
|
|
||||||
margin-right:0;\
|
|
||||||
}\
|
|
||||||
fieldset{\
|
|
||||||
margin-top:5px;\
|
|
||||||
}\
|
|
||||||
</style>\
|
|
||||||
');
|
|
||||||
|
|
||||||
// Data control row
|
|
||||||
Options.extend_tab('formatting', '\
|
|
||||||
<button onclick="formatText.add_rule();">Add Rule</button>\
|
|
||||||
<button onclick="formatText.save_rules();">Save Rules</button>\
|
|
||||||
<button onclick="formatText.reset_rules(false);">Revert</button>\
|
|
||||||
<button onclick="formatText.reset_rules(true);">Reset to Default</button>\
|
|
||||||
');
|
|
||||||
|
|
||||||
// Descriptor row
|
|
||||||
Options.extend_tab('formatting', '\
|
|
||||||
<span class="format_option" style="margin-left:25px;">Name</span>\
|
|
||||||
<span class="format_option" style="margin-left:45px;" title="Multi-line: Allow formatted area to contain linebreaks.">ML</span>\
|
|
||||||
<span class="format_option" style="margin-left:0px;" title="Exclusive-line: Require formatted area to start after and end before a linebreak.">EL</span>\
|
|
||||||
<span class="format_option" style="margin-left:25px;" title="Text injected at the start of a format area.">Prefix</span>\
|
|
||||||
<span class="format_option" style="margin-left:60px;" title="Text injected at the end of a format area.">Suffix</span>\
|
|
||||||
<span class="format_option" style="margin-left:40px;" title="Optional keybind value to allow keyboard shortcut access.">Key</span>\
|
|
||||||
');
|
|
||||||
|
|
||||||
// Rule rows
|
|
||||||
var rules = JSON.parse(localStorage.formatText_rules);
|
|
||||||
for (var index in rules){
|
|
||||||
if (!rules.hasOwnProperty(index)) continue;
|
|
||||||
self.add_rule(rules[index], index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
})(jQuery);
|
})(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);
|
|
||||||
} else {
|
|
||||||
formatText.wrap(e.target, 'textarea[name="body"]', index, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
$(document).trigger('formatText');
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user