diff options
Diffstat (limited to 'js/codeq/hint.js')
-rw-r--r-- | js/codeq/hint.js | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/js/codeq/hint.js b/js/codeq/hint.js index 06eceb0..55acac9 100644 --- a/js/codeq/hint.js +++ b/js/codeq/hint.js @@ -7,9 +7,10 @@ var firstCharacterPos = {'line': 0, 'ch': 0}, sel_no_scroll = {'scroll': false}; - codeq.makeHinter = function (jqHints, jqEditor, editor, hintDefs) { + codeq.makeHinter = function (jqHints, jqEditor, editor, hintDefs, planDef) { var hintCounter = 0, // for generating unique class-names hintCleaners = [], + planIdx = 0, clearHints = function () { var i; @@ -45,7 +46,7 @@ typeHandlers = { 'static': function (type, template, serverHint) { var args = serverHint.args, - jqContainer, jqButton, i, N; + jqContainer, jqButton, i, N, tmpl, tmplIsObject; if (template instanceof Array) { // unwrap the template if there's only one if (template.length == 0) template = ''; else if (template.length == 1) template = template[0] + ''; // it must be a string @@ -53,17 +54,23 @@ if (template instanceof Array) { codeq.log.debug('Processing an array of static hints'); jqContainer = $('<div class="hint-static-group"></div>'); - jqButton = $('<button type="button">More...</button>'); // TODO: translate "more" + jqButton = $('<a class="hint-static-link"></a>'); jqHints.append(jqContainer); N = template.length; - jqContainer.append('<div class="hint-static">' + processTemplate(template[0], args) + '</div>'); + tmpl = template[0]; + tmplIsObject = (typeof tmpl === 'object') && (tmpl !== null); + jqContainer.append('<div class="hint-static">' + processTemplate((tmplIsObject ? tmpl.message : tmpl) || '', args) + '</div>'); jqContainer.append(jqButton); + jqButton.text(tmplIsObject && tmpl.linkText ? tmpl.linkText : 'More...'); // TODO: translate "more" i = 1; jqButton.on('click', function () { - var jqNext = $('<div class="hint-static">' + processTemplate(template[i], args) + '</div>'); + var tmpl = template[i], + tmplIsObject = (typeof tmpl === 'object') && (tmpl !== null), + jqNext = $('<div class="hint-static">' + processTemplate((tmplIsObject ? tmpl.message : tmpl) || '', args) + '</div>'); i++; if (i < N) { jqButton.before(jqNext); + jqButton.text(tmplIsObject && tmpl.linkText ? tmpl.linkText : 'More...'); // TODO: translate "more" } else { jqButton.remove(); @@ -124,6 +131,16 @@ }; return { + /** Display the next "planning" hint and return whether there are + * any more available. + */ + 'planNext': function () { + if (planIdx < planDef.length) { + jqHints.append('<div class="plan">' + planDef[planIdx++] + '</div>'); + } + return planIdx < planDef.length; + }, + /** * Processes and display appropriately the server hints. * TODO: sort hints so static and popup hints come first, and a (single) drop-down hint last |