Array::slice.call x -> [x...]

This commit is contained in:
Nicolas Stepien 2013-02-25 20:55:31 +01:00
parent 0ca98e684d
commit aafae54e17
5 changed files with 15 additions and 15 deletions

View File

@ -44,6 +44,7 @@
(function() { (function() {
var $, $$, Anonymize, ArchiveLink, AutoGIF, Board, Build, Clone, Conf, Config, DeleteLink, DownloadLink, ExpandComment, ExpandThread, Favicon, FileInfo, Filter, Fourchan, Get, Header, ImageExpand, ImageHover, Keybinds, Main, Menu, Misc, Nav, Notification, Polyfill, Post, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, QuoteYou, Quotify, Recursive, Redirect, RelativeDates, ReplyHiding, ReportLink, RevealSpoilers, Sauce, Settings, Thread, ThreadExcerpt, ThreadHiding, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, d, doc, g, var $, $$, Anonymize, ArchiveLink, AutoGIF, Board, Build, Clone, Conf, Config, DeleteLink, DownloadLink, ExpandComment, ExpandThread, Favicon, FileInfo, Filter, Fourchan, Get, Header, ImageExpand, ImageHover, Keybinds, Main, Menu, Misc, Nav, Notification, Polyfill, Post, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, QuoteYou, Quotify, Recursive, Redirect, RelativeDates, ReplyHiding, ReportLink, RevealSpoilers, Sauce, Settings, Thread, ThreadExcerpt, ThreadHiding, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, d, doc, g,
__slice = [].slice,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }, __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
__hasProp = {}.hasOwnProperty, __hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
@ -323,7 +324,7 @@
Menu.prototype.findNextEntry = function(entry, direction) { Menu.prototype.findNextEntry = function(entry, direction) {
var entries; var entries;
entries = Array.prototype.slice.call(entry.parentNode.children); entries = __slice.call(entry.parentNode.children);
entries.sort(function(first, second) { entries.sort(function(first, second) {
return +(first.style.order || first.style.webkitOrder) - +(second.style.order || second.style.webkitOrder); return +(first.style.order || first.style.webkitOrder) - +(second.style.order || second.style.webkitOrder);
}); });
@ -611,7 +612,7 @@
if (root == null) { if (root == null) {
root = d.body; root = d.body;
} }
return Array.prototype.slice.call(root.querySelectorAll(selector)); return __slice.call(root.querySelectorAll(selector));
}; };
$.extend = function(object, properties) { $.extend = function(object, properties) {
@ -1059,7 +1060,7 @@
a.className = 'current'; a.className = 'current';
$('.board-title', Header.headerEl).textContent = a.title; $('.board-title', Header.headerEl).textContent = a.title;
} }
return $.add($('.board-list', Header.headerEl), Array.prototype.slice.call(nav.childNodes)); return $.add($('.board-list', Header.headerEl), __slice.call(nav.childNodes));
} }
}, },
toggleBoardList: function() { toggleBoardList: function() {
@ -3353,7 +3354,7 @@
_ref4 = [quotedPost].concat(quotedPost.clones); _ref4 = [quotedPost].concat(quotedPost.clones);
for (_k = 0, _len2 = _ref4.length; _k < _len2; _k++) { for (_k = 0, _len2 = _ref4.length; _k < _len2; _k++) {
quotedPost = _ref4[_k]; quotedPost = _ref4[_k];
quotelinks.push.apply(quotelinks, Array.prototype.slice.call(quotedPost.nodes.backlinks)); quotelinks.push.apply(quotelinks, __slice.call(quotedPost.nodes.backlinks));
} }
} }
} }
@ -3590,7 +3591,7 @@
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
deadlink = _ref[_i]; deadlink = _ref[_i];
if (deadlink.parentNode.className === 'prettyprint') { if (deadlink.parentNode.className === 'prettyprint') {
$.replace(deadlink, Array.prototype.slice.call(deadlink.childNodes)); $.replace(deadlink, __slice.call(deadlink.childNodes));
continue; continue;
} }
quote = deadlink.textContent; quote = deadlink.textContent;
@ -5981,7 +5982,7 @@
fileInput: function(files) { fileInput: function(files) {
var file, length, max, _i, _len, _ref, _ref1; var file, length, max, _i, _len, _ref, _ref1;
if (!(files instanceof FileList)) { if (!(files instanceof FileList)) {
files = Array.prototype.slice.call(this.files); files = __slice.call(this.files);
} }
QR.nodes.fileInput.value = null; QR.nodes.fileInput.value = null;
length = files.length; length = files.length;
@ -6234,7 +6235,7 @@
var el, index, newIndex, oldIndex, reply; var el, index, newIndex, oldIndex, reply;
el = $('.drag', this.parentNode); el = $('.drag', this.parentNode);
index = function(el) { index = function(el) {
return Array.prototype.slice.call(el.parentNode.children).indexOf(el); return __slice.call(el.parentNode.children).indexOf(el);
}; };
oldIndex = index(el); oldIndex = index(el);
newIndex = index(this); newIndex = index(this);

View File

@ -4,7 +4,7 @@
$ = (selector, root=d.body) -> $ = (selector, root=d.body) ->
root.querySelector selector root.querySelector selector
$$ = (selector, root=d.body) -> $$ = (selector, root=d.body) ->
Array::slice.call root.querySelectorAll selector [root.querySelectorAll(selector)...]
$.extend = (object, properties) -> $.extend = (object, properties) ->
for key, val of properties for key, val of properties

View File

@ -107,7 +107,7 @@ UI = do ->
$.off d, 'CloseMenu', @close $.off d, 'CloseMenu', @close
findNextEntry: (entry, direction) -> findNextEntry: (entry, direction) ->
entries = Array::slice.call entry.parentNode.children entries = [entry.parentNode.children...]
entries.sort (first, second) -> entries.sort (first, second) ->
+(first.style.order or first.style.webkitOrder) - +(second.style.order or second.style.webkitOrder) +(first.style.order or first.style.webkitOrder) - +(second.style.order or second.style.webkitOrder)
entries[entries.indexOf(entry) + direction] entries[entries.indexOf(entry) + direction]

View File

@ -57,8 +57,7 @@ Header =
if a = $ "a[href*='/#{g.BOARD}/']", nav if a = $ "a[href*='/#{g.BOARD}/']", nav
a.className = 'current' a.className = 'current'
$('.board-title', Header.headerEl).textContent = a.title $('.board-title', Header.headerEl).textContent = a.title
$.add $('.board-list', Header.headerEl), $.add $('.board-list', Header.headerEl), [nav.childNodes...]
Array::slice.call nav.childNodes
toggleBoardList: -> toggleBoardList: ->
node = @firstElementChild.firstChild node = @firstElementChild.firstChild
@ -2073,7 +2072,7 @@ Get =
for quote in post.quotes for quote in post.quotes
continue unless quotedPost = g.posts[quote] continue unless quotedPost = g.posts[quote]
for quotedPost in [quotedPost].concat quotedPost.clones for quotedPost in [quotedPost].concat quotedPost.clones
quotelinks.push.apply quotelinks, Array::slice.call quotedPost.nodes.backlinks quotelinks.push.apply quotelinks, [quotedPost.nodes.backlinks...]
# Third: # Third:
# Filter out irrelevant quotelinks. # Filter out irrelevant quotelinks.
quotelinks.filter (quotelink) -> quotelinks.filter (quotelink) ->
@ -2287,7 +2286,7 @@ Quotify =
if deadlink.parentNode.className is 'prettyprint' if deadlink.parentNode.className is 'prettyprint'
# Don't quotify deadlinks inside code tags, # Don't quotify deadlinks inside code tags,
# un-`span` them. # un-`span` them.
$.replace deadlink, Array::slice.call deadlink.childNodes $.replace deadlink, [deadlink.childNodes...]
continue continue
quote = deadlink.textContent quote = deadlink.textContent

View File

@ -291,7 +291,7 @@ QR =
$.addClass QR.nodes.el, 'dump' $.addClass QR.nodes.el, 'dump'
fileInput: (files) -> fileInput: (files) ->
unless files instanceof FileList unless files instanceof FileList
files = Array::slice.call @files files = [@files...]
QR.nodes.fileInput.value = null # Don't hold the files from being modified on windows QR.nodes.fileInput.value = null # Don't hold the files from being modified on windows
{length} = files {length} = files
return unless length return unless length
@ -482,7 +482,7 @@ QR =
e.dataTransfer.dropEffect = 'move' e.dataTransfer.dropEffect = 'move'
drop: -> drop: ->
el = $ '.drag', @parentNode el = $ '.drag', @parentNode
index = (el) -> Array::slice.call(el.parentNode.children).indexOf el index = (el) -> [el.parentNode.children...].indexOf el
oldIndex = index el oldIndex = index el
newIndex = index @ newIndex = index @
$.rmClass el, 'drag' # Opera doesn't fire dragEnd if we drop it on something else $.rmClass el, 'drag' # Opera doesn't fire dragEnd if we drop it on something else