This commit is contained in:
Nicolas Stepien 2012-06-19 16:25:57 +02:00
parent 2828dc7a09
commit c93a996ec0
2 changed files with 18 additions and 20 deletions

View File

@ -466,6 +466,12 @@
open: function(url) { open: function(url) {
return (GM_openInTab || window.open)(location.protocol + url, '_blank'); return (GM_openInTab || window.open)(location.protocol + url, '_blank');
}, },
event: function(el, name, type) {
var e;
e = d.createEvent(type || 'CustomEvent');
e.initEvent(name, true, false);
return el.dispatchEvent(e);
},
globalEval: function(code) { globalEval: function(code) {
var script; var script;
script = $.el('script', { script = $.el('script', {
@ -1265,16 +1271,14 @@
return key; return key;
}, },
tags: function(tag, ta) { tags: function(tag, ta) {
var e, range, selEnd, selStart, value; var range, selEnd, selStart, value;
value = ta.value; value = ta.value;
selStart = ta.selectionStart; selStart = ta.selectionStart;
selEnd = ta.selectionEnd; selEnd = ta.selectionEnd;
ta.value = value.slice(0, selStart) + ("[" + tag + "]") + value.slice(selStart, selEnd) + ("[/" + tag + "]") + value.slice(selEnd); ta.value = value.slice(0, selStart) + ("[" + tag + "]") + value.slice(selStart, selEnd) + ("[/" + tag + "]") + value.slice(selEnd);
range = ("[" + tag + "]").length + selEnd; range = ("[" + tag + "]").length + selEnd;
ta.setSelectionRange(range, range); ta.setSelectionRange(range, range);
e = d.createEvent('Event'); return $.event(ta, 'input', 'Event');
e.initEvent('input', true, false);
return ta.dispatchEvent(e);
}, },
img: function(thread, all) { img: function(thread, all) {
var thumb; var thumb;
@ -1584,9 +1588,7 @@
range += text.match(/\n/g).length; range += text.match(/\n/g).length;
} }
ta.setSelectionRange(range, range); ta.setSelectionRange(range, range);
e = d.createEvent('Event'); return $.event(ta, 'input', 'Event');
e.initEvent('input', true, false);
return ta.dispatchEvent(e);
}, },
drag: function(e) { drag: function(e) {
var i; var i;
@ -1931,7 +1933,7 @@
} }
}, },
dialog: function() { dialog: function() {
var e, fileInput, id, mimeTypes, name, spoiler, ta, thread, threads, _i, _j, _len, _len1, _ref, _ref1; var fileInput, id, mimeTypes, name, spoiler, ta, thread, threads, _i, _j, _len, _len1, _ref, _ref1;
QR.el = UI.dialog('qr', 'top:0;right:0;', '\ QR.el = UI.dialog('qr', 'top:0;right:0;', '\
<div class=move>\ <div class=move>\
Quick Reply <input type=checkbox id=autohide title=Auto-hide>\ Quick Reply <input type=checkbox id=autohide title=Auto-hide>\
@ -2028,9 +2030,7 @@
QR.cooldown.init(); QR.cooldown.init();
QR.captcha.init(); QR.captcha.init();
$.add(d.body, QR.el); $.add(d.body, QR.el);
e = d.createEvent('CustomEvent'); return $.event(QR.el, 'QRDialogCreation');
e.initEvent('QRDialogCreation', true, false);
return QR.el.dispatchEvent(e);
}, },
submit: function(e) { submit: function(e) {
var callbacks, captcha, captchas, challenge, err, m, opts, post, reply, response, threadID; var callbacks, captcha, captchas, challenge, err, m, opts, post, reply, response, threadID;

View File

@ -351,6 +351,10 @@ $.extend $,
return return
open: (url) -> open: (url) ->
(GM_openInTab or window.open) location.protocol + url, '_blank' (GM_openInTab or window.open) location.protocol + url, '_blank'
event: (el, name, type) ->
e = d.createEvent type or 'CustomEvent'
e.initEvent name, true, false
el.dispatchEvent e
globalEval: (code) -> globalEval: (code) ->
script = $.el 'script', textContent: code script = $.el 'script', textContent: code
$.add d.head, script $.add d.head, script
@ -931,9 +935,7 @@ Keybinds =
ta.setSelectionRange range, range ta.setSelectionRange range, range
# Fire the 'input' event # Fire the 'input' event
e = d.createEvent 'Event' $.event ta, 'input', 'Event'
e.initEvent 'input', true, false
ta.dispatchEvent e
img: (thread, all) -> img: (thread, all) ->
if all if all
@ -1175,9 +1177,7 @@ QR =
ta.setSelectionRange range, range ta.setSelectionRange range, range
# Fire the 'input' event # Fire the 'input' event
e = d.createEvent 'Event' $.event ta, 'input', 'Event'
e.initEvent 'input', true, false
ta.dispatchEvent e
drag: (e) -> drag: (e) ->
# Let it drag anything from the page. # Let it drag anything from the page.
@ -1519,9 +1519,7 @@ QR =
# Create a custom event when the QR dialog is first initialized. # Create a custom event when the QR dialog is first initialized.
# Use it to extend the QR's functionalities, or for XTRM RICE. # Use it to extend the QR's functionalities, or for XTRM RICE.
e = d.createEvent 'CustomEvent' $.event QR.el, 'QRDialogCreation'
e.initEvent 'QRDialogCreation', true, false
QR.el.dispatchEvent e
submit: (e) -> submit: (e) ->
e?.preventDefault() e?.preventDefault()