PageSourceSearch

https://eclos.fr/wp-content/themes/kidba/assets/js//modules/woo/general.js?ver=1790995571

js eclos.fr collected 2026-10-03 02:48:12 UTC 20,817 bytes, 534 lines download raw bytes

1(function($) {
2    'use strict';
3
4    var $window = $( window );
5    var $body = $( 'body' );
6    window.kidba = window.kidba || {};
7    $window.on('load', function() {
8        kidbaQuickViewPopup();
9    })
10    kidba.Helpers = {
11        getAjaxUrl: ( action ) => {
12            return $kidba.kidba_ajax_url.toString().replace( '%%endpoint%%', action );
13        },
14
15        isEmptyObject: ( obj ) => {
16            for ( let name in obj ) {
17                return false;
18            }
19
20            return true;
21        },
22
23        isValidSelector: ( selector ) => {
24            if ( selector.match( /^([.#])(.+)/ ) ) {
25                return true;
26            }
27
28            return false;
29        },
30
31        isHandheld: () => {
32            let check = false;
33            (
34                function( a ) {
35                    if ( /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test( a ) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test( a.substr( 0, 4 ) ) ) {
36                        check = true;
37                    }
38                }
39            )( navigator.userAgent || navigator.vendor || window.opera );
40            return check;
41        },
42
43        randomInteger: ( min, max ) => {
44            return Math.floor( Math.random() * (
45                max - min + 1
46            ) ) + min;
47        },
48
49        /**
50         * Add a URL parameter (or changing it if it already exists)
51         * @param {string} url - This is typically document.location.search
52         * @param {string} key - The key to set
53         * @param {string} val - Value
54         */
55        addUrlParam( url, key, val ) {
56            key = encodeURI( key );
57            val = encodeURI( val );
58
59            if ( '' !== val ) {
60                var re = new RegExp( "([?&])" + key + "=.*?(&|$)", "i" );
61                var separator = url.indexOf( '?' ) !== - 1 ? "&" : "?";
62
63                // Update value if key exist.
64                if ( url.match( re ) ) {
65                    url = url.replace( re, '$1' + key + "=" + val + '$2' );
66                } else {
67                    url += separator + key + '=' + val;
68                }
69            } else {
70                this.removeUrlParam( url, key );
71            }
72
73            return url;
74        },
75
76        removeUrlParam( url, key ) {
77            const params = new URLSearchParams( url );
78            params.delete( key );
79            return url;
80        },
81
82        getUrlParamsAsObject: ( query ) => {
83            var params = {};
84
85            if ( - 1 === query.indexOf( '?' ) ) {
86                return params;
87            }
88
89            query = query.substring( query.indexOf( '?' ) + 1 );
90
91            var re = /([^&=]+)=?([^&]*)/g;
92            var decodeRE = /\+/g;
93
94            var decode = function( str ) {
95                return decodeURIComponent( str.replace( decodeRE, " " ) );
96            };
97
98            var e;
99            while ( e = re.exec( query ) ) {
100                var k = decode( e[ 1 ] ), v = decode( e[ 2 ] );
101                if ( k.substring( k.length - 2 ) === '[]' ) {
102                    k = k.substring( 0, k.length - 2 );
103                    (
104                        params[ k ] || (
105                            params[ k ] = []
106                        )
107                    ).push( v );
108                }
109                else {
110                    params[ k ] = v;
111                }
112            }
113
114            var assign = function( obj, keyPath, value ) {
115                var lastKeyIndex = keyPath.length - 1;
116                for ( var i = 0; i < lastKeyIndex; ++ i ) {
117                    var key = keyPath[ i ];
118                    if ( ! (
119                        key in obj
120                    ) ) {
121                        obj[ key ] = {}
122                    }
123                    obj = obj[ key ];
124                }
125                obj[ keyPath[ lastKeyIndex ] ] = value;
126            }
127
128            for ( var prop in params ) {
129                var structure = prop.split( '[' );
130                if ( structure.length > 1 ) {
131                    var levels = [];
132                    structure.forEach( function( item, i ) {
133                        var key = item.replace( /[?[\]\\ ]/g, '' );
134                        levels.push( key );
135                    } );
136                    assign( params, levels, params[ prop ] );
137                    delete(
138                        params[ prop ]
139                    );
140                }
141            }
142            return params;
143        },
144
145        getScrollbarWidth: () => {
146            // When not has scrollbar
147            if( window.innerWidth <= document.documentElement.clientWidth ) {
148                return 0;
149            }
150
151            // Creating invisible container.
152            const outer = document.createElement( 'div' );
153            outer.style.visibility = 'hidden';
154            outer.style.overflow = 'scroll'; // forcing scrollbar to appear.
155            outer.style.msOverflowStyle = 'scrollbar'; // needed for WinJS apps.
156            document.body.appendChild( outer );
157
158            // Creating inner element and placing it in the container.
159            const inner = document.createElement( 'div' );
160            outer.appendChild( inner );
161
162            // Calculating difference between container's full width and the child width.
163            const scrollbarWidth = (
164                outer.offsetWidth - inner.offsetWidth
165            );
166
167            // Removing temporary elements from the DOM.
168            outer.parentNode.removeChild( outer );
169
170            return scrollbarWidth;
171        },
172
173        setBodyOverflow() {
174            $( 'body' ).css( {
175                'overflow': 'hidden',
176                'paddingRight': this.getScrollbarWidth() + 'px'
177            } );
178        },
179
180        unsetBodyOverflow: () => {
181            $( 'body' ).css( {
182                'overflow': 'visible',
183                'paddingRight': 0
184            } );
185        },
186
187        setBodyHandling: () => {
188            $( 'body' ).removeClass( 'completed' ).addClass( 'handling' );
189        },
190
191        setBodyCompleted: () => {
192            $( 'body' ).removeClass( 'handling' ).addClass( 'completed' );
193        },
194
195        setElementHandling: ( $element ) => {
196            $element.addClass( 'updating-icon' );
197        },
198
199        unsetElementHandling: ( $element ) => {
200            $element.removeClass( 'updating-icon' );
201        },
202
203        getStyle: ( el, style ) => {
204            if ( window.getComputedStyle ) {
205                return style ? document.defaultView.getComputedStyle( el, null ).getPropertyValue( style ) : document.defaultView.getComputedStyle( el, null );
206            }
207            else if ( el.currentStyle ) {
208                return style ? el.currentStyle[ style.replace( /-\w/g, ( s ) => {
209                    return s.toUpperCase().replace( '-', '' );
210                } ) ] : el.currentStyle;
211            }
212        },
213
214        setCookie: ( cname, cvalue, exdays ) => {
215            let d = new Date();
216            d.setTime( d.getTime() + (
217                exdays * 24 * 60 * 60 * 1000
218            ) );
219            let expires = 'expires=' + d.toUTCString();
220            document.cookie = cname + '=' + cvalue + '; ' + expires + '; path=/';
221        },
222
223        getCookie: ( cname ) => {
224            var name = cname + '=';
225            var ca = document.cookie.split( ';' );
226            for ( var i = 0; i < ca.length; i ++ ) {
227                var c = ca[ i ];
228                while ( c.charAt( 0 ) == ' ' ) {
229                    c = c.substring( 1 );
230                }
231                if ( c.indexOf( name ) == 0 ) {
232                    return c.substring( name.length, c.length );
233                }
234            }
235            return '';
236        },
237
238        copyToClipboard: ( text ) => {
239            if ( window.clipboardData && window.clipboardData.setData ) {
240                // Internet Explorer-specific code path to prevent textarea being shown while dialog is visible.
241                return window.clipboardData.setData( "Text", text );
242
243            }
244            else if ( document.queryCommandSupported && document.queryCommandSupported( "copy" ) ) {
245                var textarea = document.createElement( "textarea" );
246                textarea.textContent = text;
247                textarea.style.position = "fixed";  // Prevent scrolling to bottom of page in Microsoft Edge.
248                document.body.appendChild( textarea );
249                textarea.select();
250                try {
251                    return document.execCommand( "copy" );  // Security exception may be thrown by some browsers.
252                }
253                catch ( ex ) {
254                    console.warn( "Copy to clipboard failed.", ex );
255                    return prompt( "Copy to clipboard: Ctrl+C, Enter", text );
256                }
257                finally {
258                    document.body.removeChild( textarea );
259                }
260            }
261        },
262
263        /**
264         * Store html string into data-o_content attribute
265         * @param $element
266         * @param content
267         */
268        setContentHTML: ( $element, content ) => {
269            if ( undefined === $element.attr( 'data-o_content' ) ) {
270                $element.attr( 'data-o_content', $element.html() );
271            }
272            $element.html( content );
273        },
274
275        /**
276         * Restore original html from data-o_content
277         * @param $element
278         */
279        resetContentHTML: ( $element ) => {
280            if ( undefined !== $element.attr( 'data-o_content' ) ) {
281                $element.html( $element.attr( 'data-o_content' ) );
282            }
283        }
284    }
285    var Helpers = window.kidba.Helpers;
286
287    $( document ).ready( function() {
288        singleProductAddToCart();
289    } );
290
291    function singleProductAddToCart() {
292        // wc_add_to_cart_params is required to continue, ensure the object exists.
293        if ( typeof wc_add_to_cart_params === 'undefined' ) {
294            return false;
295        }
296
297        /**
298         * Ajax add to cart.
299         * button query selector to compatible with Lumise add on.
300         */
301        $( document ).on( 'click', 'button.single_add_to_cart_button.ajax_add_to_cart', function( evt ) {
302            evt.preventDefault();
303
304            var $thisButton = $( this );
305
306            if ( $thisButton.hasClass( 'disabled' ) ) { // Variation select required.
307                return false;
308            }
309
310            if ( $thisButton.hasClass( 'woosb-disabled' ) ) { // Smart Bundle select required.
311                return false;
312            }
313
314            var $variationsForm = $thisButton.closest( 'form.cart' ),
315                productID       = $variationsForm.find( '[name=add-to-cart]' ).val(),
316                variationID     = $variationsForm.find( 'input[name=variation_id]' ).val(),
317                quantity        = $variationsForm.find( '.quantity .qty[name=quantity]' ).val();
318            
319            if ( 'add-to-cart' === $thisButton.attr( 'name' ) ) {
320                productID = $thisButton.val();
321            }
322
323            if ( 0 === productID ) {
324                return;
325            }
326
327            var data = {
328                product_id: productID,
329                variation_id: variationID,
330            };
331
332            $variationsForm.serializeArray().map( function( attr ) {
333                if ( attr.name !== 'add-to-cart' ) {
334                    if ( attr.name.endsWith( '[]' ) ) {
335                        let name = attr.name.substring( 0, attr.name.length - 2 );
336                        if ( ! (
337                            name in data
338                        ) ) {
339                            data[name] = [];
340                        }
341                        data[name].push( attr.value );
342                    } else {
343                        data[attr.name] = attr.value;
344                    }
345                }
346            } );
347            
348            // Custom quantity per button.
349            if ( $thisButton.attr( 'data-qty' ) ) {
350                quantity = parseInt( $thisButton.attr( 'data-qty' ) );
351            }
352            data.quantity = quantity;
353            $thisButton.removeClass( 'added' ).addClass( 'loading updating-icon' );
354
355            // Trigger event.
356            $( 'body' ).trigger( 'adding_to_cart', [ $thisButton, data ] );
357            // Ajax action.
358            $.post( Helpers.getAjaxUrl( 'woocommerce_add_to_cart' ), data, function( response ) {
359                console.log(Helpers.getAjaxUrl( 'woocommerce_add_to_cart' ));
360                if ( ! response ) {
361                    return;
362                }
363
364                if ( response.error && response.product_url ) {
365                    window.location = response.product_url;
366                    return;
367                }
368
369                // Redirect to checkout for Buy Now button.
370                var redirect = $thisButton.data( 'redirect' );
371                if ( redirect && '' !== redirect ) {
372                    window.location = redirect;
373                    return;
374                }
375
376                // Redirect to cart option.
377                if ( wc_add_to_cart_params.cart_redirect_after_add === 'yes' ) {
378                    window.location = wc_add_to_cart_params.cart_url;
379                    return;
380                }
381
382                // Trigger event so themes can refresh other areas.
383                $( document.body ).trigger( 'added_to_cart', [
384                    response.fragments, response.cart_hash, $thisButton
385                ] );
386            } ).always( function() {
387                $thisButton.addClass( 'added' ).removeClass( 'loading updating-icon' );
388            } );
389        
390            return false;
391        } );
392    }
393    function kidbaQuickViewPopup() {
394        /***
395    * Product Popup
396    */
397    $('.quick-view-btn').on('click', function(e) {
398        e.preventDefault();
399        e.stopPropagation();
400        var $button = $( this );
401        // Avoid multi clicks.
402        if ( $button.hasClass( 'loading' ) ) {
403            return;
404        }
405        if ( ! $.fn.KidbaModal ) {
406            return;
407        }
408        $button.addClass( 'loading' );
409        var productID = $button.data( 'pid' );
410        /**
411         * Avoid duplicate ajax request.
412         */
413        var $popup = $body.children( '#' + 'modal-quick-view-product-' + productID );
414        console.log(productID);
415        if ( $popup.length > 0 ) {
416            openQuickViewPopup( $popup, $button );
417        } else {
418            var data = {
419                action: 'product_quick_view',
420                pid: productID
421            };
422
423            $.ajax( {
424                url: $kidba.ajaxurl,
425                type: 'GET',
426                data: $.param( data ),
427                dataType: 'json',
428                cache: true,
429                success: function( results ) {
430                    $popup = $( results.template );
431                    $body.append( $popup );
432                    openQuickViewPopup( $popup, $button );
433                },
434            } );
435        }
436    })   
437    function openQuickViewPopup( $popup, $button ) {
438            var $contentWrap    = $popup.find( '.product-container' ),
439                $productWrap    = $contentWrap.find( '.woo-single-info' ),
440                $productImages  = $contentWrap.find( '.woo-single-images' ),
441                $variationsForm = $popup.find( '.cart.variations_form' );
442
443            // Re init add to cart form variation.
444            if ( $variationsForm.length > 0 && typeof wc_add_to_cart_variation_params !== 'undefined' ) {
445                $variationsForm.wc_variation_form();
446
447                if ( typeof isw != 'undefined' && typeof isw.Swatches !== 'undefined' ) {
448                    isw.Swatches.register( $variationsForm );
449                }
450            }
451
452            Helpers.handleLazyImages( $popup );
453
454            var $form         = $popup.find( '.variations_form' ),
455                $renderTarget = $variationsForm.find( '.row-isw-swatch-quantity-wrap' );
456
457            $form.find( 'select[name="quantity"]' ).KidbaNiceSelect( { // Re init quantity dropdown.
458                renderTarget: $renderTarget
459            } );
460
461            var $sliderWrap   = $productImages.children( '.woo-single-gallery' ),
462                $mainSlider   = $sliderWrap.children( '.kidba-main-swiper' ),
463                sliderOptions = {};
464            if ( $sliderWrap.hasClass( 'has-thumbs-slider' ) ) {
465                var thumbsSlider = $sliderWrap.children( '.kidba-thumbs-swiper' ).KidbaSwiper();
466                sliderOptions    = {
467                    thumbs: {
468                        swiper: thumbsSlider
469                    }
470                };
471            }
472
473            if ( $mainSlider.length > 0 ) {
474                $mainSlider.KidbaSwiper( sliderOptions );
475            }
476
477            var modalPS = true;
478
479            if ( 767 < (
480                window.innerWidth - Helpers.getScrollbarWidth()
481            ) ) {
482                var productImageHeight = $productImages.height(),
483                    popupHeight        = productImageHeight,
484                    popupContentHeight = productImageHeight,
485                    maxHeight          = window.innerHeight - 60; // Max height of popup = Window height - top bottom spacing.
486
487                var $scrollable = $productWrap;
488                modalPS         = false;
489
490                var settings = $contentWrap.data( 'quick-view' );
491
492                var contentPadding = settings.spacing * 2;
493                if ( settings.imageCover ) {
494                    $scrollable        = $contentWrap.find( '.quick-view-col-summary .inner-content' );
495                    popupHeight        = productImageHeight + contentPadding;
496                    popupContentHeight = Math.min( maxHeight, popupHeight );
497
498                    if ( settings.spacing > 0 ) {
499                        popupContentHeight -= contentPadding;
500                    } else {
501                        popupContentHeight -= 60;
502                    }
503                } else {
504                    popupHeight        = productImageHeight + contentPadding;
505                    popupContentHeight = Math.min( maxHeight, popupHeight );
506                    popupContentHeight -= contentPadding;
507                }
508
509                $scrollable.outerHeight( parseInt( popupContentHeight ) );
510
511                if ( $.fn.perfectScrollbar && ! Helpers.isHandheld() ) {
512                    $scrollable.perfectScrollbar( {
513                        suppressScrollX: true
514                    } );
515                }
516
517                if ( settings.imageCover ) {
518                    $contentWrap.find( '.woo-single-images' ).addClass( 'image-cover' );
519                }
520            }
521
522            if ( $popup.data( 'KidbaModal' ) ) {
523                $popup.KidbaModal( 'open' );
524            } else {
525                $popup.KidbaModal( {
526                    perfectScrollbar: modalPS
527                } );
528            }
529
530            $button.removeClass( 'loading' );
531        }
532    }
533})(jQuery);
534

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.