summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleš Smodiš <aless@guru.si>2015-09-18 09:56:38 +0200
committerAleš Smodiš <aless@guru.si>2015-09-18 09:56:38 +0200
commita40a4145c724309ae58b2c7b7c3f4ab4f5d0c7df (patch)
treec4cfae52e7fa797d89d9c9cae1739051e8929eec
parent31cc69df82abce2250505c1e088d3f787a521a13 (diff)
Simplified handling of an array of static hints.
-rw-r--r--js/codeq/hint.js45
1 files changed, 18 insertions, 27 deletions
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 = $('<button type="button">More...</button>'); // 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('<div class="hint-static">' + message + '</div>');
- 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('<div class="hint-static">' + processTemplate(template[0], args) + '</div>');
+ jqContainer.append(jqButton);
+ i = 1;
+ jqButton.on('click', function () {
+ var jqNext = $('<div class="hint-static">' + processTemplate(template[i], args) + '</div>');
+ 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('<div class="hint-static">' + message + '</div>');
+ jqHints.append('<div class="hint-static">' + processTemplate(template, args) + '</div>');
}
// no hint cleaner here, a static hint remains on the screen
},