Skip to content

Commit eb605c0

Browse files
Merge branch 'master' of git://github.com/sstok/jquery-textext
2 parents 980a374 + 8b3fbcb commit eb605c0

File tree

1 file changed

+84
-17
lines changed

1 file changed

+84
-17
lines changed

src/js/textext.plugin.tags.js

Lines changed: 84 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
(function($)
1010
{
1111
/**
12-
* Tags plugin brings in the traditional tag functionality where user can assemble and
12+
* Tags plugin brings in the traditional tag functionality where user can assemble and
1313
* edit list of tags. Tags plugin works especially well together with Autocomplete, Filter,
14-
* Suggestions and Ajax plugins to provide full spectrum of features. It can also work on
14+
* Suggestions and Ajax plugins to provide full spectrum of features. It can also work on
1515
* its own and just do one thing -- tags.
1616
*
1717
* @author agorbatchev
@@ -34,7 +34,7 @@
3434
CSS_DOT_TAGS = CSS_DOT + CSS_TAGS,
3535

3636
/**
37-
* Tags plugin options are grouped under `tags` when passed to the
37+
* Tags plugin options are grouped under `tags` when passed to the
3838
* `$().textext()` function. For example:
3939
*
4040
* $('textarea').textext({
@@ -73,7 +73,7 @@
7373
* @id TextExtTags.options.tags.items
7474
*/
7575
OPT_ITEMS = 'tags.items',
76-
76+
7777
/**
7878
* HTML source that is used to generate a single tag.
7979
*
@@ -84,7 +84,7 @@
8484
* @id TextExtTags.options.html.tag
8585
*/
8686
OPT_HTML_TAG = 'html.tag',
87-
87+
8888
/**
8989
* HTML source that is used to generate container for the tags.
9090
*
@@ -169,6 +169,7 @@
169169
backspaceKeyDown : self.onBackspaceKeyDown,
170170
preInvalidate : self.onPreInvalidate,
171171
postInit : self.onPostInit,
172+
tagClick : self.onTagClick,
172173
getFormData : self.onGetFormData
173174
});
174175

@@ -182,7 +183,7 @@
182183
});
183184
}
184185

185-
self._originalPadding = {
186+
self._originalPadding = {
186187
left : parseInt(input.css('paddingLeft') || 0),
187188
top : parseInt(input.css('paddingTop') || 0)
188189
};
@@ -211,7 +212,7 @@
211212

212213
//--------------------------------------------------------------------------------
213214
// Event handlers
214-
215+
215216
/**
216217
* Reacts to the `postInit` event triggered by the core and sets default tags
217218
* if any were specified.
@@ -232,7 +233,7 @@
232233

233234
/**
234235
* Reacts to the [`getFormData`][1] event triggered by the core. Returns data with the
235-
* weight of 200 to be *greater than the Autocomplete plugin* data weight. The weights
236+
* weight of 200 to be *greater than the Autocomplete plugin* data weight. The weights
236237
* system is covered in greater detail in the [`getFormData`][1] event documentation.
237238
*
238239
* [1]: /manual/textext.html#getformdata
@@ -312,7 +313,7 @@
312313
};
313314

314315
/**
315-
* Reacts to the `backspaceKeyDown` event. When backspace key is pressed in an empty text field,
316+
* Reacts to the `backspaceKeyDown` event. When backspace key is pressed in an empty text field,
316317
* deletes last tag from the list.
317318
*
318319
* @signature TextExtTags.onBackspaceKeyDown(e)
@@ -336,7 +337,7 @@
336337
/**
337338
* Reacts to the `preInvalidate` event and updates the input box to look like the tags are
338339
* positioned inside it.
339-
*
340+
*
340341
* @signature TextExtTags.onPreInvalidate(e)
341342
*
342343
* @param e {Object} jQuery event.
@@ -351,7 +352,7 @@
351352
lastTag = self.tagElements().last(),
352353
pos = lastTag.position()
353354
;
354-
355+
355356
if(lastTag.length > 0)
356357
pos.left += lastTag.innerWidth();
357358
else
@@ -380,8 +381,8 @@
380381
{
381382
var self = this,
382383
source = $(e.target),
383-
focus = 0
384-
;
384+
focus = 0,
385+
tag ;
385386

386387
if(source.is(CSS_DOT_TAGS))
387388
{
@@ -392,6 +393,72 @@
392393
self.removeTag(source.parents(CSS_DOT_TAG + ':first'));
393394
focus = 1;
394395
}
396+
else if(source.is('.text-label'))
397+
{
398+
tag = source.parents(CSS_DOT_TAG + ':first');
399+
400+
// Store an reference so that when calling the tagUpdate(), we know which tag was clicked originally
401+
self.currentTag = tag;
402+
403+
self.trigger('tagClick', tag.data(CSS_TAG), tag, self);
404+
405+
/*
406+
// Get the current date info
407+
var Data = tag.data(CSS_TAG);
408+
409+
// Update the label, normally this would by is done using an callback
410+
Data.name = 'testing123';
411+
412+
// Update label
413+
tag.find('.text-label').text(self.itemManager().itemToString(Data));
414+
*/
415+
}
416+
417+
if(focus)
418+
self.core().focusInput();
419+
};
420+
421+
/**
422+
* Reacts to the `tagClick` event.
423+
*
424+
* @signature TextExtTags.onTagClick(e, data, tag, self)
425+
*
426+
* @param e {Object} jQuery event.
427+
* @param data {Object} object that the current `ItemManager` can understand.
428+
* Default is `String`.
429+
* @param tag {Object} object reference of the tag element
430+
* @param self {Object} object reference of self
431+
*
432+
* @author s.stok
433+
* @date 2011/01/23
434+
* @id TextExtTags.onTagClick
435+
*/
436+
p.onTagClick = function(e, data, tag, self)
437+
{
438+
};
439+
440+
/**
441+
* Update the FormData cache.
442+
* This would normally be called somewhere in the tagClick event.
443+
*
444+
* @signature TextExtTags.triggerUpdate(Tag, focus)
445+
*
446+
* @param focus {Boolean} force focus on the input-field.
447+
* @param currentTag {Object} tag reference (optional)
448+
*
449+
* @author s.stok
450+
* @date 2011/01/5
451+
* @id TextExtTags.triggerUpdate
452+
*/
453+
p.tagUpdate = function (focus, currentTag)
454+
{
455+
var self = this;
456+
457+
currentTag = currentTag || self.currentTag;
458+
currentTag.find('.text-label').text(self.itemManager().itemToString(currentTag.data(CSS_TAG)));
459+
460+
self.core().getFormData();
461+
self.core().invalidateBounds();
395462

396463
if(focus)
397464
self.core().focusInput();
@@ -458,7 +525,7 @@
458525
* any of the tags, the tags container is sent under the text area. If cursor
459526
* is over any of the tags, the tag container is brought to be over the text
460527
* area.
461-
*
528+
*
462529
* @signature TextExtTags.toggleZIndex(e)
463530
*
464531
* @param e {Object} jQuery event.
@@ -559,7 +626,7 @@
559626
*
560627
* @signature TextExtTags.getTagElement(tag)
561628
*
562-
* @param tag {Object} Tag object in the format that current `ItemManager` can understand.
629+
* @param tag {Object} Tag object in the format that current `ItemManager` can understand.
563630
* Default is `String`.
564631
565632
* @author agorbatchev
@@ -583,7 +650,7 @@
583650
*
584651
* @signature TextExtTags.removeTag(tag)
585652
*
586-
* @param tag {Object} Tag object in the format that current `ItemManager` can understand.
653+
* @param tag {Object} Tag object in the format that current `ItemManager` can understand.
587654
* Default is `String`.
588655
*
589656
* @author agorbatchev
@@ -618,7 +685,7 @@
618685
*
619686
* @signature TextExtTags.renderTag(tag)
620687
*
621-
* @param tag {Object} Tag object in the format that current `ItemManager` can understand.
688+
* @param tag {Object} Tag object in the format that current `ItemManager` can understand.
622689
* Default is `String`.
623690
*
624691
* @author agorbatchev

0 commit comments

Comments
 (0)