1/** 2 * PPOM input scripts 3 **/ 4 5"use strict" 6 7/* global wpcomment_input_vars */ 8 9var wpcomment_bulkquantity_meta = ''; 10var wpcomment_pricematrix_discount_type = ''; 11 12jQuery(function($) { 13 14 // Tooltip Init 15 // $('.wpcomment-tooltip').powerTip({ 16 // placement: 'n', 17 // smartPlacement: true, 18 // mouseOnToPopup: true 19 // }); 20 21 // Remove Emoji from text input 22 // $('.wpcomment-wrapper').on('input keyup', 'input[type="text"]', function(e) { 23 24 // const input_val = $(this).val(); 25 // const new_val = input_val.replace(/([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g, ''); 26 // $(this).val(new_val); 27 // }); 28 29 30 31 // $('[data-toggle="tooltip"]').tooltip({container:'body', trigger:'hover'}); 32 33 if ($('.wpcomment-modals').length > 0) { 34 $('.wpcomment-modals').appendTo('body'); 35 } 36 37 wpcomment_init_js_for_wpcomment_fields(wpcomment_input_vars.field_meta); 38 39}); 40 41// JS Init PPOM Inputs 42function wpcomment_init_js_for_wpcomment_fields(wpcomment_fields) { 43 44 45 // Fixed the form button issue 46 if (wpcomment_fields && wpcomment_fields.length > 0) { 47 const css_type = jQuery('form.cart').css('display'); 48 if (css_type === 'flex') { 49 jQuery('form.cart').addClass('wpcomment-flex-controller'); 50 } 51 } 52 53 jQuery.each(wpcomment_fields, function(index, input) { 54 55 // console.log(input.type); 56 var InputSelector = jQuery("#" + input.data_name); 57 58 // Applying JS on inputs 59 switch (input.type) { 60 61 // masking 62 case 'text': 63 if (input.input_mask == undefined || input.input_mask == '') break; 64 InputSelector.inputmask(); 65 if (input.type === 'text' && 66 input.input_mask !== '' && 67 input.use_regex !== 'on') { 68 InputSelector.inputmask(input.input_mask); 69 } 70 break; 71 72 73 // only allow numbers and periods in number fields 74 case "number": 75 InputSelector.bind("keydown keyup keypress", function(event) { 76 if (event.key === "Backspace" || event.key === "Delete" || event.key === "Tab" || 77 (event.ctrlKey === true && event.key === "a") || 78 (event.ctrlKey === true && event.key === "x") || 79 (event.ctrlKey === true && event.key === "Backspace") || 80 (event.which >= 48 && event.which <= 57) || 81 (event.which >= 96 && event.which <= 105) || 82 (event.key === "." && $(this).val().indexOf(".") <= 1)) { 83 // think happy thoughts :-) 84 } 85 else { event.preventDefault(); } 86 }).bind("focus blur", function() { 87 if (typeof InputSelector.attr("max") !== 'undefined') { 88 if (parseFloat(InputSelector.val()) > parseFloat(InputSelector.attr("max"))) { 89 InputSelector.val(InputSelector.attr("max")); 90 } 91 } 92 }); 93 break; 94 95 case 'date': 96 if (input.jquery_dp === 'on') { 97 98 InputSelector.datepicker("destroy"); 99 InputSelector.datepicker({ 100 changeMonth: true, 101 changeYear: true, 102 dateFormat: input.date_formats.wpcomment_js_stripSlashes(), 103 yearRange: input.year_range, 104 }); 105 106 if( input.past_dates === 'on' ){ 107 InputSelector.datepicker('option', 'minDate', 0); 108 } 109 110 if (typeof input.past_dates !== 'max_date') { 111 if (input.past_dates.length > 0) { 112 var max_date = input.max_date.trim(); 113 InputSelector.datepicker('option', 'maxDate', max_date); 114 } 115 } 116 117 if (input.no_weekends === 'on') { 118 InputSelector.datepicker('option', 'beforeShowDay', jQuery.datepicker.noWeekends); 119 } 120 } 121 break; 122 123 case 'image': 124 125 var img_id = input.data_name; 126 // Image Tooltip 127 if (input.show_popup === 'on' && !wpcomment_input_vars.is_mobile) { 128 jQuery('.wpcomment-zoom-' + img_id).imageTooltip({ 129 xOffset: 5, 130 yOffset: 5 131 }); 132 } 133 134 // Data Tooltip 135 // $(".pre_upload_image").tooltip({container: 'body'}); 136 break; 137 // date_range 138 case 'daterange': 139 140 InputSelector.daterangepicker({ 141 autoApply: (input.auto_apply == 'on') ? true : false, 142 locale: { 143 format: (input.date_formats !== '') ? input.date_formats : "YYYY-MM-DD" 144 }, 145 showDropdowns: (input.drop_down == 'on') ? true : false, 146 showWeekNumbers: (input.show_weeks == 'on') ? true : false, 147 timePicker: (input.time_picker == 'on') ? true : false, 148 timePickerIncrement: (input.tp_increment !== '') ? parseInt(input.tp_increment) : '', 149 timePicker24Hour: (input.tp_24hours == 'on') ? true : false, 150 timePickerSeconds: (input.tp_seconds == 'on') ? true : false, 151 drops: (input.open_style !== '') ? input.open_style : 'down', 152 startDate: (input.start_date == '') ? false : input.start_date, 153 endDate: (input.end_date == '') ? false : input.end_date, 154 minDate: (input.min_date == '') ? false : input.min_date, 155 maxDate: (input.max_date == '') ? false : input.max_date, 156 }); 157 break; 158 159 // color: iris 160 case 'color': 161 162 InputSelector.css('background-color', input.default_color); 163 var iris_options = { 164 'palettes': wpcomment_get_palette_setting(input), 165 'hide': input.show_onload == 'on' ? false : true, 166 'color': input.default_color, 167 'mode': input.palettes_mode != '' ? input.palettes_mode : 'hsv', 168 'width': input.palettes_width != '' ? input.palettes_width : 200, 169 change: function(event, ui) { 170 171 InputSelector.css('background-color', ui.color.toString()); 172 InputSelector.css('color', '#fff'); 173
174 // Getting Color Code for update price 175 InputSelector.val(ui.color.toString()) 176 } 177 } 178 179 console.log(iris_options); 180 181 InputSelector.iris(iris_options); 182 183 // Following script is added to close picker 184 // when color is picked 185 jQuery(document).click(function(e) { 186 if (!jQuery(e.target).is(".wpcomment-input.color, .iris-picker, .iris-picker-inner")) { 187 jQuery('.wpcomment-input.color').iris('hide'); 188 return e; 189 } 190 }); 191 192 jQuery('.wpcomment-input.color').click(function(event) { 193 jQuery('.wpcomment-input.color').iris('hide'); 194 jQuery(this).iris('show'); 195 return event; 196 }); 197 break; 198 199 // Palettes 200 case 'palettes': 201 202 const max_selected = parseInt(input.max_selected) || undefined; 203 if (!max_selected) break; 204 205 jQuery(document).on('click', `.wpcomment-palettes-${input.data_name} input.wpcomment-input`, function(e) { 206 if (jQuery(`.wpcomment-palettes-${input.data_name} input.wpcomment-input:checked`).length > max_selected) { 207 alert(`You can only select a maximum of ${max_selected} ${input.title} colors`); 208 e.preventDefault(); 209 // return false; 210 } 211 }); 212 break; 213 // Bulk quantity 214 case 'bulkquantity': 215 216 setTimeout(function() { jQuery('.quantity.buttons_added').hide(); }, 50); 217 jQuery('form.cart').find('.quantity').hide(); 218 219 // setting formatter 220 /*if ($('form.cart').closest('div').find('.price').length > 0){ 221 wc_price_DOM = $('form.cart').closest('div').find('.price'); 222 }*/ 223 224 wpcomment_bulkquantity_meta = input.options; 225 226 var min_quantity_value = jQuery('.wpcomment-bulkquantity-qty').val(); 227 228 // Starting value 229 wpcomment_bulkquantity_price_manager(min_quantity_value); 230 break; 231 232 case 'pricematrix': 233 234 wpcomment_pricematrix_discount_type = input.discount_type; 235 236 if (input.show_slider === 'on' && jQuery('.wpcomment-range-slide').length > 0) { 237 var slider = new Slider('.wpcomment-range-slide', { 238 formatter: function(value) { 239 jQuery.event.trigger({ 240 type: "wpcomment_range_slider_updated", 241 qty: value, 242 time: new Date() 243 }); 244 return wpcomment_input_vars.text_quantity + ": " + value; 245 } 246 }); 247 } 248 249 jQuery('.wpcomment-range-bs-slider').on('change', function(e) { 250 jQuery.event.trigger({ 251 type: "wpcomment_range_slider_updated", 252 qty: jQuery(this).val(), 253 time: new Date() 254 }); 255 }); 256 break; 257 case 'quantities': 258 var enable_plusminus = input.enable_plusminus; 259 var field_selectot = jQuery('.wpcomment-input-' + input.data_name); 260 if (enable_plusminus == 'on') { 261 jQuery('.wpcomment-quantity', field_selectot).niceNumber(); 262 } 263 break; 264 265 } 266 267 268 }); 269} 270 271 272 273function wpcomment_get_palette_setting(input) { 274 275 var palettes_setting = false; 276 // first check if palettes is on 277 if (input.show_palettes === 'on') { 278 palettes_setting = true; 279 } 280 if (palettes_setting && input.palettes_colors !== '') { 281 palettes_setting = input.palettes_colors.split(','); 282 } 283 284 return palettes_setting; 285} 286 287function wpcomment_get_field_type_by_id(field_id) { 288 289 var field_type = ''; 290 jQuery.each(wpcomment_input_vars.field_meta, function(i, field) { 291 292 if (field.data_name === field_id) { 293 field_type = field.field_type; 294 return; 295 } 296 }); 297 298 return field_type; 299} 300 301// Get all field meta by id 302function wpcomment_get_field_meta_by_id(field_id) { 303 304 var field_meta = ''; 305 jQuery.each(wpcomment_input_vars.field_meta, function(i, field) { 306 307 if (field.data_name === field_id) { 308 field_meta = field; 309 return; 310 } 311 }); 312 313 return field_meta; 314} 315 316function wpcomment_get_field_meta_by_type(type) { 317 318 var field_meta = Array(); 319 jQuery.each(wpcomment_input_vars.field_meta, function(i, field) { 320 321 if (field.type === type) { 322 field_meta.push(field); 323 return; 324 } 325 }); 326 327 return field_meta; 328} 329 330String.prototype.wpcomment_js_stripSlashes = function() { 331 return this.replace(/\\(.)/mg, "$1"); 332}
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.