From 3c3ed3070986f8860aa8812235297b9e2ae87960 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Wed, 4 Jul 2012 18:06:10 +0200 Subject: [PATCH] Close #578. --- 4chan_x.user.js | 11 +++++++---- script.coffee | 12 +++++++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 26f3f1246..32b20bb3d 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -424,7 +424,7 @@ }, nodes: function(nodes) { var frag, node, _i, _len; - if (nodes instanceof Node) { + if (!(nodes instanceof Array)) { return nodes; } frag = d.createDocumentFragment(); @@ -1182,6 +1182,9 @@ return e.stopPropagation(); }); $.on(this.el, 'keydown', this.keybinds); + $.on(d, 'AddMenuEntry', function(e) { + return Menu.addEntry(e.detail); + }); return Main.callbacks.push(this.node); }, node: function(post) { @@ -1215,9 +1218,9 @@ el.setAttribute('data-id', post.ID); el.setAttribute('data-rootid', post.root.id); funk = function(entry, parent) { - var child, children, open, subMenu, _i, _len; - open = entry.open, children = entry.children; - if (!open(post)) { + var child, children, subMenu, _i, _len; + children = entry.children; + if (!entry.open(post)) { return; } $.add(parent, entry.el); diff --git a/script.coffee b/script.coffee index 6cdb5a0f4..ed0741c31 100644 --- a/script.coffee +++ b/script.coffee @@ -329,7 +329,10 @@ $.extend $, tn: (s) -> d.createTextNode s nodes: (nodes) -> - if nodes instanceof Node + # In (at least) Chrome, elements created inside different + # scripts/window contexts inherit from unequal prototypes. + # window_ext1.Node !== window_ext2.Node + unless nodes instanceof Array return nodes frag = d.createDocumentFragment() for node in nodes @@ -945,6 +948,9 @@ Menu = $.on @el, 'click', (e) -> e.stopPropagation() $.on @el, 'keydown', @keybinds + # Doc here: https://github.com/MayhemYDG/4chan-x/wiki/Menu-API + $.on d, 'AddMenuEntry', (e) -> Menu.addEntry e.detail + Main.callbacks.push @node node: (post) -> if post.isInlined and !post.isCrosspost @@ -979,8 +985,8 @@ Menu = el.setAttribute 'data-rootid', post.root.id funk = (entry, parent) -> - {open, children} = entry - return unless open post + {children} = entry + return unless entry.open post $.add parent, entry.el return unless children subMenu = $.el 'div',