From a40a4145c724309ae58b2c7b7c3f4ab4f5d0c7df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Smodi=C5=A1?= Date: Fri, 18 Sep 2015 09:56:38 +0200 Subject: Simplified handling of an array of static hints. --- js/codeq/hint.js | 45 ++++++++++++++++++--------------------------- 1 file changed, 18 insertions(+), 27 deletions(-) (limited to 'js/codeq') diff --git a/js/codeq/hint.js b/js/codeq/hint.js index c22f39f..6b8d12f 100644 --- a/js/codeq/hint.js +++ b/js/codeq/hint.js @@ -41,10 +41,11 @@ typeHandlers = { 'static': function (type, template, serverHint) { - var jqContainer, jqButton, promise, i, lastIndex; + var args = serverHint.args, + jqContainer, jqButton, i, lastIndex; 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] + ''; + else if (template.length == 1) template = template[0] + ''; // it must be a string } if (template instanceof Array) { codeq.log.debug('Processing an array of static hints'); @@ -52,34 +53,24 @@ jqButton = $(''); // TODO: translate "more" jqHints.append(jqContainer); lastIndex = template.length - 1; - promise = Q(); - for (i = 0; i <= lastIndex; i++) { - promise = promise.then((function (tmpl, index) { - return Q.Promise(function (resolve, reject) { - var message = processTemplate(tmpl, serverHint.args), - onClick; - jqContainer.append('
' + message + '
'); - if (index < lastIndex) { - onClick = function () { - jqButton.off('click', onClick); - jqButton.remove(); - resolve(); - }; - jqContainer.append(jqButton); - jqButton.on('click', onClick); - } - else { - resolve(); - } - }); - })(template[i], i)); - } - promise.done(); + jqContainer.append('
' + processTemplate(template[0], args) + '
'); + jqContainer.append(jqButton); + i = 1; + jqButton.on('click', function () { + var jqNext = $('
' + processTemplate(template[i], args) + '
'); + i++; + if (i < lastIndex) { + jqButton.before(jqNext); + } + else { + jqButton.remove(); + jqContainer.append(jqNext); + } + }); } else { codeq.log.debug('Processing a single static hint'); - var message = processTemplate(template, serverHint.args); - jqHints.append('
' + message + '
'); + jqHints.append('
' + processTemplate(template, args) + '
'); } // no hint cleaner here, a static hint remains on the screen }, -- cgit v1.2.1 From d53f6ca305da14cea431433601ba20835872c83d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Smodi=C5=A1?= Date: Fri, 18 Sep 2015 10:04:07 +0200 Subject: Bugfix: handle arrays as a static hint. --- js/codeq/hint.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'js/codeq') diff --git a/js/codeq/hint.js b/js/codeq/hint.js index 6b8d12f..a94f571 100644 --- a/js/codeq/hint.js +++ b/js/codeq/hint.js @@ -153,14 +153,14 @@ } } t = typeof hintDef; - if (t === 'object') { - hintType = hintDef.type; - hintTemplate = hintDef.message; - } - else if (t === 'string') { + if ((t === 'string') || (hintDef instanceof Array)) { hintType = 'static'; hintTemplate = hintDef; } + else if (t === 'object') { + hintType = hintDef.type; + hintTemplate = hintDef.message; + } else { codeq.log.error('Unsupported hint definition: ' + t); continue; -- cgit v1.2.1