From 34d740e4d9435a954be5b683d73da6a544d7669b Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Tue, 8 Sep 2015 10:44:52 +0200 Subject: Process templates in popover hints --- js/prolog.js | 20 ++++++++++++-------- js/python.js | 20 ++++++++++++-------- 2 files changed, 24 insertions(+), 16 deletions(-) (limited to 'js') 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('
' + template + '
'); // TODO: incorporate any serverHint.args + var message = processTemplate(template, serverHint.args); + jqHints.append('
' + message + '
'); // 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('
' + template + '
'); // TODO: incorporate any serverHint.args + var message = processTemplate(template, serverHint.args); + jqHints.append('
' + message + '
'); // 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 () {}); -- cgit v1.2.1