1(function($) { 2 3 var wcff_front_end = function(){ 4 this.ajaxFlaQ = true; 5 this.prepareRequest = function( _request, _method, _data ) { 6 this.request = { 7 request : _method, 8 context : _request, 9 post : "", 10 post_type : "wccpf", 11 payload : _data, 12 }; 13 }; 14 15 this.prepareResponse = function( _status, _msg, _data ) { 16 this.response = { 17 status : _status, 18 message : _msg, 19 res : _data 20 }; 21 }; 22 if( typeof wccpf_opt_cart != "undefined" ){ 23 this.getFieldinfo = function( target, _check ){ 24 var product = target.closest( "tr.cart_item" ).find( ".wcff_get_referance_data" ); 25 var prodId = product.data( "product_id" ); 26 var field_name = target.data( "field" ); 27 var product_cart_id = product.data( "cart_id" ); 28 var value = target.find( ".wcff-color-picker-color-show" ).length != 0 ? target.find( ".wcff-color-picker-color-show" ).css( "background-color" ) : $.trim( target.find( "p" ).text() ); 29 if( target.is( "[data-cloned]" ) ){ 30 field_name = target.data( "cloned" ); 31 } 32 if( _check ){ 33 field_name = target.prev().text().toLowerCase().slice(0, -1).replace( " ", "_" ).trim() 34 } 35 var data = { product_id : prodId, product_cart_id : product_cart_id, check_edit : _check, data : { name : field_name, value : value } }; 36 this.prepareRequest( "wcff_cart_field_render", "post", data ); 37 this.dock( "update_cart_item", target ); 38 }; 39 40 this.getPharamInhtml = function( _target ){ 41 var target = _target; 42 var prodId = target.closest( "tr.cart_item" ).find( ".wcff_get_referance_data" ).data( "product_id" ); 43 var product_cart_id = target.closest( "tr.cart_item" ).find( ".wcff_get_referance_data" ).data( "cart_id" ); 44 var targetField = target.closest( ".wcff_field_cart_update_value" ).find( ".wccpf-field" ); 45 var value = targetField.val(); 46 var wcff_validator_obj = new wcffValidator(); 47 var field_type = target.attr( "data-field_type" ); 48 wcff_validator_obj.doValidate( targetField ); 49 if( !wcff_validator_obj.isValid ){ 50 return false; 51 } 52 if( field_type == "checkbox" || field_type == "radio" ){ 53 if( field_type == "checkbox" ) { 54 var value_field = target.closest( ".wcff_field_cart_update_value" ).find( ".wccpf-field:checked" ); 55 if( value_field.length >= 2 ){ 56 value = ""; 57 for( var i = 0; i < value_field.length; i++ ){ 58 value += $( value_field[i] ).val(); 59 value += i != value_field.length-1 ? ", " : ""; 60 } 61 } else { 62 value = value_field.val(); 63 } 64 } else{ 65 value = _target.closest( ".wcff_field_cart_update_value" ).find( "input:checked" ).val(); 66 } 67 } else if( field_type == "colorpicker" ){ 68 value = encodeURI( value ); 69 } else if( field_type == "file" ) { 70 71 } else if( field_type == "email" ){ 72 value = value; 73 var validate = target.closest( ".wcff_field_cart_update_value" ).find( ".wccpf-field" )[0].checkValidity(); 74 if( !validate ){ 75 targetField.next().html( "Invalid email.!" ).show(); 76 return false; 77 } else{ 78 targetField.next().html( "This field can't be Empty" ).hide(); 79 } 80 } 81 var data = { product_id : prodId, product_cart_id : product_cart_id, data : { name : target.closest( ".wcff_field_cart_update_value" ).data( "field" ), value : value, field_type : field_type, color_showin : target.attr( "data-color_show" ) } }; 82 this.prepareRequest( "update_cart_item_from_session", "post", data ); 83 this.dock( "update_cart_item_from_session", target ); 84 }; 85 } 86 87 this.dock = function( _action, _target, is_file ) { 88 var me = this; 89 /* see the ajax handler is free */ 90 if( !this.ajaxFlaQ ) { 91 return; 92 } 93 94 $.ajax({ 95 type : "POST", 96 data : { action : "wcff_ajax", wcff_param : JSON.stringify( this.request ) }, 97 dataType : "json", 98 url : woocommerce_params.ajax_url, 99 beforeSend : function(){ 100 /* enable the ajax lock - actually it disable the dock */ 101 me.ajaxFlaQ = false; 102 }, 103 success : function(data) { 104 /* disable the ajax lock */ 105 me.ajaxFlaQ = true; 106 me.prepareResponse( data.status, data.message, data.data ); 107 108 /* handle the response and route to appropriate target */ 109 if( me.response.status ) { 110 me.responseHandler( _action, _target ); 111 } else { 112 /* alert the user that some thing went wrong */ 113 //me.responseHandler( _action, _target ); 114 } 115 }, 116 error : function(jqXHR, textStatus, errorThrown) { 117 /* disable the ajax lock */ 118 me.ajaxFlaQ = true; 119 }, 120 complete : function() { 121 122 } 123 }); 124 }; 125 126 this.responseHandler = function( _action, _target ){ 127 if( _action == "update_cart_item" ){ 128 if( this.response.res == true && this.request.payload.check_edit ){ 129 _target.addClass( "wcff_field_cart_update_value" ).attr( { "title" : "Double click to edit", "data-field" : _target.prev().text().toLowerCase().slice(0, -1).replace( " ", "_" ).trim() } ); 130 return; 131 } else if( this.request.payload.check_edit ) { 132 _target.addClass( "edit_checked" ); 133 return; 134 } 135 if( this.response.res == false ){ 136 return; 137 } 138 var html = $( this.response.res.html ).find( "td:last" ).html(); 139 var header = $( "head" ); 140 if( this.response.res.field_type != "file" ){ 141 html = $( html + '<button data-field_type="'+this.response.res.field_type+'" data-color_show="'+ this.response.res.color_showin +'" class="button wcff_update_curent_field_data">Update</button>' ); 142 html.addClass( "wcff_cart_item_update" ); 143 _target.html( html ); 144 } 145 if( this.response.res.field_type == "email" || this.response.res.field_type == "text" || this.response.res.field_type == "number" || this.response.res.field_type == "textarea" ){ 146 _target.find( ".wccpf-field" ).val( this.request.payload.data.value ); 147 html.trigger( "focus" ); 148 } else if( this.response.res.field_type == "select" ){ 149 //html.val( this.request.payload.data.value.toLowerCase() ); 150 } else if( this.response.res.field_type == "colorpicker" ){ 151 header.append( this.response.res.script ); 152 } else if( this.response.res.field_type == "checkbox" ){ 153 var checked_item = this.request.payload.data.value.split( ", " ); 154 for( var i = 0; i < checked_item.length; i++ ){ 155 html.find( "input[value="+checked_item[i]+"]" ).prop( "checked", true ); 156 } 157 } else if( this.response.res.field_type == "radio" ){ 158 html.find( "input[value="+ this.request.payload.data.value +"]" ).prop( "checked", true ); 159 } else if( this.response.res.field_type == "file" ){ 160 return; 161 } else if( this.response.res.field_type == "datepicker" ){ 162 _target.find( ".wccpf-field" ).val( this.request.payload.data.value ); 163 if( header.find( "script[data-type=wpff-datepicker-script]" ).length == 0 ){ 164 header.append( this.response.res.script ); 165 } 166 header.append( $( this.response.res.html )[2] ); 167 } 168 } else if( _action == "update_cart_item_from_session" ){ 169 if( this.response.res.status ){ 170 if( this.response.res.field_type == "colorpicker" ){ 171 _target.closest( ".wcff_field_cart_update_value" ).html( '<p>'+ decodeURI( this.response.res.value ) +'</p>' ); 172 } else{ 173 _target.closest( ".wcff_field_cart_update_value" ).html( '<p>'+ this.response.res.value +'</p>' ); 174 } 175 _target.next().hide(); 176 } else { 177 _target.next().html( this.response.res.message ).show(); 178 } 179 } 180 }; 181 182 }; 183 184 $(document).on( "submit", "form.cart", function(){ 185 if( typeof( wccpf_opt.location ) != "undefined" && 186 wccpf_opt.location != "woocommerce_before_add_to_cart_button" && 187 wccpf_opt.location != "woocommerce_after_add_to_cart_button" ) { 188 var me = $(this); 189 me.find(".wccpf_fields_table").each(function(){ 190 $(this).remove(); 191 }); 192 193 $(".wccpf_fields_table").each(function(){ 194 var cloned = $(this).clone( true ); 195 cloned.css("display", "none"); 196 me.append( cloned ); 197 }); 198 199 } 200 }); 201 202 var wcffCloner = function(){ 203 this.initialize = function(){ 204 $( document ).on( "change", "input[name=quantity]", function() { 205 var product_count = $(this).val(); 206 var fields_count = parseInt( $("#wccpf_fields_clone_count").val() ); 207 $("#wccpf_fields_clone_count").val( product_count ); 208 209 if( fields_count < product_count ) { 210 for( var i = fields_count + 1; i <= product_count; i++ ) { 211 var cloned = $('.wccpf-fields-group:first').clone( true ); 212 cloned.find("script").remove(); 213 cloned.find("div.sp-replacer").remove(); 214 cloned.find("span.wccpf-fields-group-title-index").html( i ); 215 cloned.find( ".hasDatepicker" ).attr( "id", "" ); 216 cloned.find( ".hasDatepicker" ).removeClass( "hasDatepicker" ); 217 cloned.find(".wccpf-field").each(function(){ 218 var name_attr = $(this).attr("name"); 219 if( name_attr.indexOf("[]") != -1 ) { 220 var temp_name = name_attr.substring( 0, name_attr.lastIndexOf("_") ); 221 name_attr = temp_name + "_" + i + "[]"; 222 } else { 223 name_attr = name_attr.slice( 0, -1 ) + i; 224 } 225 $(this).attr( "name", name_attr ); 226 });
227 228 $("#wccpf-fields-container").append( cloned ); 229 230 setTimeout( function(){ if( typeof( wccpf_init_color_pickers ) == 'function' ) { wccpf_init_color_pickers(); } }, 500 ); 231 } 232 } else { 233 $("div.wccpf-fields-group:eq("+ ( product_count - 1 ) +")").nextAll().remove(); 234 } 235 236 if( $(this).val() == 1 ) { 237 $(".wccpf-fields-group-title-index").hide(); 238 } else { 239 $(".wccpf-fields-group-title-index").show(); 240 } 241 242 }); 243 /* Trigger to change event - fix for min product quantity */ 244 setTimeout( function(){ $( "input[name=quantity]" ).trigger("change"); }, 300 ); 245 }; 246 }; 247 248 var wcffValidator = function() { 249 this.isValid = true; 250 this.initialize = function(){ 251 var me = this; 252 if( wccpf_opt.validation_type == "blur" ) { 253 $( document ).on( "blur", ".wccpf-field", me, function(e) { 254 e.data.doValidate( $(this) ); 255 }); 256 } 257 $( document ).on( "submit", "form.cart", me, function(e) { 258 var me = e.data; 259 e.data.isValid = true; 260 $( ".wccpf-field" ).each(function(){ 261 me.doValidate( $(this) ); 262 }); 263 return e.data.isValid; 264 }); 265 }; 266 267 this.doValidate = function( field ) { 268 if( field.attr("wccpf-type") != "radio" && field.attr("wccpf-type") != "checkbox" ) { 269 if( field.attr("wccpf-mandatory") == "yes" ) { 270 if( this.doPatterns( field.attr("wccpf-pattern"), field.val() ) ) { 271 field.next().hide(); 272 } else { 273 this.isValid = false; 274 field.next().show(); 275 } 276 } 277 } else if( field.attr("wccpf-type") == "radio" ) { 278 if( field.attr("wccpf-mandatory") == "yes" ) { 279 if( $("input[name="+ field.attr("name") +"]").is(':checked') ) { 280 field.next().show(); 281 } else { 282 this.isValid = false; 283 field.next().hide(); 284 } 285 } 286 } else if( field.attr("wccpf-type") == "checkbox" ) { 287 if( field.attr("wccpf-mandatory") == "yes" ) { 288 var values = $("input[name="+ field.attr("name") +"]").serializeArray(); 289 if( values.length == 0 ) { 290 field.next().show(); 291 } else { 292 this.isValid = false; 293 field.next().hide(); 294 } 295 } 296 } else if( field.attr("wccpf-type") == "file" ) { 297 if( field.attr("wccpf-mandatory") == "yes" ) { 298 if( field.val() == "" ) { 299 field.next().show(); 300 } else { 301 field.next().hide(); 302 } 303 } 304 } 305 } 306 307 this.doPatterns = function( patt, val ){ 308 var pattern = { 309 mandatory : /\S/, 310 number : /^\d+\.\d{0,2}$/, 311 email : /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i, 312 }; 313 return pattern[ patt ].test(val); 314 }; 315 316 }; 317 318 $(document).ready(function(){ 319 var wcff_fe_dock = new wcff_front_end(); 320 $(document).on( "change", ".wccpf-field", function( e ){ 321 var target = $( this ), 322 prevExt = ['jpeg', 'jpg', 'png', 'gif', 'bmp']; 323 324 if( target.is( "input[type=file]" ) ){ 325 if ( $.inArray( target.val().split('.').pop().toLowerCase(), prevExt ) != -1 ) { 326 if( !target.next().is( ".wcff_image_prev_shop_continer" ) ){
327 target.after( '<div class="wcff_image_prev_shop_continer"></div>' ); 328 } 329 var html = ""; 330 for( var i = 0; i < target[0].files.length; i++ ){ 331 html += '<img class="wcff-prev-shop-image" src="'+ URL.createObjectURL( target[0].files[i] ) +'">'; 332 target[0].files[i].name = target[0].files[i].name.replace(/'|$|,/g, ''); 333 target[0].files[i].name = target[0].files[i].name.replace('$', ''); 334 } 335 target.next( ".wcff_image_prev_shop_continer" ).html( html ); 336 } 337 } 338 }); 339 340 if( typeof wccpf_opt != "undefined" ){ 341 if( typeof( wccpf_opt.cloning ) !== "undefined" && wccpf_opt.cloning == "yes" ) { 342 var wcff_cloner_obj = new wcffCloner(); 343 wcff_cloner_obj.initialize(); 344 } 345 if( typeof( wccpf_opt.validation ) !== "undefined" && wccpf_opt.validation == "yes" ) { 346 var wcff_validator_obj = new wcffValidator(); 347 wcff_validator_obj.initialize(); 348 } 349 } 350 if( typeof wccpf_opt_cart == "undefined" ){ 351 $( ".wcff_field_cart_update_value" ).removeClass( "wcff_field_cart_update_value" ); 352 } 353 if( typeof wccpf_opt_cart != "undefined" ){ 354 if( wccpf_opt_cart.is_edit_cart_value == "no" ){ 355 $( ".wcff_field_cart_update_value" ).removeClass( "wcff_field_cart_update_value" ); 356 } 357 //wccpf color picker value change html 358 $( document ).on( "change", ".wccpf-color, .wccaf-color", function(){ 359 var colorField = $( this ); 360 if( colorField.val().search( "," ) == -1 && colorField.attr( "hex_color_show_in_color" ) == "yes" ){ 361 colorField.val( '<span class="wcff-color-picker-color-show" code="'+ colorField.val() +'" style="padding: 0px 15px;background-color: '+ colorField.val() +'"></span>' ); 362 } 363 }); 364 $(document).on( "dblclick", "dd[class*=variation], li.wcff_field_cart_update_value", function(e){ 365 if( wccpf_opt_cart.is_edit_cart_value == "yes" && wc_add_to_cart_params.is_cart == "1" ){ 366 var target = $( this ); 367 if( !target.find( "input, select, textarea, label" ).length != 0 && target.is( ".wcff_field_cart_update_value" ) ){ 368 wcff_fe_dock.getFieldinfo( target, false ); 369 } 370 } 371 }); 372 $(document).on( "hover", "dd[class*=variation]", function(e){ 373 var target = $( this ); 374 if( !target.is( ".wcff_field_cart_update_value" ) && wccpf_opt_cart.is_edit_cart_value == "yes" && !target.is( ".edit_checked" ) ) { 375 wcff_fe_dock.getFieldinfo( target, true ); 376 } 377 }); 378 $(document).on( "click", ".wcff_update_curent_field_data", function( e ){ 379 wcff_fe_dock.getPharamInhtml( $( this ) ); 380 e.preventDefault(); 381 }); 382 } 383 384 }); 385 386})(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.