tagmanager-rails 3.0.0.1 → 3.0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 814e9b4d63f24450ab85b78b1e8415db69b9e01a
4
- data.tar.gz: 141890592431f65f5cf57a3672b17054dbee2e29
3
+ metadata.gz: 8376edc06658ca89c30cb25df5e179ff217df718
4
+ data.tar.gz: 92c8a624b33c5e91b7a56c77719cf3004ac4c9f9
5
5
  SHA512:
6
- metadata.gz: 1496a74c15890004eccb237675c05653a811773e195ad58c68c1d7c832a1717c71b107f1ee76de88ffa120f619e837c965285e4163073f6eb949e04d8ede74ea
7
- data.tar.gz: 8ee74c3565337c1988da4c550458d2d96e920e57669753744aea8fab863ad68b829f80b6fca8066fccf2b0968fba15d4f107a2e5eb6d779db08b349ed15bcf0f
6
+ metadata.gz: e03c4cf6438a365b28914210cbe5c44c21109823eba37b29a12e32461e6c37b07f158288bab23d1a0c12c9578a2caae39fb80894fd03ee5c69a9f91d63872dc9
7
+ data.tar.gz: 758e40bb6a0e8c6bbad9975d95079b1593c606a265a5b290ccbd3140e854dd8ace6944a7f8d7b882de4616c4551ab8b10c086b72a07ee7ad53bb923bc2f47dda
data/README.md CHANGED
@@ -10,8 +10,8 @@ It includes the CSS; SCSS and LESS version of the stylesheet.
10
10
 
11
11
  ## Version
12
12
 
