[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 /** 2 * @copyright (C) 2016 Open Source Matters, Inc. <https://www.joomla.org> 3 * @license GNU General Public License version 2 or later; see LICENSE.txt 4 */ 5 6 /** 7 * Field user 8 */ 9 jQuery(document).ready(function ($) { 10 11 if (Joomla.getOptions('field-tag-custom')) { 12 13 var options = Joomla.getOptions('field-tag-custom'), 14 customTagPrefix = '#new#'; 15 16 // Method to add tags pressing enter 17 $(options.selector + '_chosen input').keyup(function(event) { 18 19 var tagOption; 20 21 // Tag is greater than the minimum required chars and enter pressed 22 if (this.value && this.value.length >= options.minTermLength && (event.which === 13 || event.which === 188)) { 23 24 // Search an highlighted result 25 var highlighted = $(options.selector + '_chosen').find('li.active-result.highlighted').first(); 26 27 // Add the highlighted option 28 if (event.which === 13 && highlighted.text() !== '') 29 { 30 // Extra check. If we have added a custom tag with this text remove it 31 var customOptionValue = customTagPrefix + highlighted.text(); 32 $(options.selector + ' option').filter(function () { return $(this).val() == customOptionValue; }).remove(); 33 34 // Select the highlighted result 35 tagOption = $(options.selector + ' option').filter(function () { return $(this).html() == highlighted.text(); }); 36 tagOption.attr('selected', 'selected'); 37 } 38 // Add the custom tag option 39 else 40 { 41 var customTag = this.value; 42 43 // Extra check. Search if the custom tag already exists (typed faster than AJAX ready) 44 tagOption = $(options.selector + ' option').filter(function () { return $(this).html() == customTag; }); 45 if (tagOption.text() !== '') 46 { 47 tagOption.attr('selected', 'selected'); 48 } 49 else 50 { 51 var option = $('<option>'); 52 option.text(this.value).val(customTagPrefix + this.value); 53 option.attr('selected','selected'); 54 55 // Append the option and repopulate the chosen field 56 $(options.selector).append(option); 57 } 58 } 59 60 this.value = ''; 61 $(options.selector).trigger('chosen:updated'); 62 event.preventDefault(); 63 } 64 }); 65 } 66 });
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |