summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorRobert Zorko <robertz@gurucue.com>2015-09-18 11:36:06 +0200
committerRobert Zorko <robertz@gurucue.com>2015-09-18 11:36:06 +0200
commitb6c44a2adb82ffeed71e459667fc175b311786f1 (patch)
tree3fab86c891e733e4c6f4ebc2dc5efea2216fe6ad /js
parente31b714410968e20078ef9405bbe04c53a1efdc2 (diff)
parentd53f6ca305da14cea431433601ba20835872c83d (diff)
Merge branch 'master' into stateMachine
Diffstat (limited to 'js')
-rw-r--r--js/codeq/hint.js55
1 files changed, 23 insertions, 32 deletions
diff --git a/js/codeq/hint.js b/js/codeq/hint.js
index c22f39f..a94f571 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
},
@@ -162,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;