tagmanager-rails 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/README.md +10 -3
- data/lib/tag_manager/rails/version.rb +2 -2
- data/vendor/assets/javascripts/bootstrap-tagmanager.js +202 -259
- data/vendor/assets/stylesheets/bootstrap-tagmanager.css +90 -96
- data/vendor/assets/stylesheets/bootstrap-tagmanager.css.less +163 -90
- data/vendor/assets/stylesheets/bootstrap-tagmanager.css.scss +163 -90
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
OWY3OTU4YjAyZjA3NjMxMjdiNTFlMWMyZTgwOGI0OTMzNzExY2JkMmVjNmM5
|
10
|
-
ZTAzYWU3ZWFjMTk0MWFlOTk5ZTYyYjg2YzM5MTc0OTU5ZThjNmMzZTA0NDZk
|
11
|
-
MGY4YzkyYjMyOGY2YjljMTA1OGUwNTQ4ZjIyZDZjODJkNWEzNjU=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MGJjMTE3ODhlZTQ3MzgzNDZlODZhMGQyNDFjYjc4NDRmNzM1MGRkYzI3ZTZm
|
14
|
-
YjUwMGQ4MGY3NWQ3MjliNDRiNWZlOTIxZDAzNTdmOTRkM2E5NTc2OGZiOGIw
|
15
|
-
NmZlOGFkNWQ2MDAxZDVjNTI5OGEwOTMwNWRhNDQwZTk5MDc4OTQ=
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7f998760c26811f00fd14c8a0d77d474dc1e6e5e
|
4
|
+
data.tar.gz: 663fbab4bc681dd17f29648f3d6c5b2f7bfc92e0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 54e9299eb4e31417d53101dc926b1032858e1bc00fd14482d8ae639a16be08c0463c5cd4fc9fd1b62baad750e8d975db915e99b9d89799351bf7fc7b464a96db
|
7
|
+
data.tar.gz: 98196d4eebec118009777f3d8857e1adbd4986ceaa9d7da8f475fed6548159a214cadbfc319a9fbc5c87e4a5147d25c7633293df8068b8cba08e10d213120685
|
data/README.md
CHANGED
@@ -1,12 +1,17 @@
|
|
1
1
|
# tagmanager-rails
|
2
2
|
|
3
|
-
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/tagmanager-rails.png)](http://badge.fury.io/rb/tagmanager-rails)
|
4
|
+
[![Dependency Status](https://gemnasium.com/tmaier/tagmanager-rails.png)](https://gemnasium.com/tmaier/tagmanager-rails)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/tmaier/tagmanager-rails.png)](https://codeclimate.com/github/tmaier/tagmanager-rails)
|
6
|
+
|
7
|
+
This gem provides [Tag Manager][] for Rails asset pipeline.
|
4
8
|
|
5
9
|
It includes the CSS; SCSS and LESS version of the stylesheet.
|
6
10
|
|
7
11
|
## Version
|
8
12
|
|
9
|
-
|
13
|
+
Tag Manager version 2.4.2
|
14
|
+
[8d91c8683546409ab9ec459456f12afa1a0a870f](https://github.com/max-favilli/tagmanager/commit/8d91c8683546409ab9ec459456f12afa1a0a870f)
|
10
15
|
|
11
16
|
## Installation
|
12
17
|
|
@@ -61,7 +66,9 @@ Feel free to open an issue ticket if you find something that could be improved.
|
|
61
66
|
|
62
67
|
## Acknowledgements
|
63
68
|
|
64
|
-
Many thanks to [max-favilli](https://github.com/max-favilli) for [Tag Manager]
|
69
|
+
Many thanks to [max-favilli](https://github.com/max-favilli) for [Tag Manager][] and all Rails committer for Rails.
|
65
70
|
|
66
71
|
Copyright [Tobias L. Maier](http://tobiasmaier.info), released under the MIT License.
|
67
72
|
Tag Manager itself is under Mozilla Public License. See [license.txt](https://github.com/max-favilli/tagmanager/blob/master/license.txt) of the project.
|
73
|
+
|
74
|
+
[Tag Manager]: https://github.com/max-favilli/tagmanager
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/* ===================================================
|
2
|
-
* bootstrap-tagmanager.js v2.
|
2
|
+
* bootstrap-tagmanager.js v2.4.2
|
3
3
|
* http://welldonethings.com/tags/manager
|
4
4
|
* ===================================================
|
5
5
|
* Copyright 2012 Max Favilli
|
@@ -15,35 +15,39 @@
|
|
15
15
|
* limitations under the License.
|
16
16
|
* ========================================================== */
|
17
17
|
|
18
|
-
|
18
|
+
(function($){
|
19
|
+
|
20
|
+
"use strict";
|
19
21
|
|
20
|
-
(function (jQuery) {
|
21
22
|
if (typeof console === "undefined" || typeof console.log === "undefined") {
|
22
23
|
console = {};
|
23
24
|
console.log = function () { };
|
24
25
|
}
|
25
26
|
|
26
|
-
|
27
|
+
$.fn.tagsManager = function (options,tagToManipulate) {
|
27
28
|
var tagManagerOptions = {
|
28
29
|
prefilled: null,
|
29
30
|
CapitalizeFirstLetter: false,
|
30
|
-
preventSubmitOnEnter: true,
|
31
|
-
isClearInputOnEsc: true,
|
31
|
+
preventSubmitOnEnter: true, // deprecated
|
32
|
+
isClearInputOnEsc: true, // deprecated
|
32
33
|
typeahead: false,
|
34
|
+
typeaheadAjaxMethod: "POST",
|
33
35
|
typeaheadAjaxSource: null,
|
34
36
|
typeaheadAjaxPolling: false,
|
35
37
|
typeaheadOverrides: null,
|
38
|
+
typeaheadDelegate: {},
|
36
39
|
typeaheadSource: null,
|
37
40
|
AjaxPush: null,
|
38
41
|
AjaxPushAllTags: null,
|
39
|
-
|
42
|
+
AjaxPushParameters: null,
|
43
|
+
delimiters: [9,13,44], // tab, enter, comma
|
40
44
|
backspace: [8],
|
41
45
|
maxTags: 0,
|
42
46
|
hiddenTagListName: null,
|
43
47
|
hiddenTagListId: null,
|
44
|
-
deleteTagsOnBackspace: true,
|
48
|
+
deleteTagsOnBackspace: true, // deprecated
|
45
49
|
tagsContainer: null,
|
46
|
-
tagCloseIcon: '
|
50
|
+
tagCloseIcon: '×',
|
47
51
|
tagClass: '',
|
48
52
|
validator: null,
|
49
53
|
onlyTagList: false
|
@@ -54,8 +58,8 @@
|
|
54
58
|
this.instanceSelectHandler = null;
|
55
59
|
this.selectedClass = "selected";
|
56
60
|
this.select = null;
|
57
|
-
if ("typeahead" in
|
58
|
-
this.instanceSelectHandler =
|
61
|
+
if ("typeahead" in $.fn) {
|
62
|
+
this.instanceSelectHandler = $.fn.typeahead.Constructor.prototype.select;
|
59
63
|
this.select = function (overrides) {
|
60
64
|
this.$menu.find(".active").addClass(overrides.selectedClass);
|
61
65
|
overrides.instanceSelectHandler.apply(this, arguments);
|
@@ -72,7 +76,7 @@
|
|
72
76
|
|
73
77
|
tagManagerOptions.typeaheadOverrides = new TypeaheadOverrides();
|
74
78
|
|
75
|
-
|
79
|
+
$.extend(tagManagerOptions, options);
|
76
80
|
|
77
81
|
if (tagManagerOptions.hiddenTagListName === null) {
|
78
82
|
tagManagerOptions.hiddenTagListName = "hidden-" + this.attr('name');
|
@@ -80,27 +84,43 @@
|
|
80
84
|
|
81
85
|
var obj = this;
|
82
86
|
var objName = obj.attr('name').replace(/[^\w]/g, '_');
|
83
|
-
var
|
84
|
-
|
87
|
+
var delimiters = tagManagerOptions.delimeters || tagManagerOptions.delimiters; // 'delimeter' is deprecated
|
88
|
+
// delimiter values to be handled as key codes
|
89
|
+
var keyNums = [9,13,17,18,19,37,38,39,40];
|
90
|
+
var delimiterChars = [], delimiterKeys = [];
|
91
|
+
$.each(delimiters, function(i,v){
|
92
|
+
if ( $.inArray(v, keyNums) != -1 ){
|
93
|
+
delimiterKeys.push(v);
|
94
|
+
} else {
|
95
|
+
delimiterChars.push(v);
|
96
|
+
}
|
97
|
+
});
|
98
|
+
var baseDelimiter = String.fromCharCode(delimiterChars[0] || 44);
|
85
99
|
var backspace = tagManagerOptions.backspace;
|
86
|
-
var
|
100
|
+
var tagBaseClass = 'tm-tag';
|
101
|
+
var inputBaseClass = 'tm-input';
|
102
|
+
|
103
|
+
if ($.isFunction(tagManagerOptions.validator)) obj.data('validator', tagManagerOptions.validator);
|
87
104
|
|
88
105
|
var setupTypeahead = function () {
|
89
106
|
if (!obj.typeahead) return;
|
90
107
|
|
91
|
-
|
92
|
-
|
108
|
+
var taOpts = tagManagerOptions.typeaheadDelegate;
|
109
|
+
|
110
|
+
if (tagManagerOptions.typeaheadSource != null && $.isFunction(tagManagerOptions.typeaheadSource)) {
|
111
|
+
$.extend(taOpts, { source: tagManagerOptions.typeaheadSource });
|
112
|
+
obj.typeahead(taOpts);
|
93
113
|
} else if (tagManagerOptions.typeaheadSource != null) {
|
94
|
-
obj.typeahead();
|
114
|
+
obj.typeahead(taOpts);
|
95
115
|
setTypeaheadSource(tagManagerOptions.typeaheadSource);
|
96
116
|
} else if (tagManagerOptions.typeaheadAjaxSource != null) {
|
97
117
|
if (!tagManagerOptions.typeaheadAjaxPolling) {
|
98
|
-
obj.typeahead();
|
118
|
+
obj.typeahead(taOpts);
|
99
119
|
|
100
120
|
if (typeof (tagManagerOptions.typeaheadAjaxSource) == "string") {
|
101
|
-
|
121
|
+
$.ajax({
|
102
122
|
cache: false,
|
103
|
-
type:
|
123
|
+
type: tagManagerOptions.typeaheadAjaxMethod,
|
104
124
|
contentType: "application/json",
|
105
125
|
dataType: "json",
|
106
126
|
url: tagManagerOptions.typeaheadAjaxSource,
|
@@ -109,18 +129,17 @@
|
|
109
129
|
});
|
110
130
|
}
|
111
131
|
} else if (tagManagerOptions.typeaheadAjaxPolling) {
|
112
|
-
|
132
|
+
$.extend(taOpts, { source: ajaxPolling });
|
133
|
+
obj.typeahead(taOpts);
|
113
134
|
}
|
114
|
-
} else if (tagManagerOptions.typeaheadDelegate) {
|
115
|
-
obj.typeahead(tagManagerOptions.typeaheadDelegate);
|
116
135
|
}
|
117
136
|
|
118
137
|
var data = obj.data('typeahead');
|
119
138
|
if (data) {
|
120
139
|
// set the overrided handler
|
121
|
-
data.select =
|
122
|
-
|
123
|
-
|
140
|
+
data.select = $.proxy(tagManagerOptions.typeaheadOverrides.select,
|
141
|
+
obj.data('typeahead'),
|
142
|
+
tagManagerOptions.typeaheadOverrides);
|
124
143
|
}
|
125
144
|
};
|
126
145
|
|
@@ -133,14 +152,14 @@
|
|
133
152
|
if (data && data.tags) {
|
134
153
|
var sourceAjaxArray = [];
|
135
154
|
sourceAjaxArray.length = 0;
|
136
|
-
|
155
|
+
$.each(data.tags, function (key, val) {
|
137
156
|
sourceAjaxArray.push(val.tag);
|
138
157
|
if (isSetTypeaheadSource) {
|
139
158
|
setTypeaheadSource(sourceAjaxArray);
|
140
159
|
}
|
141
160
|
});
|
142
161
|
|
143
|
-
if (
|
162
|
+
if ($.isFunction(process)) {
|
144
163
|
process(sourceAjaxArray);
|
145
164
|
}
|
146
165
|
}
|
@@ -149,12 +168,23 @@
|
|
149
168
|
var setTypeaheadSource = function (source) {
|
150
169
|
obj.data('active', true);
|
151
170
|
obj.data('typeahead').source = source;
|
171
|
+
tagManagerOptions.typeaheadSource = source;
|
152
172
|
obj.data('active', false);
|
153
173
|
};
|
154
174
|
|
175
|
+
var typeaheadSelectedItem = function () {
|
176
|
+
var listItemSelector = '.' + tagManagerOptions.typeaheadOverrides.selectedClass;
|
177
|
+
var typeahead_data = obj.data('typeahead');
|
178
|
+
return typeahead_data ? typeahead_data.$menu.find(listItemSelector) : undefined;
|
179
|
+
};
|
180
|
+
|
181
|
+
var typeaheadVisible = function () {
|
182
|
+
return $('.typeahead:visible')[0];
|
183
|
+
};
|
184
|
+
|
155
185
|
var ajaxPolling = function (query, process) {
|
156
186
|
if (typeof (tagManagerOptions.typeaheadAjaxSource) == "string") {
|
157
|
-
|
187
|
+
$.ajax({
|
158
188
|
cache: false,
|
159
189
|
type: "POST",
|
160
190
|
contentType: "application/json",
|
@@ -166,29 +196,30 @@
|
|
166
196
|
}
|
167
197
|
};
|
168
198
|
|
169
|
-
var
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
199
|
+
var tagClasses = function () {
|
200
|
+
// 1) default class (tm-tag)
|
201
|
+
var cl = tagBaseClass;
|
202
|
+
// 2) interpolate from input class: tm-input-xxx --> tm-tag-xxx
|
203
|
+
if (obj.attr('class')) {
|
204
|
+
$.each(obj.attr('class').split(' '), function(index, value) {
|
205
|
+
if (value.indexOf(inputBaseClass+'-') != -1){
|
206
|
+
cl += ' ' + tagBaseClass + value.substring(inputBaseClass.length);
|
207
|
+
}
|
208
|
+
});
|
178
209
|
}
|
210
|
+
// 3) tags from tagClass option
|
211
|
+
cl += (tagManagerOptions.tagClass ? ' ' + tagManagerOptions.tagClass : '');
|
212
|
+
return cl;
|
213
|
+
};
|
179
214
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
if (-1 == jQuery.inArray(txt.charCodeAt(i), delimeters)) break;
|
187
|
-
t++;
|
215
|
+
var trimTag = function (tag) {
|
216
|
+
tag = $.trim(tag);
|
217
|
+
// truncate at the first delimiter char
|
218
|
+
var i = 0;
|
219
|
+
for (i; i < tag.length; i++) {
|
220
|
+
if ($.inArray(tag.charCodeAt(i), delimiterChars) != -1) break;
|
188
221
|
}
|
189
|
-
|
190
|
-
txt = txt.substring(t, l);
|
191
|
-
return txt;
|
222
|
+
return tag.substring(0, i);
|
192
223
|
};
|
193
224
|
|
194
225
|
var popTag = function () {
|
@@ -199,7 +230,7 @@
|
|
199
230
|
var tagId = tlid.pop();
|
200
231
|
tlis.pop();
|
201
232
|
// console.log("TagIdToRemove: " + tagId);
|
202
|
-
|
233
|
+
$("#" + objName + "_" + tagId).remove();
|
203
234
|
refreshHiddenTagList();
|
204
235
|
// console.log(tlis);
|
205
236
|
}
|
@@ -213,7 +244,7 @@
|
|
213
244
|
var tagId = tlid.pop();
|
214
245
|
tlis.pop();
|
215
246
|
// console.log("TagIdToRemove: " + tagId);
|
216
|
-
|
247
|
+
$("#" + objName + "_" + tagId).remove();
|
217
248
|
refreshHiddenTagList();
|
218
249
|
// console.log(tlis);
|
219
250
|
}
|
@@ -223,10 +254,10 @@
|
|
223
254
|
var tlis = obj.data("tlis");
|
224
255
|
var lhiddenTagList = obj.data("lhiddenTagList");
|
225
256
|
|
226
|
-
obj.trigger('tags:refresh', tlis.join(
|
257
|
+
obj.trigger('tags:refresh', tlis.join(baseDelimiter));
|
227
258
|
|
228
259
|
if (lhiddenTagList) {
|
229
|
-
|
260
|
+
$(lhiddenTagList).val(tlis.join(baseDelimiter)).change();
|
230
261
|
}
|
231
262
|
};
|
232
263
|
|
@@ -234,13 +265,13 @@
|
|
234
265
|
var tlis = obj.data("tlis");
|
235
266
|
var tlid = obj.data("tlid");
|
236
267
|
|
237
|
-
var p =
|
268
|
+
var p = $.inArray(tagId, tlid);
|
238
269
|
|
239
270
|
// console.log("TagIdToRemove: " + tagId);
|
240
271
|
// console.log("position: " + p);
|
241
272
|
|
242
273
|
if (-1 != p) {
|
243
|
-
|
274
|
+
$("#" + objName + "_" + tagId).remove();
|
244
275
|
tlis.splice(p, 1);
|
245
276
|
tlid.splice(p, 1);
|
246
277
|
refreshHiddenTagList();
|
@@ -254,19 +285,22 @@
|
|
254
285
|
|
255
286
|
var pushAllTags = function (e, tagstring) {
|
256
287
|
if (tagManagerOptions.AjaxPushAllTags) {
|
257
|
-
|
288
|
+
$.post(tagManagerOptions.AjaxPush, { tags: tagstring });
|
258
289
|
}
|
259
290
|
};
|
260
291
|
|
261
|
-
var pushTag = function (tag
|
262
|
-
|
292
|
+
var pushTag = function (tag) {
|
293
|
+
tag = trimTag(tag);
|
263
294
|
|
264
|
-
if(
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
295
|
+
if (!tag || tag.length <= 0) return;
|
296
|
+
|
297
|
+
if (tagManagerOptions.typeaheadSource != null)
|
298
|
+
{
|
299
|
+
var source = $.isFunction(tagManagerOptions.typeaheadSource) ?
|
300
|
+
tagManagerOptions.typeaheadSource() : tagManagerOptions.typeaheadSource;
|
301
|
+
|
302
|
+
if(tagManagerOptions.onlyTagList &&
|
303
|
+
$.inArray(tag, source) == -1) return;
|
270
304
|
}
|
271
305
|
|
272
306
|
if (tagManagerOptions.CapitalizeFirstLetter && tag.length > 1) {
|
@@ -274,9 +308,7 @@
|
|
274
308
|
}
|
275
309
|
|
276
310
|
// call the validator (if any) and do not let the tag pass if invalid
|
277
|
-
if (
|
278
|
-
if (!tagManagerOptions.validator(tag)) return;
|
279
|
-
}
|
311
|
+
if (obj.data('validator') && !obj.data('validator')(tag)) return;
|
280
312
|
|
281
313
|
var tlis = obj.data("tlis");
|
282
314
|
var tlid = obj.data("tlid");
|
@@ -286,7 +318,7 @@
|
|
286
318
|
|
287
319
|
var alreadyInList = false;
|
288
320
|
var tlisLowerCase = tlis.map(function(elem) { return elem.toLowerCase(); });
|
289
|
-
var p =
|
321
|
+
var p = $.inArray(tag.toLowerCase(), tlisLowerCase);
|
290
322
|
if (-1 != p) {
|
291
323
|
// console.log("tag:" + tag + " !!already in list!!");
|
292
324
|
alreadyInList = true;
|
@@ -294,13 +326,13 @@
|
|
294
326
|
|
295
327
|
if (alreadyInList) {
|
296
328
|
var pTagId = tlid[p];
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
329
|
+
$("#" + objName + "_" + pTagId).stop()
|
330
|
+
.animate({ backgroundColor: tagManagerOptions.blinkBGColor_1 }, 100)
|
331
|
+
.animate({ backgroundColor: tagManagerOptions.blinkBGColor_2 }, 100)
|
332
|
+
.animate({ backgroundColor: tagManagerOptions.blinkBGColor_1 }, 100)
|
333
|
+
.animate({ backgroundColor: tagManagerOptions.blinkBGColor_2 }, 100)
|
334
|
+
.animate({ backgroundColor: tagManagerOptions.blinkBGColor_1 }, 100)
|
335
|
+
.animate({ backgroundColor: tagManagerOptions.blinkBGColor_2 }, 100);
|
304
336
|
} else {
|
305
337
|
var max = Math.max.apply(null, tlid);
|
306
338
|
max = max == -Infinity ? 0 : max;
|
@@ -310,26 +342,30 @@
|
|
310
342
|
tlid.push(tagId);
|
311
343
|
|
312
344
|
if (tagManagerOptions.AjaxPush != null) {
|
313
|
-
|
345
|
+
$.post(tagManagerOptions.AjaxPush, $.extend({ tag: tag }, tagManagerOptions.AjaxPushParameters));
|
314
346
|
}
|
315
347
|
|
316
348
|
// console.log("tagList: " + tlis);
|
317
349
|
|
318
350
|
var newTagId = objName + '_' + tagId;
|
319
351
|
var newTagRemoveId = objName + '_Remover_' + tagId;
|
320
|
-
var
|
321
|
-
|
322
|
-
html
|
352
|
+
var escaped = $("<span></span>").text(tag).html();
|
353
|
+
|
354
|
+
var html = '<span class="' + tagClasses() + '" id="' + newTagId + '">';
|
355
|
+
html += '<span>' + escaped + '</span>';
|
356
|
+
html += '<a href="#" class="tm-tag-remove" id="' + newTagRemoveId + '" TagIdToRemove="' + tagId + '">';
|
357
|
+
html += tagManagerOptions.tagCloseIcon + '</a></span> ';
|
358
|
+
var $el = $(html);
|
323
359
|
|
324
360
|
if (tagManagerOptions.tagsContainer != null) {
|
325
|
-
|
361
|
+
$(tagManagerOptions.tagsContainer).append($el);
|
326
362
|
} else {
|
327
|
-
obj.before(
|
363
|
+
obj.before($el);
|
328
364
|
}
|
329
365
|
|
330
|
-
|
366
|
+
$el.find("#" + newTagRemoveId).on("click", obj, function (e) {
|
331
367
|
e.preventDefault();
|
332
|
-
var TagIdToRemove = parseInt(
|
368
|
+
var TagIdToRemove = parseInt($(this).attr("TagIdToRemove"));
|
333
369
|
spliceTag(TagIdToRemove, e.data);
|
334
370
|
});
|
335
371
|
|
@@ -342,20 +378,33 @@
|
|
342
378
|
obj.val("");
|
343
379
|
};
|
344
380
|
|
345
|
-
var
|
346
|
-
|
347
|
-
|
348
|
-
}
|
381
|
+
var prefill = function (pta) {
|
382
|
+
$.each(pta, function (key, val) {
|
383
|
+
pushTag(val);
|
384
|
+
});
|
349
385
|
};
|
350
386
|
|
351
|
-
|
352
|
-
|
353
|
-
|
387
|
+
var killEvent = function (e) {
|
388
|
+
e.cancelBubble = true;
|
389
|
+
e.returnValue = false;
|
390
|
+
e.stopPropagation();
|
391
|
+
e.preventDefault();
|
392
|
+
};
|
354
393
|
|
355
|
-
|
394
|
+
var keyInArray = function (e, ary) {
|
395
|
+
return $.inArray(e.which, ary) != -1
|
396
|
+
};
|
356
397
|
|
357
|
-
|
358
|
-
var
|
398
|
+
var applyDelimiter = function (e) {
|
399
|
+
var taItem = typeaheadSelectedItem();
|
400
|
+
var taVisible = typeaheadVisible();
|
401
|
+
if (!(e.which==13 && taItem && taVisible)) {
|
402
|
+
pushTag(obj.val());
|
403
|
+
}
|
404
|
+
e.preventDefault();
|
405
|
+
};
|
406
|
+
|
407
|
+
return this.each(function () {
|
359
408
|
|
360
409
|
if (typeof options == 'string') {
|
361
410
|
switch (options) {
|
@@ -366,13 +415,17 @@
|
|
366
415
|
popTag();
|
367
416
|
break;
|
368
417
|
case "pushTag":
|
369
|
-
pushTag(tagToManipulate
|
418
|
+
pushTag(tagToManipulate);
|
370
419
|
break;
|
371
420
|
}
|
372
421
|
return;
|
373
422
|
}
|
374
423
|
|
375
|
-
//
|
424
|
+
// prevent double-initialization of TagManager
|
425
|
+
if ($(this).data('tagManager')){ return false; }
|
426
|
+
$(this).data('tagManager', true);
|
427
|
+
|
428
|
+
// store instance-specific data in the DOM object
|
376
429
|
var tlis = new Array();
|
377
430
|
var tlid = new Array();
|
378
431
|
obj.data("tlis", tlis); //list of string tags
|
@@ -388,213 +441,103 @@
|
|
388
441
|
html += "<input name='" + tagManagerOptions.hiddenTagListName + "' type='hidden' value=''/>";
|
389
442
|
obj.after(html);
|
390
443
|
obj.data("lhiddenTagList",
|
391
|
-
|
444
|
+
obj.siblings("input[name='" + tagManagerOptions.hiddenTagListName + "']")[0]
|
392
445
|
);
|
393
446
|
} else {
|
394
|
-
obj.data("lhiddenTagList",
|
447
|
+
obj.data("lhiddenTagList", $('#' + tagManagerOptions.hiddenTagListId))
|
395
448
|
}
|
396
449
|
|
397
450
|
if (tagManagerOptions.typeahead) {
|
398
451
|
setupTypeahead();
|
399
|
-
//obj.typeahead({ source: SourceArray })
|
400
452
|
}
|
401
453
|
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
454
|
+
if (tagManagerOptions.AjaxPushAllTags) {
|
455
|
+
obj.on('tags:refresh', pushAllTags);
|
456
|
+
}
|
457
|
+
|
458
|
+
// hide popovers on focus and keypress events
|
459
|
+
obj.on('focus keypress', function (e) {
|
460
|
+
if ($(this).popover) {
|
461
|
+
$(this).popover('hide');
|
406
462
|
}
|
407
463
|
});
|
408
464
|
|
409
|
-
//
|
465
|
+
// handle ESC (keyup used for browser compatibility)
|
410
466
|
if (tagManagerOptions.isClearInputOnEsc) {
|
411
|
-
obj.on(
|
467
|
+
obj.on('keyup', function (e) {
|
412
468
|
if (e.which == 27) {
|
413
|
-
|
414
|
-
|
415
|
-
e
|
416
|
-
e.stopPropagation();
|
417
|
-
e.preventDefault();
|
418
|
-
return false;
|
469
|
+
// console.log('esc detected');
|
470
|
+
$(this).val('');
|
471
|
+
killEvent(e);
|
419
472
|
}
|
420
473
|
});
|
421
474
|
}
|
422
475
|
|
423
|
-
|
424
|
-
|
425
|
-
if (
|
426
|
-
|
427
|
-
//jQuery(this).popover = null;
|
476
|
+
obj.on('keypress', function (e) {
|
477
|
+
// push ASCII-based delimiters
|
478
|
+
if (keyInArray(e, delimiterChars)) {
|
479
|
+
applyDelimiter(e);
|
428
480
|
}
|
481
|
+
});
|
429
482
|
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
e
|
435
|
-
e.preventDefault();
|
436
|
-
//e.keyCode = 9;
|
437
|
-
return false;
|
483
|
+
obj.on('keydown', function (e) {
|
484
|
+
// disable ENTER
|
485
|
+
if (e.which == 13) {
|
486
|
+
if (tagManagerOptions.preventSubmitOnEnter) {
|
487
|
+
killEvent(e);
|
438
488
|
}
|
439
489
|
}
|
440
490
|
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
//user just entered a valid delimeter
|
445
|
-
tagIsValid = true;
|
446
|
-
var user_input = jQuery(this).val(); //user_input = jQuery().inArray(delimeters[p]);
|
447
|
-
user_input = trimTag(user_input);
|
448
|
-
pushTag(user_input, e.data, tagIsValid);
|
449
|
-
e.preventDefault();
|
450
|
-
// console.log("pushTag: keypress");
|
491
|
+
// push key-based delimiters (includes <enter> by default)
|
492
|
+
if (keyInArray(e, delimiterKeys)) {
|
493
|
+
applyDelimiter(e);
|
451
494
|
}
|
452
|
-
else {
|
453
|
-
tagIsValid = false;
|
454
|
-
}
|
455
|
-
|
456
|
-
// console.log("keypress: " + e.which);
|
457
495
|
});
|
458
496
|
|
497
|
+
// BACKSPACE (keydown used for browser compatibility)
|
459
498
|
if (tagManagerOptions.deleteTagsOnBackspace) {
|
460
|
-
obj.on(
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
var user_input = jQuery(this).val(); //user_input = jQuery().inArray(delimeters[p]);
|
465
|
-
var i = user_input.length;
|
466
|
-
if (i <= 0) {
|
467
|
-
// console.log("backspace detected");
|
468
|
-
e.preventDefault();
|
499
|
+
obj.on('keydown', function (e) {
|
500
|
+
if (keyInArray(e, backspace)) {
|
501
|
+
// console.log("backspace detected");
|
502
|
+
if ($(this).val().length <= 0) {
|
469
503
|
popTag();
|
504
|
+
killEvent(e);
|
470
505
|
}
|
471
506
|
}
|
472
507
|
});
|
473
508
|
}
|
474
509
|
|
475
510
|
obj.change(function (e) {
|
476
|
-
e.cancelBubble = true;
|
477
|
-
e.returnValue = false;
|
478
|
-
e.stopPropagation();
|
479
|
-
e.preventDefault();
|
480
|
-
|
481
|
-
var selectedItemClass = tagManagerOptions.typeaheadOverrides.selectedClass;
|
482
|
-
var listItemSelector = '.' + selectedItemClass;
|
483
|
-
|
484
|
-
// check the typeahead list selection
|
485
|
-
var data = $(this).data('typeahead');
|
486
|
-
if (data) {
|
487
|
-
isSelectedFromList = $(this).data('typeahead').$menu.find("*")
|
488
|
-
.filter(listItemSelector)
|
489
|
-
.hasClass(selectedItemClass);
|
490
|
-
|
491
|
-
if (isSelectedFromList) {
|
492
|
-
tagIsValid = true;
|
493
|
-
}
|
494
|
-
}
|
495
511
|
|
496
|
-
if (
|
497
|
-
return false;
|
498
|
-
}
|
512
|
+
if (!/webkit/.test(navigator.userAgent.toLowerCase())) { $(this).focus(); } // why?
|
499
513
|
|
500
|
-
var
|
501
|
-
var
|
502
|
-
var is_firefox = navigator.userAgent.indexOf('Firefox') > -1;
|
503
|
-
var is_safari = navigator.userAgent.indexOf("Safari") > -1;
|
504
|
-
|
505
|
-
if (!is_chrome && !is_safari)
|
506
|
-
jQuery(this).focus();
|
507
|
-
|
508
|
-
// console.log('Handler for .change() called, value selected:' + obj.val());
|
509
|
-
var ao = jQuery(".typeahead:visible");
|
510
|
-
if (ao[0] != undefined) {
|
511
|
-
// console.log('change: typeaheadIsVisible is visible');
|
512
|
-
//when the user click with the mouse on the typeahead li element we get the change event fired twice, once when the input field loose focus and later with the input field value is replaced with li value
|
513
|
-
|
514
|
-
var isClear = !isSelectedFromList;
|
515
|
-
|
516
|
-
if (isSelectedFromList) {
|
517
|
-
// if user selected from list
|
518
|
-
var user_input = $(this).data('typeahead').$menu.find(listItemSelector).attr('data-value');
|
519
|
-
user_input = trimTag(user_input);
|
520
|
-
if (queuedTag == jQuery(this).val() && queuedTag == user_input) {
|
521
|
-
isClear = true;
|
522
|
-
} else {
|
523
|
-
pushTag(user_input, null, true);
|
524
|
-
queuedTag = user_input;
|
525
|
-
// console.log('Handler for .change() called, typeahead value pushed:' + queuedTag);
|
526
|
-
}
|
527
|
-
isSelectedFromList = false;
|
528
|
-
$(this).data('typeahead').$menu.find(listItemSelector).removeClass(selectedItemClass);
|
529
|
-
}
|
514
|
+
var taItem = typeaheadSelectedItem();
|
515
|
+
var taVisible = typeaheadVisible();
|
530
516
|
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
} else {
|
536
|
-
// console.log('change: typeaheadIsVisible is NOT visible');
|
537
|
-
var user_input = jQuery(this).val(); //user_input = jQuery().inArray(delimeters[p]);
|
538
|
-
user_input = trimTag(user_input);
|
539
|
-
pushTag(user_input, null, true);
|
540
|
-
// console.log("pushTag: change ");
|
517
|
+
if (taItem && taVisible) {
|
518
|
+
taItem.removeClass(tagManagerOptions.typeaheadOverrides.selectedClass);
|
519
|
+
pushTag(taItem.attr('data-value'));
|
520
|
+
// console.log('change: pushTypeAheadTag ' + tag);
|
541
521
|
}
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
522
|
+
/* unimplemented mode to push tag on blur
|
523
|
+
else if (tagManagerOptions.pushTagOnBlur) {
|
524
|
+
console.log('change: pushTagOnBlur ' + tag);
|
525
|
+
pushTag($(this).val());
|
526
|
+
} */
|
527
|
+
killEvent(e);
|
546
528
|
});
|
547
529
|
|
548
|
-
if (1 == 1 || !tagManagerOptions.typeahead) {
|
549
|
-
obj.on("blur", function (e) {
|
550
|
-
//lost focus
|
551
|
-
e.cancelBubble = true;
|
552
|
-
e.returnValue = false;
|
553
|
-
e.stopPropagation();
|
554
|
-
e.preventDefault();
|
555
|
-
|
556
|
-
var push = true;
|
557
|
-
if (tagManagerOptions.typeahead) {
|
558
|
-
var ao = jQuery(".typeahead:visible");
|
559
|
-
if (ao[0] != undefined) {
|
560
|
-
// console.log('blur: typeaheadIsVisible is visible');
|
561
|
-
push = false;
|
562
|
-
} else {
|
563
|
-
// console.log('blur: typeaheadIsVisible is NOT visible');
|
564
|
-
push = true;
|
565
|
-
}
|
566
|
-
}
|
567
|
-
|
568
|
-
if (push) {
|
569
|
-
// console.log('lost focus');
|
570
|
-
var user_input = jQuery(this).val(); //user_input = jQuery().inArray(delimeters[p]);
|
571
|
-
user_input = trimTag(user_input);
|
572
|
-
pushTag(user_input, null, tagIsValid);
|
573
|
-
// console.log("pushTag: blur");
|
574
|
-
}
|
575
|
-
|
576
|
-
return false;
|
577
|
-
});
|
578
|
-
}
|
579
|
-
|
580
530
|
if (tagManagerOptions.prefilled != null) {
|
581
531
|
if (typeof (tagManagerOptions.prefilled) == "object") {
|
582
|
-
|
583
|
-
jQuery.each(pta, function (key, val) {
|
584
|
-
var a = 1;
|
585
|
-
pushTag(val, obj, true);
|
586
|
-
});
|
532
|
+
prefill(tagManagerOptions.prefilled);
|
587
533
|
} else if (typeof (tagManagerOptions.prefilled) == "string") {
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
var a = 1;
|
592
|
-
pushTag(val, obj, true);
|
593
|
-
});
|
594
|
-
|
534
|
+
prefill(tagManagerOptions.prefilled.split(baseDelimiter));
|
535
|
+
} else if (typeof (tagManagerOptions.prefilled) == "function") {
|
536
|
+
prefill(tagManagerOptions.prefilled());
|
595
537
|
}
|
538
|
+
} else if (tagManagerOptions.hiddenTagListId != null) {
|
539
|
+
prefill($('#' + tagManagerOptions.hiddenTagListId).val().split(baseDelimiter));
|
596
540
|
}
|
597
541
|
});
|
598
|
-
|
599
542
|
}
|
600
543
|
})(jQuery);
|