diff options
author | Timotej Lazar <timotej.lazar@araneo.org> | 2015-09-08 10:44:52 +0200 |
---|---|---|
committer | Timotej Lazar <timotej.lazar@araneo.org> | 2015-09-08 10:44:52 +0200 |
commit | 34d740e4d9435a954be5b683d73da6a544d7669b (patch) | |
tree | 610c3e7f6e855546a8f9b7cde16f8d3279416d4a | |
parent | 3752341cf43043fe89742baff35ad74df9fe0f4d (diff) |
Process templates in popover hints
-rw-r--r-- | js/prolog.js | 20 | ||||
-rw-r--r-- | js/python.js | 20 |
2 files changed, 24 insertions, 16 deletions
diff --git a/js/prolog.js b/js/prolog.js index d9bcdca..1d30f7c 100644 --- a/js/prolog.js +++ b/js/prolog.js @@ -184,20 +184,24 @@ hintCounter++; return result; }, + processTemplate = function (template, args) { + if (!args) + return template; + return template.replace(/\[%=(\w+)%\]/g, function(match, name) { + return args[name]; + }); + }, hintHandlers = { 'static': function (type, template, serverHint) { codeq.log.debug('Processing static hint'); - if (serverHint.args) { - template = template.replace(/\[%=(\w+)%\]/g, function(match, name) { - return serverHint.args[name]; - }); - } - jqHints.append('<div class="hint-static">' + template + '</div>'); // TODO: incorporate any serverHint.args + var message = processTemplate(template, serverHint.args); + jqHints.append('<div class="hint-static">' + message + '</div>'); // no hint cleaner here, a static hint remains on the screen }, 'popup': function (type, template, serverHint) { codeq.log.debug('Processing popup hint'); - var mark = addMark(serverHint.start, serverHint.end), // add the mark + var message = processTemplate(template, serverHint.args), + mark = addMark(serverHint.start, serverHint.end), // add the mark jqMark = jqEditor.find('.' + mark.className); /* jqPopup = null, onBlur = function () { @@ -236,7 +240,7 @@ mark = null; });*/ - jqMark.popover({content: template, html: true, placement: 'auto bottom', trigger: 'hover focus click', container: 'body'}); + jqMark.popover({content: message, html: true, placement: 'auto bottom', trigger: 'hover focus click', container: 'body'}); hintCleaners.push(function () { if (jqMark) { jqMark.popover('destroy'); jqMark = null; } }); mark.mark.on('', function () {}); diff --git a/js/python.js b/js/python.js index df23773..dd346c4 100644 --- a/js/python.js +++ b/js/python.js @@ -136,20 +136,24 @@ hintCounter++; return result; }, + processTemplate = function (template, args) { + if (!args) + return template; + return template.replace(/\[%=(\w+)%\]/g, function(match, name) { + return args[name]; + }); + }, hintHandlers = { 'static': function (type, template, serverHint) { codeq.log.debug('Processing static hint'); - if (serverHint.args) { - template = template.replace(/\[%=(\w+)%\]/g, function(match, name) { - return serverHint.args[name]; - }); - } - jqHints.append('<div class="hint-static">' + template + '</div>'); // TODO: incorporate any serverHint.args + var message = processTemplate(template, serverHint.args); + jqHints.append('<div class="hint-static">' + message + '</div>'); // no hint cleaner here, a static hint remains on the screen }, 'popup': function (type, template, serverHint) { codeq.log.debug('Processing popup hint'); - var mark = addMark(serverHint.start, serverHint.end), // add the mark + var message = processTemplate(template, serverHint.args), + mark = addMark(serverHint.start, serverHint.end), // add the mark jqMark = jqEditor.find('.' + mark.className); /* jqPopup = null, onBlur = function () { @@ -188,7 +192,7 @@ mark = null; });*/ - jqMark.popover({content: template, html: true, placement: 'auto bottom', trigger: 'hover focus click', container: 'body'}); + jqMark.popover({content: message, html: true, placement: 'auto bottom', trigger: 'hover focus click', container: 'body'}); hintCleaners.push(function () { if (jqMark) { jqMark.popover('destroy'); jqMark = null; } }); mark.mark.on('', function () {}); |