// source --> https://nspirewedding.com/wp-content/plugins/weddingdir/assets/script.js?ver=1774626179 
/**
 *  WeddingDir Project Scripts
 *  --------------------------
 */
(function($) {

    "use strict";

    /**
     * Check variable is NOT empty
     * ---------------------------
     */
    window._is_empty = function (value) {

        // null or undefined
        if (value === null || value === undefined) {
            return false;
        }

        // NaN
        if (typeof value === 'number' && isNaN(value)) {
            return false;
        }

        // String
        if (typeof value === 'string') {
            return value.trim().length > 0;
        }

        // Array
        if (Array.isArray(value)) {
            return value.length > 0;
        }

        // Object
        if (typeof value === 'object') {
            return Object.keys(value).length > 0;
        }

        // Boolean / Number (0 allowed)
        return true;
    };

    window._wait = function(callback, ms){

        var timer = 0;
          
        return function() {

            var context = this, args = arguments;

            clearTimeout(timer);

            timer = setTimeout(function () {

                callback.apply(context, args);

            }, ms || 0);

        };
    }

    /**
     * Generate Random String
     * ----------------------
     * More secure + safe fallback
     */
    window._rand = function (length = 8) {

        const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
        const charsLength = chars.length;

        let result = '';

        // Use crypto if available (better randomness)
        if (window.crypto && window.crypto.getRandomValues) {

            const array = new Uint32Array(length);
            window.crypto.getRandomValues(array);

            for (let i = 0; i < length; i++) {
                result += chars[array[i] % charsLength];
            }

        } else {
            // Fallback (older browsers)
            for (let i = 0; i < length; i++) {
                result += chars.charAt(Math.floor(Math.random() * charsLength));
            }
        }

        const prefix = (typeof WEDDINGDIR_AJAX_OBJ === 'object' && WEDDINGDIR_AJAX_OBJ.brand_name)
            ? WEDDINGDIR_AJAX_OBJ.brand_name
            : 'wd';

        return prefix + '_' + result;
    };

    var WeddingDir_Elements  = {

        /**
         *  Datepicker
         *  ----------
         *  http://$ui.com/datepicker/#min-max
         *  ----------------------------------
         */
        date_picker: function(){

            // if( $( '.weddingdir_datepicker' ).length ){

            //     $( ".weddingdir_datepicker" ).datepicker();
            // }
        },

        /**
         *  WeddingDir - Select Option
         *  --------------------------
         */
        weddingdir_select_option: function(){

            /**
             *  1. Light Select Option Style
             *  ----------------------------
             */
            if( $('.weddingdir-light-select').length ) {

                $('.weddingdir-light-select').select2( {

                    width                           :   '100%', // resolve

                    theme                           :   'form-light',

                    placeholder                     :   $(this).attr( 'data-placeholder' ) != '' 

                                                        ?   $(this).attr( 'data-placeholder' ) 

                                                        :   '',

                } );
            }

            /**
             *  2. Dark Select Option Style
             *  ---------------------------
             */
            if( $('.weddingdir-dark-select').length ) {

                $('.weddingdir-dark-select').select2( {

                    width                           :   '100%', // resolve

                    theme                           :   'form-dark',

                    placeholder                     :   $(this).attr( 'data-placeholder' )

                } );
            }

            /**
             *  3. Light Select Option Style
             *  ----------------------------
             */
            if( $('.weddingdir-light-multiple-select').length ) {

                $('.weddingdir-light-multiple-select').map( function(){

                    var _id             =    '#' + $(this).attr( 'id' ),

                        _placeholder    =   $( _id ).attr( 'data-placeholder' ),

                        _selection      =   parseInt( $( _id ).attr( 'data-selection-limit' ) );


                    if( _selection >= 2 ){

                        $( _id ).select2( {

                            width                           :   '100%', // resolve

                            theme                           :   'form-light',

                            tags                            :   true,

                            placeholder                     :   _placeholder,

                            maximumSelectionLength          :   _selection,

                        } );

                    }else{

                        $( _id ).select2( {

                            width                           :   '100%', // resolve

                            theme                           :   'form-light',

                            tags                            :   true,

                            placeholder                     :   _placeholder,

                        } );
                    }

                } );
            }

            /**
             *  4. Dark Select Option Style
             *  ---------------------------
             */
            if( $('.weddingdir-dark-multiple-select').length ) {

                $('.weddingdir-dark-multiple-select').map( function(){

                    var _id             =    '#' + $(this).attr( 'id' ),

                        _placeholder    =   $( _id ).attr( 'data-placeholder' ),

                        _selection      =   parseInt( $( _id ).attr( 'data-selection-limit' ) );


                    if( _selection >= 2 ){

                        $( _id ).select2( {

                            width                           :   '100%', // resolve

                            theme                           :   'form-dark',

                            tags                            :   true,

                            placeholder                     :   _placeholder,

                            maximumSelectionLength          :   _selection,

                        } );

                    }else{

                        $( _id ).select2( {

                            width                           :   '100%', // resolve

                            theme                           :   'form-dark',

                            tags                            :   true,

                            placeholder                     :   _placeholder,

                        } );
                    }

                } );
            }
        },

        /**
         *  WeddingDir - Accordion
         *  ----------------------
         */
        weddingdir_accordion: function() {
            
            /**
             *  Document Have Class ?
             *  ---------------------
             */
            if( $('.theme-accordian [data-toggle="collapse"]').length ) {

                $('.theme-accordian [data-toggle="collapse"]').on('click', function (e) {

                    if( $(this).parents('.accordion').find('.collapse.show') ) {

                        var idx = $(this).index('[data-toggle="collapse"]');

                        if (idx == $('.collapse.show').index('.collapse')) {

                            e.stopPropagation();
                        }
                    }

                });
            }
        },

        /**
         *  WeddingDir - Brand / Partner / Logo Carouse
         *  -------------------------------------------
         */
        weddingdir_brand_logo_carousel : function(){

            /**
             *  Have Class on Document ?
             *  ------------------------
             */
            if( $('.weddingdir-brand-logo-carousel').length ){

                /**
                 *  Each Class To Load Script
                 *  -------------------------
                 */
                $('.weddingdir-brand-logo-carousel').map( function(){

                    /**
                     *  Create Owl Carousel Slider
                     *  --------------------------
                     *  Owl Carousel v2.3.4
                     *  --------------------
                     *  Copyright 2013-2018 David Deutsch
                     *  ---------------------------------
                     *  Licensed under: SEE LICENSE IN https://github.com/OwlCarousel2/OwlCarousel2/blob/master/LICENSE
                     *  -----------------------------------------------------------------------------------------------
                     *  @credit - https://owlcarousel2.github.io/OwlCarousel2/
                     *  ------------------------------------------------------
                     */
                    $( this ).owlCarousel({
        
                        loop                : true,

                        stagePadding        : 0,

                        margin              : 30,

                        autoplay            : true,

                        autoplayTimeout     : 10000,

                        smartSpeed          : 1000,

                        nav                 : false,

                        dots                : true,

                        /**
                         *  Next  |  Pre  Text
                         *  ------------------
                         */
                        navText                 :  [
                                                        /**
                                                         *   1. Left Side Text
                                                         *   -----------------
                                                         */
                                                        '<i class="fa fa-angle-left"></i>',

                                                        /**
                                                         *   2. Right Side Text
                                                         *   ------------------
                                                         */
                                                        '<i class="fa fa-angle-right"></i>'
                                                    ],

                        /**
                         *  Responsive Brekpoint
                         *  --------------------
                         */
                        responsive              :   {
                                                        0       : {  items: 2  },

                                                        600     : {  items: 2  },

                                                        767     : {  items: 3  },

                                                        1000    : {  items: 5  }
                                                    }
                    });

                } );
            }
        },

        /**
         *  Gallery Open with Magnific Popup
         *  --------------------------------
         *  1. Load in Listing Singular Page Gallery
         *  ----------------------------------------
         *  2. Load in RealWedding Singular Page Gallery
         *  --------------------------------------------
         *  3. Load in Vendor Singular Page Gallery
         *  ---------------------------------------
         *  @credit - https://dimsemenov.com/plugins/magnific-popup/
         *  --------------------------------------------------------
         */
        weddingdir_gallery_popup : function(){

            /**
             *  Documemnt Have Class ?
             *  ----------------------
             */
            if( $('.weddingdir-gallery-popup').length ){

                /**
                 *  One by one class to load object
                 *  -------------------------------
                 */
                $('.weddingdir-gallery-popup').each(function() {

                    $( this ) .magnificPopup( {

                        delegate    :   'a',

                        type        :   'image',

                        tLoading    :   'Loading image #%curr%...',

                        mainClass   :   'mfp-img-mobile',

                        gallery     :   {
                                            enabled                 : true,
                                        
                                            preload                 : [0,2],
            
                                            navigateByImgClick      : true,
            
                                            arrowMarkup             : '<button title="%title%" type="button" class="mfp-arrow mfp-arrow-%dir%"></button>',
                        
                                            tPrev                   : 'Previous (Left arrow key)',

                                            tNext                   : 'Next (Right arrow key)',

                                            tCounter                : '<span class="mfp-counter">%curr% of %total%</span>'
                                        },

                        image       :   {

                                            tError                  :   '<a href="%url%">The image #%curr%</a> could not be loaded.',

                                            titleSrc                :   function(item) {

                                                                            return item.el.attr('title');
                                                                        }
                        }

                    });

                });

            }
        },

        /**
         *  WeddingDir - Owl Carousel Script
         *  --------------------------------
         */
        weddingdir_owl: function(){

            /**
             *  Have Class on Document ?
             *  ------------------------
             */
            if( $('.weddingdir-owl-carousel').length ){

                /**
                 *  Each Class To Load Script
                 *  -------------------------
                 */
                $('.weddingdir-owl-carousel').map( function(){

                    /**
                     *  Collect Args
                     *  ------------
                     */
                    var     _args               =       [];

                    /**
                     *  Is RTL ?
                     *  --------
                     */
                    if( $( 'html' ).attr( 'dir' ) == 'rtl' ){

                        _args[ 'rtl' ]     =       true;
                    }

                    /**
                     *  Enable Loop ?
                     *  -------------
                     */
                    _args[ 'loop' ]             =       $(this).attr( 'data-loop' ) == true || $(this).attr( 'data-loop' ) == 'true' 

                                                        ?   true    : false;
                    /**
                     *  Padding
                     *  -------
                     */
                    _args[ 'stagePadding' ]     =       0;

                    /**
                     *  Margin
                     *  ------
                     */
                    _args[ 'margin' ]           =       $(this).attr( 'data-margin' ) !== ''

                                                        ?   parseInt( $(this).attr( 'data-margin' ) )

                                                        :   parseInt( 15 );
                    /**
                     *  Enable Auto Play
                     *  ----------------
                     */
                    if( $(this).attr( 'data-auto-play' ) == true || $(this).attr( 'data-auto-play' ) == 'true' ){

                        /**
                         *  Auto Play
                         *  ---------
                         */
                        _args[ 'autoplay' ]             =       true;

                        /**
                         *  Auto Play Timout
                         *  ----------------
                         */
                        _args[ 'autoplayTimeout' ]      =       _is_empty( $(this).attr( 'data-auto-play-timeout' ) )

                                                                ?   parseInt( $(this).attr( 'data-auto-play-timeout' ) )

                                                                :   10000;
                    }

                    /**
                     *  Auto Play Off
                     *  -------------
                     */
                    else{

                        /**
                         *  Auto Play
                         *  ---------
                         */
                        _args[ 'autoplay' ]         =       false;
                    }

                    /**
                     *  Auto Play Smart Speed
                     *  ---------------------
                     */
                    _args[ 'smartSpeed' ]      =       _is_empty( $(this).attr( 'data-auto-play-speed' ) )

                                                        ?   parseInt( $(this).attr( 'data-auto-play-speed' ) )

                                                        :   1000;

                    /**
                     *  Navigation
                     *  ----------
                     */
                    _args[ 'nav' ]      =       $(this).attr( 'data-nav' ) == true || $(this).attr( 'data-nav' ) == 'true' 

                                                ?   true    : false;

                    /**
                     *  Dots
                     *  ----
                     */
                    _args[ 'dots' ]     =       $(this).attr( 'data-dots' ) == true || $(this).attr( 'data-dots' ) == 'true'

                                                ?   true    : false;

                    /**
                     *  Have Custom DOTS container ?
                     *  ----------------------------
                     */
                    if( _is_empty( $(this).attr( 'data-dots-container' ) ) ){

                        _args[ 'dotsContainer' ]    =   $(this).attr( 'data-dots-container' );
                    }

                    /**
                     *  Next  |  Pre  Text
                     *  ------------------
                     */
                    _args[ 'navText' ]     =       [
                                                        /**
                                                         *   1. Left Side Text
                                                         *   -----------------
                                                         */
                                                        '<i class="fa fa-angle-left"></i>',

                                                        /**
                                                         *   2. Right Side Text
                                                         *   ------------------
                                                         */
                                                        '<i class="fa fa-angle-right"></i>'
                                                    ];

                    /**
                     *  Responsive
                     *  ----------
                     */
                    _args[ 'responsive' ]     =       $.parseJSON( $(this).attr( 'data-breakpoint' ) );


                    /**
                     *  Create Owl Carousel Slider
                     *  --------------------------
                     *  Owl Carousel v2.3.4
                     *  --------------------
                     *  Copyright 2013-2018 David Deutsch
                     *  ---------------------------------
                     *  Licensed under: SEE LICENSE IN https://github.com/OwlCarousel2/OwlCarousel2/blob/master/LICENSE
                     *  -----------------------------------------------------------------------------------------------
                     *  @credit - https://owlcarousel2.github.io/OwlCarousel2/
                     *  ------------------------------------------------------
                     */
                    $( this ).owlCarousel( Object.assign( {}, _args ) );

                } );
            }

        },

        /**
         *  WeddingDir - Testimonials Carousel
         *  ----------------------------------
         */
        weddingdir_testimonials_carousel : function(){

            /**
             *  Have Class on Document ?
             *  ------------------------
             */
            if( $('.weddingdir-testimonial-carousel').length ){

                /**
                 *  Each Class To Load Script
                 *  -------------------------
                 */
                $('.weddingdir-testimonial-carousel').map( function(){

                    /**
                     *  Create Owl Carousel Slider
                     *  --------------------------
                     *  Owl Carousel v2.3.4
                     *  --------------------
                     *  Copyright 2013-2018 David Deutsch
                     *  ---------------------------------
                     *  Licensed under: SEE LICENSE IN https://github.com/OwlCarousel2/OwlCarousel2/blob/master/LICENSE
                     *  -----------------------------------------------------------------------------------------------
                     *  @credit - https://owlcarousel2.github.io/OwlCarousel2/
                     *  ------------------------------------------------------
                     */
                    $( this ).owlCarousel({
        
                        loop                    : true,

                        stagePadding            : 0,

                        margin                  : 30,

                        autoplay                : true,

                        autoplayTimeout         : 10000,

                        smartSpeed              : 1000,

                        nav                     : false,

                        dots                    : true,

                        /**
                         *  Next  |  Pre  Text
                         *  ------------------
                         */
                        navText                 :  [
                                                        /**
                                                         *   1. Left Side Text
                                                         *   -----------------
                                                         */
                                                        '<i class="fa fa-angle-left"></i>',

                                                        /**
                                                         *   2. Right Side Text
                                                         *   ------------------
                                                         */
                                                        '<i class="fa fa-angle-right"></i>'
                                                    ],

                        responsive              :   {
                                                        0       : {  items: 1  },

                                                        600     : {  items: 1  },

                                                        767     : {  items: 2  }
                                                    }
                    });
                });
            }
        },

        /**
         *  WeddingDir - Location Carousel
         *  ------------------------------
         *  Home Page version two
         *  ---------------------
         */
        weddingdir_location_post_carousel : function(){
    
            /**
             *  Document Have Class ?
             *  ---------------------
             */
            if( $('.weddingdir-location-post-carousel').length ){

                /**
                 *  Each Class To Load Script
                 *  -------------------------
                 */
                $('.weddingdir-location-post-carousel').map( function(){

                    /**
                     *  Create Owl Carousel Slider
                     *  --------------------------
                     *  Owl Carousel v2.3.4
                     *  --------------------
                     *  Copyright 2013-2018 David Deutsch
                     *  ---------------------------------
                     *  Licensed under: SEE LICENSE IN https://github.com/OwlCarousel2/OwlCarousel2/blob/master/LICENSE
                     *  -----------------------------------------------------------------------------------------------
                     *  @credit - https://owlcarousel2.github.io/OwlCarousel2/
                     *  ------------------------------------------------------
                     */
                    $( this ).owlCarousel({
    
                        loop                :  true,

                        stagePadding        :  0,

                        margin              :  30,

                        autoplay            :  true,

                        autoplayTimeout     :  10000,

                        smartSpeed          :  1000,

                        nav                 :  false,

                        dots                :  true,

                        /**
                         *  Next | Prev
                         *  -----------
                         */
                        navText             :   [
                                                    /**
                                                     *   1. Left Side Text
                                                     *   -----------------
                                                     */
                                                    '<i class="fa fa-angle-left"></i>',

                                                    /**
                                                     *   2. Right Side Text
                                                     *   ------------------
                                                     */
                                                    '<i class="fa fa-angle-right"></i>'
                                                ],
                        /**
                         *  Responsive
                         *  ----------
                         */
                        responsive          :  {

                                                    0     : {  items: 1  },

                                                    600   : {  items: 1  },

                                                    767   : {  items: 2  },

                                                    992   : {  items: 3  },

                                                    1000  : {  items: 3  }
                                                }

                    });

                });
            }
        },

        /**
         *  WeddingDir - Listing Post Carousel
         *  ----------------------------------
         */
        weddingdir_listing_post_carousel : function(){
    
            /**
             *  Document Have Class ?
             *  ---------------------
             */
            if( $('.weddingdir-listing-post-carousel').length ){

                /**
                 *  Each Class To Load Script
                 *  -------------------------
                 */
                $('.weddingdir-listing-post-carousel').map( function(){

                    /**
                     *  Create Owl Carousel Slider
                     *  --------------------------
                     *  Owl Carousel v2.3.4
                     *  --------------------
                     *  Copyright 2013-2018 David Deutsch
                     *  ---------------------------------
                     *  Licensed under: SEE LICENSE IN https://github.com/OwlCarousel2/OwlCarousel2/blob/master/LICENSE
                     *  -----------------------------------------------------------------------------------------------
                     *  @credit - https://owlcarousel2.github.io/OwlCarousel2/
                     *  ------------------------------------------------------
                     */
                    $( this ).owlCarousel({
    
                        loop                :  true,

                        stagePadding        :  0,

                        margin              :  30,

                        autoplay            :  false,

                        autoplayTimeout     :  10000,

                        smartSpeed          :  1000,

                        nav                 :  false,

                        dots                :  true,

                        /**
                         *  Next | Prev
                         *  -----------
                         */
                        navText             :   [
                                                    /**
                                                     *   1. Left Side Text
                                                     *   -----------------
                                                     */
                                                    '<i class="fa fa-angle-left"></i>',

                                                    /**
                                                     *   2. Right Side Text
                                                     *   ------------------
                                                     */
                                                    '<i class="fa fa-angle-right"></i>'
                                                ],
                        /**
                         *  Responsive
                         *  ----------
                         */
                        responsive          :  $( this ).attr( 'data-listing-layout' ) == 1 

                                            ?   {

                                                    0     : {  items: 1  },

                                                    600   : {  items: 1  },

                                                    767   : {  items: 2  },

                                                    992   : {  items: 3  },

                                                    1000  : {  items: 3  }
                                                }

                                            :   {

                                                    0     : {  items: 1  },

                                                    600   : {  items: 1  },

                                                    767   : {  items: 1  },

                                                    992   : {  items: 1  },

                                                    1000  : {  items: 1  }
                                                }

                    });

                });
            }
        },

        /**
         *  About us page - Slider Carousel
         *  -------------------------------
         */
        weddingdir_about_us_slider : function(){

            /**
             *  Document Have Class ?
             *  ---------------------
             */
            if( $('.weddingdir-about-us-carousel').length ){
        
                /**
                 *  WeddingDir - About Us Slider
                 *  ----------------------------
                 */
                $('.weddingdir-about-us-carousel').map( function(){

                    /**
                     *  Create Owl Carousel Slider
                     *  --------------------------
                     *  Owl Carousel v2.3.4
                     *  --------------------
                     *  Copyright 2013-2018 David Deutsch
                     *  ---------------------------------
                     *  Licensed under: SEE LICENSE IN https://github.com/OwlCarousel2/OwlCarousel2/blob/master/LICENSE
                     *  -----------------------------------------------------------------------------------------------
                     *  @credit - https://owlcarousel2.github.io/OwlCarousel2/
                     *  ------------------------------------------------------
                     */
                    $( this ).owlCarousel({
        
                        loop                    :  true,

                        stagePadding            :  325,

                        margin                  :  30,

                        autoplay                :  true,

                        autoplayTimeout         :  10000,

                        smartSpeed              :  1000,

                        nav                     :  false,

                        dots                    :  true,

                        /**
                         *  Next  |  Pre  Text
                         *  ------------------
                         */
                        navText                 :  [
                                                        /**
                                                         *   1. Left Side Text
                                                         *   -----------------
                                                         */
                                                        '<i class="fa fa-angle-left"></i>',

                                                        /**
                                                         *   2. Right Side Text
                                                         *   ------------------
                                                         */
                                                        '<i class="fa fa-angle-right"></i>'
                                                    ],

                        /**
                         *  Responsive Break Point Object
                         *  -----------------------------
                         */
                        responsive              :  {

                                                        0       : { items: 1, stagePadding: 40  },

                                                        600     : { items: 1, stagePadding: 50  },

                                                        1200    : { items: 1, stagePadding: 325 }
                                                    }
                    });

                } );
            }
        },

        /**
         *  Home Page Slider Section
         *  ------------------------
         */
        weddingdir_home_page_slider : function(){

            /**
             *  Document Have Class ?
             *  ---------------------
             */
            if( $('.weddingdir-home-page-slider').length ){

                /**
                 *  Each Class To Load Script
                 *  -------------------------
                 */
                $('.weddingdir-home-page-slider').map( function(){

                    /**
                     *  Create Owl Carousel Slider
                     *  --------------------------
                     *  Owl Carousel v2.3.4
                     *  --------------------
                     *  Copyright 2013-2018 David Deutsch
                     *  ---------------------------------
                     *  Licensed under: SEE LICENSE IN https://github.com/OwlCarousel2/OwlCarousel2/blob/master/LICENSE
                     *  -----------------------------------------------------------------------------------------------
                     *  @credit - https://owlcarousel2.github.io/OwlCarousel2/
                     *  ------------------------------------------------------
                     */
                    $( this ).owlCarousel( {

                        rtl             :   $( 'html' ).attr( 'dir' ) == "rtl"  ?   true   :   false,
        
                        loop            :   true,

                        stagePadding    :   0,

                        margin          :   0,

                        items           :   1,

                        autoplay        :   true,

                        autoplayTimeout :   10000,

                        smartSpeed      :   1000,

                        nav             :   true,

                        dots            :   true,

                        touchDrag       :   false,

                        mouseDrag       :   false,

                        autoHeight      :   true,

                        navText         :   [   
                                                /**
                                                 *   1. Left Side Text
                                                 *   -----------------
                                                 */
                                                '<i class="fa fa-angle-left"></i>',

                                                /**
                                                 *   2. Right Side Text
                                                 *   ------------------
                                                 */
                                                '<i class="fa fa-angle-right"></i>'
                                            ]
                    });
                });
            }
        },

        /**
         *   Button On click scroll
         *   ----------------------
         */
        click_to_go : function( click_id, move_to_id ){

            /**
             *  Have lenght ?
             *  -------------
             */
            if( $( '#' + click_id ).length && $( '#' + move_to_id ).length ){

                /**
                 *  When click
                 *  ----------
                 */
                $( '#' + click_id ).on( 'click', function( e ) {

                     e.preventDefault();
                     
                    $('html, body').animate({

                        scrollTop: $( '#' + move_to_id ).offset().top - 170

                    }, 1500 );

                });
            }
        },

        /**
         *  Submit Button Click to show loader icon
         *  ---------------------------------------
         */
        button_loader_start: function(elm){

            if (elm === undefined) {
                elm = $( 'form button.loader' );
            }

            if( $( elm + ' button.loader' ).find( 'i' ).length ){
                $( elm + ' button.loader' ).find( 'i' ).remove();
            }

            $( elm +' button.loader' ).append( '<i class="ms-2 fa fa-spinner fa-spin"></i>' );
        },

        /**
         *  Submit Button Click to show loader icon
         *  ---------------------------------------
         */
        button_loader_end: function( elm ){

            if (elm === undefined) {
                elm = $( 'form button.loader' );
            }

            if( $( elm + ' button.loader' ).find( 'i' ).length ){

                $( elm + ' button.loader' ).find( 'i' ).remove();
            }
        },

        /**
         *  Function Check the Location link have ID ?
         *  ------------------------------------------
         *  @credit - https://stackoverflow.com/questions/4656843/get-querystring-from-url-using-jquery#answer-4656873
         *  ----------------------------------------------------------------------------------------------------------
         */
        check_link_args: function(){

            var vars = [], hash;

            var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

            for(var i = 0; i < hashes.length; i++){

                hash = hashes[i].split('=');

                vars.push(hash[0]);

                vars[hash[0]] = hash[1];
            }

            return vars;
        },

        /**
         *  Show Model Popup By Adress have model ID
         *  ----------------------------------------
         */
        show_model_poup_by_id: function(){

            if( typeof WEDDINGDIR_AJAX_OBJ === 'object' ){

                $.map( WEDDINGDIR_AJAX_OBJ.popup_list, function( val, element ) {

                    var url = window.location.href;

                    if( WeddingDir_Elements.check_link_args()[ element ] == val ) {

                        $( '#' + val ).modal( 'show' );
                    }

                } );
            }
        },

        /**
         *  WeddingDir - Product Price update with Currency Position + Sign too
         *  -------------------------------------------------------------------
         */
        price_with_currency: function( price = '' ){

            /**
             *  Check possition to set pricing
             *  ------------------------------
             */
            var possition     =   WEDDINGDIR_AJAX_OBJ.currency_position,

                is_left       =   possition != '' && possition == 'left',

                is_right      =   possition != '' && possition == 'right',

                currency      =   WEDDINGDIR_AJAX_OBJ.currency_sign;

                /**
                 *  Is Left Side Currency Setting ?
                 *  -------------------------------
                 */
                if( is_left ){

                    return  currency + price;
                }

                /**
                 *  Is Right Side Currency Setting ?
                 *  --------------------------------
                 */
                if( is_right ){

                    return  price + currency;
                }
        },

        /**
         *  Textare Charactor Limit
         *  -----------------------
         */
        textarea_content_limit: function(){

            if( $( '.weddingdir-textarea-limit' ).length ){

                $( '.weddingdir-textarea-limit' ).map( function( e ){

                    /**
                     *  If Key Up Event pass
                     *  --------------------
                     */
                    $( this ).keyup( function() {

                        WeddingDir_Elements.textarea_content_limit_reload( this );

                    } );

                    /**
                     *  Reload Script
                     *  -------------
                     */
                    WeddingDir_Elements.textarea_content_limit_reload( this );

                } );
            }
        },

        /**
         *  textare script reload
         *  ---------------------
         *  https://www.codeply.com/go/s0F9Iz38yn/bootstrap-textarea-with-character-count-_-bootstrap-3
         *  -------------------------------------------------------------------------------------------
         */
        textarea_content_limit_reload: function( _this ){

            var _length         =  $(_this ).attr( 'data-limit' ),

                alert           =  $(_this ).next( 'span.count_message' ),

                text_length     =  $( _this  ).val().length,

                length          =  '';

            /**
             *  Text length Check
             *  -----------------
             */
            if( text_length > _length ){

                length = '<span style="color: red;">'+text_length+'</span>'; 

            }else{

                length = '<span style="color:green;">'+text_length+'</span>';
            }
          
            $( alert ).html( length + ' / ' + _length );           
        },

        /**
         *  11. Remove Group Member
         *  -----------------------
         */
        removed_accordion: function(){

            $( document ).on( 'click', '.remove_core_collapse, .remove_collapse', function(){

                $(this).closest( 'div.collpase_section' ).remove();

            } );
        },

        /**
         *  10. Add Group Member
         *  --------------------
         */
        add_new_group_member: function(){

            if( $('.weddingdir_core_group_accordion').length ){

                $( '.weddingdir_core_group_accordion' ).each( function(){

                    var _id         =   '#' + $(this).attr( 'id' ),

                        _ajax       =   $(this).attr( 'data-ajax-action' ),

                        _section    =   '#' + $(this).attr( 'data-parent' ),

                        _class      =   $(this).attr( 'data-class' ),

                        _member     =   $(this).attr( 'data-member' );

                    /**
                     *  When Click to Add
                     *  -----------------
                     */
                    $(document).on( 'click', _id, function(e){

                        if( $( _id ).find( 'i' ).length ){
                            
                            $( _id ).find( 'i' ).remove();
                        }

                        /**
                         *  Wait... When Data not Load
                         *  --------------------------
                         */
                        $( _id ).addClass( 'disabled' );

                        /**
                         *  Create Counter
                         *  --------------
                         */
                        var     _count      =   $( _section + ' .collpase_section' ).length >= 1

                                            ?   $( _section + ' .collpase_section' ).length

                                            :   0;

                        $( _id ).append( '<i class="ms-2 fa fa-spinner fa-spin"></i>' );

                        $.ajax({

                            type: 'POST',

                            dataType: 'json',

                            url: WEDDINGDIR_AJAX_OBJ.ajaxurl,

                            data: {

                                /**
                                 *  Action + Security
                                 *  -----------------
                                 */
                                'action'            :   'weddingdir_add_new_request_handler',

                                'class'             :   _class,

                                'member'            :   _member,

                                'counter'           :   _count
                            },

                            success: function( PHP_RESPONSE ){

                                if( $( _id ).find( 'i' ).length ){
                                    
                                    $( _id ).find( 'i' ).remove();
                                }

                                /**
                                 *  Is Object ?
                                 *  -----------
                                 */
                                if( $.type( PHP_RESPONSE.weddingdir_ajax_data ) == 'object' ){

                                    /**
                                     *  Alert
                                     *  -----
                                     */
                                    weddingdir_alert( PHP_RESPONSE.weddingdir_ajax_data );

                                }else{

                                    /**
                                     *  Have Length
                                     *  -----------
                                     */
                                    if( $( _section ).length ){

                                        $( _section ).append( PHP_RESPONSE.weddingdir_ajax_data );
                                    }

                                    /**
                                     *  Read the removed icon process
                                     *  -----------------------------
                                     */
                                    WeddingDir_Elements.removed_accordion();
                                }
                            },

                            beforeSend: function(){

                            },

                            error: function (xhr, ajaxOptions, thrownError) {

                                console.log( 'WeddingDir Plugin - Add New Repetable Group Error...' );

                                console.log(xhr.status);

                                console.log(thrownError);

                                console.log(xhr.responseText);
                            },

                            complete: function( event, request, settings ){

                                /**
                                 *  Wait... When Data not Load
                                 *  --------------------------
                                 */
                                $( _id ).removeClass( 'disabled' );
                            }
                        });

                        e.preventDefault();

                    } );

                } );
            }
        },

        /**
         *  Have Collpase ?
         *  ---------------
         */
        input_collapse: function(){

            /**
             *  Have Collapse ?
             *  ---------------
             *  @link - https://getbootstrap.com/docs/5.3/components/collapse/#methods
             *  ----------------------------------------------------------------------
             */
            if( $( 'input.input-collapse' ).length ){

                /**
                 *  Each loop
                 *  ---------
                 */
                $( 'input.input-collapse' ).map( function(){

                    /**
                     *  When click on input
                     *  -------------------
                     */
                    $( this ).on( 'focus focusin', function(){

                        var _target     =   $(this).attr( 'data-target' );

                        $( _target ).addClass( 'show' );

                    } );

                } );
            }

            /**
             *  When collapse off
             *  -----------------
             */
            if( $( '.input-collapse-box' ).length ){

                /**
                 *  Each loop
                 *  ---------
                 */
                $( '.input-collapse-box a' ).map( function(){

                    /**
                     *  When click on input
                     *  -------------------
                     */
                    $( this ).on( 'click', function(){

                        /**
                         *  Data
                         *  ----
                         */
                        var     location_id         =   $(this).attr( 'data-location-id' ),

                                location_name       =   $(this).attr( 'data-location-name' ),

                                target_handler      =   $(this).closest( '.select-item-data' ).attr( 'data-handler' ),

                                target_id           =   '#' + target_handler;

                        /**
                         *  Update the Data in Input Fields
                         *  -------------------------------
                         */
                        $( target_id + '-input' ).val( location_name );

                        $( target_id + '-input-data' ).val( location_id );

                        /**
                         *  First check class exists to removed after added
                         *  -----------------------------------------------
                         */
                        $( '#input-collapse-' + target_handler + ' a' ).removeClass( 'active' );

                        $( '#input-collapse-' + target_handler + ' a[data-location-id='+ location_id +']' ).addClass( 'active' );

                        $(this).closest( '.collapse' ).removeClass( 'show' );

                    } );

                } );
            }
        },

        /**
         *  Write Input Data to get options with search
         *  -------------------------------------------
         *  requird : input fields data attribute 
         *  -------------------------------------
         *  input attr = data-search-id ( target filter box )
         *  -------------------------------------------------
         *  input attr = data-search-target ( find target filter box tag )
         *  --------------------------------------------------------------
         */
        find_key: function(){

            if( $( '.input-search-data' ).length ){

                $( '.input-search-data' ).map( function(){

                    $(this).on( 'keyup', function( e ){

                        /**
                         *  Var
                         *  ---
                         */
                        var     target_id       =   $(this).attr( 'data-search-id' ),

                                target_tag      =   $(this).attr( 'data-search-target' ),

                                input_value     =   $( this ).val().toLowerCase();

                        /**
                         *  Target
                         *  ------
                         */
                        $( target_id + ' ' + target_tag ).filter( function() {

                            $(this).toggle($(this).text().toLowerCase().indexOf( input_value ) > -1);
                        });

                    } );

                } );
            }
        },

        /**
         *  Tooltip Load
         *  ------------
         *  https://getbootstrap.com/docs/5.0/components/tooltips/#overview
         *  ---------------------------------------------------------------
         */
        tooltip: function(){

            /**
             *  Tooltip Work
             *  ------------
             */
            if( $( '[data-bs-toggle="tooltip"]' ).length ){

                /**
                 *  Tooltip Work
                 *  ------------
                 */
                var tooltipTriggerList  =   [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]') );

                var tooltipList         =   tooltipTriggerList.map(function (tooltipTriggerEl) {

                                                return new bootstrap.Tooltip( tooltipTriggerEl );

                                            } );
            }
        },

        /**
         *  Copy Link
         *  ---------
         */
        clipboard: function(){

            /**
             *  Make sure class exists
             *  ----------------------
             */
            if( $( '.__copy_text__' ).length ){

                var clipboard = new ClipboardJS( '.__copy_text__' );

                clipboard.on('success', function(e) {

                    var message_id  =   $( '.__copy_text__' ).attr( 'data-success-message' );

                    $( message_id ).removeClass( 'd-none' );

                    $( message_id ).html( $( message_id ).attr( 'data-success-message' ) );

                    setTimeout( function(){

                        $( message_id ).addClass( 'd-none' );

                    }, 3000 );

                    e.clearSelection();
                });
            }
        },

        /**
         *  Input Password Show / Hide
         *  --------------------------
         *  Couple Profile / Vendor Profile / Vendor Login / Couple Login
         *  -------------------------------------------------------------
         */
        input_password_show_hide: function(){

            /**
             *  Toggle Password
             *  ---------------
             */
            if( $( '.password-eye' ).length ){

                $( '.password-eye span' ).off( 'click' ).on( 'click', function() {

                    /**
                     *  Toggle Two Class
                     *  ----------------
                     */
                    $(this).toggleClass( 'fa-eye fa-eye-slash' );

                    /**
                     *  Get Input Type
                     *  --------------
                     */
                    var input   =   $(this).closest( '.password-eye' ).find( 'input' );

                    /**
                     *  Show Password
                     *  -------------
                     */
                    if( $( input ).attr( 'type' ) == 'password' ){

                        $( input ).attr( 'type', 'text' );
                    }

                    else if( $( input ).attr( 'type' ) == 'text' ){

                        $( input ).attr( 'type', 'password' );
                    }

                });
            }
        },

        /**
         *  Modal Open with Redirection Link Update
         *  ---------------------------------------
         */
        modal_redirection_link: function(){

            /**
             *  Have Length ?
             *  -------------
             */
            if( $( 'a[data-modal-redirection], button[data-modal-redirection]' ).length ){

                $( 'a[data-modal-redirection], button[data-modal-redirection]' ).on( 'click', function(){

                    var     _modal_id           =   $(this).attr( 'data-modal-id' ),

                            _redirection_link   =   $(this).attr( 'data-modal-redirection' ),

                            _redirection        =   '#' + _modal_id + '_redirect_link';

                    /**
                     *  Replace Redirection Link
                     *  ------------------------
                     */
                    if( $( _redirection ).length ){

                        $( _redirection ).val( _redirection_link );
                    }

                } );
            }
        },

        /**
         *  By Default Load Script
         *  ----------------------
         */
        init: function(){

            /**
             *  Find Data
             *  ---------
             */
            this.find_key();

            /**
             *  Input Collapse
             *  --------------
             */
            this.input_collapse();

            /**
             *  WeddingDir - Date Picker
             *  ------------------------
             */
            this.date_picker();

            /**
             *  WeddingDir - Select Options
             *  ---------------------------
             */
            this.weddingdir_select_option();

            /**
             *  WeddingDir - Accordion
             *  ----------------------
             */
            this.weddingdir_accordion();

            /**
             *  WeddingDir - Brand / Partner / Logo Carousel
             *  ---------------------------------------------
             */
            this.weddingdir_brand_logo_carousel();

            /**
             *  WeddingDir - Magnific Popup Gallery
             *  ------------------------------------
             */
            this.weddingdir_gallery_popup();

            /**
             *  WeddingDir - Testimonial Carousel
             *  ---------------------------------
             */
            this.weddingdir_testimonials_carousel();

            /**
             *  WeddingDir - Location Post Carousel
             *  ------------------------------------
             */
            this.weddingdir_location_post_carousel();

            /**
             *  WeddingDir - About Us Slider Section
             *  ------------------------------------
             */
            this.weddingdir_about_us_slider();

            /**
             *  Home Page Slider Section
             *  ------------------------
             */
            this.weddingdir_home_page_slider();

            /**
             *  Listing Post Carousel
             *  ---------------------
             */
            this.weddingdir_listing_post_carousel();

            /**
             *  Show Model Popup with Target Address Model #ID
             *  ----------------------------------------------
             */
            this.show_model_poup_by_id();

            /**
             *  Textare Charactor Limit
             *  -----------------------
             */
            this.textarea_content_limit();

            /**
             *  Add New Fields
             *  --------------
             */
            this.add_new_group_member();

            /**
             *  Remove Fields
             *  -------------
             */
            this.removed_accordion();

            /**
             *  Owl
             *  ---
             */
            this.weddingdir_owl();

            /**
             *  Load ToolTip
             *  ------------
             */
            this.tooltip();

            /**
             *  Clipboard to Copy
             *  -----------------
             */
            this.clipboard();

            /**
             *  Input Password Show / Hide
             *  --------------------------
             */
            this.input_password_show_hide();

            /**
             *  Modal Open with Redirection Link Update
             *  ---------------------------------------
             */
            this.modal_redirection_link();
        }
    };

    /**
     *  Common Script updated in Window Variable
     *  ----------------------------------------
     */
    window.WeddingDir_Elements     = WeddingDir_Elements;

    /**
     *  Document Ready to Run Object
     *  ----------------------------
     */
    $(document).ready( function(){   WeddingDir_Elements.init(); } );

})(jQuery);