Revision 757:d38f5a55c590 vendor/plugins/redmine_tags/assets/javascripts
| vendor/plugins/redmine_tags/assets/javascripts/tags_input.js | ||
|---|---|---|
| 1 |
/** |
|
| 2 |
* This file is a part of redmine_tags |
|
| 3 |
* redMine plugin, that adds tagging support. |
|
| 4 |
* |
|
| 5 |
* Copyright (c) 2010 Aleksey V Zapparov AKA ixti |
|
| 6 |
* |
|
| 7 |
* redmine_tags is free software: you can redistribute it and/or modify |
|
| 8 |
* it under the terms of the GNU General Public License as published by |
|
| 9 |
* the Free Software Foundation, either version 3 of the License, or |
|
| 10 |
* (at your option) any later version. |
|
| 11 |
* |
|
| 12 |
* redmine_tags is distributed in the hope that it will be useful, |
|
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 15 |
* GNU General Public License for more details. |
|
| 16 |
* |
|
| 17 |
* You should have received a copy of the GNU General Public License |
|
| 18 |
* along with redmine_tags. If not, see <http://www.gnu.org/licenses/>. |
|
| 19 |
*/ |
|
| 20 |
|
|
| 21 |
var Redmine = Redmine || {};
|
|
| 22 |
|
|
| 23 |
Redmine.TagsInput = Class.create({
|
|
| 24 |
initialize: function(element) {
|
|
| 25 |
this.element = $(element); |
|
| 26 |
this.input = new Element('input', { 'type': 'text', 'autocomplete': 'off', 'size': 10 });
|
|
| 27 |
this.button = new Element('span', { 'class': 'tag-add icon icon-add' });
|
|
| 28 |
this.tags = new Hash(); |
|
| 29 |
|
|
| 30 |
Event.observe(this.button, 'click', this.readTags.bind(this)); |
|
| 31 |
Event.observe(this.input, 'keypress', this.onKeyPress.bindAsEventListener(this)); |
|
| 32 |
|
|
| 33 |
this.element.insert({ 'after': this.input });
|
|
| 34 |
this.input.insert({ 'after': this.button });
|
|
| 35 |
this.addTagsList(this.element.value); |
|
| 36 |
}, |
|
| 37 |
|
|
| 38 |
readTags: function() {
|
|
| 39 |
this.addTagsList(this.input.value); |
|
| 40 |
this.input.value = ''; |
|
| 41 |
}, |
|
| 42 |
|
|
| 43 |
onKeyPress: function(event) {
|
|
| 44 |
if (Event.KEY_RETURN == event.keyCode) {
|
|
| 45 |
this.readTags(event); |
|
| 46 |
Event.stop(event); |
|
| 47 |
} |
|
| 48 |
}, |
|
| 49 |
|
|
| 50 |
addTag: function(tag) {
|
|
| 51 |
if (tag.blank() || this.tags.get(tag)) return; |
|
| 52 |
|
|
| 53 |
var button = new Element('span', { 'class': 'tag-delete icon icon-del' });
|
|
| 54 |
var label = new Element('span', { 'class': 'tag-label' }).insert(tag).insert(button);
|
|
| 55 |
|
|
| 56 |
this.tags.set(tag, 1); |
|
| 57 |
this.element.value = this.getTagsList(); |
|
| 58 |
this.element.insert({ 'before': label });
|
|
| 59 |
|
|
| 60 |
Event.observe(button, 'click', function(){
|
|
| 61 |
this.tags.unset(tag); |
|
| 62 |
this.element.value = this.getTagsList(); |
|
| 63 |
label.remove(); |
|
| 64 |
}.bind(this)); |
|
| 65 |
}, |
|
| 66 |
|
|
| 67 |
addTagsList: function(tags_list) {
|
|
| 68 |
var tags = tags_list.split(',');
|
|
| 69 |
for (var i = 0; i < tags.length; i++) {
|
|
| 70 |
this.addTag(tags[i].strip()); |
|
| 71 |
} |
|
| 72 |
}, |
|
| 73 |
|
|
| 74 |
getTagsList: function() {
|
|
| 75 |
return this.tags.keys().join(',');
|
|
| 76 |
}, |
|
| 77 |
|
|
| 78 |
autocomplete: function(container, url) {
|
|
| 79 |
new Ajax.Autocompleter(this.input, container, url, {
|
|
| 80 |
'minChars': 1, |
|
| 81 |
'frequency': 0.5, |
|
| 82 |
'paramName': 'q', |
|
| 83 |
'updateElement': function(el) {
|
|
| 84 |
this.input.value = el.getAttribute('name');
|
|
| 85 |
this.readTags(); |
|
| 86 |
}.bind(this) |
|
| 87 |
}); |
|
| 88 |
} |
|
| 89 |
}); |
|
| 90 |
|
|
| 91 |
|
|
| 92 |
function observeIssueTagsField(url) {
|
|
| 93 |
new Redmine.TagsInput('issue_tag_list').autocomplete('issue_tag_candidates', url);
|
|
| 94 |
} |
|
| 95 |
|
|
| 96 |
|
|
| 97 |
function observeProjectTagsField(url) {
|
|
| 98 |
new Redmine.TagsInput('project_tag_list').autocomplete('project_tag_candidates', url);
|
|
| 99 |
} |
|
Also available in: Unified diff