|
32 | 32 | CSS_DOT_TAG = CSS_DOT + CSS_TAG, |
33 | 33 | CSS_TAGS = 'text-tags', |
34 | 34 | 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, |
35 | 39 |
|
36 | 40 | /** |
37 | 41 | * Tags plugin options are grouped under `tags` when passed to the |
|
124 | 128 | */ |
125 | 129 | EVENT_IS_TAG_ALLOWED = 'isTagAllowed', |
126 | 130 |
|
| 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 | + |
127 | 160 | DEFAULT_OPTS = { |
128 | 161 | tags : { |
129 | 162 | enabled : true, |
|
169 | 202 | backspaceKeyDown : self.onBackspaceKeyDown, |
170 | 203 | preInvalidate : self.onPreInvalidate, |
171 | 204 | postInit : self.onPostInit, |
172 | | - tagClick : self.onTagClick, |
173 | 205 | getFormData : self.onGetFormData |
174 | 206 | }); |
175 | 207 |
|
|
380 | 412 | p.onClick = function(e) |
381 | 413 | { |
382 | 414 | var self = this, |
| 415 | + core = self.core(), |
383 | 416 | source = $(e.target), |
384 | 417 | focus = 0, |
385 | | - tag ; |
| 418 | + tag |
| 419 | + ; |
386 | 420 |
|
387 | 421 | if(source.is(CSS_DOT_TAGS)) |
388 | 422 | { |
389 | 423 | focus = 1; |
390 | 424 | } |
391 | | - else if(source.is('.text-remove')) |
| 425 | + else if(source.is(CSS_DOT_REMOVE)) |
392 | 426 | { |
393 | 427 | self.removeTag(source.parents(CSS_DOT_TAG + ':first')); |
394 | 428 | focus = 1; |
395 | 429 | } |
396 | | - else if(source.is('.text-label')) |
| 430 | + else if(source.is(CSS_DOT_LABEL)) |
397 | 431 | { |
398 | 432 | 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); |
415 | 434 | } |
416 | 435 |
|
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)); |
456 | 440 |
|
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(); |
459 | 444 |
|
460 | | - self.core().getFormData(); |
461 | | - self.core().invalidateBounds(); |
| 445 | + if(refocus) |
| 446 | + core.focusInput(); |
| 447 | + } |
462 | 448 |
|
463 | 449 | if(focus) |
464 | | - self.core().focusInput(); |
| 450 | + core.focusInput(); |
465 | 451 | }; |
466 | 452 |
|
467 | 453 | /** |
|
0 commit comments