From 69a11dc26345b28023252e522576eecf50f033f1 Mon Sep 17 00:00:00 2001 From: Izak Burger Date: Tue, 28 May 2013 13:26:34 +0200 Subject: [PATCH 1/2] Avoid errors with undefined populator, selector For reasons I could not determine, and which disappear whenever you add a debugger to the mix (that is, it is a race condition), The populator and helper members are sometimes undefined causing errors. In addition, this code makes sure we don't get the entire hierarchy if more than one parent matches the selector, for we most certainly don't want more than one popup. Fixes #408. --- src/plugins/oer/popover/lib/popover-plugin.coffee | 9 +++++++-- src/plugins/oer/popover/lib/popover-plugin.js | 8 ++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/plugins/oer/popover/lib/popover-plugin.coffee b/src/plugins/oer/popover/lib/popover-plugin.coffee index 573cc25a6d..83d8110191 100644 --- a/src/plugins/oer/popover/lib/popover-plugin.coffee +++ b/src/plugins/oer/popover/lib/popover-plugin.coffee @@ -328,9 +328,14 @@ define [ 'aloha', 'jquery' ], (Aloha, jQuery) -> insideScope = false Aloha.bind 'aloha-selection-changed', (event, rangeObject) -> + # How this is even possible I do not understand, but apparently it is + # possible for our helper to not be completely initialised at this point. + if not (helper.populator and helper.selector) + return + # Hide all popovers except for the current one maybe? $el = jQuery(rangeObject.getCommonAncestorContainer()) - $el = $el.parents(helper.selector) if not $el.is(helper.selector) + $el = $el.parents(helper.selector).eq(0) if not $el.is(helper.selector) if Aloha.activeEditable # Hide other tooltips of the same type @@ -342,7 +347,7 @@ define [ 'aloha', 'jquery' ], (Aloha, jQuery) -> if insideScope isnt enteredLinkScope insideScope = enteredLinkScope if not $el.is(helper.selector) - $el = $el.parents(helper.selector) + $el = $el.parents(helper.selector).eq(0) if enteredLinkScope $el.trigger 'show' $el.data('aloha-bubble-selected', true) diff --git a/src/plugins/oer/popover/lib/popover-plugin.js b/src/plugins/oer/popover/lib/popover-plugin.js index 3ecce1d954..b81a7993fe 100644 --- a/src/plugins/oer/popover/lib/popover-plugin.js +++ b/src/plugins/oer/popover/lib/popover-plugin.js @@ -357,9 +357,12 @@ There are 3 variables that are stored on each element; Aloha.bind('aloha-selection-changed', function(event, rangeObject) { var $el, nodes; + if (!(helper.populator && helper.selector)) { + return; + } $el = jQuery(rangeObject.getCommonAncestorContainer()); if (!$el.is(helper.selector)) { - $el = $el.parents(helper.selector); + $el = $el.parents(helper.selector).eq(0); } if (Aloha.activeEditable) { nodes = jQuery(Aloha.activeEditable.obj).find(helper.selector); @@ -369,9 +372,10 @@ There are 3 variables that are stored on each element; if (insideScope !== enteredLinkScope) { insideScope = enteredLinkScope; if (!$el.is(helper.selector)) { - $el = $el.parents(helper.selector); + $el = $el.parents(helper.selector).eq(0); } if (enteredLinkScope) { + console.log("selector is " + helper.selector); $el.trigger('show'); $el.data('aloha-bubble-selected', true); $el.off('.bubble'); From b8bdfb977b5aafbddec55422b9123f173eacc38f Mon Sep 17 00:00:00 2001 From: Izak Burger Date: Tue, 28 May 2013 15:20:56 +0200 Subject: [PATCH 2/2] Sync with coffee --- src/plugins/oer/popover/lib/popover-plugin.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/plugins/oer/popover/lib/popover-plugin.js b/src/plugins/oer/popover/lib/popover-plugin.js index b81a7993fe..2d5f18c061 100644 --- a/src/plugins/oer/popover/lib/popover-plugin.js +++ b/src/plugins/oer/popover/lib/popover-plugin.js @@ -375,7 +375,6 @@ There are 3 variables that are stored on each element; $el = $el.parents(helper.selector).eq(0); } if (enteredLinkScope) { - console.log("selector is " + helper.selector); $el.trigger('show'); $el.data('aloha-bubble-selected', true); $el.off('.bubble');