From d4089d09c5803e6a3f5573f10d472bc6c485761b Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Fri, 22 Feb 2013 23:28:45 +0100 Subject: [PATCH] Faster Menu's makeButton. Callback name fixes. --- 4chan_x.user.js | 37 +++++++++++++++++++++---------------- src/features.coffee | 27 +++++++++++++++------------ src/main.coffee | 2 ++ 3 files changed, 38 insertions(+), 28 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 68e095be9..e2fd10c2d 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1679,7 +1679,7 @@ return; } return Post.prototype.callbacks.push({ - name: 'Thread Hiding', + name: 'Filter', cb: this.node }); }, @@ -2104,7 +2104,7 @@ if (!Conf['Hiding Buttons']) { return; } - return $.replace($('.sideArrows', this.nodes.root), ReplyHiding.makeButton(this, 'hide')); + return $.replace(this.nodes.root.firstElementChild, ReplyHiding.makeButton(this, 'hide')); }, getHiddenPosts: function() { var hiddenPosts; @@ -2348,20 +2348,25 @@ } return $.add(this.nodes.info, [$.tn('\u00A0'), button]); }, - makeButton: function(post) { + makeButton: (function() { var a; - a = $.el('a', { - className: 'menu-button', - innerHTML: '[]', - href: 'javascript:;' - }); - a.setAttribute('data-postid', post.fullID); - if (post.isClone) { - a.setAttribute('data-clone', true); - } - $.on(a, 'click', Menu.toggle); - return a; - }, + a = null; + return function(post) { + var clone; + a || (a = $.el('a', { + className: 'menu-button', + innerHTML: '[]', + href: 'javascript:;' + })); + clone = a.cloneNode(true); + clone.setAttribute('data-postid', post.fullID); + if (post.isClone) { + clone.setAttribute('data-clone', true); + } + $.on(clone, 'click', Menu.toggle); + return clone; + }; + })(), toggle: function(e) { var post; post = this.dataset.clone ? Get.postFromNode(this) : g.posts[this.dataset.postid]; @@ -4611,7 +4616,7 @@ return; } return Post.prototype.callbacks.push({ - name: 'Auto-GIF', + name: 'Image Hover', cb: this.node }); }, diff --git a/src/features.coffee b/src/features.coffee index 9a8508f2e..3063ad997 100644 --- a/src/features.coffee +++ b/src/features.coffee @@ -666,7 +666,7 @@ Filter = return unless Object.keys(@filters).length Post::callbacks.push - name: 'Thread Hiding' + name: 'Filter' cb: @node createFilter: (regexp, op, stub, hl, top) -> @@ -1036,7 +1036,7 @@ ReplyHiding = else Recursive.hide @, data.makeStub return unless Conf['Hiding Buttons'] - $.replace $('.sideArrows', @nodes.root), ReplyHiding.makeButton @, 'hide' + $.replace @nodes.root.firstElementChild, ReplyHiding.makeButton @, 'hide' getHiddenPosts: -> hiddenPosts = $.get "hiddenPosts.#{g.BOARD}" @@ -1209,15 +1209,18 @@ Menu = return $.add @nodes.info, [$.tn('\u00A0'), button] - makeButton: (post) -> - a = $.el 'a', - className: 'menu-button' - innerHTML: '[]' - href: 'javascript:;' - a.setAttribute 'data-postid', post.fullID - a.setAttribute 'data-clone', true if post.isClone - $.on a, 'click', Menu.toggle - a + makeButton: do -> + a = null + (post) -> + a or= $.el 'a', + className: 'menu-button' + innerHTML: '[]' + href: 'javascript:;' + clone = a.cloneNode true + clone.setAttribute 'data-postid', post.fullID + clone.setAttribute 'data-clone', true if post.isClone + $.on clone, 'click', Menu.toggle + clone toggle: (e) -> post = @@ -3070,7 +3073,7 @@ ImageHover = return if g.VIEW is 'catalog' or !Conf['Image Hover'] Post::callbacks.push - name: 'Auto-GIF' + name: 'Image Hover' cb: @node node: -> return unless @file?.isImage diff --git a/src/main.coffee b/src/main.coffee index 29e8deba3..2da7a543c 100644 --- a/src/main.coffee +++ b/src/main.coffee @@ -431,6 +431,7 @@ Main = # get the nodes' length only once len = nodes.length for callback in klass::callbacks + # console.profile callback.name for i in [0...len] node = nodes[i] try @@ -441,6 +442,7 @@ Main = errors.push message: "\"#{callback.name}\" crashed on #{klass.name} No.#{node} (/#{node.board}/)." error: err + # console.profileEnd callback.name Main.handleErrors errors if errors handleErrors: (errors) ->