aboutsummaryrefslogtreecommitdiff
path: root/app/public
diff options
context:
space:
mode:
authorrubenwardy <rw@rubenwardy.com>2020-07-14 03:49:30 +0100
committerrubenwardy <rw@rubenwardy.com>2020-07-14 23:45:54 +0100
commitc9e4638b348a5d9004376ed90e72fe8bb9df40e3 (patch)
tree3d333240f1cbafc7a7f4bdcbf7034600ced2d951 /app/public
parentff2cd6dc2f2e1c500744c2e2e0c45a5590774484 (diff)
downloadcheatdb-c9e4638b348a5d9004376ed90e72fe8bb9df40e3.tar.xz
Add start of bulk tag editor
Diffstat (limited to 'app/public')
-rw-r--r--app/public/static/tagselector.js132
1 files changed, 66 insertions, 66 deletions
diff --git a/app/public/static/tagselector.js b/app/public/static/tagselector.js
index 9bbb764..f099415 100644
--- a/app/public/static/tagselector.js
+++ b/app/public/static/tagselector.js
@@ -19,80 +19,80 @@
$.fn.selectSelector = function(source, select) {
return this.each(function() {
- var selector = $(this),
- input = $('input[type=text]', this);
+ var selector = $(this),
+ input = $('input[type=text]', this);
- selector.click(function() { input.focus(); })
- .delegate('.badge a', 'click', function() {
- var id = $(this).parent().data("id");
- select.find("option[value=" + id + "]").attr("selected", false)
- recreate();
- });
+ selector.click(function() { input.focus(); })
+ .delegate('.badge a', 'click', function() {
+ var id = $(this).parent().data("id");
+ select.find("option[value=" + id + "]").attr("selected", false)
+ recreate();
+ });
- function addTag(id, text) {
- $('<span class="badge badge-pill badge-primary"/>')
- .text(text + ' ')
- .data("id", id)
- .append('<a>x</a>')
- .insertBefore(input);
- input.attr("placeholder", null);
- select.find("option[value='" + id + "']").attr("selected", "selected")
- hide_error(input);
- }
+ function addTag(id, text) {
+ $('<span class="badge badge-pill badge-primary"/>')
+ .text(text + ' ')
+ .data("id", id)
+ .append('<a>x</a>')
+ .insertBefore(input);
+ input.attr("placeholder", null);
+ select.find("option[value='" + id + "']").attr("selected", "selected")
+ hide_error(input);
+ }
- function recreate() {
- selector.find("span").remove();
- select.find("option").each(function() {
- if (this.hasAttribute("selected")) {
- addTag(this.getAttribute("value"), this.innerText);
- }
- });
+ function recreate() {
+ selector.find("span").remove();
+ select.find("option").each(function() {
+ if (this.hasAttribute("selected")) {
+ addTag(this.getAttribute("value"), this.innerText);
+ }
+ });
+ }
+ recreate();
+
+ input.focusout(function(e) {
+ var value = input.val().trim()
+ if (value != "") {
+ show_error(input, "Please select an existing tag, it;s not possible to add custom ones.");
}
- recreate();
+ })
- input.focusout(function(e) {
- var value = input.val().trim()
- if (value != "") {
- show_error(input, "Please select an existing tag, it;s not possible to add custom ones.");
- }
+ input.keydown(function(e) {
+ if (e.keyCode === $.ui.keyCode.TAB && $(this).data('ui-autocomplete').menu.active)
+ e.preventDefault();
})
+ .autocomplete({
+ minLength: 0,
+ source: source,
+ select: function(event, ui) {
+ addTag(ui.item.id, ui.item.toString());
+ input.val("");
+ return false;
+ }
+ }).focus(function() {
+ // The following works only once.
+ // $(this).trigger('keydown.autocomplete');
+ // As suggested by digitalPBK, works multiple times
+ // $(this).data("autocomplete").search($(this).val());
+ // As noted by Jonny in his answer, with newer versions use uiAutocomplete
+ $(this).data("ui-autocomplete").search($(this).val());
+ });
- input.keydown(function(e) {
- if (e.keyCode === $.ui.keyCode.TAB && $(this).data('ui-autocomplete').menu.active)
- e.preventDefault();
- })
- .autocomplete({
- minLength: 0,
- source: source,
- select: function(event, ui) {
- addTag(ui.item.id, ui.item.toString());
- input.val("");
- return false;
- }
- }).focus(function() {
- // The following works only once.
- // $(this).trigger('keydown.autocomplete');
- // As suggested by digitalPBK, works multiple times
- // $(this).data("autocomplete").search($(this).val());
- // As noted by Jonny in his answer, with newer versions use uiAutocomplete
- $(this).data("ui-autocomplete").search($(this).val());
- });
-
- input.data('ui-autocomplete')._renderItem = function(ul, item) {
- return $('<li/>')
- .data('item.autocomplete', item)
- .append($('<a/>').text(item.toString()))
- .appendTo(ul);
- };
+ input.data('ui-autocomplete')._renderItem = function(ul, item) {
+ return $('<li/>')
+ .data('item.autocomplete', item)
+ .append($('<a/>').text(item.toString()))
+ .appendTo(ul);
+ };
- input.data('ui-autocomplete')._resizeMenu = function(ul, item) {
- var ul = this.menu.element;
- ul.outerWidth(Math.max(
- ul.width('').outerWidth(),
- selector.outerWidth()
- ));
- };
- });
+ input.data('ui-autocomplete')._resizeMenu = function(ul, item) {
+ var ul = this.menu.element;
+ ul.outerWidth(Math.max(
+ ul.width('').outerWidth(),
+ selector.outerWidth()
+ ));
+ };
+ });
}
$.fn.csvSelector = function(source, name, result, allowSlash) {