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..2d5f18c061 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,7 +372,7 @@ 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) { $el.trigger('show');