$.append -> $.add

This commit is contained in:
James Campos 2011-09-04 22:42:36 -07:00
parent b8abb2b16d
commit ef086934f1
2 changed files with 61 additions and 61 deletions

View File

@ -311,7 +311,7 @@
script = $.el('script', { script = $.el('script', {
textContent: "(" + code + ")()" textContent: "(" + code + ")()"
}); });
$.append(d.head, script); $.add(d.head, script);
return $.rm(script); return $.rm(script);
}, },
xhr: function(url, cb) { xhr: function(url, cb) {
@ -360,7 +360,7 @@
style = $.el('style', { style = $.el('style', {
textContent: css textContent: css
}); });
$.append(d.head, style); $.add(d.head, style);
return style; return style;
}, },
x: function(path, root) { x: function(path, root) {
@ -384,7 +384,7 @@
rm: function(el) { rm: function(el) {
return el.parentNode.removeChild(el); return el.parentNode.removeChild(el);
}, },
append: function() { add: function() {
var child, children, parent, _i, _len, _results; var child, children, parent, _i, _len, _results;
parent = arguments[0], children = 2 <= arguments.length ? __slice.call(arguments, 1) : []; parent = arguments[0], children = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
_results = []; _results = [];
@ -733,7 +733,7 @@
div = $.el('div', { div = $.el('div', {
className: 'stub' className: 'stub'
}); });
$.append(div, a); $.add(div, a);
$.before(table, div); $.before(table, div);
} }
id = reply.id; id = reply.id;
@ -994,8 +994,8 @@
}); });
$.bind(prev, 'click', nav.prev); $.bind(prev, 'click', nav.prev);
$.bind(next, 'click', nav.next); $.bind(next, 'click', nav.next);
$.append(span, prev, $.tn(' '), next); $.add(span, prev, $.tn(' '), next);
return $.append(d.body, span); return $.add(d.body, span);
}, },
prev: function() { prev: function() {
return nav.scroll(-1); return nav.scroll(-1);
@ -1096,15 +1096,15 @@
innerHTML: "<label><input type=checkbox name='" + key + "' " + checked + ">" + key + "</label><span class=description>: " + description + "</span>" innerHTML: "<label><input type=checkbox name='" + key + "' " + checked + ">" + key + "</label><span class=description>: " + description + "</span>"
}); });
$.bind($('input', li), 'click', $.cb.checked); $.bind($('input', li), 'click', $.cb.checked);
$.append(ul, li); $.add(ul, li);
} }
$.append(main, ul); $.add(main, ul);
} }
li = $.el('li', { 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." 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); $.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($('#flavors', dialog), 'change', $.cb.value);
$.bind($('input[name=time]', dialog), 'keyup', options.time); $.bind($('input[name=time]', dialog), 'keyup', options.time);
$.bind($('input[name=backlink]', dialog), 'keyup', options.backlink); $.bind($('input[name=backlink]', dialog), 'keyup', options.backlink);
@ -1123,8 +1123,8 @@
overlay = $.el('div', { overlay = $.el('div', {
id: 'overlay' id: 'overlay'
}); });
$.append(overlay, dialog); $.add(overlay, dialog);
$.append(d.body, overlay); $.add(d.body, overlay);
options.time.call($('input[name=time]', dialog)); options.time.call($('input[name=time]', dialog));
options.backlink.call($('input[name=backlink]', dialog)); options.backlink.call($('input[name=backlink]', dialog));
$.bind(overlay, 'click', function() { $.bind(overlay, 'click', function() {
@ -1241,7 +1241,7 @@
name: 'iframe', name: 'iframe',
hidden: true hidden: true
}); });
$.append(d.body, iframe); $.add(d.body, iframe);
return $('#recaptcha_response_field').id = ''; return $('#recaptcha_response_field').id = '';
}, },
attach: function() { attach: function() {
@ -1253,7 +1253,7 @@
$.bind(fileDiv.lastChild, 'click', (function() { $.bind(fileDiv.lastChild, 'click', (function() {
return $.rm(this.parentNode); return $.rm(this.parentNode);
})); }));
return $.append($('#files', qr.el), fileDiv); return $.add($('#files', qr.el), fileDiv);
}, },
attachNext: function() { attachNext: function() {
var file, fileDiv, oldFile; var file, fileDiv, oldFile;
@ -1324,7 +1324,7 @@
$.bind($('img', qr.el), 'click', Recaptcha.reload); $.bind($('img', qr.el), 'click', Recaptcha.reload);
$.bind($('#dummy', qr.el), 'keydown', Recaptcha.listener); $.bind($('#dummy', qr.el), 'keydown', Recaptcha.listener);
$.bind($('#dummy', qr.el), 'keydown', qr.captchaKeydown); $.bind($('#dummy', qr.el), 'keydown', qr.captchaKeydown);
return $.append(d.body, qr.el); return $.add(d.body, qr.el);
}, },
message: function(e) { message: function(e) {
var data, duration, fileCount; var data, duration, fileCount;
@ -1557,10 +1557,10 @@
}); });
$.before(node, op); $.before(node, op);
while (node.nodeName !== 'BLOCKQUOTE') { while (node.nodeName !== 'BLOCKQUOTE') {
$.append(op, node); $.add(op, node);
node = op.nextSibling; node = op.nextSibling;
} }
$.append(op, node); $.add(op, node);
op.id = $('input[name]', op).name; op.id = $('input[name]', op).name;
return op; return op;
}, },
@ -1575,7 +1575,7 @@
}); });
$.before(node, div); $.before(node, div);
while (node.nodeName !== 'HR') { while (node.nodeName !== 'HR') {
$.append(div, node); $.add(div, node);
node = div.nextSibling; node = div.nextSibling;
} }
node = node.nextElementSibling; node = node.nextElementSibling;
@ -1648,8 +1648,8 @@
div = $.el('div', { div = $.el('div', {
className: 'block' className: 'block'
}); });
$.append(div, a); $.add(div, a);
$.append(thread, div); $.add(thread, div);
return $.addClass(thread, 'stub'); return $.addClass(thread, 'stub');
} else { } else {
thread.hidden = true; thread.hidden = true;
@ -1723,7 +1723,7 @@
$.bind(input, 'click', updater.updateNow); $.bind(input, 'click', updater.updateNow);
} }
} }
return $.append(d.body, dialog); return $.add(d.body, dialog);
}, },
cb: { cb: {
verbose: function() { verbose: function() {
@ -1827,7 +1827,7 @@
top: '50px', top: '50px',
left: '0px' left: '0px'
}, html); }, html);
$.append(d.body, watcher.dialog); $.add(d.body, watcher.dialog);
inputs = $$('.op input'); inputs = $$('.op input');
for (_i = 0, _len = inputs.length; _i < _len; _i++) { for (_i = 0, _len = inputs.length; _i < _len; _i++) {
input = inputs[_i]; input = inputs[_i];
@ -1869,8 +1869,8 @@
}); });
$.bind(x, 'click', watcher.cb.x); $.bind(x, 'click', watcher.cb.x);
link = $.el('a', props); link = $.el('a', props);
$.append(div, x, $.tn(' '), link); $.add(div, x, $.tn(' '), link);
$.append(watcher.dialog, div); $.add(watcher.dialog, div);
} }
} }
watchedBoard = watched[g.BOARD] || {}; watchedBoard = watched[g.BOARD] || {};
@ -1980,7 +1980,7 @@
href: prefix + suffix, href: prefix + suffix,
target: '_blank' target: '_blank'
}); });
_results.push($.append(span, $.tn(' '), link)); _results.push($.add(span, $.tn(' '), link));
} }
return _results; return _results;
} }
@ -2165,7 +2165,7 @@
root = $('.reportbutton', el) || $('span[id^=no]', el); root = $('.reportbutton', el) || $('span[id^=no]', el);
$.after(root, container); $.after(root, container);
} }
_results.push($.append(container, $.tn(' '), link)); _results.push($.add(container, $.tn(' '), link));
} }
return _results; return _results;
}); });
@ -2202,7 +2202,7 @@
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
inlined = _ref[_i]; inlined = _ref[_i];
if (hidden = $.id(inlined.name)) { if (hidden = $.id(inlined.name)) {
$.x('ancestor::table[1]', hidden).hidden = true; $.x('ancestor::table[1]', hidden).hidden = false;
} }
} }
return; return;
@ -2305,7 +2305,7 @@
id: 'qp', id: 'qp',
className: 'replyhl' className: 'replyhl'
}); });
$.append(d.body, qp); $.add(d.body, qp);
id = this.hash.slice(1); id = this.hash.slice(1);
if (el = $.id(id)) { if (el = $.id(id)) {
qp.innerHTML = el.innerHTML; qp.innerHTML = el.innerHTML;
@ -2422,7 +2422,7 @@
dialog.className = 'dialog'; dialog.className = 'dialog';
threadStats.postcountEl = $('#postcount', dialog); threadStats.postcountEl = $('#postcount', dialog);
threadStats.imagecountEl = $('#imagecount', dialog); threadStats.imagecountEl = $('#imagecount', dialog);
$.append(d.body, dialog); $.add(d.body, dialog);
return g.callbacks.push(threadStats.node); return g.callbacks.push(threadStats.node);
}, },
node: function(root) { node: function(root) {
@ -2601,7 +2601,7 @@
id: 'iHover', id: 'iHover',
src: this.parentNode.href src: this.parentNode.href
}); });
return $.append(d.body, ui.el); return $.add(d.body, ui.el);
} }
}; };
imgPreloading = { imgPreloading = {
@ -2722,7 +2722,7 @@
_ref2 = filesize.textContent.match(/(\d+)x/), _ = _ref2[0], max = _ref2[1]; _ref2 = filesize.textContent.match(/(\d+)x/), _ = _ref2[0], max = _ref2[1];
img.style.maxWidth = "-moz-calc(" + max + "px)"; img.style.maxWidth = "-moz-calc(" + max + "px)";
} }
return $.append(a, img); return $.add(a, img);
}, },
dialog: function() { dialog: function() {
var controls, delform, imageType, option, select, _i, _len, _ref2; var controls, delform, imageType, option, select, _i, _len, _ref2;
@ -2761,7 +2761,7 @@
className: 'firstrun', 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>" 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); return $.bind(window, 'click', firstRun.close);
}, },
close: function() { close: function() {

View File

@ -217,7 +217,7 @@ $.extend $,
globalEval: (code) -> globalEval: (code) ->
script = $.el 'script', script = $.el 'script',
textContent: "(#{code})()" textContent: "(#{code})()"
$.append d.head, script $.add d.head, script
$.rm script $.rm script
xhr: (url, cb) -> xhr: (url, cb) ->
r = new XMLHttpRequest() r = new XMLHttpRequest()
@ -245,7 +245,7 @@ $.extend $,
addStyle: (css) -> addStyle: (css) ->
style = $.el 'style', style = $.el 'style',
textContent: css textContent: css
$.append d.head, style $.add d.head, style
style style
x: (path, root=d.body) -> x: (path, root=d.body) ->
d.evaluate(path, root, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null). d.evaluate(path, root, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).
@ -260,7 +260,7 @@ $.extend $,
el.classList.remove className el.classList.remove className
rm: (el) -> rm: (el) ->
el.parentNode.removeChild el el.parentNode.removeChild el
append: (parent, children...) -> add: (parent, children...) ->
for child in children for child in children
parent.appendChild child parent.appendChild child
prepend: (parent, child) -> prepend: (parent, child) ->
@ -524,7 +524,7 @@ replyHiding =
div = $.el 'div', div = $.el 'div',
className: 'stub' className: 'stub'
$.append div, a $.add div, a
$.before table, div $.before table, div
id = reply.id id = reply.id
@ -717,8 +717,8 @@ nav =
$.bind prev, 'click', nav.prev $.bind prev, 'click', nav.prev
$.bind next, 'click', nav.next $.bind next, 'click', nav.next
$.append span, prev, $.tn(' '), next $.add span, prev, $.tn(' '), next
$.append d.body, span $.add d.body, span
prev: -> prev: ->
nav.scroll -1 nav.scroll -1
@ -870,13 +870,13 @@ options =
li = $.el 'li', li = $.el 'li',
innerHTML: "<label><input type=checkbox name='#{key}' #{checked}>#{key}</label><span class=description>: #{description}</span>" innerHTML: "<label><input type=checkbox name='#{key}' #{checked}>#{key}</label><span class=description>: #{description}</span>"
$.bind $('input', li), 'click', $.cb.checked $.bind $('input', li), 'click', $.cb.checked
$.append ul, li $.add ul, li
$.append main, ul $.add main, ul
li = $.el 'li', 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." 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 $.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 $('#flavors', dialog), 'change', $.cb.value
$.bind $('input[name=time]', dialog), 'keyup', options.time $.bind $('input[name=time]', dialog), 'keyup', options.time
@ -892,8 +892,8 @@ options =
https://bugzilla.mozilla.org/show_bug.cgi?id=579776 https://bugzilla.mozilla.org/show_bug.cgi?id=579776
### ###
overlay = $.el 'div', id: 'overlay' overlay = $.el 'div', id: 'overlay'
$.append overlay, dialog $.add overlay, dialog
$.append d.body, overlay $.add d.body, overlay
options.time.call $('input[name=time]', dialog) options.time.call $('input[name=time]', dialog)
options.backlink.call $('input[name=backlink]', dialog) options.backlink.call $('input[name=backlink]', dialog)
@ -981,7 +981,7 @@ qr =
iframe = $.el 'iframe', iframe = $.el 'iframe',
name: 'iframe' name: 'iframe'
hidden: true hidden: true
$.append d.body, iframe $.add d.body, iframe
#hack - nuke id so it doesn't grab focus when reloading #hack - nuke id so it doesn't grab focus when reloading
$('#recaptcha_response_field').id = '' $('#recaptcha_response_field').id = ''
@ -990,7 +990,7 @@ qr =
fileDiv = $.el 'div', innerHTML: "<input type=file name=upfile accept='#{qr.acceptFiles}'><a>X</a>" fileDiv = $.el 'div', innerHTML: "<input type=file name=upfile accept='#{qr.acceptFiles}'><a>X</a>"
$.bind fileDiv.firstChild, 'change', qr.validateFileSize $.bind fileDiv.firstChild, 'change', qr.validateFileSize
$.bind fileDiv.lastChild, 'click', (-> $.rm @parentNode) $.bind fileDiv.lastChild, 'click', (-> $.rm @parentNode)
$.append $('#files', qr.el), fileDiv $.add $('#files', qr.el), fileDiv
attachNext: -> attachNext: ->
fileDiv = $.rm $('#files div', qr.el) fileDiv = $.rm $('#files div', qr.el)
@ -1076,7 +1076,7 @@ qr =
$.bind $('#dummy', qr.el), 'keydown', Recaptcha.listener $.bind $('#dummy', qr.el), 'keydown', Recaptcha.listener
$.bind $('#dummy', qr.el), 'keydown', qr.captchaKeydown $.bind $('#dummy', qr.el), 'keydown', qr.captchaKeydown
$.append d.body, qr.el $.add d.body, qr.el
message: (e) -> message: (e) ->
$('iframe[name=iframe]').src = 'about:blank' $('iframe[name=iframe]').src = 'about:blank'
@ -1268,9 +1268,9 @@ threading =
className: 'op' className: 'op'
$.before node, op $.before node, op
while node.nodeName isnt 'BLOCKQUOTE' while node.nodeName isnt 'BLOCKQUOTE'
$.append op, node $.add op, node
node = op.nextSibling node = op.nextSibling
$.append op, node #add the blockquote $.add op, node #add the blockquote
op.id = $('input[name]', op).name op.id = $('input[name]', op).name
op op
@ -1284,7 +1284,7 @@ threading =
$.before node, div $.before node, div
while node.nodeName isnt 'HR' while node.nodeName isnt 'HR'
$.append div, node $.add div, node
node = div.nextSibling node = div.nextSibling
node = node.nextElementSibling #skip text node node = node.nextElementSibling #skip text node
@ -1346,8 +1346,8 @@ threadHiding =
div = $.el 'div', div = $.el 'div',
className: 'block' className: 'block'
$.append div, a $.add div, a
$.append thread, div $.add thread, div
$.addClass thread, 'stub' $.addClass thread, 'stub'
else else
thread.hidden = true thread.hidden = true
@ -1408,7 +1408,7 @@ updater =
else if input.type is 'button' else if input.type is 'button'
$.bind input, 'click', updater.updateNow $.bind input, 'click', updater.updateNow
$.append d.body, dialog $.add d.body, dialog
cb: cb:
verbose: -> verbose: ->
@ -1495,7 +1495,7 @@ watcher =
init: -> init: ->
html = '<div class=move>Thread Watcher</div>' html = '<div class=move>Thread Watcher</div>'
watcher.dialog = ui.dialog 'watcher', top: '50px', left: '0px', html watcher.dialog = ui.dialog 'watcher', top: '50px', left: '0px', html
$.append d.body, watcher.dialog $.add d.body, watcher.dialog
#add watch buttons #add watch buttons
inputs = $$ '.op input' inputs = $$ '.op input'
@ -1528,8 +1528,8 @@ watcher =
$.bind x, 'click', watcher.cb.x $.bind x, 'click', watcher.cb.x
link = $.el 'a', props link = $.el 'a', props
$.append div, x, $.tn(' '), link $.add div, x, $.tn(' '), link
$.append watcher.dialog, div $.add watcher.dialog, div
watchedBoard = watched[g.BOARD] or {} watchedBoard = watched[g.BOARD] or {}
for favicon in $$ 'img.favicon' for favicon in $$ 'img.favicon'
@ -1596,7 +1596,7 @@ sauce =
textContent: sauce.names[i] textContent: sauce.names[i]
href: prefix + suffix href: prefix + suffix
target: '_blank' target: '_blank'
$.append span, $.tn(' '), link $.add span, $.tn(' '), link
revealSpoilers = revealSpoilers =
init: -> init: ->
@ -1718,7 +1718,7 @@ quoteBacklink =
container = $.el 'span', className: 'container' container = $.el 'span', className: 'container'
root = $('.reportbutton', el) or $('span[id^=no]', el) root = $('.reportbutton', el) or $('span[id^=no]', el)
$.after root, container $.after root, container
$.append container, $.tn(' '), link $.add container, $.tn(' '), link
quoteInline = quoteInline =
init: -> init: ->
@ -1802,7 +1802,7 @@ quotePreview =
qp = ui.el = $.el 'div', qp = ui.el = $.el 'div',
id: 'qp' id: 'qp'
className: 'replyhl' className: 'replyhl'
$.append d.body, qp $.add d.body, qp
id = @hash[1..] id = @hash[1..]
if el = $.id id if el = $.id id
@ -1876,7 +1876,7 @@ threadStats =
dialog.className = 'dialog' dialog.className = 'dialog'
threadStats.postcountEl = $ '#postcount', dialog threadStats.postcountEl = $ '#postcount', dialog
threadStats.imagecountEl = $ '#imagecount', dialog threadStats.imagecountEl = $ '#imagecount', dialog
$.append d.body, dialog $.add d.body, dialog
g.callbacks.push threadStats.node g.callbacks.push threadStats.node
node: (root) -> node: (root) ->
return if root.className return if root.className
@ -1986,7 +1986,7 @@ imgHover =
ui.el = $.el 'img' ui.el = $.el 'img'
id: 'iHover' id: 'iHover'
src: @parentNode.href src: @parentNode.href
$.append d.body, ui.el $.add d.body, ui.el
imgPreloading = imgPreloading =
init: -> init: ->
@ -2064,7 +2064,7 @@ imgExpand =
filesize = $ 'span.filesize', a.parentNode filesize = $ 'span.filesize', a.parentNode
[_, max] = filesize.textContent.match /(\d+)x/ [_, max] = filesize.textContent.match /(\d+)x/
img.style.maxWidth = "-moz-calc(#{max}px)" img.style.maxWidth = "-moz-calc(#{max}px)"
$.append a, img $.add a, img
dialog: -> dialog: ->
controls = $.el 'div', controls = $.el 'div',
@ -2159,7 +2159,7 @@ firstRun =
<p>If you don't see the buttons, try disabling your userstyles.</p> <p>If you don't see the buttons, try disabling your userstyles.</p>
</div> </div>
</div>" </div>"
$.append d.body, dialog $.add d.body, dialog
$.bind window, 'click', firstRun.close $.bind window, 'click', firstRun.close