jquery.yith-wcwl.js
1796 lines
| 1 | /** |
| 2 | * Main YITH WooCommerce Wishlist JS |
| 3 | * |
| 4 | * @author YITH |
| 5 | * @package YITH WooCommerce Wishlist |
| 6 | * @version 3.0.0 |
| 7 | */ |
| 8 | |
| 9 | /* globals yith_wcwl_l10n, wc_add_to_cart_params, yith_wccl_general */ |
| 10 | |
| 11 | jQuery( function( $ ){ |
| 12 | |
| 13 | /* === MAIN INIT === */ |
| 14 | |
| 15 | $(document).on( 'yith_wcwl_init', function(){ |
| 16 | var t = $(this), |
| 17 | cart_redirect_after_add = ( typeof( wc_add_to_cart_params ) !== 'undefined' && wc_add_to_cart_params !== null ) ? wc_add_to_cart_params.cart_redirect_after_add : ''; |
| 18 | |
| 19 | t.on( 'click', '.add_to_wishlist', function( ev ) { |
| 20 | var t = $(this), |
| 21 | product_id = t.attr( 'data-product-id' ), |
| 22 | el_wrap = $( '.add-to-wishlist-' + product_id ), |
| 23 | filtered_data = null, |
| 24 | data = { |
| 25 | action: yith_wcwl_l10n.actions.add_to_wishlist_action, |
| 26 | context: 'frontend', |
| 27 | add_to_wishlist: product_id, |
| 28 | product_type: t.data( 'product-type' ), |
| 29 | wishlist_id: t.data( 'wishlist-id' ), |
| 30 | fragments: retrieve_fragments( product_id ) |
| 31 | }; |
| 32 | |
| 33 | // allow third party code to filter data |
| 34 | if( filtered_data = $(document).triggerHandler( 'yith_wcwl_add_to_wishlist_data', [ t, data ] ) ) { |
| 35 | data = filtered_data; |
| 36 | } |
| 37 | |
| 38 | ev.preventDefault(); |
| 39 | |
| 40 | jQuery( document.body ).trigger( 'adding_to_wishlist' ); |
| 41 | |
| 42 | if( yith_wcwl_l10n.multi_wishlist && yith_wcwl_l10n.modal_enable ){ |
| 43 | var wishlist_popup_container = t.parents( '.yith-wcwl-popup-footer' ).prev( '.yith-wcwl-popup-content' ), |
| 44 | wishlist_popup_select = wishlist_popup_container.find( '.wishlist-select' ), |
| 45 | wishlist_popup_name = wishlist_popup_container.find( '.wishlist-name' ), |
| 46 | wishlist_popup_visibility = wishlist_popup_container.find( '.wishlist-visibility' ).filter(':checked'); |
| 47 | |
| 48 | data.wishlist_id = wishlist_popup_select.is(':visible') ? wishlist_popup_select.val() : 'new'; |
| 49 | data.wishlist_name = wishlist_popup_name.val(); |
| 50 | data.wishlist_visibility = wishlist_popup_visibility.val(); |
| 51 | |
| 52 | if( 'new' === data.wishlist_id && ! data.wishlist_name ){ |
| 53 | wishlist_popup_name.closest('p').addClass('woocommerce-invalid'); |
| 54 | return false; |
| 55 | } |
| 56 | else{ |
| 57 | wishlist_popup_name.closest('p').removeClass('woocommerce-invalid'); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | if( ! is_cookie_enabled() ){ |
| 62 | window.alert( yith_wcwl_l10n.labels.cookie_disabled ); |
| 63 | return; |
| 64 | } |
| 65 | |
| 66 | $.ajax({ |
| 67 | type: 'POST', |
| 68 | url: yith_wcwl_l10n.ajax_url, |
| 69 | data: data, |
| 70 | dataType: 'json', |
| 71 | beforeSend: function(){ |
| 72 | block( t ); |
| 73 | }, |
| 74 | complete: function(){ |
| 75 | unblock( t ); |
| 76 | }, |
| 77 | success: function( response ) { |
| 78 | var response_result = response.result, |
| 79 | response_message = response.message; |
| 80 | |
| 81 | if( yith_wcwl_l10n.multi_wishlist ) { |
| 82 | // close PrettyPhoto popup |
| 83 | close_pretty_photo( response_message ); |
| 84 | |
| 85 | // update options for all wishlist selects |
| 86 | if( typeof( response.user_wishlists ) !== 'undefined' ) { |
| 87 | update_wishlists( response.user_wishlists ); |
| 88 | } |
| 89 | } |
| 90 | else { |
| 91 | print_message(response_message); |
| 92 | } |
| 93 | |
| 94 | if( response_result === 'true' || response_result === 'exists' ) { |
| 95 | if( typeof response.fragments !== 'undefined' ) { |
| 96 | replace_fragments( response.fragments ); |
| 97 | } |
| 98 | |
| 99 | if( ! yith_wcwl_l10n.multi_wishlist || yith_wcwl_l10n.hide_add_button ) { |
| 100 | el_wrap.find('.yith-wcwl-add-button').remove(); |
| 101 | } |
| 102 | |
| 103 | el_wrap.addClass('exists'); |
| 104 | } |
| 105 | |
| 106 | init_handling_after_ajax(); |
| 107 | |
| 108 | $('body').trigger('added_to_wishlist', [ t, el_wrap ] ); |
| 109 | } |
| 110 | |
| 111 | }); |
| 112 | |
| 113 | return false; |
| 114 | } ); |
| 115 | |
| 116 | t.on( 'click', '.wishlist_table .remove_from_wishlist', function( ev ){ |
| 117 | var t = $( this ); |
| 118 | |
| 119 | ev.preventDefault(); |
| 120 | |
| 121 | remove_item_from_wishlist( t ); |
| 122 | |
| 123 | return false; |
| 124 | } ); |
| 125 | |
| 126 | t.on( 'adding_to_cart', 'body', function( ev, button, data ){ |
| 127 | if( typeof button !== 'undefined' && typeof data !== 'undefined' && button.closest( '.wishlist_table' ).length ){ |
| 128 | data.remove_from_wishlist_after_add_to_cart = button.closest( '[data-row-id]' ).data( 'row-id' ); |
| 129 | data.wishlist_id = button.closest( '.wishlist_table' ).data( 'id' ); |
| 130 | typeof wc_add_to_cart_params !== 'undefined' && ( wc_add_to_cart_params.cart_redirect_after_add = yith_wcwl_l10n.redirect_to_cart ); |
| 131 | typeof yith_wccl_general !== 'undefined' && ( yith_wccl_general.cart_redirect = isTrue( yith_wcwl_l10n.redirect_to_cart ) ); |
| 132 | } |
| 133 | } ); |
| 134 | |
| 135 | t.on( 'added_to_cart', 'body', function( ev, fragments, carthash, button ){ |
| 136 | if( typeof button !== 'undefined' && button.closest( '.wishlist_table' ).length ) { |
| 137 | typeof wc_add_to_cart_params !== 'undefined' && ( wc_add_to_cart_params.cart_redirect_after_add = cart_redirect_after_add ); |
| 138 | typeof yith_wccl_general !== 'undefined' && ( yith_wccl_general.cart_redirect = isTrue( cart_redirect_after_add ) ); |
| 139 | |
| 140 | var tr = button.closest('[data-row-id]'), |
| 141 | table = tr.closest('.wishlist-fragment'), |
| 142 | options = table.data('fragment-options'); |
| 143 | |
| 144 | button.removeClass('added'); |
| 145 | tr.find('.added_to_cart').remove(); |
| 146 | |
| 147 | if ( yith_wcwl_l10n.remove_from_wishlist_after_add_to_cart && options.is_user_owner ) { |
| 148 | tr.remove(); |
| 149 | } |
| 150 | } |
| 151 | } ); |
| 152 | |
| 153 | t.on( 'added_to_cart', 'body', function(){ |
| 154 | var messages = $( '.woocommerce-message'); |
| 155 | |
| 156 | if( messages.length === 0 ){ |
| 157 | $( '#yith-wcwl-form').prepend( yith_wcwl_l10n.labels.added_to_cart_message ); |
| 158 | } |
| 159 | else{ |
| 160 | messages.fadeOut( 300, function(){ |
| 161 | $(this).replaceWith( yith_wcwl_l10n.labels.added_to_cart_message ).fadeIn(); |
| 162 | } ); |
| 163 | } |
| 164 | } ); |
| 165 | |
| 166 | t.on( 'cart_page_refreshed', 'body', init_handling_after_ajax ); |
| 167 | |
| 168 | t.on( 'click', '.show-title-form', show_title_form ); |
| 169 | |
| 170 | t.on( 'click', '.wishlist-title-with-form h2', show_title_form ); |
| 171 | |
| 172 | t.on( 'click', '.remove_from_all_wishlists', function( ev ){ |
| 173 | var t = $(this), |
| 174 | prod_id = t.attr('data-product-id'), |
| 175 | wishlist_id = t.data('wishlist-id'), |
| 176 | content = t.closest( '.content' ), |
| 177 | data = { |
| 178 | action: yith_wcwl_l10n.actions.remove_from_all_wishlists, |
| 179 | context: 'frontend', |
| 180 | prod_id: prod_id, |
| 181 | wishlist_id: wishlist_id, |
| 182 | fragments: retrieve_fragments( prod_id ) |
| 183 | }; |
| 184 | |
| 185 | ev.preventDefault(); |
| 186 | |
| 187 | $.ajax({ |
| 188 | beforeSend: function(){ |
| 189 | block( content ); |
| 190 | }, |
| 191 | complete: function(){ |
| 192 | unblock( content ); |
| 193 | }, |
| 194 | data: data, |
| 195 | dataType: 'json', |
| 196 | method: 'post', |
| 197 | success: function( data ){ |
| 198 | if( typeof data.fragments !== 'undefined' ){ |
| 199 | replace_fragments( data.fragments ); |
| 200 | } |
| 201 | |
| 202 | init_handling_after_ajax(); |
| 203 | }, |
| 204 | url: yith_wcwl_l10n.ajax_url |
| 205 | }); |
| 206 | } ); |
| 207 | |
| 208 | t.on( 'click', '.hide-title-form', hide_title_form ); |
| 209 | |
| 210 | t.on( 'click', '.save-title-form', submit_title_form ); |
| 211 | |
| 212 | t.on( 'change', '.wishlist_manage_table .wishlist-visibility', save_privacy ); |
| 213 | |
| 214 | t.on( 'change', '.change-wishlist', function(){ |
| 215 | var t = $(this), |
| 216 | table = t.parents( '.cart.wishlist_table'), |
| 217 | wishlist_token = table.data('token'), |
| 218 | item_id = t.parents( '[data-row-id]').data('row-id'), |
| 219 | to_token = t.val(); |
| 220 | |
| 221 | call_ajax_move_item_to_another_wishlist( |
| 222 | { |
| 223 | wishlist_token : wishlist_token, |
| 224 | destination_wishlist_token: to_token, |
| 225 | item_id : item_id, |
| 226 | fragments : retrieve_fragments() |
| 227 | }, |
| 228 | function(){ |
| 229 | block( table ); |
| 230 | }, |
| 231 | function( data ){ |
| 232 | if( typeof data.fragments !== 'undefined' ) { |
| 233 | replace_fragments( data.fragments ); |
| 234 | } |
| 235 | |
| 236 | unblock( table ); |
| 237 | } |
| 238 | ); |
| 239 | } ); |
| 240 | |
| 241 | t.on( 'click', '.yith-wcwl-popup-footer .move_to_wishlist', function(){ |
| 242 | var t = $(this), |
| 243 | product_id = t.attr('data-product-id'), |
| 244 | wishlist_token = t.data('origin-wishlist-id'), |
| 245 | form = t.closest('form'), |
| 246 | to_token = form.find('.wishlist-select').val(), |
| 247 | wishlist_name_field = form.find('.wishlist-name'), |
| 248 | wishlist_name = wishlist_name_field.val(), |
| 249 | wishlist_visibility = form.find('.wishlist-visibility').filter(':checked').val(); |
| 250 | |
| 251 | if( 'new' === to_token && ! wishlist_name ){ |
| 252 | wishlist_name_field.closest('p').addClass('woocommerce-invalid'); |
| 253 | return false; |
| 254 | } |
| 255 | else{ |
| 256 | wishlist_name_field.closest('p').removeClass('woocommerce-invalid'); |
| 257 | } |
| 258 | |
| 259 | call_ajax_move_item_to_another_wishlist( |
| 260 | { |
| 261 | wishlist_token : wishlist_token, |
| 262 | destination_wishlist_token: to_token, |
| 263 | item_id : product_id, |
| 264 | wishlist_name : wishlist_name, |
| 265 | wishlist_visibility : wishlist_visibility, |
| 266 | fragments : retrieve_fragments( product_id ) |
| 267 | }, |
| 268 | function(){ |
| 269 | block( t ); |
| 270 | }, |
| 271 | function( response ){ |
| 272 | var response_message = response.message; |
| 273 | |
| 274 | if( yith_wcwl_l10n.multi_wishlist ) { |
| 275 | close_pretty_photo( response_message ); |
| 276 | |
| 277 | if( typeof( response.user_wishlists ) !== 'undefined' ){ |
| 278 | update_wishlists( response.user_wishlists ); |
| 279 | } |
| 280 | } |
| 281 | else { |
| 282 | print_message(response_message); |
| 283 | } |
| 284 | |
| 285 | if( typeof response.fragments !== 'undefined' ) { |
| 286 | replace_fragments( response.fragments ); |
| 287 | } |
| 288 | |
| 289 | init_handling_after_ajax(); |
| 290 | |
| 291 | unblock( t ); |
| 292 | } |
| 293 | ); |
| 294 | } ); |
| 295 | |
| 296 | t.on( 'click', '.delete_item', function(){ |
| 297 | var t = $(this), |
| 298 | product_id = t.attr('data-product-id'), |
| 299 | item_id = t.data('item-id'), |
| 300 | el_wrap = $( '.add-to-wishlist-' + product_id ), |
| 301 | data = { |
| 302 | action: yith_wcwl_l10n.actions.delete_item_action, |
| 303 | context: 'frontend', |
| 304 | item_id: item_id, |
| 305 | fragments: retrieve_fragments( product_id ) |
| 306 | }; |
| 307 | |
| 308 | $.ajax( { |
| 309 | url: yith_wcwl_l10n.ajax_url, |
| 310 | data : data, |
| 311 | dataType: 'json', |
| 312 | beforeSend: function(){ |
| 313 | block( t ); |
| 314 | }, |
| 315 | complete: function(){ |
| 316 | unblock( t ); |
| 317 | }, |
| 318 | method: 'post', |
| 319 | success: function( response ){ |
| 320 | var fragments = response.fragments, |
| 321 | response_message = response.message; |
| 322 | |
| 323 | if( yith_wcwl_l10n.multi_wishlist ) { |
| 324 | close_pretty_photo( response_message ); |
| 325 | } |
| 326 | |
| 327 | if( ! t.closest( '.yith-wcwl-remove-button' ).length ){ |
| 328 | print_message(response_message); |
| 329 | } |
| 330 | |
| 331 | if( typeof fragments !== 'undefined' ){ |
| 332 | replace_fragments( fragments ); |
| 333 | } |
| 334 | |
| 335 | init_handling_after_ajax(); |
| 336 | |
| 337 | $('body').trigger('removed_from_wishlist', [ t, el_wrap ] ); |
| 338 | } |
| 339 | } ); |
| 340 | |
| 341 | return false; |
| 342 | } ); |
| 343 | |
| 344 | t.on( 'change', '.yith-wcwl-popup-content .wishlist-select', function(){ |
| 345 | var t = $(this); |
| 346 | |
| 347 | if( t.val() === 'new' ){ |
| 348 | t.parents( '.yith-wcwl-first-row' ).next( '.yith-wcwl-second-row' ).show(); |
| 349 | } |
| 350 | else{ |
| 351 | t.parents( '.yith-wcwl-first-row' ).next( '.yith-wcwl-second-row' ).hide(); |
| 352 | } |
| 353 | } ); |
| 354 | |
| 355 | t.on( 'change', '#bulk_add_to_cart', function(){ |
| 356 | var t = $(this), |
| 357 | checkboxes = t.closest( '.wishlist_table' ).find( '[data-row-id]' ).find( 'input[type="checkbox"]:not(:disabled)' ); |
| 358 | |
| 359 | if( t.is( ':checked' ) ){ |
| 360 | checkboxes.prop( 'checked','checked').change(); |
| 361 | } |
| 362 | else{ |
| 363 | checkboxes.removeProp( 'checked').change(); |
| 364 | } |
| 365 | } ); |
| 366 | |
| 367 | t.on( 'submit', '.wishlist-ask-an-estimate-popup', function(){ |
| 368 | var t = $(this), |
| 369 | form = t.closest( 'form' ), |
| 370 | pp_content = t.closest('.pp_content'), |
| 371 | data = form.serializeArray().reduce( ( data, field ) => { data[ field.name ] = field.value; return data; }, {} ); |
| 372 | |
| 373 | data.action = yith_wcwl_l10n.actions.ask_an_estimate; |
| 374 | data.context = 'frontend'; |
| 375 | |
| 376 | $.ajax({ |
| 377 | beforeSend: function(){ |
| 378 | block( form ); |
| 379 | }, |
| 380 | complete: function(){ |
| 381 | unblock( form ); |
| 382 | }, |
| 383 | data: data, |
| 384 | dataType: 'json', |
| 385 | method: 'post', |
| 386 | success: function( data ){ |
| 387 | if( typeof data.result !== 'undefined' && data.result ){ |
| 388 | var template = data.template; |
| 389 | |
| 390 | if( typeof template !== 'undefined' ){ |
| 391 | form.replaceWith( template ); |
| 392 | pp_content.css('height', 'auto'); |
| 393 | |
| 394 | setTimeout( close_pretty_photo, yith_wcwl_l10n.time_to_close_prettyphoto ); |
| 395 | } |
| 396 | } |
| 397 | else if( typeof data.message !== 'undefined' ){ |
| 398 | form.find( '.woocommerce-error' ).remove(); |
| 399 | form.find( '.popup-description' ).after( $('<div>', { |
| 400 | 'text' : data.message, |
| 401 | 'class': 'woocommerce-error' |
| 402 | } ) ); |
| 403 | } |
| 404 | }, |
| 405 | url: yith_wcwl_l10n.ajax_url |
| 406 | }); |
| 407 | |
| 408 | return false; |
| 409 | } ); |
| 410 | |
| 411 | t.on( 'click', '.yith-wfbt-add-wishlist', function(e){ |
| 412 | e.preventDefault(); |
| 413 | var t = $(this), |
| 414 | form = $( '#yith-wcwl-form' ); |
| 415 | |
| 416 | $('html, body').animate({ |
| 417 | scrollTop: ( form.offset().top) |
| 418 | },500); |
| 419 | |
| 420 | // ajax call |
| 421 | reload_wishlist_and_adding_elem( t, form ); |
| 422 | }); |
| 423 | |
| 424 | t.on( 'submit', '.yith-wcwl-popup-form', function(){ |
| 425 | return false; |
| 426 | } ); |
| 427 | |
| 428 | t.on( 'yith_infs_added_elem', function(){ |
| 429 | init_wishlist_pretty_photo(); |
| 430 | } ); |
| 431 | |
| 432 | t.on( 'found_variation', function( ev, variation ){ |
| 433 | var t = $( ev.target ), |
| 434 | product_id = t.data( 'product_id' ), |
| 435 | variation_id = variation.variation_id, |
| 436 | targets = $('[data-product-id="' + product_id + '"]').add('[data-original-product-id="' + product_id + '"]'), |
| 437 | fragments = targets.closest( '.wishlist-fragment' ).filter(':visible'); |
| 438 | |
| 439 | if( ! product_id || ! variation_id || ! targets.length ){ |
| 440 | return; |
| 441 | } |
| 442 | |
| 443 | targets.each( function(){ |
| 444 | var t = $(this), |
| 445 | container = t.closest( '.yith-wcwl-add-to-wishlist' ), |
| 446 | options; |
| 447 | |
| 448 | t.attr( 'data-original-product-id', product_id ); |
| 449 | t.attr( 'data-product-id', variation_id ); |
| 450 | |
| 451 | if( container.length ) { |
| 452 | options = container.data( 'fragment-options' ); |
| 453 | |
| 454 | if( typeof options !== 'undefined' ){ |
| 455 | options.product_id = variation_id; |
| 456 | container.data( 'fragment-options', options ); |
| 457 | } |
| 458 | |
| 459 | container |
| 460 | .removeClass(function (i, classes) { |
| 461 | return classes.match(/add-to-wishlist-\S+/g).join(' '); |
| 462 | }) |
| 463 | .addClass('add-to-wishlist-' + variation_id) |
| 464 | .attr('data-fragment-ref', variation_id); |
| 465 | } |
| 466 | } ); |
| 467 | |
| 468 | if( ! yith_wcwl_l10n.reload_on_found_variation ) { |
| 469 | return; |
| 470 | } |
| 471 | |
| 472 | block( fragments ); |
| 473 | |
| 474 | load_fragments( { |
| 475 | fragments: fragments, |
| 476 | firstLoad: false |
| 477 | } ); |
| 478 | } ); |
| 479 | |
| 480 | t.on( 'reset_data', function( ev ){ |
| 481 | var t = $( ev.target ), |
| 482 | product_id = t.data( 'product_id' ), |
| 483 | targets = $('[data-original-product-id="' + product_id + '"]'), |
| 484 | fragments = targets.closest( '.wishlist-fragment' ).filter(':visible'); |
| 485 | |
| 486 | if( ! product_id || ! targets.length ){ |
| 487 | return; |
| 488 | } |
| 489 | |
| 490 | targets.each( function(){ |
| 491 | var t = $(this), |
| 492 | container = t.closest( '.yith-wcwl-add-to-wishlist' ), |
| 493 | variation_id = t.attr( 'data-product-id' ), |
| 494 | options; |
| 495 | |
| 496 | t.attr( 'data-product-id', product_id ); |
| 497 | t.attr( 'data-original-product-id', '' ); |
| 498 | |
| 499 | if( container.length ) { |
| 500 | options = container.data( 'fragment-options' ); |
| 501 | |
| 502 | if( typeof options !== 'undefined' ){ |
| 503 | options.product_id = product_id; |
| 504 | container.data( 'fragment-options', options ); |
| 505 | } |
| 506 | |
| 507 | container |
| 508 | .removeClass('add-to-wishlist-' + variation_id) |
| 509 | .addClass('add-to-wishlist-' + product_id) |
| 510 | .attr('data-fragment-ref', product_id); |
| 511 | } |
| 512 | } ); |
| 513 | |
| 514 | if( ! yith_wcwl_l10n.reload_on_found_variation ) { |
| 515 | return; |
| 516 | } |
| 517 | |
| 518 | block( fragments ); |
| 519 | |
| 520 | load_fragments( { |
| 521 | fragments: fragments, |
| 522 | firstLoad: false |
| 523 | } ); |
| 524 | } ); |
| 525 | |
| 526 | t.on( 'yith_wcwl_reload_fragments', load_fragments ); |
| 527 | |
| 528 | t.on( 'yith_infs_added_elem', function( ev, elem ){ |
| 529 | load_fragments( { |
| 530 | container: elem, |
| 531 | firstLoad: false |
| 532 | } ); |
| 533 | } ); |
| 534 | |
| 535 | t.on( 'yith_wcwl_fragments_loaded', function( ev, original, update, firstLoad ){ |
| 536 | if ( ! firstLoad ) { |
| 537 | return; |
| 538 | } |
| 539 | |
| 540 | $( '.variations_form' ).find( '.variations select' ).last().change(); |
| 541 | } ); |
| 542 | |
| 543 | t.on( 'click', '.yith-wcwl-popup-feedback .close-popup', function(ev){ |
| 544 | ev.preventDefault(); |
| 545 | |
| 546 | close_pretty_photo(); |
| 547 | } ); |
| 548 | |
| 549 | init_wishlist_popup(); |
| 550 | |
| 551 | init_wishlist_tooltip(); |
| 552 | |
| 553 | init_wishlist_dropdown(); |
| 554 | |
| 555 | init_wishlist_drag_n_drop(); |
| 556 | |
| 557 | init_quantity(); |
| 558 | |
| 559 | init_wishlist_details_popup(); |
| 560 | |
| 561 | init_wishlist_popup_tabs(); |
| 562 | |
| 563 | init_select_box(); |
| 564 | |
| 565 | init_checkbox_handling(); |
| 566 | |
| 567 | init_wishlist_pretty_photo(); |
| 568 | |
| 569 | init_add_to_cart_icon(); |
| 570 | |
| 571 | init_wishlist_responsive(); |
| 572 | |
| 573 | init_copy_wishlist_link(); |
| 574 | |
| 575 | if( yith_wcwl_l10n.enable_ajax_loading ){ |
| 576 | load_fragments(); |
| 577 | } |
| 578 | |
| 579 | } ).trigger('yith_wcwl_init'); |
| 580 | |
| 581 | /* === INIT FUNCTIONS === */ |
| 582 | |
| 583 | /** |
| 584 | * Adds selectbox where needed |
| 585 | * |
| 586 | * @return void |
| 587 | * @since 3.0.0 |
| 588 | */ |
| 589 | function init_select_box() { |
| 590 | if( typeof $.fn.selectBox !== 'undefined' ) { |
| 591 | $('select.selectBox').filter(':visible').not('.enhanced').selectBox().addClass('enhanced'); |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | /** |
| 596 | * Init PrettyPhoto for all links withi the plugin that open a popup |
| 597 | * |
| 598 | * @return void |
| 599 | * @since 2.0.16 |
| 600 | */ |
| 601 | function init_wishlist_pretty_photo() { |
| 602 | if( typeof $.prettyPhoto === 'undefined' ){ |
| 603 | return; |
| 604 | } |
| 605 | |
| 606 | var ppParams = { |
| 607 | hook : 'data-rel', |
| 608 | social_tools : false, |
| 609 | theme : 'pp_woocommerce', |
| 610 | horizontal_padding : 20, |
| 611 | opacity : 0.8, |
| 612 | deeplinking : false, |
| 613 | overlay_gallery : false, |
| 614 | default_width : 500, |
| 615 | changepicturecallback : function(){ |
| 616 | init_select_box(); |
| 617 | |
| 618 | $('.wishlist-select').filter(':visible').change(); |
| 619 | $(document).trigger( 'yith_wcwl_popup_opened', [ this ] ); |
| 620 | }, |
| 621 | markup: '<div class="pp_pic_holder">' + |
| 622 | '<div class="ppt"> </div>' + |
| 623 | '<div class="pp_top">' + |
| 624 | '<div class="pp_left"></div>' + |
| 625 | '<div class="pp_middle"></div>' + |
| 626 | '<div class="pp_right"></div>' + |
| 627 | '</div>' + |
| 628 | '<div class="pp_content_container">' + |
| 629 | '<div class="pp_left">' + |
| 630 | '<div class="pp_right">' + |
| 631 | '<div class="pp_content">' + |
| 632 | '<div class="pp_loaderIcon"></div>' + |
| 633 | '<div class="pp_fade">' + |
| 634 | '<a href="#" class="pp_expand" title="Expand the image">Expand</a>' + |
| 635 | '<div class="pp_hoverContainer">' + |
| 636 | '<a class="pp_next" href="#">next</a>' + |
| 637 | '<a class="pp_previous" href="#">previous</a>' + |
| 638 | '</div>' + |
| 639 | '<div id="pp_full_res"></div>' + |
| 640 | '<div class="pp_details">' + |
| 641 | '<a class="pp_close" href="#">Close</a>' + |
| 642 | '</div>' + |
| 643 | '</div>' + |
| 644 | '</div>' + |
| 645 | '</div>' + |
| 646 | '</div>' + |
| 647 | '</div>' + |
| 648 | '<div class="pp_bottom">' + |
| 649 | '<div class="pp_left"></div>' + |
| 650 | '<div class="pp_middle"></div>' + |
| 651 | '<div class="pp_right"></div>' + |
| 652 | '</div>' + |
| 653 | '</div>' + |
| 654 | '<div class="pp_overlay yith-wcwl-overlay"></div>' |
| 655 | }; |
| 656 | |
| 657 | $('a[data-rel^="prettyPhoto[add_to_wishlist_"]') |
| 658 | .add('a[data-rel="prettyPhoto[ask_an_estimate]"]') |
| 659 | .add('a[data-rel="prettyPhoto[create_wishlist]"]') |
| 660 | .unbind( 'click' ) |
| 661 | .prettyPhoto( ppParams ); |
| 662 | |
| 663 | $('a[data-rel="prettyPhoto[move_to_another_wishlist]"]').on( 'click', function(){ |
| 664 | var t = $(this), |
| 665 | popup = $('#move_to_another_wishlist'), |
| 666 | form = popup.find('form'), |
| 667 | row_id = form.find( '.row-id' ), |
| 668 | id = t.closest('[data-row-id]').data('row-id'); |
| 669 | |
| 670 | if( row_id.length ){ |
| 671 | row_id.remove(); |
| 672 | } |
| 673 | |
| 674 | form.append( '<input type="hidden" name="row_id" class="row-id" value="' + id + '"/>' ); |
| 675 | } ).prettyPhoto( ppParams ); |
| 676 | |
| 677 | // add & remove class to body when popup is opened |
| 678 | var callback = function( node, op ){ |
| 679 | if( typeof node.classList !== 'undefined' && node.classList.contains( 'yith-wcwl-overlay' ) ){ |
| 680 | var method = 'remove' === op ? 'removeClass' : 'addClass'; |
| 681 | |
| 682 | $('body')[method]( 'yith-wcwl-with-pretty-photo' ); |
| 683 | } |
| 684 | }, |
| 685 | callbackAdd = function( node ) { |
| 686 | callback( node, 'add' ); |
| 687 | }, |
| 688 | callbackRemove = function( node ) { |
| 689 | callback( node, 'remove' ); |
| 690 | }, |
| 691 | observer = new MutationObserver( function( mutationsList ){ |
| 692 | for ( var i in mutationsList ) { |
| 693 | var mutation = mutationsList[ i ]; |
| 694 | if ( mutation.type === 'childList' ) { |
| 695 | typeof mutation.addedNodes !== 'undefined' && mutation.addedNodes.forEach( callbackAdd); |
| 696 | |
| 697 | typeof mutation.removedNodes !== 'undefined' && mutation.removedNodes.forEach( callbackRemove ); |
| 698 | } |
| 699 | } |
| 700 | } ); |
| 701 | |
| 702 | observer.observe( document.body, { |
| 703 | childList: true |
| 704 | } ); |
| 705 | } |
| 706 | |
| 707 | /** |
| 708 | * Init checkbox handling |
| 709 | * |
| 710 | * @return void |
| 711 | * @since 3.0.0 |
| 712 | */ |
| 713 | function init_checkbox_handling() { |
| 714 | var checkboxes = $('.wishlist_table').find('.product-checkbox input[type="checkbox"]'); |
| 715 | |
| 716 | checkboxes.off('change').on( 'change', function(){ |
| 717 | var t = $(this), |
| 718 | p = t.parent(); |
| 719 | |
| 720 | p |
| 721 | .removeClass( 'checked' ) |
| 722 | .removeClass( 'unchecked' ) |
| 723 | .addClass( t.is(':checked') ? 'checked' : 'unchecked' ); |
| 724 | } ).trigger('change'); |
| 725 | } |
| 726 | |
| 727 | /** |
| 728 | * Show icon on Add to Cart button |
| 729 | * |
| 730 | * @return void |
| 731 | */ |
| 732 | function init_add_to_cart_icon() { |
| 733 | $('.add_to_cart').filter('[data-icon]').not('.icon-added').each( function(){ |
| 734 | var t = $(this), |
| 735 | data = t.data('icon'), |
| 736 | icon; |
| 737 | |
| 738 | if( data.match( /[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)?/gi ) ){ |
| 739 | icon = $( '<img/>', { 'src': data } ); |
| 740 | } |
| 741 | else{ |
| 742 | icon = $( '<i/>', { 'class': 'fa ' + data } ); |
| 743 | } |
| 744 | |
| 745 | t.prepend( icon ).addClass('icon-added'); |
| 746 | } ); |
| 747 | } |
| 748 | |
| 749 | /** |
| 750 | * Init js handling on wishlist table items after ajax update |
| 751 | * |
| 752 | * @return void |
| 753 | * @since 2.0.7 |
| 754 | */ |
| 755 | function init_handling_after_ajax() { |
| 756 | init_select_box(); |
| 757 | init_wishlist_pretty_photo(); |
| 758 | init_checkbox_handling(); |
| 759 | init_add_to_cart_icon(); |
| 760 | init_wishlist_dropdown(); |
| 761 | init_wishlist_tooltip(); |
| 762 | init_wishlist_details_popup(); |
| 763 | init_wishlist_drag_n_drop(); |
| 764 | init_quantity(); |
| 765 | init_copy_wishlist_link(); |
| 766 | |
| 767 | $(document).trigger( 'yith_wcwl_init_after_ajax' ); |
| 768 | } |
| 769 | |
| 770 | /** |
| 771 | * Add tooltip to Add to Wishlist buttons |
| 772 | * |
| 773 | * @return void |
| 774 | * @since 3.0.0 |
| 775 | */ |
| 776 | function init_wishlist_tooltip() { |
| 777 | if( ! yith_wcwl_l10n.enable_tooltip ){ |
| 778 | return; |
| 779 | } |
| 780 | |
| 781 | $('.yith-wcwl-add-to-wishlist').find('[data-title]').each( function(){ |
| 782 | var t = $(this); |
| 783 | |
| 784 | if( t.hasClass( 'tooltip-added' ) ){ |
| 785 | return; |
| 786 | } |
| 787 | |
| 788 | t |
| 789 | .on('mouseenter', function () { |
| 790 | var t = $(this), |
| 791 | tooltip = null, |
| 792 | wrapperWidth = t.outerWidth(), |
| 793 | left = 0, |
| 794 | width = 0; |
| 795 | |
| 796 | tooltip = $('<span>', {'class': 'yith-wcwl-tooltip', 'text': t.data('title')}); |
| 797 | |
| 798 | t.append(tooltip); |
| 799 | |
| 800 | width = tooltip.outerWidth() + 6; |
| 801 | tooltip.outerWidth(width); |
| 802 | left = (wrapperWidth - width) / 2; |
| 803 | |
| 804 | tooltip.css({left: left.toFixed(0) + 'px'}).fadeIn(200); |
| 805 | |
| 806 | t.addClass('with-tooltip'); |
| 807 | }) |
| 808 | .on('mouseleave', function () { |
| 809 | var t = $(this); |
| 810 | |
| 811 | t.find('.yith-wcwl-tooltip').fadeOut(200, function(){ |
| 812 | t.removeClass('with-tooltip').find('.yith-wcwl-tooltip').remove(); |
| 813 | }); |
| 814 | }); |
| 815 | |
| 816 | t.addClass('tooltip-added'); |
| 817 | } ); |
| 818 | } |
| 819 | |
| 820 | /** |
| 821 | * Add wishlist popup message |
| 822 | * |
| 823 | * @return void |
| 824 | * @since 2.0.0 |
| 825 | */ |
| 826 | function init_wishlist_popup() { |
| 827 | if( typeof yith_wcwl_l10n.enable_notices !== 'undefined' && ! yith_wcwl_l10n.enable_notices ){ |
| 828 | return; |
| 829 | } |
| 830 | |
| 831 | if( $('.yith-wcwl-add-to-wishlist').length && ! $( '#yith-wcwl-popup-message' ).length ) { |
| 832 | var message_div = $( '<div>' ) |
| 833 | .attr( 'id', 'yith-wcwl-message' ), |
| 834 | popup_div = $( '<div>' ) |
| 835 | .attr( 'id', 'yith-wcwl-popup-message' ) |
| 836 | .html( message_div ) |
| 837 | .hide(); |
| 838 | |
| 839 | $( 'body' ).prepend( popup_div ); |
| 840 | } |
| 841 | } |
| 842 | |
| 843 | /** |
| 844 | * Add Dropdown to Add to Wishlist when modal is disabled and Multi Wishlist enabled |
| 845 | * |
| 846 | * @return void |
| 847 | * @since 3.0.0 |
| 848 | */ |
| 849 | function init_wishlist_dropdown() { |
| 850 | $('.yith-wcwl-add-button').filter('.with-dropdown') |
| 851 | .on( 'mouseleave', function(){ |
| 852 | var t = $(this), |
| 853 | dropdown = t.find('.yith-wcwl-dropdown'); |
| 854 | |
| 855 | if( dropdown.length ) { |
| 856 | dropdown.fadeOut(200); |
| 857 | } |
| 858 | } ) |
| 859 | .children('a') |
| 860 | .on( 'mouseenter', function(){ |
| 861 | var t = $(this), |
| 862 | el_wrap = t.closest('.with-dropdown'), |
| 863 | dropdown = el_wrap.find('.yith-wcwl-dropdown'); |
| 864 | |
| 865 | if( dropdown.length && dropdown.children().length ){ |
| 866 | el_wrap.find('.yith-wcwl-dropdown').fadeIn(200); |
| 867 | } |
| 868 | } ); |
| 869 | } |
| 870 | |
| 871 | /** |
| 872 | * Handle Drag & Drop of wishlist items for sorting |
| 873 | * |
| 874 | * @return void |
| 875 | * @since 3.0.0 |
| 876 | */ |
| 877 | function init_wishlist_drag_n_drop() { |
| 878 | if( typeof yith_wcwl_l10n.enable_drag_n_drop === 'undefined' || ! yith_wcwl_l10n.enable_drag_n_drop ){ |
| 879 | return; |
| 880 | } |
| 881 | |
| 882 | $('.wishlist_table').filter('.sortable').not('.no-interactions').each( function(){ |
| 883 | var t = $(this), |
| 884 | jqxhr = false; |
| 885 | |
| 886 | t.sortable( { |
| 887 | items: '[data-row-id]', |
| 888 | scroll: true, |
| 889 | helper: function( e, ui ){ |
| 890 | ui.children().each(function() { |
| 891 | $(this).width($(this).width()); |
| 892 | }); |
| 893 | return ui; |
| 894 | }, |
| 895 | update: function(){ |
| 896 | var row = t.find('[data-row-id]'), |
| 897 | positions = [], |
| 898 | i = 0; |
| 899 | |
| 900 | if( ! row.length ){ |
| 901 | return; |
| 902 | } |
| 903 | |
| 904 | if( jqxhr ){ |
| 905 | jqxhr.abort(); |
| 906 | } |
| 907 | |
| 908 | row.each( function(){ |
| 909 | var t = $(this); |
| 910 | |
| 911 | t.find( 'input[name*="[position]"]' ).val(i++); |
| 912 | |
| 913 | positions.push( t.data('row-id') ); |
| 914 | } ); |
| 915 | |
| 916 | jqxhr = $.ajax({ |
| 917 | data: { |
| 918 | action: yith_wcwl_l10n.actions.sort_wishlist_items, |
| 919 | context: 'frontend', |
| 920 | positions: positions, |
| 921 | wishlist_token: t.data('token'), |
| 922 | page: t.data('page'), |
| 923 | per_page: t.data('per-page') |
| 924 | }, |
| 925 | method: 'POST', |
| 926 | url: yith_wcwl_l10n.ajax_url |
| 927 | }); |
| 928 | } |
| 929 | } ); |
| 930 | } ); |
| 931 | } |
| 932 | |
| 933 | /** |
| 934 | * Handle quantity input change for each wishlist item |
| 935 | * |
| 936 | * @return void |
| 937 | * @since 3.0.0 |
| 938 | */ |
| 939 | function init_quantity() { |
| 940 | var jqxhr, |
| 941 | timeout; |
| 942 | |
| 943 | $('.wishlist_table').on( 'change', '.product-quantity :input', function(){ |
| 944 | var t = $(this), |
| 945 | row = t.closest('[data-row-id]'), |
| 946 | product_id = row.data('row-id'), |
| 947 | table = t.closest('.wishlist_table'), |
| 948 | token = table.data('token'); |
| 949 | |
| 950 | clearTimeout( timeout ); |
| 951 | |
| 952 | // set add to cart link to add specific qty to cart |
| 953 | row.find( '.add_to_cart' ).attr('data-quantity', t.val()); |
| 954 | |
| 955 | timeout = setTimeout( function(){ |
| 956 | if( jqxhr ){ |
| 957 | jqxhr.abort(); |
| 958 | } |
| 959 | |
| 960 | jqxhr = $.ajax({ |
| 961 | beforeSend: function(){ |
| 962 | block( table ); |
| 963 | }, |
| 964 | complete: function(){ |
| 965 | unblock( table ); |
| 966 | }, |
| 967 | data: { |
| 968 | action: yith_wcwl_l10n.actions.update_item_quantity, |
| 969 | context: 'frontend', |
| 970 | product_id: product_id, |
| 971 | wishlist_token: token, |
| 972 | quantity: t.val() |
| 973 | }, |
| 974 | method: 'POST', |
| 975 | url: yith_wcwl_l10n.ajax_url |
| 976 | }); |
| 977 | }, 1000 ); |
| 978 | } ); |
| 979 | } |
| 980 | |
| 981 | /** |
| 982 | * Init handling for copy button |
| 983 | * |
| 984 | * @return void |
| 985 | * @since 2.2.11 |
| 986 | */ |
| 987 | function init_copy_wishlist_link () { |
| 988 | $('.copy-trigger').on('click', function () { |
| 989 | |
| 990 | var obj_to_copy = $('.copy-target'); |
| 991 | |
| 992 | if (obj_to_copy.length > 0) { |
| 993 | if (obj_to_copy.is('input')) { |
| 994 | |
| 995 | if (isOS()) { |
| 996 | |
| 997 | obj_to_copy[0].setSelectionRange(0, 9999); |
| 998 | } else { |
| 999 | obj_to_copy.select(); |
| 1000 | } |
| 1001 | document.execCommand( 'copy' ); |
| 1002 | } else { |
| 1003 | |
| 1004 | var hidden = $('<input/>', { |
| 1005 | val : obj_to_copy.text(), |
| 1006 | type: 'text' |
| 1007 | }); |
| 1008 | |
| 1009 | $('body').append(hidden); |
| 1010 | |
| 1011 | if (isOS()) { |
| 1012 | hidden[0].setSelectionRange(0, 9999); |
| 1013 | } else { |
| 1014 | hidden.select(); |
| 1015 | } |
| 1016 | document.execCommand('copy'); |
| 1017 | |
| 1018 | hidden.remove(); |
| 1019 | } |
| 1020 | } |
| 1021 | }); |
| 1022 | } |
| 1023 | |
| 1024 | /** |
| 1025 | * Handle popup for images grid layout |
| 1026 | * |
| 1027 | * @return void |
| 1028 | * @since 3.0.0 |
| 1029 | */ |
| 1030 | function init_wishlist_details_popup() { |
| 1031 | $('.wishlist_table').filter('.images_grid').not('.enhanced') |
| 1032 | .on( 'click', '[data-row-id] .product-thumbnail a', function(ev){ |
| 1033 | var t = $(this), |
| 1034 | item = t.closest('[data-row-id]'), |
| 1035 | items = item.siblings( '[data-row-id]' ), |
| 1036 | popup = item.find('.item-details'); |
| 1037 | |
| 1038 | ev.preventDefault(); |
| 1039 | |
| 1040 | if( popup.length ){ |
| 1041 | items.removeClass('show'); |
| 1042 | item.toggleClass( 'show' ); |
| 1043 | } |
| 1044 | } ) |
| 1045 | .on( 'click', '[data-row-id] a.close', function (ev){ |
| 1046 | var t = $(this), |
| 1047 | item = t.closest('[data-row-id]'), |
| 1048 | popup = item.find('.item-details'); |
| 1049 | |
| 1050 | ev.preventDefault(); |
| 1051 | |
| 1052 | if( popup.length ){ |
| 1053 | item.removeClass('show'); |
| 1054 | } |
| 1055 | } ) |
| 1056 | .on( 'click', '[data-row-id] a.remove_from_wishlist', function(ev){ |
| 1057 | var t = $(this); |
| 1058 | |
| 1059 | ev.stopPropagation(); |
| 1060 | |
| 1061 | remove_item_from_wishlist( t ); |
| 1062 | |
| 1063 | return false; |
| 1064 | } ) |
| 1065 | .addClass( 'enhanced' ); |
| 1066 | |
| 1067 | |
| 1068 | $(document) |
| 1069 | .on( 'click', function( ev ){ |
| 1070 | if( ! $( ev.target ).closest( '[data-row-id]' ).length ){ |
| 1071 | $('.wishlist_table').filter('.images_grid').find('.show').removeClass('show'); |
| 1072 | } |
| 1073 | } ) |
| 1074 | .on( 'added_to_cart', function(){ |
| 1075 | $('.wishlist_table').filter('.images_grid').find('.show').removeClass('show'); |
| 1076 | } ); |
| 1077 | } |
| 1078 | |
| 1079 | /** |
| 1080 | * Handle tabs inside wishlist popups |
| 1081 | * |
| 1082 | * @return void |
| 1083 | * @since 3.0.0 |
| 1084 | */ |
| 1085 | function init_wishlist_popup_tabs() { |
| 1086 | $(document).on( 'click', '.show-tab', function(ev){ |
| 1087 | var t = $(this), |
| 1088 | container = t.closest('.yith-wcwl-popup-content'), |
| 1089 | tab = t.data('tab'), |
| 1090 | target = container.find('.tab').filter( '.' + tab ); |
| 1091 | |
| 1092 | ev.preventDefault(); |
| 1093 | |
| 1094 | if( ! target.length ){ |
| 1095 | return false; |
| 1096 | } |
| 1097 | |
| 1098 | t.addClass('active').siblings('.show-tab').removeClass('active'); |
| 1099 | |
| 1100 | target.show().siblings('.tab').hide(); |
| 1101 | |
| 1102 | if( 'create' === tab ){ |
| 1103 | container.prepend( '<input type="hidden" id="new_wishlist_selector" class="wishlist-select" value="new">' ); |
| 1104 | } |
| 1105 | else{ |
| 1106 | container.find( '#new_wishlist_selector' ).remove(); |
| 1107 | } |
| 1108 | } ); |
| 1109 | |
| 1110 | $(document).on( 'change', '.wishlist-select', function(){ |
| 1111 | var t = $(this), |
| 1112 | container = t.closest('.yith-wcwl-popup-content'), |
| 1113 | tab = t.closest( '.tab' ), |
| 1114 | createTab = container.find( '.tab.create' ), |
| 1115 | showTab = container.find( '.show-tab' ), |
| 1116 | createShowTab = showTab.filter( '[data-tab="create"]' ), |
| 1117 | val = t.val(); |
| 1118 | |
| 1119 | if( val === 'new' && createTab.length ){ |
| 1120 | tab.hide(); |
| 1121 | createTab.show(); |
| 1122 | |
| 1123 | showTab.removeClass( 'active' ); |
| 1124 | createShowTab.addClass( 'active' ); |
| 1125 | |
| 1126 | t.find('option').removeProp( 'selected' ); |
| 1127 | t.change(); |
| 1128 | } |
| 1129 | } ); |
| 1130 | } |
| 1131 | |
| 1132 | /** |
| 1133 | * Init responsive behaviour of the wishlist |
| 1134 | * |
| 1135 | * @return void |
| 1136 | * @since 3.0.0 |
| 1137 | */ |
| 1138 | function init_wishlist_responsive() { |
| 1139 | var jqxhr = false; |
| 1140 | |
| 1141 | if( ! yith_wcwl_l10n.is_wishlist_responsive ){ |
| 1142 | return; |
| 1143 | } |
| 1144 | |
| 1145 | $( window ).on( 'resize', function(){ |
| 1146 | var table = $('.wishlist_table.responsive'), |
| 1147 | mobile = table.is('.mobile'), |
| 1148 | media = window.matchMedia( '(max-width: 768px)' ), |
| 1149 | form = table.closest('form'), |
| 1150 | id = form.attr('class'), |
| 1151 | options = form.data('fragment-options'), |
| 1152 | fragments = {}, |
| 1153 | load = false; |
| 1154 | |
| 1155 | if( ! table.length ){ |
| 1156 | return; |
| 1157 | } |
| 1158 | |
| 1159 | if( media.matches && table && ! mobile ){ |
| 1160 | options.is_mobile = 'yes'; |
| 1161 | load = true; |
| 1162 | } |
| 1163 | else if( ! media.matches && table && mobile ){ |
| 1164 | options.is_mobile = 'no'; |
| 1165 | load = true; |
| 1166 | } |
| 1167 | |
| 1168 | if( load ){ |
| 1169 | if( jqxhr ){ |
| 1170 | jqxhr.abort(); |
| 1171 | } |
| 1172 | |
| 1173 | fragments[ id.split( ' ' ).join( yith_wcwl_l10n.fragments_index_glue ) ] = options; |
| 1174 | |
| 1175 | jqxhr = $.ajax( { |
| 1176 | beforeSend: function(){ |
| 1177 | block( table ); |
| 1178 | }, |
| 1179 | complete: function(){ |
| 1180 | unblock( table ); |
| 1181 | }, |
| 1182 | data: { |
| 1183 | action: yith_wcwl_l10n.actions.load_mobile_action, |
| 1184 | context: 'frontend', |
| 1185 | fragments: fragments |
| 1186 | }, |
| 1187 | method: 'post', |
| 1188 | success: function( data ){ |
| 1189 | if( typeof data.fragments !== 'undefined' ){ |
| 1190 | replace_fragments( data.fragments ); |
| 1191 | |
| 1192 | init_handling_after_ajax(); |
| 1193 | |
| 1194 | $(document).trigger( 'yith_wcwl_responsive_template', [ mobile, data.fragments ] ); |
| 1195 | } |
| 1196 | }, |
| 1197 | url: yith_wcwl_l10n.ajax_url |
| 1198 | } ); |
| 1199 | } |
| 1200 | } ); |
| 1201 | } |
| 1202 | |
| 1203 | /* === EVENT HANDLING === */ |
| 1204 | |
| 1205 | /** |
| 1206 | * Move item to another wishlist |
| 1207 | * |
| 1208 | * @return void |
| 1209 | * @since 3.0.0 |
| 1210 | */ |
| 1211 | function call_ajax_move_item_to_another_wishlist( data, beforeSend, complete ) { |
| 1212 | data.action = yith_wcwl_l10n.actions.move_to_another_wishlist_action; |
| 1213 | data.context = 'frontend'; |
| 1214 | |
| 1215 | if( data.wishlist_token === '' || data.destination_wishlist_token === '' || data.item_id === '' ){ |
| 1216 | return; |
| 1217 | } |
| 1218 | |
| 1219 | $.ajax( { |
| 1220 | beforeSend: beforeSend, |
| 1221 | url: yith_wcwl_l10n.ajax_url, |
| 1222 | data: data, |
| 1223 | dataType: 'json', |
| 1224 | method: 'post', |
| 1225 | success: function( response ){ |
| 1226 | complete( response ); |
| 1227 | |
| 1228 | init_handling_after_ajax(); |
| 1229 | |
| 1230 | $('body').trigger('moved_to_another_wishlist', [ $(this), data.item_id ] ); |
| 1231 | } |
| 1232 | }); |
| 1233 | } |
| 1234 | |
| 1235 | /** |
| 1236 | * Remove a product from the wishlist. |
| 1237 | * |
| 1238 | * @param el |
| 1239 | * @return void |
| 1240 | * @since 1.0.0 |
| 1241 | */ |
| 1242 | function remove_item_from_wishlist( el ) { |
| 1243 | var table = el.parents( '.cart.wishlist_table' ), |
| 1244 | row = el.parents( '[data-row-id]' ), |
| 1245 | data_row_id = row.data( 'row-id'), |
| 1246 | wishlist_id = table.data( 'id' ), |
| 1247 | wishlist_token = table.data( 'token' ), |
| 1248 | data = { |
| 1249 | action: yith_wcwl_l10n.actions.remove_from_wishlist_action, |
| 1250 | context: 'frontend', |
| 1251 | remove_from_wishlist: data_row_id, |
| 1252 | wishlist_id: wishlist_id, |
| 1253 | wishlist_token: wishlist_token, |
| 1254 | fragments: retrieve_fragments( data_row_id ) |
| 1255 | }; |
| 1256 | |
| 1257 | $.ajax( { |
| 1258 | beforeSend: function(){ |
| 1259 | block( table ); |
| 1260 | }, |
| 1261 | complete: function(){ |
| 1262 | unblock( table ); |
| 1263 | }, |
| 1264 | data: data, |
| 1265 | method: 'post', |
| 1266 | success: function( data ){ |
| 1267 | if( typeof data.fragments !== 'undefined' ){ |
| 1268 | replace_fragments( data.fragments ); |
| 1269 | } |
| 1270 | |
| 1271 | init_handling_after_ajax(); |
| 1272 | |
| 1273 | $('body').trigger('removed_from_wishlist', [ el, row ] ); |
| 1274 | }, |
| 1275 | url: yith_wcwl_l10n.ajax_url |
| 1276 | } ); |
| 1277 | } |
| 1278 | |
| 1279 | /** |
| 1280 | * Remove a product from the wishlist. |
| 1281 | * |
| 1282 | * @param el |
| 1283 | * @param form |
| 1284 | * @return void |
| 1285 | * @since 1.0.0 |
| 1286 | */ |
| 1287 | function reload_wishlist_and_adding_elem( el, form ) { |
| 1288 | |
| 1289 | var product_id = el.attr( 'data-product-id' ), |
| 1290 | table = $(document).find( '.cart.wishlist_table' ), |
| 1291 | pagination = table.data( 'pagination' ), |
| 1292 | per_page = table.data( 'per-page' ), |
| 1293 | wishlist_id = table.data( 'id' ), |
| 1294 | wishlist_token = table.data( 'token' ), |
| 1295 | data = { |
| 1296 | action: yith_wcwl_l10n.actions.reload_wishlist_and_adding_elem_action, |
| 1297 | context: 'frontend', |
| 1298 | pagination: pagination, |
| 1299 | per_page: per_page, |
| 1300 | wishlist_id: wishlist_id, |
| 1301 | wishlist_token: wishlist_token, |
| 1302 | add_to_wishlist: product_id, |
| 1303 | product_type: el.data( 'product-type' ) |
| 1304 | }; |
| 1305 | |
| 1306 | if( ! is_cookie_enabled() ){ |
| 1307 | window.alert( yith_wcwl_l10n.labels.cookie_disabled ); |
| 1308 | return; |
| 1309 | } |
| 1310 | |
| 1311 | $.ajax({ |
| 1312 | type: 'POST', |
| 1313 | url: yith_wcwl_l10n.ajax_url, |
| 1314 | data: data, |
| 1315 | dataType : 'html', |
| 1316 | beforeSend: function(){ |
| 1317 | block( table ); |
| 1318 | }, |
| 1319 | complete: function(){ |
| 1320 | unblock( table ); |
| 1321 | }, |
| 1322 | success: function(res) { |
| 1323 | var obj = $(res), |
| 1324 | new_form = obj.find('#yith-wcwl-form'), // get new form |
| 1325 | shortcode = obj.find('.yith-wfbt-slider-wrapper'); // get new form |
| 1326 | |
| 1327 | form.replaceWith( new_form ); |
| 1328 | $('.yith-wfbt-slider-wrapper').replaceWith( shortcode ); |
| 1329 | init_handling_after_ajax(); |
| 1330 | |
| 1331 | $(document).trigger( 'yith_wcwl_reload_wishlist_from_frequently' ); |
| 1332 | } |
| 1333 | }); |
| 1334 | } |
| 1335 | |
| 1336 | /** |
| 1337 | * Show form to edit wishlist title |
| 1338 | * |
| 1339 | * @param ev event |
| 1340 | * @return void |
| 1341 | * @since 2.0.0 |
| 1342 | */ |
| 1343 | function show_title_form( ev ) { |
| 1344 | var t = $(this), |
| 1345 | table = t.closest( '.wishlist_table' ), |
| 1346 | title = null; |
| 1347 | ev.preventDefault(); |
| 1348 | |
| 1349 | // if button is in table |
| 1350 | if( table.length ){ |
| 1351 | title = t.closest('[data-wishlist-id]').find('.wishlist-title'); |
| 1352 | } |
| 1353 | else{ |
| 1354 | title = t.parents( '.wishlist-title' ); |
| 1355 | } |
| 1356 | |
| 1357 | title.next().css( 'display', 'inline-block' ).find('input[type="text"]').focus(); |
| 1358 | title.hide(); |
| 1359 | } |
| 1360 | |
| 1361 | /** |
| 1362 | * Hide form to edit wishlist title |
| 1363 | * |
| 1364 | * @param ev event |
| 1365 | * @return void |
| 1366 | * @since 2.0.0 |
| 1367 | */ |
| 1368 | function hide_title_form( ev ) { |
| 1369 | var t = $(this); |
| 1370 | ev.preventDefault(); |
| 1371 | |
| 1372 | t.parents( '.hidden-title-form').hide(); |
| 1373 | t.parents( '.hidden-title-form').prev().show(); |
| 1374 | } |
| 1375 | |
| 1376 | /** |
| 1377 | * Submit form to save a new wishlist title |
| 1378 | * |
| 1379 | * @param ev event |
| 1380 | * @return void |
| 1381 | * @since 2.0.7 |
| 1382 | */ |
| 1383 | function submit_title_form( ev ) { |
| 1384 | var t = $(this), |
| 1385 | form = t.closest( '.hidden-title-form' ), |
| 1386 | row = t.closest( '[data-wishlist-id]' ), |
| 1387 | wishlist_id = row.data( 'wishlist-id' ), |
| 1388 | title_input = form.find( 'input[type="text"]' ), |
| 1389 | new_title = title_input.val(), |
| 1390 | data = {}; |
| 1391 | |
| 1392 | ev.preventDefault(); |
| 1393 | |
| 1394 | if( ! new_title ){ |
| 1395 | form.addClass('woocommerce-invalid'); |
| 1396 | title_input.focus(); |
| 1397 | return; |
| 1398 | } |
| 1399 | |
| 1400 | if( ! wishlist_id ) { |
| 1401 | wishlist_id = $( '#wishlist_id' ).val(); |
| 1402 | } |
| 1403 | |
| 1404 | data = { |
| 1405 | action: yith_wcwl_l10n.actions.save_title_action, |
| 1406 | context: 'frontend', |
| 1407 | wishlist_id: wishlist_id, |
| 1408 | title: new_title, |
| 1409 | fragments: retrieve_fragments() |
| 1410 | }; |
| 1411 | |
| 1412 | $.ajax({ |
| 1413 | type: 'POST', |
| 1414 | url: yith_wcwl_l10n.ajax_url, |
| 1415 | data: data, |
| 1416 | dataType: 'json', |
| 1417 | beforeSend: function(){ |
| 1418 | block( form ); |
| 1419 | }, |
| 1420 | complete: function(){ |
| 1421 | unblock( form ); |
| 1422 | }, |
| 1423 | success: function( response ) { |
| 1424 | var fragments = response.fragments, |
| 1425 | status = response.result; |
| 1426 | |
| 1427 | if( status ) { |
| 1428 | form.hide(); |
| 1429 | form.prev().find('.wishlist-anchor, h1, h2').text( new_title ).end().show(); |
| 1430 | } |
| 1431 | else{ |
| 1432 | form.addClass( 'woocommerce-invalid' ); |
| 1433 | title_input.focus(); |
| 1434 | } |
| 1435 | |
| 1436 | if( typeof fragments !== 'undefined' ){ |
| 1437 | replace_fragments( fragments ); |
| 1438 | } |
| 1439 | } |
| 1440 | }); |
| 1441 | } |
| 1442 | |
| 1443 | /** |
| 1444 | * Submit form to save a new wishlist privacy |
| 1445 | * |
| 1446 | * @return void |
| 1447 | * @since 2.0.7 |
| 1448 | */ |
| 1449 | function save_privacy(){ |
| 1450 | var t = $(this), |
| 1451 | new_privacy = t.val(), |
| 1452 | row = t.closest( '[data-wishlist-id]' ), |
| 1453 | wishlist_id = row.data( 'wishlist-id' ), |
| 1454 | data = { |
| 1455 | action: yith_wcwl_l10n.actions.save_privacy_action, |
| 1456 | context: 'frontend', |
| 1457 | wishlist_id: wishlist_id, |
| 1458 | privacy: new_privacy, |
| 1459 | fragments: retrieve_fragments() |
| 1460 | }; |
| 1461 | |
| 1462 | $.ajax({ |
| 1463 | type: 'POST', |
| 1464 | url: yith_wcwl_l10n.ajax_url, |
| 1465 | data: data, |
| 1466 | dataType: 'json', |
| 1467 | success: function( response ) { |
| 1468 | var fragments = response.fragments; |
| 1469 | |
| 1470 | if( typeof fragments !== 'undefined' ){ |
| 1471 | replace_fragments( fragments ); |
| 1472 | } |
| 1473 | } |
| 1474 | }); |
| 1475 | } |
| 1476 | |
| 1477 | /* === UTILS === */ |
| 1478 | |
| 1479 | /** |
| 1480 | * Closes pretty photo popup, if any |
| 1481 | * |
| 1482 | * @return void |
| 1483 | * @since 3.0.0 |
| 1484 | */ |
| 1485 | function close_pretty_photo( message ) { |
| 1486 | if( typeof $.prettyPhoto !== 'undefined' && typeof $.prettyPhoto.close !== 'undefined' ) { |
| 1487 | if( typeof message !== 'undefined' ){ |
| 1488 | var container = $('.pp_content_container'), |
| 1489 | content = container.find('.pp_content'), |
| 1490 | form = container.find('.yith-wcwl-popup-form'), |
| 1491 | popup = form.closest( '.pp_pic_holder' ); |
| 1492 | |
| 1493 | if( form.length ){ |
| 1494 | var new_content = $( '<div/>', { |
| 1495 | 'class': 'yith-wcwl-popup-feedback' |
| 1496 | } ); |
| 1497 | |
| 1498 | new_content.append( $( '<i/>', { 'class': 'fa fa-check heading-icon' } ) ); |
| 1499 | new_content.append( $( '<p/>', { 'class': 'feedback', 'html': message } ) ); |
| 1500 | new_content.css( 'display', 'none' ); |
| 1501 | |
| 1502 | content.css( 'height', 'auto' ); |
| 1503 | |
| 1504 | form.after( new_content ); |
| 1505 | form.fadeOut( 200, function(){ |
| 1506 | new_content.fadeIn(); |
| 1507 | } ); |
| 1508 | |
| 1509 | popup.addClass( 'feedback' ); |
| 1510 | popup.css( 'left', ( ( $( window ).innerWidth() / 2 ) - ( popup.outerWidth() / 2 ) ) + 'px' ); |
| 1511 | |
| 1512 | if( typeof yith_wcwl_l10n.auto_close_popup === 'undefined' || yith_wcwl_l10n.auto_close_popup ) { |
| 1513 | setTimeout(close_pretty_photo, yith_wcwl_l10n.popup_timeout); |
| 1514 | } |
| 1515 | } |
| 1516 | } |
| 1517 | else{ |
| 1518 | try { |
| 1519 | $.prettyPhoto.close(); |
| 1520 | } |
| 1521 | catch( e ){ /* do nothing, no popup to close */ } |
| 1522 | } |
| 1523 | } |
| 1524 | } |
| 1525 | |
| 1526 | /** |
| 1527 | * Print wishlist message for the user |
| 1528 | * |
| 1529 | * @var response_message string Message to print |
| 1530 | * @return void |
| 1531 | * @since 3.0.0 |
| 1532 | */ |
| 1533 | function print_message( response_message ) { |
| 1534 | var msgPopup = $( '#yith-wcwl-popup-message' ), |
| 1535 | msg = $( '#yith-wcwl-message' ), |
| 1536 | timeout = typeof yith_wcwl_l10n.popup_timeout !== 'undefined' ? yith_wcwl_l10n.popup_timeout : 3000; |
| 1537 | |
| 1538 | if( typeof yith_wcwl_l10n.enable_notices !== 'undefined' && ! yith_wcwl_l10n.enable_notices ){ |
| 1539 | return; |
| 1540 | } |
| 1541 | |
| 1542 | msg.html( response_message ); |
| 1543 | msgPopup.css( 'margin-left', '-' + $( msgPopup ).width() + 'px' ).fadeIn(); |
| 1544 | window.setTimeout( function() { |
| 1545 | msgPopup.fadeOut(); |
| 1546 | }, timeout ); |
| 1547 | } |
| 1548 | |
| 1549 | /** |
| 1550 | * Update lists after a new list is added |
| 1551 | * |
| 1552 | * @param wishlists array Array of wishlists |
| 1553 | * @return void |
| 1554 | * @since 3.0.0 |
| 1555 | */ |
| 1556 | function update_wishlists( wishlists ) { |
| 1557 | var wishlist_select = $( 'select.wishlist-select' ), |
| 1558 | wishilst_dropdown = $( 'ul.yith-wcwl-dropdown' ); |
| 1559 | |
| 1560 | // update options for all wishlist selects |
| 1561 | wishlist_select.each( function(){ |
| 1562 | var t = $(this), |
| 1563 | wishlist_options = t.find( 'option' ), |
| 1564 | new_option = wishlist_options.filter( '[value="new"]' ); |
| 1565 | |
| 1566 | wishlist_options.not( new_option ).remove(); |
| 1567 | |
| 1568 | $.each( wishlists, function( i, v ){ |
| 1569 | $('<option>', { value: v.id, html: v.wishlist_name } ).appendTo(t); |
| 1570 | } ); |
| 1571 | |
| 1572 | t.append( new_option ); |
| 1573 | } ); |
| 1574 | |
| 1575 | // update options for all wishlist dropdown |
| 1576 | wishilst_dropdown.each( function(){ |
| 1577 | var t = $(this), |
| 1578 | wishlist_options = t.find( 'li' ), |
| 1579 | container = t.closest( '.yith-wcwl-add-button' ), |
| 1580 | default_button = container.children( 'a.add_to_wishlist' ), |
| 1581 | product_id = default_button.attr('data-product-id'), |
| 1582 | product_type = default_button.attr('data-product-type'); |
| 1583 | |
| 1584 | wishlist_options.remove(); |
| 1585 | $.each( wishlists, function( i, v ) { |
| 1586 | if ( v['default'] ) { |
| 1587 | return; |
| 1588 | } |
| 1589 | |
| 1590 | $('<li>').append( $('<a>', { |
| 1591 | 'rel': 'nofollow', |
| 1592 | 'html': v.wishlist_name, |
| 1593 | 'class': 'add_to_wishlist', |
| 1594 | 'href': v.add_to_this_wishlist_url, |
| 1595 | 'data-product-id': product_id, |
| 1596 | 'data-product-type': product_type, |
| 1597 | 'data-wishlist-id': v.id |
| 1598 | } ) ).appendTo(t); |
| 1599 | } ); |
| 1600 | } ); |
| 1601 | } |
| 1602 | |
| 1603 | /** |
| 1604 | * Block item if possible |
| 1605 | * |
| 1606 | * @param item jQuery object |
| 1607 | * @return void |
| 1608 | * @since 3.0.0 |
| 1609 | */ |
| 1610 | function block( item ) { |
| 1611 | if( typeof $.fn.block !== 'undefined' ) { |
| 1612 | item.fadeTo('400', '0.6').block( { |
| 1613 | message: null, |
| 1614 | overlayCSS : { |
| 1615 | background : 'transparent url(' + yith_wcwl_l10n.ajax_loader_url + ') no-repeat center', |
| 1616 | backgroundSize: '40px 40px', |
| 1617 | opacity : 1 |
| 1618 | } |
| 1619 | } ); |
| 1620 | } |
| 1621 | } |
| 1622 | |
| 1623 | /** |
| 1624 | * Unblock item if possible |
| 1625 | * |
| 1626 | * @param item jQuery object |
| 1627 | * @return void |
| 1628 | * @since 3.0.0 |
| 1629 | */ |
| 1630 | function unblock( item ) { |
| 1631 | if( typeof $.fn.unblock !== 'undefined' ) { |
| 1632 | item.stop(true).css('opacity', '1').unblock(); |
| 1633 | } |
| 1634 | } |
| 1635 | |
| 1636 | /** |
| 1637 | * Check if cookies are enabled |
| 1638 | * |
| 1639 | * @return bool |
| 1640 | * @since 2.0.0 |
| 1641 | */ |
| 1642 | function is_cookie_enabled() { |
| 1643 | if ( navigator.cookieEnabled ) { |
| 1644 | return true; |
| 1645 | } |
| 1646 | |
| 1647 | // set and read cookie |
| 1648 | document.cookie = 'cookietest=1'; |
| 1649 | var ret = document.cookie.indexOf('cookietest=') !== -1; |
| 1650 | |
| 1651 | // delete cookie |
| 1652 | document.cookie = 'cookietest=1; expires=Thu, 01-Jan-1970 00:00:01 GMT'; |
| 1653 | |
| 1654 | return ret; |
| 1655 | } |
| 1656 | |
| 1657 | /** |
| 1658 | * Retrieve fragments that need to be refreshed in the page |
| 1659 | * |
| 1660 | * @param search string Ref to search among all fragments in the page |
| 1661 | * @return object Object containing a property for each fragments that matches search |
| 1662 | * @since 3.0.0 |
| 1663 | */ |
| 1664 | function retrieve_fragments( search ) { |
| 1665 | var options = {}, |
| 1666 | fragments = null; |
| 1667 | |
| 1668 | if( search ){ |
| 1669 | if( typeof search === 'object' ){ |
| 1670 | search = $.extend( { |
| 1671 | fragments: null, |
| 1672 | s: '', |
| 1673 | container: $(document), |
| 1674 | firstLoad: false |
| 1675 | }, search ); |
| 1676 | |
| 1677 | if( ! search.fragments ) { |
| 1678 | fragments = search.container.find('.wishlist-fragment'); |
| 1679 | } else { |
| 1680 | fragments = search.fragments; |
| 1681 | } |
| 1682 | |
| 1683 | if( search.s ){ |
| 1684 | fragments = fragments.not('[data-fragment-ref]').add(fragments.filter('[data-fragment-ref="' + search.s + '"]')); |
| 1685 | } |
| 1686 | |
| 1687 | if( search.firstLoad ){ |
| 1688 | fragments = fragments.filter( '.on-first-load' ); |
| 1689 | } |
| 1690 | } |
| 1691 | else { |
| 1692 | fragments = $('.wishlist-fragment'); |
| 1693 | |
| 1694 | if (typeof search === 'string' || typeof search === 'number') { |
| 1695 | fragments = fragments.not('[data-fragment-ref]').add(fragments.filter('[data-fragment-ref="' + search + '"]')); |
| 1696 | } |
| 1697 | } |
| 1698 | } |
| 1699 | else{ |
| 1700 | fragments = $('.wishlist-fragment'); |
| 1701 | } |
| 1702 | |
| 1703 | if ( fragments.length ) { |
| 1704 | fragments.each( function () { |
| 1705 | var t = $( this ), |
| 1706 | id = t.attr( 'class' ).split( ' ' ).filter( ( val ) => { |
| 1707 | return val.length && val !== 'exists'; |
| 1708 | } ).join( yith_wcwl_l10n.fragments_index_glue ); |
| 1709 | |
| 1710 | options[ id ] = t.data( 'fragment-options' ); |
| 1711 | } ); |
| 1712 | } else { |
| 1713 | return null; |
| 1714 | } |
| 1715 | |
| 1716 | return options; |
| 1717 | } |
| 1718 | |
| 1719 | /** |
| 1720 | * Load fragments on page loading |
| 1721 | * |
| 1722 | * @param search string Ref to search among all fragments in the page |
| 1723 | * @since 3.0.0 |
| 1724 | */ |
| 1725 | function load_fragments( search ) { |
| 1726 | search = $.extend( { |
| 1727 | firstLoad: true |
| 1728 | }, search ); |
| 1729 | |
| 1730 | var fragments = retrieve_fragments( search ); |
| 1731 | |
| 1732 | if( ! fragments ){ |
| 1733 | return; |
| 1734 | } |
| 1735 | |
| 1736 | $.ajax( { |
| 1737 | data: { |
| 1738 | action: yith_wcwl_l10n.actions.load_fragments, |
| 1739 | context: 'frontend', |
| 1740 | fragments: fragments |
| 1741 | }, |
| 1742 | method: 'post', |
| 1743 | success: function( data ){ |
| 1744 | if( typeof data.fragments !== 'undefined' ){ |
| 1745 | replace_fragments( data.fragments ); |
| 1746 | |
| 1747 | init_handling_after_ajax(); |
| 1748 | |
| 1749 | $(document).trigger( 'yith_wcwl_fragments_loaded', [ fragments, data.fragments, search.firstLoad ] ); |
| 1750 | } |
| 1751 | }, |
| 1752 | url: yith_wcwl_l10n.ajax_url |
| 1753 | } ); |
| 1754 | } |
| 1755 | |
| 1756 | /** |
| 1757 | * Replace fragments with template received |
| 1758 | * |
| 1759 | * @param fragments array Array of fragments to replace |
| 1760 | * @since 3.0.0 |
| 1761 | */ |
| 1762 | function replace_fragments( fragments ) { |
| 1763 | $.each( fragments, function( i, v ){ |
| 1764 | var itemSelector = '.' + i.split( yith_wcwl_l10n.fragments_index_glue ).filter( ( val ) => { return val.length && val !== 'exists'; } ).join( '.' ), |
| 1765 | toReplace = $( itemSelector ); |
| 1766 | |
| 1767 | // find replace tempalte |
| 1768 | var replaceWith = $(v).filter( itemSelector ); |
| 1769 | |
| 1770 | if( ! replaceWith.length ){ |
| 1771 | replaceWith = $(v).find( itemSelector ); |
| 1772 | } |
| 1773 | |
| 1774 | if( toReplace.length && replaceWith.length ){ |
| 1775 | toReplace.replaceWith( replaceWith ); |
| 1776 | } |
| 1777 | } ) ; |
| 1778 | } |
| 1779 | |
| 1780 | /** |
| 1781 | * Check if device is an IOS device |
| 1782 | * @since 2.2.11 |
| 1783 | */ |
| 1784 | function isOS() { |
| 1785 | return navigator.userAgent.match(/ipad|iphone/i); |
| 1786 | } |
| 1787 | |
| 1788 | /** |
| 1789 | * Check if passed value could be considered true |
| 1790 | * @since 3.0.14 |
| 1791 | */ |
| 1792 | function isTrue( value ) { |
| 1793 | return true === value || 'yes' === value || '1' === value || 1 === value; |
| 1794 | } |
| 1795 | } ); |
| 1796 |