1 2 /******************************************************************************* 3 **************** CONTROLLING INDUSTRY TYPES MULTI-SELECT LIST ***************** 4 ********************** created by Lajos Deli ToucanTech ********************* 5 *******************************************************************************/ 6 7 //WHEN DOM is ready 8 $( function() { 9 if ( $(".multilevel-multiselect-group") ) { 10 //If click happened outside the multiselect list, somewhere on the document, then closing multiselect containers 11 $(document).on('click', function(event) { 12 //to avoid firing events multiple times 13 event.stopPropagation(); 14 15 //Just if the div.multilevel-multiselect-group is really in the DOM (can be loaded into the DOM later) 16 if ( $(".multilevel-multiselect-group")[0] ) { 17 //close industries_list div if click event happened outside of the div 18 jQuery.each( $('.multilevel-multiselect-group'), function() { 19 var $list_container = $(this).find('ul.multilevel-container'); 20 if ( $list_container.is(":visible") ) { 21 if ( $(this).hasClass('open')) { 22 $(this).removeClass('open'); 23 } 24 } 25 }); 26 } 27 }); 28 29 // Special event when Bootstrap select gets focus 30 // This cannot be handled by click event 31 $(document).on('show.bs.select', function() { 32 $.each($('.multilevel-multiselect-group'), function() { 33 var $list_container = $(this).find('ul.multilevel-container'); 34 if ($list_container.is(":visible") && $(this).hasClass('open')) { 35 $(this).removeClass('open'); 36 } 37 }); 38 }); 39 40 $(document).on('keyup click', '.multilevel-multiselect-group li, .multilevel-multiselect-group button, .multilevel-multiselect-group span', function(event) { 41 //Just if the div.multilevel-multiselect-group is really in the DOM (can be loaded into the DOM later) 42 if ($(".multilevel-multiselect-group")[0]) { 43 //to avoid firing events multiple times 44 event.stopPropagation(); 45 event.preventDefault(); 46 47 //Set some variables 48 var $this = $(this); 49 var $container = $this.closest('div.multilevel-multiselect-group'); 50 51 // Close other controls of the same type if they have open list containers 52 $.each($('.multilevel-multiselect-group').not($container), function() { 53 var $list_container = $(this).find('ul.multilevel-container'); 54 if ($list_container.is(":visible") && $(this).hasClass('open')) { 55 $(this).removeClass('open'); 56 } 57 }); 58 59 var $list_container = $container.find('ul.multilevel-container'); 60 var isSetPlaceholder = ($container.find('.animated-multicolor-placeholder').length > 0); 61 62 if (isSetPlaceholder) { 63 $placeholderContainer = $container.find('.animated-multicolor-placeholder'); 64 } 65 66 //Set some closure functions 67 var _OpenMainList = function(to_open) { 68 if (to_open) { 69 $container.addClass('open'); 70 if ( isSetPlaceholder ) { 71 $placeholderContainer.addClass('active'); 72 } 73 } else { 74 $container.removeClass('open'); 75 if ( isSetPlaceholder ) { 76 if ( ! $list_container.find('li.selected').length > 0 ) { 77 $placeholderContainer.removeClass('active').removeClass('empty'); 78 } 79 } 80 } 81 }; 82 var _OpenSubList = function(el, to_open) { 83 var children = $list_container.find('li[data-parent_id="' + el.data('id') + '"]'); 84 if (to_open) { 85 el.addClass('open'); 86 children.css('display', 'list-item'); 87 } else { 88 el.removeClass('open'); 89 children.css('display', 'none'); 90 } 91 }; 92 var _SetSelected = function(el) { 93 //Determine number of max allowed selections 94 var $hdnMaxAllowedSelection = $container.find('input.max_allowed_selection'); 95 var maxAllowedSelection = 0; 96 if ($hdnMaxAllowedSelection.length > 0) { 97 maxAllowedSelection = parseInt($hdnMaxAllowedSelection.val()); 98 } 99 100 //Set li element css class 101 var id = null; 102 var soFarSelected = 0; 103 if(el.hasClass('selected')) { 104 el.removeClass('selected'); 105 id = null; 106 } else { 107 el.addClass('selected'); 108 id = el.data('id'); 109 soFarSelected = 1; 110 } 111 112 //Set number of selected secondary class 113 114 var parent_id = el.data('parent_id'); 115 var el_parent = $list_container.find('[data-id="' + parent_id + '"]'); 116 if (parent_id == 0) { 117 (el.attr('class').indexOf('seperatly-selected') == -1) 118 ? el.addClass('seperatly-selected') 119 : el.removeClass('seperatly-selected'); 120 } else { 121 var selected_count = $list_container.find('.selected[data-parent_id="' + parent_id + '"]').length; 122 if (selected_count > 0) { 123 selected_text = '(' + selected_count + ')'; 124 if (el_parent.attr('class').indexOf('selected') == -1) { 125 el_parent.addClass('selected'); 126 } 127 } else { 128 selected_text = ''; 129 if (el_parent.attr('class').indexOf('selected') > -1 && el_parent.attr('class').indexOf('seperatly-selected') == -1) el_parent.removeClass('selected'); 130 } 131 el_parent.find('span.sub_selected').html(selected_text); 132 } 133 134 //Set list hidden field value - value will be the selected li elements' ids - That only field will be just posted 135 var all_selected_ids = ''; 136 var all_selected_text = ''; 137 var all_selected = 0; 138 var separator = ''; 139 $list_container.find('li').each(function() { 140 var $this = $(this); 141 var isAllowedToSelect = $this.hasClass('selected'); 142 143 //Recheck allowance - newly added must be selected and its parent, but if max allowed selection determined, then no more 144 if (el.attr('data-id') != $this.attr('data-id') && maxAllowedSelection > 0) { 145 if (soFarSelected >= maxAllowedSelection) { 146 isAllowedToSelect = false; 147 } 148 } 149 150 /* Please leave this commented code part here - probably still will be needed */ 151 // if ($this.data('id') == id || (parent_id > 0 && $this.data('parent_id') == parent_id)) { 152 // isAllowedToSelect = true; 153 // } 154 155 if (isAllowedToSelect) { 156 all_selected_ids += separator + String($this.data('id')).trim(); 157 all_selected_text += separator + String($this.data('value')).trim(); 158 separator = ', '; 159 all_selected++; 160 soFarSelected++; 161 $this.addClass('selected'); 162 } else { 163 $this.removeClass('selected'); 164 } 165 }); 166 167 var $hiddenSelectedIds = $container.find('input.selected_ids'); 168 ( all_selected == 0 ) 169 ? $container.find('input.selected_ids').val(all_selected_ids).trigger('blur') 170 : $container.find('input.selected_ids').val(all_selected_ids).trigger('input'); 171 172 // Trigger change event for input field 173 $hiddenSelectedIds.val(all_selected_ids).trigger('change'); 174 175 //Set selected values text 176 var buttonText = $container.find('input.default_button_text').val(); 177 if ( isSetPlaceholder ) { 178 var buttonText = ''; 179 } 180 var html = (all_selected > parseInt($container.find('input.max_display_selected').val())) 181 ? all_selected + " selected" 182 : ((all_selected == 0) ? buttonText : all_selected_text); 183 $container.find('span.selected_values').text(html.replace(/(<([^>]+)>)/ig,"")); //pattern gives like strp_tags in php 184 185 //Set placeholder behaving 186 if ( isSetPlaceholder ) { 187 ( all_selected > 0 ) 188 ? $placeholderContainer.addClass('active not-empty') 189 : $placeholderContainer.removeClass('active').removeClass('not-empty'); 190 } 191 192 //Closing selections if only one selection allowed 193 if (maxAllowedSelection === 1) { 194 $container.removeClass('open'); 195 } 196 }; 197 198 //Here comes the "controller" part 199 //If click happened on a child element 200 if ($(event.target).is('.multilevel-multiselect-group *, .multilevel-multiselect-group')) { 201 //if a keyup event happened and was pressed ESC 202 if (event.type == 'keyup' && event.key === 'Escape') { 203 _OpenMainList(false); 204 } else if ($this[0].type == "button" || $this.parent()[0].type == "button" || $this.parent().parent()[0].type == "button") { 205 //if a click event happened on a button 206 _OpenMainList(!$container.hasClass('open')); 207 } else if ($this.hasClass('toggle-sub-list')) { 208 //if a click event happened on a menu arrow 209 if ($this.hasClass('action-open-sub-list')) { 210 _OpenSubList( $this.parent().parent().parent(), true); 211 } else if ($this.hasClass('action-close-sub-list')) { 212 _OpenSubList( $this.parent().parent().parent(), false); 213 } 214 } 215 216 //if a click event on a li element 217 else if ($this.hasClass("multi-select-option") || $this.closest("li").hasClass("multi-select-option")) { 218 _SetSelected($( $this).closest('li')); 219 if ($( $this).closest('li').hasClass('selected')) { 220 _OpenSubList( $( $this).closest('li'), true); 221 } 222 else{ 223 _OpenSubList( $( $this).closest('li'), false); 224 } 225 } 226 } 227 } 228 })//END .on 229 }//END if ($(".multilevel-multiselect-group")[0]) 230 231 });//END WHEN DOM is ready 232 233 /********************************** 234 * END INDUSTRY TYPES * 235 ***********************************/ 236 237
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.