Merge branch 'master' into QR

This commit is contained in:
James Campos 2011-09-04 22:50:39 -07:00
commit 7cc74db296
2 changed files with 95 additions and 102 deletions

View File

@ -311,14 +311,17 @@
script = $.el('script', {
textContent: "(" + code + ")()"
});
$.append(d.head, script);
$.add(d.head, script);
return $.rm(script);
},
xhr: function(url, cb) {
ajax: function(url, cb, type) {
var r;
if (type == null) {
type = 'get';
}
r = new XMLHttpRequest();
r.onload = cb;
r.open('get', url, true);
r.open(type, url, true);
r.send();
return r;
},
@ -331,7 +334,7 @@
return req.callbacks.push(cb);
}
} else {
req = $.xhr(url, (function() {
req = $.ajax(url, (function() {
var cb, _i, _len, _ref, _results;
_ref = this.callbacks;
_results = [];
@ -360,7 +363,7 @@
style = $.el('style', {
textContent: css
});
$.append(d.head, style);
$.add(d.head, style);
return style;
},
x: function(path, root) {
@ -375,12 +378,6 @@
replace: function(root, el) {
return root.parentNode.replaceChild(el, root);
},
hide: function(el) {
return el.hidden = true;
},
show: function(el) {
return el.hidden = false;
},
addClass: function(el, className) {
return el.classList.add(className);
},
@ -390,7 +387,7 @@
rm: function(el) {
return el.parentNode.removeChild(el);
},
append: function() {
add: function() {
var child, children, parent, _i, _len, _results;
parent = arguments[0], children = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
_results = [];
@ -728,7 +725,7 @@
hide: function(reply) {
var a, div, id, name, table, trip, _ref;
table = reply.parentNode.parentNode.parentNode;
$.hide(table);
table.hidden = true;
if (conf['Show Stubs']) {
name = $('span.commentpostername', reply).textContent;
trip = ((_ref = $('span.postertrip', reply)) != null ? _ref.textContent : void 0) || '';
@ -739,7 +736,7 @@
div = $.el('div', {
className: 'stub'
});
$.append(div, a);
$.add(div, a);
$.before(table, div);
}
id = reply.id;
@ -748,7 +745,7 @@
},
show: function(table) {
var id;
$.show(table);
table.hidden = false;
id = $('td[id]', table).id;
delete g.hiddenReplies[id];
return $.set("hiddenReplies/" + g.BOARD + "/", g.hiddenReplies);
@ -997,8 +994,8 @@
});
$.bind(prev, 'click', nav.prev);
$.bind(next, 'click', nav.next);
$.append(span, prev, $.tn(' '), next);
return $.append(d.body, span);
$.add(span, prev, $.tn(' '), next);
return $.add(d.body, span);
},
prev: function() {
return nav.scroll(-1);
@ -1099,15 +1096,15 @@
innerHTML: "<label><input type=checkbox name='" + key + "' " + checked + ">" + key + "</label><span class=description>: " + description + "</span>"
});
$.bind($('input', li), 'click', $.cb.checked);
$.append(ul, li);
$.add(ul, li);
}
$.append(main, ul);
$.add(main, ul);
}
li = $.el('li', {
innerHTML: "<button>hidden: " + hiddenNum + "</button> <span class=description>: Forget all hidden posts. Useful if you accidentally hide a post and have `show stubs` disabled."
});
$.bind($('button', li), 'click', options.clearHidden);
$.append($('ul:nth-child(2)', dialog), li);
$.add($('ul:nth-child(2)', dialog), li);
$.bind($('#flavors', dialog), 'change', $.cb.value);
$.bind($('input[name=time]', dialog), 'keyup', options.time);
$.bind($('input[name=backlink]', dialog), 'keyup', options.backlink);
@ -1126,8 +1123,8 @@
overlay = $.el('div', {
id: 'overlay'
});
$.append(overlay, dialog);
$.append(d.body, overlay);
$.add(overlay, dialog);
$.add(d.body, overlay);
options.time.call($('input[name=time]', dialog));
options.backlink.call($('input[name=backlink]', dialog));
$.bind(overlay, 'click', function() {
@ -1606,7 +1603,7 @@
name: 'iframe',
hidden: true
});
$.append(d.body, iframe);
$.add(d.body, iframe);
return $('#recaptcha_response_field').id = '';
},
attach: function() {
@ -1618,7 +1615,7 @@
$.bind(fileDiv.lastChild, 'click', (function() {
return $.rm(this.parentNode);
}));
return $.append($('#files', qr.el), fileDiv);
return $.add($('#files', qr.el), fileDiv);
},
attachNext: function() {
var file, fileDiv, oldFile;
@ -1689,7 +1686,7 @@
$.bind($('img', qr.el), 'click', Recaptcha.reload);
$.bind($('#dummy', qr.el), 'keydown', Recaptcha.listener);
$.bind($('#dummy', qr.el), 'keydown', qr.captchaKeydown);
return $.append(d.body, qr.el);
return $.add(d.body, qr.el);
},
message: function(e) {
var data, duration, fileCount;
@ -1922,10 +1919,10 @@
});
$.before(node, op);
while (node.nodeName !== 'BLOCKQUOTE') {
$.append(op, node);
$.add(op, node);
node = op.nextSibling;
}
$.append(op, node);
$.add(op, node);
op.id = $('input[name]', op).name;
return op;
},
@ -1940,7 +1937,7 @@
});
$.before(node, div);
while (node.nodeName !== 'HR') {
$.append(div, node);
$.add(div, node);
node = div.nextSibling;
}
node = node.nextElementSibling;
@ -2013,20 +2010,20 @@
div = $.el('div', {
className: 'block'
});
$.append(div, a);
$.append(thread, div);
$.add(div, a);
$.add(thread, div);
return $.addClass(thread, 'stub');
} else {
$.hide(thread);
return $.hide(thread.nextSibling);
thread.hidden = true;
return thread.nextSibling.hidden = true;
}
},
show: function(thread) {
var hiddenThreads, id;
$.rm($('div.block', thread));
$.removeClass(thread, 'stub');
$.show(thread);
$.show(thread.nextSibling);
thread.hidden = false;
thread.nextSibling.hidden = false;
id = thread.firstChild.id;
hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {});
delete hiddenThreads[id];
@ -2088,19 +2085,19 @@
$.bind(input, 'click', updater.updateNow);
}
}
return $.append(d.body, dialog);
return $.add(d.body, dialog);
},
cb: {
verbose: function() {
if (conf['Verbose']) {
updater.count.textContent = '+0';
return $.show(updater.timer);
return updater.timer.hidden = false;
} else {
$.extend(updater.count, {
className: '',
textContent: 'Thread Updater'
});
return $.hide(updater.timer);
return updater.timer.hidden = true;
}
},
autoUpdate: function() {
@ -2181,7 +2178,7 @@
}
url = location.pathname + '?' + Date.now();
cb = updater.cb.update;
return updater.request = $.xhr(url, cb);
return updater.request = $.ajax(url, cb);
}
};
watcher = {
@ -2192,7 +2189,7 @@
top: '50px',
left: '0px'
}, html);
$.append(d.body, watcher.dialog);
$.add(d.body, watcher.dialog);
inputs = $$('.op input');
for (_i = 0, _len = inputs.length; _i < _len; _i++) {
input = inputs[_i];
@ -2234,8 +2231,8 @@
});
$.bind(x, 'click', watcher.cb.x);
link = $.el('a', props);
$.append(div, x, $.tn(' '), link);
$.append(watcher.dialog, div);
$.add(div, x, $.tn(' '), link);
$.add(watcher.dialog, div);
}
}
watchedBoard = watched[g.BOARD] || {};
@ -2345,7 +2342,7 @@
href: prefix + suffix,
target: '_blank'
});
_results.push($.append(span, $.tn(' '), link));
_results.push($.add(span, $.tn(' '), link));
}
return _results;
}
@ -2530,7 +2527,7 @@
root = $('.reportbutton', el) || $('span[id^=no]', el);
$.after(root, container);
}
_results.push($.append(container, $.tn(' '), link));
_results.push($.add(container, $.tn(' '), link));
}
return _results;
});
@ -2567,7 +2564,7 @@
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
inlined = _ref[_i];
if (hidden = $.id(inlined.name)) {
$.show($.x('ancestor::table[1]', hidden));
$.x('ancestor::table[1]', hidden).hidden = false;
}
}
return;
@ -2580,7 +2577,7 @@
return;
}
$.after(this.parentNode, inline);
$.hide($.x('ancestor::table[1]', el));
$.x('ancestor::table[1]', el).hidden = true;
} else {
$.after(root, inline);
}
@ -2670,7 +2667,7 @@
id: 'qp',
className: 'replyhl'
});
$.append(d.body, qp);
$.add(d.body, qp);
id = this.hash.slice(1);
if (el = $.id(id)) {
qp.innerHTML = el.innerHTML;
@ -2787,7 +2784,7 @@
dialog.className = 'dialog';
threadStats.postcountEl = $('#postcount', dialog);
threadStats.imagecountEl = $('#imagecount', dialog);
$.append(d.body, dialog);
$.add(d.body, dialog);
return g.callbacks.push(threadStats.node);
},
node: function(root) {
@ -2966,7 +2963,7 @@
id: 'iHover',
src: this.parentNode.href
});
return $.append(d.body, ui.el);
return $.add(d.body, ui.el);
}
};
imgPreloading = {
@ -3072,12 +3069,12 @@
}
},
contract: function(thumb) {
$.show(thumb);
thumb.hidden = false;
return $.rm(thumb.nextSibling);
},
expand: function(thumb) {
var a, filesize, img, max, _, _ref2;
$.hide(thumb);
thumb.hidden = true;
a = thumb.parentNode;
img = $.el('img', {
src: a.href
@ -3087,7 +3084,7 @@
_ref2 = filesize.textContent.match(/(\d+)x/), _ = _ref2[0], max = _ref2[1];
img.style.maxWidth = "-moz-calc(" + max + "px)";
}
return $.append(a, img);
return $.add(a, img);
},
dialog: function() {
var controls, delform, imageType, option, select, _i, _len, _ref2;
@ -3126,7 +3123,7 @@
className: 'firstrun',
innerHTML: " <div id=options> <div class='reply dialog'> <p>Click the <strong>4chan X</strong> buttons for options; they are at the top and bottom of the page.</p> <p>Updater options are in the updater dialog in replies at the bottom-right corner of the window.</p> <p>If you don't see the buttons, try disabling your userstyles.</p> </div> </div>"
});
$.append(d.body, dialog);
$.add(d.body, dialog);
return $.bind(window, 'click', firstRun.close);
},
close: function() {

View File

@ -217,12 +217,12 @@ $.extend $,
globalEval: (code) ->
script = $.el 'script',
textContent: "(#{code})()"
$.append d.head, script
$.add d.head, script
$.rm script
xhr: (url, cb) ->
ajax: (url, cb, type='get') ->
r = new XMLHttpRequest()
r.onload = cb
r.open 'get', url, true
r.open type, url, true
r.send()
r
cache: (url, cb) ->
@ -232,7 +232,7 @@ $.extend $,
else
req.callbacks.push cb
else
req = $.xhr url, (-> cb.call @ for cb in @callbacks)
req = $.ajax url, (-> cb.call @ for cb in @callbacks)
req.callbacks = [cb]
$.cache.requests[url] = req
cb:
@ -245,7 +245,7 @@ $.extend $,
addStyle: (css) ->
style = $.el 'style',
textContent: css
$.append d.head, style
$.add d.head, style
style
x: (path, root=d.body) ->
d.evaluate(path, root, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).
@ -254,17 +254,13 @@ $.extend $,
d.createTextNode s
replace: (root, el) ->
root.parentNode.replaceChild el, root
hide: (el) ->
el.hidden = true
show: (el) ->
el.hidden = false
addClass: (el, className) ->
el.classList.add className
removeClass: (el, className) ->
el.classList.remove className
rm: (el) ->
el.parentNode.removeChild el
append: (parent, children...) ->
add: (parent, children...) ->
for child in children
parent.appendChild child
prepend: (parent, child) ->
@ -517,7 +513,7 @@ replyHiding =
hide: (reply) ->
table = reply.parentNode.parentNode.parentNode
$.hide table
table.hidden = true
if conf['Show Stubs']
name = $('span.commentpostername', reply).textContent
@ -528,7 +524,7 @@ replyHiding =
div = $.el 'div',
className: 'stub'
$.append div, a
$.add div, a
$.before table, div
id = reply.id
@ -536,7 +532,7 @@ replyHiding =
$.set "hiddenReplies/#{g.BOARD}/", g.hiddenReplies
show: (table) ->
$.show table
table.hidden = false
id = $('td[id]', table).id
delete g.hiddenReplies[id]
@ -719,8 +715,8 @@ nav =
$.bind prev, 'click', nav.prev
$.bind next, 'click', nav.next
$.append span, prev, $.tn(' '), next
$.append d.body, span
$.add span, prev, $.tn(' '), next
$.add d.body, span
prev: ->
nav.scroll -1
@ -872,13 +868,13 @@ options =
li = $.el 'li',
innerHTML: "<label><input type=checkbox name='#{key}' #{checked}>#{key}</label><span class=description>: #{description}</span>"
$.bind $('input', li), 'click', $.cb.checked
$.append ul, li
$.append main, ul
$.add ul, li
$.add main, ul
li = $.el 'li',
innerHTML: "<button>hidden: #{hiddenNum}</button> <span class=description>: Forget all hidden posts. Useful if you accidentally hide a post and have `show stubs` disabled."
$.bind $('button', li), 'click', options.clearHidden
$.append $('ul:nth-child(2)', dialog), li
$.add $('ul:nth-child(2)', dialog), li
$.bind $('#flavors', dialog), 'change', $.cb.value
$.bind $('input[name=time]', dialog), 'keyup', options.time
@ -894,8 +890,8 @@ options =
https://bugzilla.mozilla.org/show_bug.cgi?id=579776
###
overlay = $.el 'div', id: 'overlay'
$.append overlay, dialog
$.append d.body, overlay
$.add overlay, dialog
$.add d.body, overlay
options.time.call $('input[name=time]', dialog)
options.backlink.call $('input[name=backlink]', dialog)
@ -1269,7 +1265,7 @@ qr =
iframe = $.el 'iframe',
name: 'iframe'
hidden: true
$.append d.body, iframe
$.add d.body, iframe
#hack - nuke id so it doesn't grab focus when reloading
$('#recaptcha_response_field').id = ''
@ -1278,7 +1274,7 @@ qr =
fileDiv = $.el 'div', innerHTML: "<input type=file name=upfile accept='#{qr.acceptFiles}'><a>X</a>"
$.bind fileDiv.firstChild, 'change', qr.validateFileSize
$.bind fileDiv.lastChild, 'click', (-> $.rm @parentNode)
$.append $('#files', qr.el), fileDiv
$.add $('#files', qr.el), fileDiv
attachNext: ->
fileDiv = $.rm $('#files div', qr.el)
@ -1364,7 +1360,7 @@ qr =
$.bind $('#dummy', qr.el), 'keydown', Recaptcha.listener
$.bind $('#dummy', qr.el), 'keydown', qr.captchaKeydown
$.append d.body, qr.el
$.add d.body, qr.el
message: (e) ->
$('iframe[name=iframe]').src = 'about:blank'
@ -1556,9 +1552,9 @@ threading =
className: 'op'
$.before node, op
while node.nodeName isnt 'BLOCKQUOTE'
$.append op, node
$.add op, node
node = op.nextSibling
$.append op, node #add the blockquote
$.add op, node #add the blockquote
op.id = $('input[name]', op).name
op
@ -1572,7 +1568,7 @@ threading =
$.before node, div
while node.nodeName isnt 'HR'
$.append div, node
$.add div, node
node = div.nextSibling
node = node.nextElementSibling #skip text node
@ -1634,18 +1630,18 @@ threadHiding =
div = $.el 'div',
className: 'block'
$.append div, a
$.append thread, div
$.add div, a
$.add thread, div
$.addClass thread, 'stub'
else
$.hide thread
$.hide thread.nextSibling
thread.hidden = true
thread.nextSibling.hidden = true
show: (thread) ->
$.rm $ 'div.block', thread
$.removeClass thread, 'stub'
$.show thread
$.show thread.nextSibling
thread.hidden = false
thread.nextSibling.hidden = false
id = thread.firstChild.id
@ -1696,18 +1692,18 @@ updater =
else if input.type is 'button'
$.bind input, 'click', updater.updateNow
$.append d.body, dialog
$.add d.body, dialog
cb:
verbose: ->
if conf['Verbose']
updater.count.textContent = '+0'
$.show updater.timer
updater.timer.hidden = false
else
$.extend updater.count,
className: ''
textContent: 'Thread Updater'
$.hide updater.timer
updater.timer.hidden = true
autoUpdate: ->
if @checked
updater.timeoutID = setTimeout updater.timeout, 1000
@ -1777,13 +1773,13 @@ updater =
updater.request?.abort()
url = location.pathname + '?' + Date.now() # fool the cache
cb = updater.cb.update
updater.request = $.xhr url, cb
updater.request = $.ajax url, cb
watcher =
init: ->
html = '<div class=move>Thread Watcher</div>'
watcher.dialog = ui.dialog 'watcher', top: '50px', left: '0px', html
$.append d.body, watcher.dialog
$.add d.body, watcher.dialog
#add watch buttons
inputs = $$ '.op input'
@ -1816,8 +1812,8 @@ watcher =
$.bind x, 'click', watcher.cb.x
link = $.el 'a', props
$.append div, x, $.tn(' '), link
$.append watcher.dialog, div
$.add div, x, $.tn(' '), link
$.add watcher.dialog, div
watchedBoard = watched[g.BOARD] or {}
for favicon in $$ 'img.favicon'
@ -1884,7 +1880,7 @@ sauce =
textContent: sauce.names[i]
href: prefix + suffix
target: '_blank'
$.append span, $.tn(' '), link
$.add span, $.tn(' '), link
revealSpoilers =
init: ->
@ -2006,7 +2002,7 @@ quoteBacklink =
container = $.el 'span', className: 'container'
root = $('.reportbutton', el) or $('span[id^=no]', el)
$.after root, container
$.append container, $.tn(' '), link
$.add container, $.tn(' '), link
quoteInline =
init: ->
@ -2025,7 +2021,7 @@ quoteInline =
$.removeClass @, 'inlined'
for inlined in $$ 'input', table
if hidden = $.id inlined.name
$.show $.x 'ancestor::table[1]', hidden
$.x('ancestor::table[1]', hidden).hidden = false
return
root = if @parentNode.nodeName is 'FONT' then @parentNode else if @nextSibling then @nextSibling else @
if el = $.id id
@ -2033,7 +2029,7 @@ quoteInline =
if @className is 'backlink'
return if $("a.backlink[href='##{id}']", el)
$.after @parentNode, inline
$.hide $.x 'ancestor::table[1]', el
$.x('ancestor::table[1]', el).hidden = true
else
$.after root, inline
else
@ -2090,7 +2086,7 @@ quotePreview =
qp = ui.el = $.el 'div',
id: 'qp'
className: 'replyhl'
$.append d.body, qp
$.add d.body, qp
id = @hash[1..]
if el = $.id id
@ -2164,7 +2160,7 @@ threadStats =
dialog.className = 'dialog'
threadStats.postcountEl = $ '#postcount', dialog
threadStats.imagecountEl = $ '#imagecount', dialog
$.append d.body, dialog
$.add d.body, dialog
g.callbacks.push threadStats.node
node: (root) ->
return if root.className
@ -2274,7 +2270,7 @@ imgHover =
ui.el = $.el 'img'
id: 'iHover'
src: @parentNode.href
$.append d.body, ui.el
$.add d.body, ui.el
imgPreloading =
init: ->
@ -2340,11 +2336,11 @@ imgExpand =
imgExpand.expand thumb
contract: (thumb) ->
$.show thumb
thumb.hidden = false
$.rm thumb.nextSibling
expand: (thumb) ->
$.hide thumb
thumb.hidden = true
a = thumb.parentNode
img = $.el 'img',
src: a.href
@ -2352,7 +2348,7 @@ imgExpand =
filesize = $ 'span.filesize', a.parentNode
[_, max] = filesize.textContent.match /(\d+)x/
img.style.maxWidth = "-moz-calc(#{max}px)"
$.append a, img
$.add a, img
dialog: ->
controls = $.el 'div',
@ -2447,7 +2443,7 @@ firstRun =
<p>If you don't see the buttons, try disabling your userstyles.</p>
</div>
</div>"
$.append d.body, dialog
$.add d.body, dialog
$.bind window, 'click', firstRun.close