more conformant tagPrompt behaviour

This commit is contained in:
ansuz
2017-09-20 17:55:05 +02:00
parent db4c3e7e2c
commit 68f7d4bc0a
2 changed files with 23 additions and 12 deletions

View File

@@ -135,6 +135,11 @@ define([
}); });
}; };
var $root = $t.parent();
$t.on('tokenfield:removetoken', function (e) {
$root.find('.token-input').focus();
});
t.preventDuplicates = function (cb) { t.preventDuplicates = function (cb) {
$t.on('tokenfield:createtoken', function (ev) { $t.on('tokenfield:createtoken', function (ev) {
var val; var val;
@@ -185,22 +190,29 @@ define([
var $t = $(tagger).fadeOut(150, function () { $t.remove(); }); var $t = $(tagger).fadeOut(150, function () { $t.remove(); });
}); });
var listener = listenForKeys(function () {}, function () { var listener;
close(); var close = Util.once(function (result, ev) {
stopListening(listener); var $frame = $(tagger).fadeOut(150, function () {
stopListening(listener);
$frame.remove();
cb(result, ev);
});
}); });
var CB = Util.once(cb); var $ok = findOKButton(tagger).click(function () {
findOKButton(tagger).click(function () {
var tokens = field.getTokens(); var tokens = field.getTokens();
close(); close(tokens);
CB(tokens);
}); });
findCancelButton(tagger).click(function () { var $cancel = findCancelButton(tagger).click(function () {
close(); close(null);
CB(null); });
listenForKeys(function () {
$ok.click();
}, function () {
$cancel.click();
}); });
document.body.appendChild(tagger);
// :( // :(
setTimeout(function () { setTimeout(function () {
field.setTokens(tags); field.setTokens(tags);

View File

@@ -203,12 +203,11 @@ define([
.click(function () { .click(function () {
sframeChan.query('Q_TAGS_GET', null, function (err, res) { sframeChan.query('Q_TAGS_GET', null, function (err, res) {
if (err || res.error) { return void console.error(err || res.error); } if (err || res.error) { return void console.error(err || res.error); }
var dialog = Cryptpad.dialog.tagPrompt(res.data, function (tags) { Cryptpad.dialog.tagPrompt(res.data, function (tags) {
if (!Array.isArray(tags)) { return; } if (!Array.isArray(tags)) { return; }
console.error(tags); console.error(tags);
sframeChan.event('EV_TAGS_SET', tags); sframeChan.event('EV_TAGS_SET', tags);
}); });
document.body.appendChild(dialog);
}); });
}); });
break; break;