1/** 2 * vmsite.js: General Javascript Library for VirtueMart Frontpage 3 * 4 * 5 * @package VirtueMart 6 * @subpackage Javascript Library 7 * @authors Patrick Kohl, Max Milbers, Abhishek Das 8 * @copyright Copyright (c) 2014-2016 VirtueMart Team. All rights reserved. 9 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL 10 */ 11if (typeof Virtuemart === "undefined") 12 var Virtuemart = {}; 13//var Virtuemart = window.Virtuemart || {}; 14 15(function($) { 16 var methods = { 17 _cache: {}, 18 list: function(options) { 19 if (typeof Virtuemart.vmSiteurl === 'undefined') Virtuemart.vmSiteurl = ''; 20 21 return this.each(function() { 22 this.self = $(this); 23 this.opt = this.opt || {}; 24 this.opt = $.extend(true, {}, $.fn.vm2front.defaults, this.opt, methods._processOpt(options)); 25 this.form = $(this).closest('form'); 26 this.state_fields = $(this.form).find(this.opt.state_field_selector); 27 28 methods._update.call(this, false); 29 30 $(this).on('change', function() { 31 methods._update.call(this, this.opt.show_list_loader); 32 }); 33 }); 34 }, 35 setOpt: function(options) { 36 return this.each(function() { 37 this.opt = $.extend(true, {}, $.fn.vm2front.defaults, this.opt, methods._processOpt(options)); 38 }); 39 }, 40 _processOpt: function(options) { 41 if (options.hasOwnProperty('dest')) { 42 options['state_field_selector'] = options.dest; 43 delete options.dest; 44 } 45 if (options.hasOwnProperty('ids')) { 46 options['selected_state_ids'] = options.ids; 47 delete options.ids; 48 } 49 if (options.hasOwnProperty('prefiks')) { 50 options['field_prefix'] = options.prefiks; 51 delete options.prefiks; 52 } 53 return options; 54 }, 55 _update: function(showLoader) { 56 var that = this, 57 selected_country_ids = $(this).val() || []; 58 59 if (!$.isArray(selected_country_ids)) { 60 selected_country_ids = $.makeArray(selected_country_ids); 61 } 62 63 if (selected_country_ids.length) { 64 selected_country_ids = selected_country_ids.join(','); 65 66 if (methods._cache.hasOwnProperty(selected_country_ids)) { 67 methods._addToList.call(that, methods._cache[selected_country_ids]); 68 } else { 69 $.ajax({ 70 dataType: 'JSON', 71 url: Virtuemart.vmSiteurl + 'index.php?option=com_virtuemart&view=state&format=json&virtuemart_country_id=' + selected_country_ids, 72 beforeSend: function() { 73 if (showLoader) { 74 methods.startVmLoading(); 75 } 76 }, 77 success: function(data) { 78 if (data) { 79 methods._cache[selected_country_ids] = data; 80 methods._addToList.call(that, methods._cache[selected_country_ids]); 81 } 82 if (showLoader) { 83 methods.stopVmLoading(); 84 } 85 }, 86 error: function(e, t, n) { 87 console.log(e); 88 console.log(t); 89 console.log(n); 90 if (showLoader) { 91 methods.stopVmLoading(); 92 } 93 } 94 }) 95 } 96 } 97 }, 98 _addToList: function(data) { 99 var that = this, 100 dataType = $.type(data), 101 i = 0; 102 selected_state_ids = []; 103 104 if (that.opt.selected_state_ids && that.opt.selected_state_ids.length) { 105 if (that.opt.selected_state_ids) { 106 if ($.type(that.opt.selected_state_ids) === 'string') { 107 selected_state_ids = that.opt.selected_state_ids.split(','); 108 } 109 if ($.type(that.opt.selected_state_ids) === 'number') { 110 selected_state_ids.push(that.opt.selected_state_ids); 111 } 112 } 113 } 114 115 $(that.state_fields).each(function() { 116 var state_field = this, 117 id = $(this).attr('id'), 118 form = $(that.form), 119 label = id && form.length ? form.find('label[for="' + id + '"]') : null, 120 required = $(state_field).data('required'), 121 hasData = false; 122 123 $(state_field).data('label', label); 124 125 if ((required !== true && required !== false) || ($(state_field).attr('required') || $(state_field).hasClass('required'))) { 126 if ($(state_field).attr('required') || $(state_field).hasClass('required')) { 127 $(state_field).data('required', true).removeAttr('required').removeAttr('aria-required').removeClass('required'); 128 if (label && label.length && that.opt.asterisk_class) { 129 label.find('.' + that.opt.asterisk_class).hide(); 130 } 131 } else { 132 $(state_field).data('required', false); 133 } 134 } 135 136 $('optgroup', state_field).each(function() { 137 if ($(this).data('ajaxloaded')) $(this).remove(); 138 }); 139 140 if (dataType === 'object' || dataType === 'array') { 141 hasData = false;
142 143 $.each(data, function(country_id, states) { 144 var country_name = $(that).find('option[value="' + country_id + '"]').text(), 145 prefix = that.opt.field_prefix ? that.opt.field_prefix + '-' : that.opt.field_prefix, 146 optgroup_id = prefix + 'group-' + i + '-' + country_id, 147 optgroup, option; 148 149 if (!$('#' + optgroup_id, this).length) { 150 optgroup = $('<optgroup />', { 151 id: optgroup_id, 152 label: country_name 153 }).data('ajaxloaded', true); 154 155 $.each(states, function(index, state) { 156 option = $('<option />', { 157 value: state.virtuemart_state_id 158 }).text(state.state_name); 159 160 if ($.inArray(state.virtuemart_state_id, selected_state_ids) >= 0) { 161 option.attr('selected', true); 162 } 163 164 optgroup.append(option); 165 hasData = true; 166 }); 167 } 168 169 if (optgroup && hasData) { 170 $(state_field).append(optgroup); 171 } 172 }); 173 } 174 175 if (hasData && $(state_field).data('required')) { 176 $(state_field).attr('required', true).attr('aria-required', true); 177 label = $(state_field).data('label'); 178 if (label && $(label).length && that.opt.asterisk_class) { 179 $(label).find('.' + that.opt.asterisk_class).show(); 180 } 181 } 182 183 if ($(state_field).hasClass('invalid') || $(state_field).attr('aria-invalid') == 'true') { 184 $(state_field).trigger('blur'); 185 } 186 187 if (that.opt.field_update_trigger && $.type(that.opt.field_update_trigger) === 'string') { 188 $(state_field).trigger(that.opt.field_update_trigger); 189 } 190 191 i++; 192 }); 193 }, 194 startVmLoading: function(message) { 195 var object = { 196 data: { 197 msg: (!message ? '' : message) 198 } 199 }; 200 Virtuemart.startVmLoading(object); 201 }, 202 stopVmLoading: function() { 203 Virtuemart.stopVmLoading(); 204 } 205 }; 206 207 208 $.fn.vm2front = function(method) { 209 if (methods[method]) { 210 return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); 211 } else if (typeof method === 'object' || !method) { 212 return methods.init.apply(this, arguments); 213 } else { 214 $.error('Method ' + method + ' does not exist in Vm2front plugin.'); 215 } 216 }; 217 218 $.fn.vm2front.defaults = { 219 state_field_selector : '#virtuemart_state_id_field', 220 selected_state_ids : '', 221 field_prefix : '', 222 field_update_trigger : 'liszt:updated', 223 show_list_loader : true, 224 asterisk_class : 'asterisk' 225 }; 226 227 /* You can override default options like below. 228 jQuery(function($) { 229 $('#virtuemart_country_id_field').vm2front('setOpt', {show_list_loader : true}); 230 }); 231 */ 232 233 Virtuemart.startVmLoading = function(a) { 234 var msg = ''; 235 if (typeof a.data.msg !== 'undefined') { 236 msg = a.data.msg; 237 } 238 $('body').addClass('vmLoading'); 239 if (!$('div.vmLoadingDiv').length) { 240 $('body').append('<div class="vmLoadingDiv"><div class="vmLoadingDivMsg">' + msg + '</div></div>'); 241 } 242 }; 243 244 Virtuemart.stopVmLoading = function() { 245 if ($('body').hasClass('vmLoading')) { 246 $('body').removeClass('vmLoading'); 247 $('div.vmLoadingDiv').remove(); 248 } 249 }; 250 251 Virtuemart.sendCurrForm = function(event){ 252 event.preventDefault(); 253 if(event.currentTarget.length > 0){ 254 $(event.currentTarget[0].form.submit()); 255 } else { 256 var f = jQuery(event.currentTarget).closest('form'); 257 f.submit(); 258 } 259 }; 260})(jQuery)
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.