Skip to content

Commit 22edd91

Browse files
Cleaned up tagClick.
1 parent eb605c0 commit 22edd91

File tree

3 files changed

+53
-66
lines changed

3 files changed

+53
-66
lines changed

src/js/textext.core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,7 @@
10781078
p.getFormData = function(keyCode)
10791079
{
10801080
var self = this,
1081-
data = self.getWeightedEventResponse(EVENT_GET_FORM_DATA, keyCode)
1081+
data = self.getWeightedEventResponse(EVENT_GET_FORM_DATA, keyCode || 0)
10821082
;
10831083

10841084
self.trigger(EVENT_SET_FORM_DATA , data['form']);

src/js/textext.plugin.autocomplete.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@
720720
* @author agorbatchev
721721
* @date 2011/12/27
722722
* @id TextExtAutocomplete.onToggleDropdown
723-
* @version 1.1
723+
* @version 1.1.0
724724
*/
725725
p.onToggleDropdown = function(e)
726726
{
@@ -1099,6 +1099,7 @@
10991099
* @param element {HTMLElement} element to check if contained by wrap element
11001100
*
11011101
* @author adamayres
1102+
* @version 1.3.0
11021103
* @date 2012/01/15
11031104
* @id TextExtAutocomplete.withinWrapElement
11041105
*/

src/js/textext.plugin.tags.js

Lines changed: 50 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
CSS_DOT_TAG = CSS_DOT + CSS_TAG,
3333
CSS_TAGS = 'text-tags',
3434
CSS_DOT_TAGS = CSS_DOT + CSS_TAGS,
35+
CSS_LABEL = 'text-label',
36+
CSS_DOT_LABEL = CSS_DOT + CSS_LABEL,
37+
CSS_REMOVE = 'text-remove',
38+
CSS_DOT_REMOVE = CSS_DOT + CSS_REMOVE,
3539

3640
/**
3741
* Tags plugin options are grouped under `tags` when passed to the
@@ -124,6 +128,35 @@
124128
*/
125129
EVENT_IS_TAG_ALLOWED = 'isTagAllowed',
126130

131+
/**
132+
* Tags plugin triggers the `tagClick` event when user clicks on one of the tags. This allows to process
133+
* the click and potentially change the value of the tag (for example in case of user feedback).
134+
*
135+
* $('textarea').textext({...}).bind('tagClick', function(e, tag, value, callback)
136+
* {
137+
* var newValue = window.prompt('New value', value);
138+
139+
* if(newValue)
140+
* callback(newValue, true);
141+
* })
142+
*
143+
* Callback argument has the following signature:
144+
*
145+
* function(newValue, refocus)
146+
* {
147+
* ...
148+
* }
149+
*
150+
* Please check out [example](/manual/examples/tags-changing.html).
151+
*
152+
* @name tagClick
153+
* @version 1.3.0
154+
* @author s.stok
155+
* @date 2011/01/23
156+
* @id TextExtTags.events.tagClick
157+
*/
158+
EVENT_TAG_CLICK = 'tagClick',
159+
127160
DEFAULT_OPTS = {
128161
tags : {
129162
enabled : true,
@@ -169,7 +202,6 @@
169202
backspaceKeyDown : self.onBackspaceKeyDown,
170203
preInvalidate : self.onPreInvalidate,
171204
postInit : self.onPostInit,
172-
tagClick : self.onTagClick,
173205
getFormData : self.onGetFormData
174206
});
175207

@@ -380,88 +412,42 @@
380412
p.onClick = function(e)
381413
{
382414
var self = this,
415+
core = self.core(),
383416
source = $(e.target),
384417
focus = 0,
385-
tag ;
418+
tag
419+
;
386420

387421
if(source.is(CSS_DOT_TAGS))
388422
{
389423
focus = 1;
390424
}
391-
else if(source.is('.text-remove'))
425+
else if(source.is(CSS_DOT_REMOVE))
392426
{
393427
self.removeTag(source.parents(CSS_DOT_TAG + ':first'));
394428
focus = 1;
395429
}
396-
else if(source.is('.text-label'))
430+
else if(source.is(CSS_DOT_LABEL))
397431
{
398432
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-
*/
433+
self.trigger(EVENT_TAG_CLICK, tag, tag.data(CSS_TAG), tagClickCallback);
415434
}
416435

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;
436+
function tagClickCallback(newValue, refocus)
437+
{
438+
tag.data(CSS_TAG, newValue);
439+
tag.find(CSS_DOT_LABEL).text(self.itemManager().itemToString(newValue));
456440

457-
currentTag = currentTag || self.currentTag;
458-
currentTag.find('.text-label').text(self.itemManager().itemToString(currentTag.data(CSS_TAG)));
441+
self.updateFormCache();
442+
core.getFormData();
443+
core.invalidateBounds();
459444

460-
self.core().getFormData();
461-
self.core().invalidateBounds();
445+
if(refocus)
446+
core.focusInput();
447+
}
462448

463449
if(focus)
464-
self.core().focusInput();
450+
core.focusInput();
465451
};
466452

467453
/**

0 commit comments

Comments
 (0)