13
- Tag Manager version 3.0.0
14
- [3088482a18c776ed55ff685abedfed28d476b807](https://github.com/max-favilli/tagmanager/commit/3088482a18c776ed55ff685abedfed28d476b807)
13
+ Tag Manager version 3.0.1
14
+ [e71e5e3991cd30a9ad93c3cf879279602e68a85e](https://github.com/max-favilli/tagmanager/commit/e71e5e3991cd30a9ad93c3cf879279602e68a85e)
15
15
 
16
16
  ## Installation
17
17
 
@@ -1,6 +1,6 @@
1
1
  module TagManager
2
2
  module Rails
3
- VERSION = '3.0.0.1'
4
- TAGMANAGER_VERSION = '3088482a18c776ed55ff685abedfed28d476b807'
3
+ VERSION = '3.0.1.0'
4
+ TAGMANAGER_VERSION = 'e71e5e3991cd30a9ad93c3cf879279602e68a85e'
5
5
  end
6
6
  end
@@ -1,5 +1,5 @@
1
1
  /* ===================================================
2
- * tagmanager.js v3.0.0
2
+ * tagmanager.js v3.0.1
3
3
  * http://welldonethings.com/tags/manager
4
4
  * ===================================================
5
5
  * Copyright 2012 Max Favilli
@@ -14,488 +14,468 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  * ========================================================== */
17
+ (function($) {
18
+
19
+ "use strict";
20
+
21
+ var defaults = {
22
+ prefilled: null,
23
+ CapitalizeFirstLetter: false,
24
+ preventSubmitOnEnter: true, // deprecated
25
+ isClearInputOnEsc: true, // deprecated
26
+ AjaxPush: null,
27
+ AjaxPushAllTags: null,
28
+ AjaxPushParameters: null,
29
+ delimiters: [9, 13, 44], // tab, enter, comma
30
+ backspace: [8],
31
+ maxTags: 0,
32
+ hiddenTagListName: null, // deprecated
33
+ hiddenTagListId: null, // deprecated
34
+ replace: true,
35
+ output: null,
36
+ deleteTagsOnBackspace: true, // deprecated
37
+ tagsContainer: null,
38
+ tagCloseIcon: 'x',
39
+ tagClass: '',
40
+ validator: null,
41
+ onlyTagList: false,
42
+ tagList: null,
43
+ },
44
+
45
+ publicMethods = {
46
+ pushTag : function (tag, ignoreEvents) {
47
+ var $self = $(this), opts = $self.data('opts'), alreadyInList, tlisLowerCase, max, tagId,
48
+ tlis = $self.data("tlis"), tlid = $self.data("tlid"), idx, newTagId, newTagRemoveId, escaped,
49
+ html, $el, lastTagId, lastTagObj;
50
+
51
+ tag = privateMethods.trimTag(tag, opts.delimiterChars);
52
+
53
+ if (!tag || tag.length <= 0) { return; }
54
+
55
+ // check if restricted only to the tagList suggestions
56
+ if (opts.onlyTagList && undefined !== opts.tagList ){
57
+
58
+ //if the list has been updated by look pushed tag in the tagList. if not found return
59
+ if (opts.tagList){
60
+ var $tagList = opts.tagList;
61
+
62
+ // change each array item to lower case
63
+ $.each($tagList, function(index, item) {
64
+ $tagList[index] = item.toLowerCase();
65
+ });
66
+ var suggestion = $.inArray(tag.toLowerCase(), $tagList);
67
+
68
+ if ( -1 === suggestion ) {
69
+ //console.log("tag:" + tag + " not in tagList, not adding it");
70
+ return;
71
+ }
72
+ }
17
73
 
18
- (function ($) {
19
-
20
- "use strict";
21
-
22
- if (typeof console === "undefined" || typeof console.log === "undefined") {
23
- console = {};
24
- console.log = function () { };
25
- }
26
-
27
- $.fn.tagsManager = function (options, tagToManipulate) {
28
- var obj = this;
29
- var rndid = "";
30
-
31
- var tagManagerOptions = {
32
- prefilled: null,
33
- CapitalizeFirstLetter: false,
34
- preventSubmitOnEnter: true, // deprecated
35
- isClearInputOnEsc: true, // deprecated
36
- AjaxPush: null,
37
- AjaxPushAllTags: null,
38
- AjaxPushParameters: null,
39
- delimiters: [9, 13, 44], // tab, enter, comma
40
- backspace: [8],
41
- maxTags: 0,
42
- hiddenTagListName: null, // deprecated
43
- hiddenTagListId: null, // deprecated
44
- replace: true,
45
- output: null,
46
- deleteTagsOnBackspace: true, // deprecated
47
- tagsContainer: null,
48
- tagCloseIcon: 'x',
49
- tagClass: '',
50
- validator: null,
51
- onlyTagList: false
52
- };
53
-
54
- // exit when no matched elements
55
- if (!(0 in this)) {
56
- return this;
57
- }
58
-
59
- if (typeof options == 'string') {
60
- tagManagerOptions = obj.data("tm_options");
61
- } else {
62
- $.extend(tagManagerOptions, options);
63
- obj.data("tm_options", tagManagerOptions);
64
- }
65
-
66
- if (typeof options == 'string') {
67
- rndid = obj.data("tm_rndid");
68
- } else {
69
- var albet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
70
- for (var i = 0; i < 5; i++)
71
- rndid += albet.charAt(Math.floor(Math.random() * albet.length));
72
- obj.data("tm_rndid", rndid);
73
- }
74
-
75
- if (tagManagerOptions.replace === true && tagManagerOptions.hiddenTagListName === null) {
76
- var original_name = obj.attr('name');
77
- tagManagerOptions.hiddenTagListName = original_name;
78
- obj.attr('name', "display-" + rndid);
79
- }
80
- if (tagManagerOptions.hiddenTagListName === null) {
81
- tagManagerOptions.hiddenTagListName = "hidden-" + rndid;
82
- }
83
-
84
- var delimiters = tagManagerOptions.delimeters || tagManagerOptions.delimiters; // 'delimeter' is deprecated
85
- // delimiter values to be handled as key codes
86
- var keyNums = [9, 13, 17, 18, 19, 37, 38, 39, 40];
87
- var delimiterChars = [], delimiterKeys = [];
88
- $.each(delimiters, function (i, v) {
89
- if ($.inArray(v, keyNums) != -1) {
90
- delimiterKeys.push(v);
91
- } else {
92
- delimiterChars.push(v);
93
- }
94
- });
95
- var baseDelimiter = String.fromCharCode(delimiterChars[0] || 44);
96
- var backspace = tagManagerOptions.backspace;
97
- var tagBaseClass = 'tm-tag';
98
- var inputBaseClass = 'tm-input';
99
-
100
- if ($.isFunction(tagManagerOptions.validator)) obj.data('validator', tagManagerOptions.validator);
101
-
102
-
103
- //var ajaxPolling = function (query, process) {
104
- // if (typeof (tagManagerOptions.typeaheadAjaxSource) == "string") {
105
- // $.ajax({
106
- // cache: false,
107
- // type: "POST",
108
- // contentType: "application/json",
109
- // dataType: "json",
110
- // url: tagManagerOptions.typeaheadAjaxSource,
111
- // data: JSON.stringify({ typeahead: query }),
112
- // success: function (data) { onTypeaheadAjaxSuccess(data, false, process); }
113
- // });
114
- // }
115
- //};
116
-
117
-
118
- var tagClasses = function () {
119
- // 1) default class (tm-tag)
120
- var cl = tagBaseClass;
121
- // 2) interpolate from input class: tm-input-xxx --> tm-tag-xxx
122
- if (obj.attr('class')) {
123
- $.each(obj.attr('class').split(' '), function (index, value) {
124
- if (value.indexOf(inputBaseClass + '-') != -1) {
125
- cl += ' ' + tagBaseClass + value.substring(inputBaseClass.length);
126
- }
127
- });
128
- }
129
- // 3) tags from tagClass option
130
- cl += (tagManagerOptions.tagClass ? ' ' + tagManagerOptions.tagClass : '');
131
- return cl;
132
- };
133
-
134
- var trimTag = function (tag) {
135
- tag = $.trim(tag);
136
- // truncate at the first delimiter char
137
- var i = 0;
138
- for (i; i < tag.length; i++) {
139
- if ($.inArray(tag.charCodeAt(i), delimiterChars) != -1) break;
140
- }
141
- return tag.substring(0, i);
142
- };
143
-
144
- var showOrHide = function () {
145
- var tlis = obj.data("tlis");
146
- if (tagManagerOptions.maxTags > 0 && tlis.length < tagManagerOptions.maxTags) {
147
- obj.show();
148
- obj.trigger('tm:show');
149
- }
150
- if (tagManagerOptions.maxTags > 0 && tlis.length >= tagManagerOptions.maxTags) {
151
- obj.hide();
152
- obj.trigger('tm:hide');
153
- }
154
- };
155
-
156
- var popTag = function () {
157
- var tlis = obj.data("tlis");
158
- var tlid = obj.data("tlid");
159
-
160
- if (tlid.length > 0) {
161
- var tagId = tlid.pop();
162
-
163
- var tagBeingRemoved = tlis[tlis.length - 1];
164
- obj.trigger('tm:popping', tagBeingRemoved);
165
- tlis.pop();
166
-
167
- // console.log("TagIdToRemove: " + tagId);
168
- $("#" + rndid + "_" + tagId).remove();
169
- refreshHiddenTagList();
170
- obj.trigger('tm:popped', tagBeingRemoved);
171
- // console.log(tlis);
172
- }
74
+ }
173
75
 
174
- showOrHide();
175
- //if (tagManagerOptions.maxTags > 0 && tlis.length < tagManagerOptions.maxTags) {
176
- // obj.show();
177
- //}
178
- };
76
+ if (opts.CapitalizeFirstLetter && tag.length > 1) {
77
+ tag = tag.charAt(0).toUpperCase() + tag.slice(1).toLowerCase();
78
+ }
179
79
 
180
- var empty = function () {
181
- var tlis = obj.data("tlis");
182
- var tlid = obj.data("tlid");
183
-
184
- while (tlid.length > 0) {
185
- var tagId = tlid.pop();
186
- tlis.pop();
187
- // console.log("TagIdToRemove: " + tagId);
188
- $("#" + rndid + "_" + tagId).remove();
189
- refreshHiddenTagList();
190
- // console.log(tlis);
191
- }
192
- obj.trigger('tm:emptied', null);
193
-
194
- showOrHide();
195
- //if (tagManagerOptions.maxTags > 0 && tlis.length < tagManagerOptions.maxTags) {
196
- // obj.show();
197
- //}
198
- };
80
+ // call the validator (if any) and do not let the tag pass if invalid
81
+ if (opts.validator && !opts.validator(tag)) { return; }
199
82
 
200
- var refreshHiddenTagList = function () {
201
- var tlis = obj.data("tlis");
202
- var lhiddenTagList = obj.data("lhiddenTagList");
83
+ // dont accept new tags beyond the defined maximum
84
+ if (opts.maxTags > 0 && tlis.length >= opts.maxTags) { return; }
203
85
 
204
- if (lhiddenTagList) {
205
- $(lhiddenTagList).val(tlis.join(baseDelimiter)).change();
206
- }
86
+ alreadyInList = false;
87
+ //use jQuery.map to make this work in IE8 (pure JS map is JS 1.6 but IE8 only supports JS 1.5)
88
+ tlisLowerCase = jQuery.map(tlis, function(elem) {
89
+ return elem.toLowerCase();
90
+ });
207
91
 
208
- obj.trigger('tm:refresh', tlis.join(baseDelimiter));
209
- };
92
+ idx = $.inArray(tag.toLowerCase(), tlisLowerCase);
210
93
 
211
- var spliceTag = function (tagId) {
212
- var tlis = obj.data("tlis");
213
- var tlid = obj.data("tlid");
94
+ if (-1 !== idx) {
95
+ // console.log("tag:" + tag + " !!already in list!!");
96
+ alreadyInList = true;
97
+ }
214
98
 
215
- var p = $.inArray(tagId, tlid);
99
+ if (alreadyInList) {
100
+ $self.trigger('tm:duplicated', tag);
101
+ $("#" + $self.data("tm_rndid") + "_" + tlid[idx]).stop()
102
+ .animate({backgroundColor: opts.blinkBGColor_1}, 100)
103
+ .animate({backgroundColor: opts.blinkBGColor_2}, 100)
104
+ .animate({backgroundColor: opts.blinkBGColor_1}, 100)
105
+ .animate({backgroundColor: opts.blinkBGColor_2}, 100)
106
+ .animate({backgroundColor: opts.blinkBGColor_1}, 100)
107
+ .animate({backgroundColor: opts.blinkBGColor_2}, 100);
108
+ } else {
109
+ if (!ignoreEvents) { $self.trigger('tm:pushing', tag); }
110
+
111
+ max = Math.max.apply(null, tlid);
112
+ max = max === -Infinity ? 0 : max;
113
+
114
+ tagId = ++max;
115
+ tlis.push(tag);
116
+ tlid.push(tagId);
117
+
118
+ if (!ignoreEvents)
119
+ if (opts.AjaxPush !== null && opts.AjaxPushAllTags == null) {
120
+ if ($.inArray(tag, opts.prefilled) === -1) {
121
+ $.post(opts.AjaxPush, $.extend({tag: tag}, opts.AjaxPushParameters));
122
+ }
123
+ }
124
+
125
+ // console.log("tagList: " + tlis);
126
+
127
+ newTagId = $self.data("tm_rndid") + '_' + tagId;
128
+ newTagRemoveId = $self.data("tm_rndid") + '_Remover_' + tagId;
129
+ escaped = $("<span/>").text(tag).html();
130
+
131
+ html = '<span class="' + privateMethods.tagClasses.call($self) + '" id="' + newTagId + '">';
132
+ html+= '<span>' + escaped + '</span>';
133
+ html+= '<a href="#" class="tm-tag-remove" id="' + newTagRemoveId + '" TagIdToRemove="' + tagId + '">';
134
+ html+= opts.tagCloseIcon + '</a></span> ';
135
+ $el = $(html);
136
+
137
+ if (opts.tagsContainer !== null) {
138
+ $(opts.tagsContainer).append($el);
139
+ } else {
140
+ if (tagId > 1) {
141
+ lastTagId = tagId - 1;
142
+ lastTagObj = $("#" + $self.data("tm_rndid") + "_" + lastTagId);
143
+ lastTagObj.after($el);
144
+ } else {
145
+ $self.before($el);
146
+ }
147
+ }
148
+
149
+ $el.find("#" + newTagRemoveId).on("click", $self, function(e) {
150
+ e.preventDefault();
151
+ var TagIdToRemove = parseInt($(this).attr("TagIdToRemove"));
152
+ privateMethods.spliceTag.call($self, TagIdToRemove, e.data);
153
+ });
154
+
155
+ privateMethods.refreshHiddenTagList.call($self);
156
+
157
+ if (!ignoreEvents) { $self.trigger('tm:pushed', tag); }
158
+
159
+ privateMethods.showOrHide.call($self);
160
+ //if (tagManagerOptions.maxTags > 0 && tlis.length >= tagManagerOptions.maxTags) {
161
+ // obj.hide();
162
+ //}
163
+ }
164
+ $self.val("");
165
+ },
166
+
167
+ popTag : function () {
168
+ var $self = $(this), tagId, tagBeingRemoved,
169
+ tlis = $self.data("tlis"),
170
+ tlid = $self.data("tlid");
171
+
172
+ if (tlid.length > 0) {
173
+ tagId = tlid.pop();
174
+
175
+ tagBeingRemoved = tlis[tlis.length - 1];
176
+ $self.trigger('tm:popping', tagBeingRemoved);
177
+ tlis.pop();
178
+
179
+ // console.log("TagIdToRemove: " + tagId);
180
+ $("#" + $self.data("tm_rndid") + "_" + tagId).remove();
181
+ privateMethods.refreshHiddenTagList.call($self);
182
+ $self.trigger('tm:popped', tagBeingRemoved);
183
+ // console.log(tlis);
184
+ }
185
+ },
186
+
187
+ empty : function() {
188
+ var $self = $(this), tlis = $self.data("tlis"), tlid = $self.data("tlid"), tagId;
189
+
190
+ while (tlid.length > 0) {
191
+ tagId = tlid.pop();
192
+ tlis.pop();
193
+ // console.log("TagIdToRemove: " + tagId);
194
+ $("#" + $self.data("tm_rndid") + "_" + tagId).remove();
195
+ privateMethods.refreshHiddenTagList.call($self);
196
+ // console.log(tlis);
197
+ }
198
+ $self.trigger('tm:emptied', null);
216
199
 
217
- // console.log("TagIdToRemove: " + tagId);
218
- // console.log("position: " + p);
200
+ privateMethods.showOrHide.call($self);
201
+ //if (tagManagerOptions.maxTags > 0 && tlis.length < tagManagerOptions.maxTags) {
202
+ // obj.show();
203
+ //}
204
+ },
219
205
 
220
- if (-1 != p) {
221
- var tagBeingRemoved = tlis[p];
206
+ tags : function() {
207
+ var $self = this, tlis = $self.data("tlis");
208
+ return tlis;
209
+ }
210
+ },
222
211
 
223
- obj.trigger('tm:splicing', tagBeingRemoved);
212
+ privateMethods = {
213
+ showOrHide : function () {
214
+ var $self = this, opts = $self.data('opts'), tlis = $self.data("tlis");
224
215
 
225
- $("#" + rndid + "_" + tagId).remove();
226
- tlis.splice(p, 1);
227
- tlid.splice(p, 1);
228
- refreshHiddenTagList();
216
+ if (opts.maxTags > 0 && tlis.length < opts.maxTags) {
217
+ $self.show();
218
+ $self.trigger('tm:show');
219
+ }
229
220
 
230
- obj.trigger('tm:spliced', tagBeingRemoved);
221
+ if (opts.maxTags > 0 && tlis.length >= opts.maxTags) {
222
+ $self.hide();
223
+ $self.trigger('tm:hide');
224
+ }
225
+ },
226
+
227
+ tagClasses : function () {
228
+ var $self = $(this), opts = $self.data('opts'), tagBaseClass = opts.tagBaseClass,
229
+ inputBaseClass = opts.inputBaseClass, cl;
230
+ // 1) default class (tm-tag)
231
+ cl = tagBaseClass;
232
+ // 2) interpolate from input class: tm-input-xxx --> tm-tag-xxx
233
+ if ($self.attr('class')) {
234
+ $.each($self.attr('class').split(' '), function (index, value) {
235
+ if (value.indexOf(inputBaseClass + '-') !== -1) {
236
+ cl += ' ' + tagBaseClass + value.substring(inputBaseClass.length);
237
+ }
238
+ });
239
+ }
240
+ // 3) tags from tagClass option
241
+ cl += (opts.tagClass ? ' ' + opts.tagClass : '');
242
+ return cl;
243
+ },
244
+
245
+ trimTag : function (tag, delimiterChars) {
246
+ var i;
247
+ tag = $.trim(tag);
248
+ // truncate at the first delimiter char
249
+ i = 0;
250
+ for (i; i < tag.length; i++) {
251
+ if ($.inArray(tag.charCodeAt(i), delimiterChars) !== -1) { break; }
252
+ }
253
+ return tag.substring(0, i);
254
+ },
231
255
 
232
- // console.log(tlis);
233
- }
256
+ refreshHiddenTagList : function () {
257
+ var $self = $(this), tlis = $self.data("tlis"), lhiddenTagList = $self.data("lhiddenTagList");
234
258
 
259
+ if (lhiddenTagList) {
260
+ $(lhiddenTagList).val(tlis.join($self.data('opts').baseDelimiter)).change();
261
+ }
235
262
 
236
- showOrHide();
237
- //if (tagManagerOptions.maxTags > 0 && tlis.length < tagManagerOptions.maxTags) {
238
- // obj.show();
239
- //}
240
- };
263
+ $self.trigger('tm:refresh', tlis.join($self.data('opts').baseDelimiter));
264
+ },
265
+
266
+ killEvent : function (e) {
267
+ e.cancelBubble = true;
268
+ e.returnValue = false;
269
+ e.stopPropagation();
270
+ e.preventDefault();
271
+ },
272
+
273
+ keyInArray : function (e, ary) {
274
+ return $.inArray(e.which, ary) !== -1;
275
+ },
276
+
277
+ applyDelimiter : function (e) {
278
+ var $self = $(this);
279
+ publicMethods.pushTag.call($self,$(this).val());
280
+ e.preventDefault();
281
+ },
282
+
283
+ prefill : function (pta) {
284
+ var $self = $(this);
285
+ $.each(pta, function (key, val) {
286
+ publicMethods.pushTag.call($self, val, true);
287
+ });
288
+ },
289
+
290
+ pushAllTags : function (e, tag) {
291
+ var $self = $(this), opts = $self.data('opts'), tlis = $self.data("tlis");
292
+ if (opts.AjaxPushAllTags) {
293
+ if (e.type !== 'tm:pushed' || $.inArray(tag, opts.prefilled) === -1) {
294
+ $.post(opts.AjaxPush, $.extend({ tags: tlis.join(opts.baseDelimiter) }, opts.AjaxPushParameters));
295
+ }
296
+ }
297
+ },
298
+
299
+ spliceTag : function (tagId) {
300
+ var $self = this, tlis = $self.data("tlis"), tlid = $self.data("tlid"), idx = $.inArray(tagId, tlid),
301
+ tagBeingRemoved;
302
+
303
+ // console.log("TagIdToRemove: " + tagId);
304
+ // console.log("position: " + idx);
305
+
306
+ if (-1 !== idx) {
307
+ tagBeingRemoved = tlis[idx];
308
+ $self.trigger('tm:splicing', tagBeingRemoved);
309
+ $("#" + $self.data("tm_rndid") + "_" + tagId).remove();
310
+ tlis.splice(idx, 1);
311
+ tlid.splice(idx, 1);
312
+ privateMethods.refreshHiddenTagList.call($self);
313
+ $self.trigger('tm:spliced', tagBeingRemoved);
314
+ // console.log(tlis);
315
+ }
241
316
 
242
- var pushAllTags = function (e, tag) {
243
- if (tagManagerOptions.AjaxPushAllTags) {
244
- if (e.type != 'tm:pushed' || $.inArray(tag, tagManagerOptions.prefilled) == -1) {
245
- var tlis = obj.data("tlis");
246
- $.post(tagManagerOptions.AjaxPush, { tags: tlis.join(baseDelimiter) });
317
+ privateMethods.showOrHide.call($self);
318
+ //if (tagManagerOptions.maxTags > 0 && tlis.length < tagManagerOptions.maxTags) {
319
+ // obj.show();
320
+ //}
321
+ },
322
+
323
+ init : function (options) {
324
+ var opts = $.extend({}, defaults, options), delimiters, keyNums;
325
+
326
+ opts.hiddenTagListName = (opts.hiddenTagListName === null)
327
+ ? 'hidden-' + this.attr('name')
328
+ : opts.hiddenTagListName;
329
+
330
+ delimiters = opts.delimeters || opts.delimiters; // 'delimeter' is deprecated
331
+ keyNums = [9, 13, 17, 18, 19, 37, 38, 39, 40]; // delimiter values to be handled as key codes
332
+ opts.delimiterChars = [];
333
+ opts.delimiterKeys = [];
334
+
335
+ $.each(delimiters, function (i, v) {
336
+ if ($.inArray(v, keyNums) !== -1) {
337
+ opts.delimiterKeys.push(v);
338
+ } else {
339
+ opts.delimiterChars.push(v);
340
+ }
341
+ });
342
+
343
+ opts.baseDelimiter = String.fromCharCode(opts.delimiterChars[0] || 44);
344
+ opts.tagBaseClass = 'tm-tag';
345
+ opts.inputBaseClass = 'tm-input';
346
+
347
+ if (!$.isFunction(opts.validator)) { opts.validator = null; };
348
+
349
+ this.each(function() {
350
+ var $self = $(this), hiddenObj ='', rndid ='', albet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
351
+
352
+ // prevent double-initialization of TagManager
353
+ if ($self.data('tagManager')) { return false; }
354
+ $self.data('tagManager', true);
355
+
356
+ for (var i = 0; i < 5; i++) {
357
+ rndid += albet.charAt(Math.floor(Math.random() * albet.length));
358
+ }
359
+
360
+ $self.data("tm_rndid", rndid);
361
+
362
+ // store instance-specific data in the DOM object
363
+ $self.data('opts',opts)
364
+ .data('tlis', []) //list of string tags
365
+ .data('tlid', []); //list of ID of the string tags
366
+
367
+ if (opts.output === null) {
368
+ hiddenObj = $('<input/>', {
369
+ type: 'hidden',
370
+ name: opts.hiddenTagListName
371
+ });
372
+ $self.after(hiddenObj);
373
+ $self.data("lhiddenTagList", hiddenObj);
374
+ } else {
375
+ $self.data("lhiddenTagList", $(opts.output));
376
+ }
377
+
378
+ if (opts.AjaxPushAllTags) {
379
+ $self.on('tm:spliced', privateMethods.pushAllTags);
380
+ $self.on('tm:popped', privateMethods.pushAllTags);
381
+ $self.on('tm:pushed', privateMethods.pushAllTags);
382
+ }
383
+
384
+ // hide popovers on focus and keypress events
385
+ $self.on('focus keypress', function(e) {
386
+ if ($(this).popover) { $(this).popover('hide'); }
387
+ });
388
+
389
+ // handle ESC (keyup used for browser compatibility)
390
+ if (opts.isClearInputOnEsc) {
391
+ $self.on('keyup', function(e) {
392
+ if (e.which === 27) {
393
+ // console.log('esc detected');
394
+ $(this).val('');
395
+ privateMethods.killEvent(e);
396
+ }
397
+ });
398
+ }
399
+
400
+ $self.on('keypress', function(e) {
401
+ // push ASCII-based delimiters
402
+ if (privateMethods.keyInArray(e, opts.delimiterChars)) {
403
+ privateMethods.applyDelimiter.call($self, e);
404
+ }
405
+ });
406
+
407
+ $self.on('keydown', function(e) {
408
+ // disable ENTER
409
+ if (e.which === 13) {
410
+ if (opts.preventSubmitOnEnter) {
411
+ privateMethods.killEvent(e);
412
+ }
413
+ }
414
+
415
+ // push key-based delimiters (includes <enter> by default)
416
+ if (privateMethods.keyInArray(e, opts.delimiterKeys)) {
417
+ privateMethods.applyDelimiter.call($self, e);
418
+ }
419
+ });
420
+
421
+ // BACKSPACE (keydown used for browser compatibility)
422
+ if (opts.deleteTagsOnBackspace) {
423
+ $self.on('keydown', function(e) {
424
+ if (privateMethods.keyInArray(e, opts.backspace)) {
425
+ // console.log("backspace detected");
426
+ if ($(this).val().length <= 0) {
427
+ publicMethods.popTag.call($self);
428
+ privateMethods.killEvent(e);
429
+ }
430
+ }
431
+ });
432
+ }
433
+
434
+ $self.change(function(e) {
435
+ if (!/webkit/.test(navigator.userAgent.toLowerCase())) {
436
+ $self.focus();
437
+ } // why?
438
+
439
+ /* unimplemented mode to push tag on blur
440
+ else if (tagManagerOptions.pushTagOnBlur) {
441
+ console.log('change: pushTagOnBlur ' + tag);
442
+ pushTag($(this).val());
443
+ } */
444
+ privateMethods.killEvent(e);
445
+ });
446
+
447
+ if (opts.prefilled !== null) {
448
+ if (typeof (opts.prefilled) === "object") {
449
+ privateMethods.prefill.call($self, opts.prefilled);
450
+ } else if (typeof (opts.prefilled) === "string") {
451
+ privateMethods.prefill.call($self, opts.prefilled.split(opts.baseDelimiter));
452
+ } else if (typeof (opts.prefilled) === "function") {
453
+ privateMethods.prefill.call($self, opts.prefilled());
454
+ }
455
+ } else if (opts.output !== null) {
456
+ if ($(opts.output) && $(opts.output).val()) { var existing_tags = $(opts.output); }
457
+ privateMethods.prefill.call($self,$(opts.output).val().split(opts.baseDelimiter));
458
+ }
459
+
460
+ });
461
+
462
+ return this;
247
463
  }
248
- }
249
464
  };
250
465
 
251
- var pushTag = function (tag, ignore_events) {
252
- tag = trimTag(tag);
253
-
254
- if (!tag || tag.length <= 0) return;
255
-
256
- if (tagManagerOptions.CapitalizeFirstLetter && tag.length > 1) {
257
- tag = tag.charAt(0).toUpperCase() + tag.slice(1).toLowerCase();
258
- }
259
-
260
- // call the validator (if any) and do not let the tag pass if invalid
261
- if (obj.data('validator') && !obj.data('validator')(tag)) return;
262
-
263
- var tlis = obj.data("tlis");
264
- var tlid = obj.data("tlid");
265
-
266
- // dont accept new tags beyond the defined maximum
267
- if (tagManagerOptions.maxTags > 0 && tlis.length >= tagManagerOptions.maxTags) return;
268
-
269
- var alreadyInList = false;
270
- var tlisLowerCase = tlis.map(function (elem) { return elem.toLowerCase(); });
271
- var p = $.inArray(tag.toLowerCase(), tlisLowerCase);
272
- if (-1 != p) {
273
- // console.log("tag:" + tag + " !!already in list!!");
274
- alreadyInList = true;
275
- }
276
-
277
- if (alreadyInList) {
278
- var pTagId = tlid[p];
279
- $("#" + rndid + "_" + pTagId).stop()
280
- .animate({ backgroundColor: tagManagerOptions.blinkBGColor_1 }, 100)
281
- .animate({ backgroundColor: tagManagerOptions.blinkBGColor_2 }, 100)
282
- .animate({ backgroundColor: tagManagerOptions.blinkBGColor_1 }, 100)
283
- .animate({ backgroundColor: tagManagerOptions.blinkBGColor_2 }, 100)
284
- .animate({ backgroundColor: tagManagerOptions.blinkBGColor_1 }, 100)
285
- .animate({ backgroundColor: tagManagerOptions.blinkBGColor_2 }, 100);
286
- } else {
287
- if(!ignore_events)
288
- obj.trigger('tm:pushing', tag);
289
-
290
- var max = Math.max.apply(null, tlid);
291
- max = max == -Infinity ? 0 : max;
292
-
293
- var tagId = ++max;
294
- tlis.push(tag);
295
- tlid.push(tagId);
296
-
297
- if (!ignore_events)
298
- if (tagManagerOptions.AjaxPush != null) {
299
- if ($.inArray(tag, tagManagerOptions.prefilled) == -1) {
300
- $.post(tagManagerOptions.AjaxPush, $.extend({ tag: tag }, tagManagerOptions.AjaxPushParameters));
301
- }
302
- }
466
+ $.fn.tagsManager = function(method) {
467
+ var $self = $(this);
303
468
 
304
- // console.log("tagList: " + tlis);
469
+ if (!(0 in this)) { return this; }
305
470
 
306
- var newTagId = rndid + '_' + tagId;
307
- var newTagRemoveId = rndid + '_Remover_' + tagId;
308
- var escaped = $("<span></span>").text(tag).html();
309
-
310
- var html = '<span class="' + tagClasses() + '" id="' + newTagId + '">';
311
- html += '<span>' + escaped + '</span>';
312
- html += '<a href="#" class="tm-tag-remove" id="' + newTagRemoveId + '" TagIdToRemove="' + tagId + '">';
313
- html += tagManagerOptions.tagCloseIcon + '</a></span> ';
314
- var $el = $(html);
315
-
316
- if (tagManagerOptions.tagsContainer != null) {
317
- $(tagManagerOptions.tagsContainer).append($el);
471
+ if ( publicMethods[method] ) {
472
+ return publicMethods[method].apply( $self, Array.prototype.slice.call(arguments, 1) );
473
+ } else if ( typeof method === 'object' || ! method ) {
474
+ return privateMethods.init.apply( this, arguments );
318
475
  } else {
319
- if (tagId > 1) {
320
- var lastTagId = tagId - 1;
321
- var lastTagObj = $("#" + rndid + "_" + lastTagId);
322
- lastTagObj.after($el);
323
- } else {
324
- obj.before($el);
325
- }
476
+ $.error( 'Method ' + method + ' does not exist.' );
477
+ return false;
326
478
  }
327
-
328
- $el.find("#" + newTagRemoveId).on("click", obj, function (e) {
329
- e.preventDefault();
330
- var TagIdToRemove = parseInt($(this).attr("TagIdToRemove"));
331
- spliceTag(TagIdToRemove, e.data);
332
- });
333
-
334
- refreshHiddenTagList();
335
-
336
- if (!ignore_events)
337
- obj.trigger('tm:pushed', tag);
338
-
339
- showOrHide();
340
- //if (tagManagerOptions.maxTags > 0 && tlis.length >= tagManagerOptions.maxTags) {
341
- // obj.hide();
342
- //}
343
- }
344
- obj.val("");
345
- };
346
-
347
- var prefill = function (pta) {
348
- $.each(pta, function (key, val) {
349
- pushTag(val,true);
350
- });
351
- };
352
-
353
- var killEvent = function (e) {
354
- e.cancelBubble = true;
355
- e.returnValue = false;
356
- e.stopPropagation();
357
- e.preventDefault();
358
- };
359
-
360
- var keyInArray = function (e, ary) {
361
- return $.inArray(e.which, ary) != -1
362
479
  };
363
480
 
364
- var applyDelimiter = function (e) {
365
- pushTag(obj.val());
366
- e.preventDefault();
367
- };
368
-
369
- var returnValue = null;
370
- this.each(function () {
371
-
372
- if (typeof options == 'string') {
373
- switch (options) {
374
- case "empty":
375
- empty();
376
- break;
377
- case "popTag":
378
- popTag();
379
- break;
380
- case "pushTag":
381
- pushTag(tagToManipulate);
382
- break;
383
- case "tags":
384
- returnValue = { tags: obj.data("tlis") };
385
- break;
386
- }
387
- return;
388
- }
389
-
390
- // prevent double-initialization of TagManager
391
- if ($(this).data('tagManager')) { return false; }
392
- $(this).data('tagManager', true);
393
-
394
- // store instance-specific data in the DOM object
395
- var tlis = new Array();
396
- var tlid = new Array();
397
- obj.data("tlis", tlis); //list of string tags
398
- obj.data("tlid", tlid); //list of ID of the string tags
399
-
400
- if (tagManagerOptions.output == null) {
401
- var hiddenObj = jQuery('<input/>', {
402
- type: 'hidden',
403
- name: tagManagerOptions.hiddenTagListName
404
- });
405
- obj.after(hiddenObj);
406
- obj.data("lhiddenTagList", hiddenObj);
407
- } else {
408
- obj.data("lhiddenTagList", jQuery(tagManagerOptions.output))
409
- }
410
-
411
- if (tagManagerOptions.AjaxPushAllTags) {
412
- obj.on('tm:spliced', pushAllTags);
413
- obj.on('tm:popped', pushAllTags);
414
- obj.on('tm:pushed', pushAllTags);
415
- }
416
-
417
- // hide popovers on focus and keypress events
418
- obj.on('focus keypress', function (e) {
419
- if ($(this).popover) {
420
- $(this).popover('hide');
421
- }
422
- });
423
-
424
- // handle ESC (keyup used for browser compatibility)
425
- if (tagManagerOptions.isClearInputOnEsc) {
426
- obj.on('keyup', function (e) {
427
- if (e.which == 27) {
428
- // console.log('esc detected');
429
- $(this).val('');
430
- killEvent(e);
431
- }
432
- });
433
- }
434
-
435
- obj.on('keypress', function (e) {
436
- // push ASCII-based delimiters
437
- if (keyInArray(e, delimiterChars)) {
438
- applyDelimiter(e);
439
- }
440
- });
441
-
442
- obj.on('keydown', function (e) {
443
- // disable ENTER
444
- if (e.which == 13) {
445
- if (tagManagerOptions.preventSubmitOnEnter) {
446
- killEvent(e);
447
- }
448
- }
449
-
450
- // push key-based delimiters (includes <enter> by default)
451
- if (keyInArray(e, delimiterKeys)) {
452
- applyDelimiter(e);
453
- }
454
- });
455
-
456
- // BACKSPACE (keydown used for browser compatibility)
457
- if (tagManagerOptions.deleteTagsOnBackspace) {
458
- obj.on('keydown', function (e) {
459
- if (keyInArray(e, backspace)) {
460
- // console.log("backspace detected");
461
- if ($(this).val().length <= 0) {
462
- popTag();
463
- killEvent(e);
464
- }
465
- }
466
- });
467
- }
468
-
469
- obj.change(function (e) {
470
-
471
- if (!/webkit/.test(navigator.userAgent.toLowerCase())) { $(this).focus(); } // why?
472
-
473
- /* unimplemented mode to push tag on blur
474
- else if (tagManagerOptions.pushTagOnBlur) {
475
- console.log('change: pushTagOnBlur ' + tag);
476
- pushTag($(this).val());
477
- } */
478
- killEvent(e);
479
- });
480
-
481
- if (tagManagerOptions.prefilled != null) {
482
- if (typeof (tagManagerOptions.prefilled) == "object") {
483
- prefill(tagManagerOptions.prefilled);
484
- } else if (typeof (tagManagerOptions.prefilled) == "string") {
485
- prefill(tagManagerOptions.prefilled.split(baseDelimiter));
486
- } else if (typeof (tagManagerOptions.prefilled) == "function") {
487
- prefill(tagManagerOptions.prefilled());
488
- }
489
- } else if (tagManagerOptions.output != null) {
490
- if (jQuery(tagManagerOptions.output) && jQuery(tagManagerOptions.output).val())
491
- var existing_tags = jQuery(tagManagerOptions.output)
492
- prefill(jQuery(tagManagerOptions.output).val().split(baseDelimiter));
493
- }
494
- });
495
-
496
- if (!returnValue)
497
- returnValue = this;
498
-
499
- return returnValue;
500
- }
501
- })(jQuery);
481
+ }(jQuery));
metadata CHANGED
@@ -1,33 +1,33 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tagmanager-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.1
4
+ version: 3.0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias L. Maier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-15 00:00:00.000000000 Z
11
+ date: 2014-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.0'
20
- - - <
20
+ - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '5.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - '>='
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
29
  version: '3.0'
30
- - - <
30
+ - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '5.0'
33
33
  description: This gem provides Tag Manager for your Rails 3 application.
@@ -37,18 +37,18 @@ executables: []
37
37
  extensions: []
38
38
  extra_rdoc_files: []
39
39
  files:
40
+ - LICENSE
41
+ - README.md
42
+ - Rakefile
43
+ - lib/tag_manager/rails.rb
40
44
  - lib/tag_manager/rails/engine.rb
41
45
  - lib/tag_manager/rails/version.rb
42
- - lib/tag_manager/rails.rb
43
46
  - lib/tagmanager-rails.rb
44
- - vendor/assets/javascripts/tagmanager.js
45
47
  - vendor/assets/LICENSE
48
+ - vendor/assets/javascripts/tagmanager.js
46
49
  - vendor/assets/stylesheets/tagmanager.css
47
50
  - vendor/assets/stylesheets/tagmanager.css.less
48
51
  - vendor/assets/stylesheets/tagmanager.css.scss
49
- - LICENSE
50
- - Rakefile
51
- - README.md
52
52
  homepage: https://github.com/tmaier/tagmanager-rails
53
53
  licenses:
54
54
  - MIT
@@ -59,17 +59,17 @@ require_paths:
59
59
  - lib
60
60
  required_ruby_version: !ruby/object:Gem::Requirement
61
61
  requirements:
62
- - - '>='
62
+ - - ">="
63
63
  - !ruby/object:Gem::Version
64
64
  version: '0'
65
65
  required_rubygems_version: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - '>='
67
+ - - ">="
68
68
  - !ruby/object:Gem::Version
69
69
  version: 1.3.6
70
70
  requirements: []
71
71
  rubyforge_project:
72
- rubygems_version: 2.0.3
72
+ rubygems_version: 2.2.0
73
73
  signing_key:
74
74
  specification_version: 4
75
75
  summary: Use Tag Manager with Rails 3