summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--js/codeq/hint.js36
1 files changed, 27 insertions, 9 deletions
diff --git a/js/codeq/hint.js b/js/codeq/hint.js
index a97c14b..fc2429a 100644
--- a/js/codeq/hint.js
+++ b/js/codeq/hint.js
@@ -10,9 +10,16 @@
codeq.makeHinter = function (jqHints, jqEditor, editor, trNamespace, problemDef, commonDef) {
var hintCounter = 0, // for generating unique class-names
hintCleaners = [],
+ popoverHintCleaners = [], // we require separate cleaners for popups, because they are rebuilt when the editor's DOM changes
+ popoverCreators = [], // functions that rebuild popover handlers after the editor's DOM changes
planIdx = 0,
dictionary = [],
jqHintsContainer = jqHints.parent(),
+ hintProblemDefs = problemDef.hint_type,
+ hintCommonDefs = commonDef.hint_type,
+ hintProblemTr = problemDef.hint,
+ hintCommonTr = commonDef.hint,
+ planDef = problemDef.plan,
clearHints = function () {
var i;
@@ -20,6 +27,10 @@
hintCleaners[i]();
}
hintCleaners.length = 0;
+ for (i = popoverHintCleaners.length - 1; i >= 0; i--) {
+ popoverHintCleaners[i]();
+ }
+ popoverHintCleaners.length = 0;
hintCounter = 0;
},
@@ -240,7 +251,7 @@
mark = addMark(serverHint.start, serverHint.end), // add the mark
langs = codeq.availableLangs,
translations = {},
- lang, i, content, htmlPrefix;
+ lang, i, content, htmlPrefix, instFunc;
// execute templates for all languages
for (i = langs.length - 1; i >= 0; i--) {
@@ -257,7 +268,7 @@
// construct the wrapper element for the translation mechanism
htmlPrefix = '<span ' + ta(translations) + '>';
// create the popover after all the DOM modifications have been made, otherwise only the last made popover can be triggered
- return function () {
+ instFunc = function () {
var jqMark = jqEditor.find('.' + mark.className);
jqMark.popover({
'content': function () {
@@ -270,8 +281,10 @@
'container': 'body'
});
// remove the popup on next hint pack
- hintCleaners.push(function () { if (jqMark) { jqMark.popover('destroy'); jqMark = null; } });
+ popoverHintCleaners.push(function () { if (jqMark) { jqMark.popover('destroy'); jqMark = null; } });
};
+ popoverCreators.push(instFunc);
+ return instFunc;
},
'dropdown': function (type, template, serverHint) {
@@ -305,15 +318,19 @@
hintCleaners.push(close);
}
+ },
+
+ /**
+ * When the editor updates its DOM, we have to re-register any popup hints.
+ */
+ onEditorUpdate = function () {
+ var i;
+ for (i = 0; i < popoverHintCleaners.length; i++) popoverHintCleaners[i]();
+ for (i = 0; i < popoverCreators.length; i++) popoverCreators[i]();
};
codeq.tr.registerDictionary(trNamespace, dictionary);
-
- var hintProblemDefs = problemDef.hint_type,
- hintCommonDefs = commonDef.hint_type,
- hintProblemTr = problemDef.hint,
- hintCommonTr = commonDef.hint,
- planDef = problemDef.plan;
+ editor.on('update', onEditorUpdate);
return {
/**
@@ -387,6 +404,7 @@
},
'destroy': function () {
+ editor.off('update', onEditorUpdate);
clearHints();
codeq.tr.unregisterDictionary(trNamespace);
jqHints.empty();