PageSourceSearch

https://circulareconomyafrica.org/wp-content/themes/listdo/js/listing.js?ver=1.5.1

js circulareconomyafrica.org collected 2026-10-04 22:43:46 UTC 101,233 bytes, 2,196 lines download raw bytes

1(function($) {
2    "use strict";
3    
4    var map, mapSidebar, markers, CustomHtmlIcon, group;
5    var markerArray = [];
6
7    $.extend($.apusThemeCore, {
8        /**
9         *  Initialize scripts
10         */
11        listing_init: function() {
12            var self = this;
13
14            if ($('#apus-listing-map').length) {
15                L.Icon.Default.imagePath = 'wp-content/themes/listdo/images/';
16            }
17            
18
19            if ($('.detail-haft-map').length > 0) {
20                $('body').addClass( 'no-breadscrumb no-footer fix-header' );
21            }
22            if ($('.detail-full-gallery').length > 0 || $('.detail-full-map').length > 0) {
23                $('body').addClass( 'no-breadscrumb' );
24            }
25            
26            $('.write-a-review').on('click', function(e){
27                e.preventDefault();
28                $('html, body').animate({
29                    scrollTop: $("#review_form_wrapper").offset().top
30                }, 1000);
31            });
32            
33            self.select2Init();
34
35            self.listingBtnFilter();
36
37            self.halfMapPaddingTop();
38
39            self.listingFilter();
40
41            self.bookmarkInit();
42
43            self.searchAjaxInit();
44
45            self.searchInit();
46
47            self.getListings();
48            
49            setTimeout(function(){
50                self.mapInit();
51                self.mapSidebarInit();
52            }, 50);
53            
54            self.previewInit();
55
56            // listing detail
57            self.listingDetail();
58            self.listingComment();
59            self.listingReview();
60
61            self.submitForm();
62            
63            self.editProfile();
64
65            $('.login-form-popup-message').on('click', function(){
66                var target = $('.apus-user-login').attr('href');
67                
68                self.loginRegisterPopup(target);
69                return false;
70            });
71        },
72        searchAjaxInit: function() {
73            if ( $.isFunction( $.fn.typeahead ) ) {
74                $('.apus-autocompleate-input').each(function(){
75                    var $this = $(this);
76                    $this.typeahead({
77                            'hint': true,
78                            'highlight': true,
79                            'minLength': 2,
80                            'limit': 4
81                        }, {
82                            name: 'search',
83                            source: function (query, processSync, processAsync) {
84                                processSync([listdo_listing_opts.empty_msg]);
85                                $this.closest('.twitter-typeahead').addClass('loading');
86                                return $.ajax({
87                                    url: listdo_listing_opts.ajaxurl, 
88                                    type: 'GET',
89                                    data: {
90                                        'search': query,
91                                        'action': 'listdo_autocomplete_search_listing'
92                                    },
93                                    dataType: 'json',
94                                    success: function (json) {
95                                        $this.closest('.twitter-typeahead').removeClass('loading');
96                                        $this.closest('.has-suggestion').removeClass('active');
97                                        return processAsync(json);
98                                    }
99                                });
100                            },
101                            templates: {
102                                empty : [
103                                    '<div class="empty-message">',
104                                    listdo_listing_opts.empty_msg,
105                                    '</div>'
106                                ].join('\n'),
107                                suggestion: Handlebars.compile( listdo_listing_opts.template )
108                            },
109                        }
110                    );
111                    $this.on('typeahead:selected', function (e, data) {
112                        e.preventDefault();
113                        setTimeout(function(){
114                            $('.apus-autocompleate-input').val(data.title);    
115                        }, 5);
116                        
117                        return false;
118                    });
119                });
120            }
121        },
122        listingChangeMarginTopAffix: function() {
123            var affix_height = 0;
124            //if ($(window).width() > 991) {
125                if ( $('.panel-affix').length > 0 ) {
126                    affix_height = $('.panel-affix').outerHeight();
127                    $('.panel-affix-wrapper').css({'height': affix_height});
128                }
129            //}
130            return affix_height;
131        },
132        listingDetail: function() {
133            var self = this;
134            // sticky tabs
135            var affix_height = 0;
136            var affix_height_top = 0;
137            setTimeout(function(){
138                affix_height = affix_height_top = self.listingChangeMarginTopAffix();
139            }, 50);
140            $(window).resize(function(){
141                affix_height = affix_height_top = self.listingChangeMarginTopAffix();
142            });
143            if ($(window).width() >= 1200) {
144                //Function from Bluthemes, lets you add li elemants to affix object without having to alter and data attributes set out by bootstrap
145                setTimeout(function(){
146                    // name your elements here
147                    var stickyElement   = '.panel-affix',   // the element you want to make sticky
148                        bottomElement   = '#apus-footer'; // the bottom element where you want the sticky element to stop (usually the footer) 
149
150                    // make sure the element exists on the page before trying to initalize
151                    if($( stickyElement ).length){
152                        $( stickyElement ).each(function(){
153                            var header_height = 0;
154                            if ($(window).width() >= 1200) {
155                                if ($('.main-sticky-header').length > 0) {
156                                    header_height = $('.main-sticky-header').outerHeight();
157                                    affix_height_top = affix_height + header_height;
158                                }
159                            } else {
160                                header_height = $('#apus-header-mobile').outerHeight();
161                                affix_height_top = affix_height + header_height;
162                                header_height = 0;
163                            }
164                            affix_height_top = affix_height_top + 10;
165                            // let's save some messy code in clean variables
166                            // when should we start affixing? (the amount of pixels to the top from the element)
167                            var fromTop = $( this ).offset().top, 
168                                // where is the bottom of the element?
169                                fromBottom = $( document ).height()-($( this ).offset().top + $( this ).outerHeight()),
170                                // where should we stop? (the amount of pixels from the top where the bottom element is)
171                                // also add the outer height mismatch to the height of the element to account for padding and borders
172                                stopOn = $( document ).height()-( $( bottomElement ).offset().top)+($( this ).outerHeight() - $( this ).height()); 
173                
174                            // if the element doesn't need to get sticky, then skip it so it won't mess up your layout
175                            if( (fromBottom-stopOn) > 200 ){
176                                // let's put a sticky width on the element and assign it to the top
177                                $( this ).css('width', $( this ).width()).css('top', 0).css('position', '');
178                                // assign the affix to the element
179                                $( this ).affix({
180                                    offset: { 
181                                        // make it stick where the top pixel of the element is
182                                        top: fromTop - header_height,  
183                                        // make it stop where the top pixel of the bottom element is
184                                        bottom: stopOn
185                                    }
186                                // when the affix get's called then make sure the position is the default (fixed) and it's at the top
187                                }).on('affix.bs.affix', function(){
188                                    var header_height = 0;
189                                    if ($(window).width() >= 1200) {
190                                        if ($('.main-sticky-header').length > 0) {
191                                            header_height = $('.main-sticky-header').outerHeight();
192                                            affix_height_top = affix_height + header_height;
193                                        }
194                                    } else {
195                                        header_height = $('#apus-header-mobile').outerHeight();
196                                        affix_height_top = affix_height + header_height;
197                                        header_height = 0;
198                                    }
199                                    affix_height_top = affix_height_top + 10;
200                                    $( this ).css('top', header_height).css('position', header_height);
201                                });
202                            }
203                            // trigger the scroll event so it always activates 
204                            $( window ).trigger('scroll'); 
205                        }); 
206                    }
207
208                    //Offset scrollspy height to highlight li elements at good window height
209                    $('body').scrollspy({
210                        target: ".header-tabs-nav",
211                        offset: affix_height_top + 20
212                    });
213                }, 50);
214            }
215            
216
217            //Smooth Scrolling For Internal Page Links
218              $('.panel-affix a[href*="#"]:not([href="#"])').on('click', function() {
219                if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
220                  var target = $(this.hash);
221                  target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
222                  if (target.length) {
223                    $('html,body').animate({
224                      scrollTop: target.offset().top - affix_height_top
225                    }, 1000);
226                    return false;
227                  }
228                }
229              });
230            
231
232
233            $('.listing-review-btn .listing-reviews').on('click', function(e){
234                e.preventDefault();
235                $('html, body').animate({
236                    scrollTop: $( $.attr(this, 'href') ).offset().top
237                }, 500);
238            });
239
240            $('.event-schedule-wrapper .panel-heading').on('click', function (e) {
241                $(this).toggleClass('active');           
242            });
243        },
244        imagesPreview: function(input, placeToInsertImagePreview) {
245            if (input.files) {
246                var filesAmount = input.files.length;
247                
248                for (var i = 0; i < filesAmount; i++) {
249                    var reader = new FileReader();
250                    reader.onload = function(event) {
251                        $($.parseHTML('<img>')).attr('src', event.target.result).appendTo(placeToInsertImagePreview);
252                    }
253                    reader.readAsDataURL(input.files[i]);
254                }
255            }
256        },
257        listingComment: function() {
258            var self = this;
259            // file attachments
260            $('#field_attachments_cover').on('click', function(){
261                $("#field_attachments").trigger('click');
262            });
263            $('#field_attachments').on('change', function() {
264                $('.group-upload-preview').html('');
265                self.imagesPreview(this, 'div.group-upload-preview');
266                $('.group-upload-preview').css("display","block");
267            });
268
269            var isAdvancedUpload = function() {
270                var div = document.createElement('div');
271                return (('draggable' in div) || ('ondragstart' in div && 'ondrop' in div)) && 'FormData' in window && 'FileReader' in window;
272            }();
273
274            if (isAdvancedUpload) {
275                var droppedFiles = false;
276                
277                $('#field_attachments_cover').on('drag dragstart dragend dragover dragenter dragleave drop', function(e) {
278                    e.preventDefault();
279                    e.stopPropagation();
280                }).on('dragover dragenter', function() {
281                    $('#field_attachments_cover').addClass('is-dragover');
282                }).on('dragleave dragend drop', function() {
283                    $('#field_attachments_cover').removeClass('is-dragover');
284                }).on('drop', function(e) {
285                    droppedFiles = e.originalEvent.dataTransfer.files;
286                    $('#field_attachments').prop('files', droppedFiles).trigger('change');
287                });
288            }
289
290            $('.comment-attactments').each(function(){
291                var $this = $(this);
292                $('.show-more-images', $this).on('click', function(){
293                    $('.attachment', $this).removeClass('hidden');
294                    $(this).addClass('hidden');
295                    initProductImageLoad();
296                });
297            });
298
299            $('.photos-wrapper').each(function(){
300                var $this = $(this);
301                $('.show-more-images', $this).on('click', function(){
302                    $('.attachment', $this).removeClass('hidden');
303                    $(this).addClass('hidden');
304                    initProductImageLoad();
305                });
306            });
307
308            // like
309            $('.comment-actions .comment-like').on('click', function(e){
310                e.preventDefault();
311                var $this = $(this);
312                $this.addClass('loading');
313
314                $.ajax({
315                    url: listdo_listing_opts.ajaxurl,
316                    type:'POST',
317                    dataType: 'json',
318                    data:  "action=listdo_comment_like&comment_id="+$this.data('id') + "&security=" + listdo_listing_opts.ajax_nonce
319                }).done(function(data) {
320                    $this.removeClass('loading');
321                    $this.html(data.icon + data.dtitle);
322                    $this.attr( 'title', data.dtitle );
323                    $this.attr( 'data-original-title', data.dtitle );
324                    $this.toggleClass('active');
325                });
326            });
327            // dislike
328            $('.comment-actions .comment-dislike').on('click', function(e){
329                e.preventDefault();
330                var $this = $(this);
331                $this.addClass('loading');
332
333                $.ajax({
334                    url: listdo_listing_opts.ajaxurl,
335                    type:'POST',
336                    dataType: 'json',
337                    data:  "action=listdo_comment_dislike&comment_id="+$this.data('id') + "&security=" + listdo_listing_opts.ajax_nonce
338                }).done(function(data) {
339                    $this.removeClass('loading');
340                    $this.html(data.icon + data.dtitle);
341                    $this.attr( 'title', data.dtitle );
342                    $this.attr( 'data-original-title', data.dtitle );
343                    $this.toggleClass('active');
344                });
345            });
346            // love
347            $('.comment-actions .comment-love').on('click', function(e){
348                e.preventDefault();
349                var $this = $(this);
350                $this.addClass('loading');
351
352                $.ajax({
353                    url: listdo_listing_opts.ajaxurl,
354                    type:'POST',
355                    dataType: 'json',
356                    data:  "action=listdo_comment_love&comment_id="+$this.data('id') + "&security=" + listdo_listing_opts.ajax_nonce
357                }).done(function(data) {
358                    $this.removeClass('loading');
359                    $this.html(data.icon + data.dtitle);
360                    $this.attr( 'title', data.dtitle );
361                    $this.attr( 'data-original-title', data.dtitle );
362                    $this.toggleClass('active');
363                });
364            });
365
366            // edit comment
367            $('.comment-actions .listdo-edit-comment').on('click', function(e){
368                e.preventDefault();
369                var $this = $(this);
370                var ajax_val;
371                $this.addClass('loading');
372
373                $.ajax({
374                    url: listdo_listing_opts.ajaxurl,
375                    type:'POST',
376                    dataType: 'html',
377                    data:  "action=listdo_comment_edit&comment_id="+$this.data('id') + "&security=" + listdo_listing_opts.ajax_nonce
378                }).done(function(data) {
379                    $this.removeClass('loading');
380                    
381                    $.magnificPopup.open({
382                        mainClass: 'apus-mfp-zoom-in',
383                        items    : {
384                            src : data,
385                            type: 'inline'
386                        },
387                        callbacks: {
388                            open: function() {
389                                self.listingReview();
390
391                                // process edit comment
392                                $(document).on('submit', 'form.edit-review-form', function(e){
393                                    e.preventDefault();
394                                    if ( ajax_val ) {
395                                        return;
396                                    }
397                                    var $form = $(this);
398                                    $form.addClass('loading');
399                                    $form.find('.alert-text').remove();
400
401                                    ajax_val = $.ajax({
402                                        url: listdo_listing_opts.ajaxurl,
403                                        type:'POST',
404                                        dataType: 'json',
405                                        data: $form.serialize() + "&action=listdo_process_comment_edit"
406                                    }).done(function(data) {
407                                        $form.removeClass('loading');
408                                        
409                                        $form.find('.alert-text').remove();
410                                        if ( data.status ) {
411                                            var comment_data = data.comment_data;
412                                            $this.closest('.the-comment').find('.description').html(comment_data.comment_content);
413                                            $this.closest('.the-comment').find('.star-rating').replaceWith(comment_data.rating_ouput);
414
415                                            $form.prepend('<div class="alert-text text-info">' + data.msg + '</div>');
416                                        } else {
417                                            $form.prepend('<div class="alert-text text-warning">' + data.msg + '</div>');
418                                        }
419
420                                        $form.toggleClass('active');
421                                        ajax_val = null;
422                                    });
423                                    return false;
424                                });
425
426                            }
427                        }
428                    });
429                    
430                    $this.toggleClass('active');
431                });
432
433            });
434            
435            //
436            $('.comment-box').each(function(){
437                var $this = $(this);
438                $('.comment-see-more', $this).on('click', function(){
439                    $('.comment-text', $this).slideToggle();
440                    $('.title-job', $this).toggleClass("active");
441                    initProductImageLoad();
442                });
443            });
444            
445            // follow/following
446            $( "body" ).on( "click", ".btn-follow-following", function( e ) {
447                e.preventDefault();
448
449                var user_id = $(this).data('id');
450                var $self = $(this);
451                if ( $self.hasClass('loading') ) {
452                    return false;
453                }
454                $self.addClass('loading');
455                $.ajax({
456                    url: listdo_listing_opts.ajaxurl,
457                    type:'POST',
458                    dataType: 'json',
459                    data: {
460                        'action': 'listdo_follow_user',
461                        'user_id': user_id,
462                        'security': listdo_listing_opts.ajax_nonce
463                    }
464                }).done(function(response) {
465                    if ( response.status === 'error' ) {
466                        self.showMessage(response.msg, response.status);
467                    } else {
468                        $self.removeClass('btn-follow-user').removeClass('btn-following-user').addClass(response.class);
469                        if ( $self.hasClass('btn-outline') ) {
470                            $self.removeClass('btn-outline');
471                        } else {
472                            $self.addClass('btn-outline');
473                        }
474                        $self.html(response.msg);
475                    }
476                    $self.removeClass('loading');
477                });
478            });
479        },
480
481        halfMapPaddingTop:function(){
482            if ( $('#apus-header').length > 0 ) {
483                var header_h = $('#apus-header').outerHeight();
484                
485                if ($('#apus-listing-map').is('.fix-map')) {
486                    $('.fix-header #apus-main-content').css({'padding-top': header_h});
487                }
488            }
489        },
490
491        listingBtnFilter: function() {
492            var self = this;
493            $('.btn-show-filter').on('click', function(e){
494                e.preventDefault();
495                $('.job_filters .search_jobs').slideToggle(500);
496
497                var $slick = $('.job_filters .search_jobs [data-carousel=slick]');
498
499                if ($slick.length > 0 && $slick.hasClass('slick-initialized')) {
500                    $slick.slick('refresh');
501                }
502                self.layzyLoadImage();
503            });
504
505            //  show amenities
506            $('.apus-half-map-layout .title-amenity').on('click', function(e){
507                $('.apus-half-map-layout .amenities-wrap').slideToggle(500);
508            });
509
510            // scroll filter sidebar
511            if ($(window).width() < 992) {
512                $('.wrapper-filters1 .job_filters').perfectScrollbar();
513            }
514
515            $(window).resize(function(){
516                if ($(window).width() < 992) {
517                    $('.wrapper-filters1 .job_filters').perfectScrollbar();
518                }
519            });
520
521            // halfmap version 3
522            if ($(window).width() >= 992) {
523                $('.apus-half-map-layout-v3 .list-content .wrapper-filters1 .job_filters').perfectScrollbar();
524                $('.apus-half-map-layout-v4 .list-content .wrapper-filters1 .job_filters').perfectScrollbar();
525            }
526
527            $('.btn-view-map').on('click', function(e){
528                e.preventDefault();
529                $('.apus-listing-map').removeClass('hidden-sm').removeClass('hidden-xs');
530                $('.apus-listing-warpper .job_listings').addClass('hidden-sm').addClass('hidden-xs');
531                $('.apus-listing-warpper .main-results').addClass('p-results-mobile');
532                $('.btn-view-listing').removeClass('hidden-sm').removeClass('hidden-xs');
533                $(this).addClass('hidden-sm').addClass('hidden-xs');
534                $('.showing_jobs').addClass('hidden-sm').addClass('hidden-xs');
535                $('.listing-action').addClass('hidden-sm').addClass('hidden-xs');
536                setTimeout(function() {
537                    $(window).trigger('pxg:refreshmap');
538                    window.dispatchEvent(new Event('resize'));
539                });
540            });
541            $('.btn-view-listing').on('click', function(e){
542                e.preventDefault();
543                $('.apus-listing-warpper .main-results').removeClass('p-results-mobile');
544                $('.apus-listing-map').addClass('hidden-sm').addClass('hidden-xs');
545                $('.apus-listing-warpper .job_listings').removeClass('hidden-sm').removeClass('hidden-xs');
546                $('.btn-view-map').removeClass('hidden-sm').removeClass('hidden-xs');
547                $(this).addClass('hidden-sm').addClass('hidden-xs');
548                $('.showing_jobs').removeClass('hidden-sm').removeClass('hidden-xs');
549                $('.listing-action').removeClass('hidden-sm').removeClass('hidden-xs');
550            });
551
552            $('.showmore').on('click', function(e){
553                e.preventDefault();
554                $(this).parent().find('.content-inner').toggleClass('active');
555            });
556
557            if ( $( 'input.field-datetimepicker' ).length > 0 && $.isFunction( $.fn.datetimepicker ) ) {
558                jQuery.datetimepicker.setLocale(listdo_listing_opts.lang_code);
559                $('input.field-datetimepicker').datetimepicker({'scrollInput': false});
560            }
561            // scrollbar
562            function change_padding_filters() {
563                if ($(window).width() >= 992) {
564                    $('.apus-half-map-layout-v2 form.job_filters, .apus-grid-layout form.job_filters').perfectScrollbar();
565                    var header_h = $('#apus-header').outerHeight();
566                    if(header_h > 0){
567                       $('.apus-half-map-layout-v2 .wrapper-filters').css({ 'top': header_h,'height': 'calc(100vh - ' + header_h+ 'px)' }); 
568                    }
569                } else {
570                    $('.apus-half-map-layout-v2 .wrapper-filters').css({ 'top': 'inherit', 'he
570ight': 'auto' }); 
571                }
572            }
573
574            function change_padding_filters_v3() {
575                if ($(window).width() >= 1200) {
576                    var header_h = $('#apus-header').outerHeight();
577                    if(header_h > 0){
578                       $('.apus-half-map-layout-v3 .wrapper-filters1').css({ 'top': header_h,'height': 'calc(100vh - ' + header_h+ 'px)' }); 
579                       $('.apus-half-map-layout-v4 .wrapper-filters1').css({ 'top': header_h,'height': 'calc(100vh - ' + header_h+ 'px)' }); 
580                    }
581                } else {
582                    $('.apus-half-map-layout-v3 .wrapper-filters1').css({ 'top': 0 }); 
583                    $('.apus-half-map-layout-v4 .wrapper-filters1').css({ 'top': 0 }); 
584                }
585            }
586
587            setTimeout(function(){
588                change_padding_filters();    
589                change_padding_filters_v3();    
590            }, 50);
591            $(window).resize(function(){
592                change_padding_filters();
593                change_padding_filters_v3();
594                $('.apus-listing-warpper').removeClass('active')
595            });
596
597            $('.listings-filter-header, .mobile-groups-button .btn-filter').on('click', function(e){
598                e.stopPropagation();
599                $('.apus-half-map-layout, .apus-grid-layout').toggleClass('active');
600                var $slick = $('.job_filters .search_jobs [data-carousel=slick]');
601
602                if ($slick.length > 0 && $slick.hasClass('slick-initialized')) {
603                    $slick.slick('refresh');
604                }
605                self.layzyLoadImage();
606            });
607            $('body').on('click', function() {
608                if ($('.apus-half-map-layout, .apus-grid-layout').hasClass('active')) {
609                    $('.apus-half-map-layout, .apus-grid-layout').removeClass('active');
610                }
611            });
612            $('.apus-half-map-layout .wrapper-filters, .apus-grid-layout .wrapper-filters').on('click', function(e) {
613                e.stopPropagation();
614            });
615
616            // filter 1
617            $('.show-filter1, .btn-view-map, .btn-view-listing').on('click', function(e) {
618                e.stopPropagation();
619                $('.wrapper-filters1').toggleClass('active');
620            });
621            // filter 2
622            $('.show-filter2').on('click', function(e) {
623                e.stopPropagation();
624                $('.wrapper-filters1').toggleClass('active');
625                $('.over-dark').toggleClass('active');
626                $(this).toggleClass('active');
627            });
628            $('body').on('click', function() {
629                if ($('.wrapper-filters1').hasClass('active')) {
630                    $('.wrapper-filters1').removeClass('active');
631                    $('.over-dark').removeClass('active');
632                }
633            });
634            $('.wrapper-filters1').on('click', function(e) {
635                e.stopPropagation();
636            });
637        },
638        select2Init: function() {
639            // select2
640            if ( $.isFunction( $.fn.select2 ) && typeof job_manager_select2_args !== 'undefined' ) {
641                var select2_args = job_manager_select2_args;
642                select2_args['allowClear']              = true;
643                select2_args['minimumResultsForSearch'] = 10;
644                var order_args = { minimumResultsForSearch: 10 };
645                if ( $('html').attr('dir') == 'rtl' ) {
646                    order_args.dir = 'rtl';
647                }
648                $( 'select[name^="filter_order"]' ).select2( order_args );
649
650                order_args.width = '100%';
651                if( $('.widget-listingsearch select[name^="search_categories"],.widget-listingsearch select[name^="job_region_select"]').length ){
652                    select2_args.theme = 'default customizer-orderby';
653                }
654                $( 'select[name^="job_region_select"]' ).select2( select2_args );
655                $( 'select[name^="filter_price_range"]' ).select2( select2_args );
656                $( 'select[name^="search_categories"]' ).select2( select2_args );
657                $( 'select[name^="job_type_select"]' ).select2( select2_args );
658                $( 'select[name^="search_types"]' ).select2( select2_args );
659
660                // submit form
661                $( 'select[name^="job_regions"]' ).select2( order_args );
662                $( 'select[name^="job_categories"]' ).select2( order_args );
663                $( 'select[name^="job_c_category"]' ).select2( order_args );
664                $( 'select[name^="job_c_type"]' ).select2( order_args );
665
666                $( 'select[name="job_amenities"]' ).select2( order_args );
667                $( 'select[name="job_type"]' ).select2( order_args );
668                $( 'select[name="job_category"]' ).select2( order_args );
669                $( 'select[name="job_price_range"]' ).select2( order_args );
670            }
671        },
672        listingFilterProcess:function() {
673            var $supports_html5_history = false;
674            if ( window.history && window.history.pushState ) {
675                $supports_html5_history = true;
676            }
677
678            var target = $('.job_listings');
679            target.find('.job_listings').addClass('loading');
680            target.triggerHandler( 'update_results', [ 1, false ] );
681
682            if ( $supports_html5_history ) {
683                var form  = target.find( '.job_filters' );
684                var data  = $( form ).serialize();
685                var index = $( 'div.job_listings' ).index( target );
686                window.history.replaceState( { id: 'job_manager_state', page: 1, data: data, index: index }, '', location );
687            }
688        },
689        listingFilter: function() {
690            var self = this;
691            
692            if ( $('input[name^=filter_event_date_]').length > 0 && $.isFunction( $.fn.datetimepicker ) ) {
693                jQuery.datetimepicker.setLocale(listdo_listing_opts.lang_code);
694                $('input[name^=filter_event_date_]').datetimepicker({
695                    timepicker: false,
696                    format: listdo_listing_opts.date_format,
697                    'scrollInput': false
698                });
699                var date_from_val = '', date_to_val = '';
700                $('input[name^=filter_event_date_from]').on('change', function(){
701                    if ( date_from_val == $(this).val() ) {
702                        return false;
703                    }
704                    date_from_val = $(this).val();
705                    self.listingFilterProcess();
706                });
707                $('input[name^=filter_event_date_to]').on('change', function(){
708                    if ( date_to_val == $(this).val() ) {
709                        return false;
710                    }
711                    date_to_val = $(this).val();
712                    self.listingFilterProcess();
713                });
714            }
715            $('.submit-filter .btn-filter').on('click', function(){
716                self.listingFilterProcess();
717                if ( $(window).width() <= 991 ) {
718                    $('.wrapper-filters1').removeClass('active');
719                }
720            });
721            
722            $('input[name^=search_keywords]').on('change', function(){
723                self.listingFilterProcess();
724            });
725
726            // Category
727            var change_category_fc = function(val) {
728                if ( $('select[name^="job_type_select"]').length > 0 ) {
729                    var main_select = $('select[name^="job_type_select"]');
730                    main_select.val('');
731                    var main_con = main_select.parent();
732                    main_con.addClass('loading');
733                    var placeholder = '';
734                    if ( main_select.data('placeholder') !== 'undefined' ) {
735                        placeholder = main_select.data('placeholder');
736                    }
737                    $.ajax({
738                        url: listdo_listing_opts.ajaxurl,
739                        type:'POST',
740                        dataType: 'html',
741                        data:{
742                            'action': 'listdo_process_change_category',
743                            'category_parent': val,
744                            'security': listdo_listing_opts.ajax_nonce,
745                            'name': main_select.attr('name'),
746                            'id': '',
747                            'placeholder': placeholder,
748                        }
749                    }).done(function(data) {
750                        main_con.removeClass('loading');
751                        if ( $.isFunction( $.fn.select2 ) ) {
752                            main_con.find('select[name^="job_type_select"]').select2("close");
753                        }
754                        main_con.html(data);
755                        if ( $.isFunction( $.fn.select2 ) ) {
756                            var select2_args = job_manager_select2_args;
757                            select2_args['allowClear']              = true;
758                            select2_args['minimumResultsForSearch'] = 10;
759                            main_con.find('select[name^="job_type_select"]').select2(select2_args);
760                        }
761                        
762                    });
763                }
764            }
765            $(document).on('change', 'body.listing-type-car select[name^="search_categories"]', function(){
766                var val = $(this).val();
767                change_category_fc(val);
768            });
769            // var val = $('body.listing-type-car .job_filters select[name^="search_categories"]').val();
770            // if ( val ) {
771            //     change_category_fc(val);
772            // }
773            
774            // Category change amenity
775            var change_category_amenities_fc = function(val) {
776                if ( $('.search_amenity_wrapper .amenities-wrap').length > 0 ) {
777                    var main_con = $('.search_amenity_wrapper .amenities-wrap');
778
779                    main_con.find('input:checked').each(function(i, obj) {
780                        $(obj).attr('checked', false);
781                        $(obj).parent().removeClass('active');
782                    });
783
784                    main_con.addClass('loading');
785                    
786                    $.ajax({
787                        url: listdo_listing_opts.ajaxurl,
788                        type:'POST',
789                        dataType: 'html',
790                        data:{
791                            'action': 'listdo_process_change_category_amenities',
792                            'category_parent': val,
793                            'security': listdo_listing_opts.ajax_nonce
794                        }
795                    }).done(function(data) {
796                        main_con.removeClass('loading');
797                        main_con.replaceWith(data);
798                    });
799                }
800            }
801            $(document).on('change', 'select[name^="search_categories"]', function(){
802                var val = $(this).val();
803                change_category_amenities_fc(val);
804            });
805
806
807            $(document).on('change', '.job_filters select[name^="search_categories"]', function(){
808                setTimeout(function(){
809                    self.listingFilterProcess();
810                }, 50);
811            });
812            $(document).on('change', '.job_filters select[name^="job_region_select"]', function(){
813                setTimeout(function(){
814                    self.listingFilterProcess();
815                }, 50);
816            });
817
818            $('.job_filters select[name^=job_type_select]').change(function(){
819                self.listingFilterProcess();
820            });
821
822
823            $( 'select[name^="search_rooms"]' ).change(function(){
824                self.listingFilterProcess();
825            });
826
827            // amenities
828            var updateAmenities = function() {
829                $('.job_filters').on('change', '.job_tags :input, .job_amenities :input', function(){
830                    $( this ).parent().toggleClass('active');
831                    self.listingFilterProcess();
832                });
833            };
834            updateAmenities();
835            $( '.job_tags :input, .job_amenities :input' ).each( function() {
836                if ($(this).is(':checked') ) {
837                    $( this ).parent().addClass('active');
838                } else {
839                    $( this ).parent().removeClass('active');
840                }
841            });
842
843            $('.listing-action select[name=filter_order]').change(function(){
844                $('#input_filter_order').val($(this).val());
845                self.listingFilterProcess();
846            });
847
848            $('.search-distance-slider').each(function(){
849                var $this = $(this);
850                var search_distance = $this.closest('.search-distance-wrapper').find('input[name^=search_distance]');
851                var search_wrap = $this.closest('.search_distance_wrapper');
852                $(this).slider({
853                    range: "min",
854                    value: search_distance.val(),
855                    min: 0,
856                    max: 100,
857                    slide: function( event, ui ) {
858                        search_distance.val( ui.value );
859                        $('.text-distance', search_wrap).text( ui.value );
860                        $('.distance-custom-handle', $this).attr( "data-value", ui.value );
861
862                        self.listingFilterProcess();
863                    },
864                    create: function() {
865                        $('.distance-custom-handle', $this).attr( "data-value", $( this ).slider( "value" ) );
866                    }
867                } );
868            } );
869
870            $('.price_slider_wrapper .price_range_slider').each(function(){
871                var $this = $(this);
872                $this.slider({
873                    range: true,
874                    min: $this.data('min'),
875                    max: $this.data('max'),
876                    values: [ $this.parent().find('.filter-price-from').val(), $this.parent().find('.filter-price-to').val() ],
877                    slide: function( event, ui ) {
878                        $this.parent().find('.price_from .price').text( self.addCommas(ui.values[ 0 ]) );
879                        $this.parent().find('.filter-price-from').val( ui.values[ 0 ] )
880                        $this.parent().find('.price_to .price').text( self.addCommas(ui.values[ 1 ]) );
881                        $this.parent().find('.filter-price-to').val( ui.values[ 1 ] );
882
883                        self.listingFilterProcess();
884                    }
885                } );
886            });
887            
888
889            $.fn.bindFirst = function(name, selector, fn) {
890                // bind as you normally would
891                // don't want to miss out on any jQuery magic
892                this.on(name, selector, fn);
893
894                // Thanks to a comment by @Martin, adding support for
895                // namespaced events too.
896                this.each(function() {
897                    var handlers = $._data(this, 'events')[name.split('.')[0]];
898                    // take out the handler we just inserted from the end
899                    var handler = handlers.pop();
900                    // move it at the beginning
901                    handlers.splice(0, 0, handler);
902                });
903            };
904
905            $('.job_filters').bindFirst('click', '.reset', function() {
906                
907                $('.job_amenities').find(':checked').each(function(i, obj) {
908                    $(obj).attr('checked', false);
909                    $(obj).prop('checked', false);
910                    $(obj).parent().removeClass('active');
911                });
912                
913                $('.job_filters select[name^="job_region_select"]').find(':selected').each(function(i, obj) {
914                    $(obj).attr('selected', false);
915                    $(obj).prop('selected', false);
916                });
917                $('.job_filters select[name^="job_region_select"]').trigger('change.select2');
918
919
920                $('.job_filters select[name^=job_type_select]').find(':selected').each(function(i, obj) {
921                    $(obj).attr('selected', false);
922                    $(obj).prop('selected', false);
923                });
924                $('.job_filters select[name^=job_type_select]').trigger('change.select2');
925
926
927
928
929                $('input[name="search_keywords"]').each(function(i, obj) {
930                    $(obj).val('');
931                });
932                $('input[name^="search_lat"]').val('');
933                $('input[name^="search_lng"]').val('');
934                $('input[name^="search_location"]').val('');
935                $('input[name^="search_location"]').parent().find('.clear-location').removeClass('hidden').addClass('hidden');
936
937                self.listingFilterProcess();
938            });
939            $( '.search_location').on('click', '.clear-location', function() {
940                var container = $(this).parent();
941                container.find('input[name^="search_lat"]').val('');
942                container.find('input[name^="search_lng"]').val('');
943                container.find('input[name^="search_location"]').val('');
944                $('input[name="search_location"]').val('');
945                $('#leaflet-geocode-container').html('').removeClass('active');
946                container.find('.clear-location').removeClass('hidden').addClass('hidden');
947            });
948            $('input[name^="search_location"]').on('keyup', function(){
949                var val = $(this).val();
950                if ( $(this).val() !== '' ) {
951                    $(this).parent().find('.clear-location').removeClass('hidden');
952                } else {
953                    $(this).parent().find('.clear-location').removeClass('hidden').addClass('hidden');
954                }
955            });
956            $('input[name^="search_location"]').each(function(){
957                var this_e = $(this);
958                var parent = $(this).parent();
959                var val = this_e.val();
960                if ( this_e.val() !== '' ) {
961                    parent.find('.clear-location').removeClass('hidden');
962                } else {
963                    parent.find('.clear-location').removeClass('hidden').addClass('hidden');
964                }
965            });
966
967            // $('.fields-filter.list-inner-full').perfectScrollbar();
968
969            // find me
970            $('.find-me').on('click', function() {
971                $(this).addClass('loading');
972                var this_e = $(this);
973                var container = $(this).parent();
974
975                navigator.geolocation.getCurrentPosition(function (position) {
976                    container.find('input[name^="search_lat"]').val(position.coords.latitude);
977                    container.find('input[name^="search_lng"]').val(position.coords.longitude);
978                    $('input[name="search_location"]').val('location');
979                    container.find('.clear-location').removeClass('hidden');
980
981                    var position = [position.coords.latitude, position.coords.longitude];
982
983                    var geocodeService = L.esri.Geocoding.geocodeService();
984                    geocodeService.reverse().latlng(position).run(function(error, result) {
985                        $('input[name="search_location"]').val(result.address.Match_addr);
986                    });
987
988                    setTimeout(function(){
989                        $('.job_listings').triggerHandler('update_results', [1, false]);
990                    }, 50);
991                    return this_e.removeClass('loading');
992                }, function (e) {
993                    return this_e.removeClass('loading');
994                }, {
995                    enableHighAccuracy: true
996                });
997            });
998
999            // search autocomplete location
1000            if ( listdo_listing_opts.geocoder_country ) {
1001                var geocoder = new L.Control.Geocoder.Nominatim({
1002                    geocodingQueryParams: {countrycodes: listdo_listing_opts.geocoder_country}
1003                });
1004            } else {
1005                var geocoder = new L.Control.Geocoder.Nominatim();
1006            }
1007
1008            $("input[name=search_location]").attr('autocomplete', 'off').after('<div id="leaflet-geocode-container"></div>');
1009            $("input[name=search_location]").on("keyup",function search(e) {
1010                var s = $(this).val(), $this = $(this);
1011                if (s && s.length >= 2) {
1012                    
1013                    $this.parent().addClass('loading');
1014                    geocoder.geocode(s, function(results) {
1015                        var output_html = '';
1016                        for (var i = 0; i < results.length; i++) {
1017                            output_html += '<li class="result-item" data-latitude="'+results[i].center.lat+'" data-longitude="'+results[i].center.lng+'" ><i class="fa fa-map-marker" aria-hidden="true"></i> '+results[i].name+'</li>';
1018                        }
1019                        if ( output_html ) {
1020                            output_html = '<ul>'+ output_html +'</ul>';
1021                        }
1022
1023                        $('#leaflet-geocode-container').html(output_html).addClass('active');
1024
1025                        var highlight_texts = s.split(' ');
1026
1027                        highlight_texts.forEach(function (item) {
1028                            $('#leaflet-geocode-container').highlight(item);
1029                        });
1030
1031                        $this.parent().removeClass('loading');
1032                    });
1033                } else {
1034                    $("#leaflet-geocode-container").html('').removeClass('active');
1035                }
1036            });
1037            $('.search_location').on('click', '#leaflet-geocode-container ul li', function() {
1038                var container = $(this).closest('.search_location');
1039                container.find('input[name=search_lat]').val($(this).data('latitude'));
1040                container.find('input[name=search_lng]').val($(this).data('longitude'));
1041                container.find('input[name=search_location]').val($(this).text());
1042                $('#leaflet-geocode-container').removeClass('active').html('');
1043
1044                jQuery('.job_listings').triggerHandler('update_results', [1, false]);
1045            });
1046
1047        },
1048        addCommas: function(str) {
1049            var parts = (str + "").split("."),
1050                main = parts[0],
1051                len = main.length,
1052                output = "",
1053                first = main.charAt(0),
1054                i;
1055            
1056            if (first === '-') {
1057                main = main.slice(1);
1058                len = main.length;    
1059            } else {
1060                first = "";
1061            }
1062            i = len - 1;
1063            while(i >= 0) {
1064                output = main.charAt(i) + output;
1065                if ((len - i) % 3 === 0 && i > 0) {
1066                    output = listdo_listing_opts.money_thousands_separator + output;
1067                }
1068                --i;
1069            }
1070            // put sign back
1071            output = first + output;
1072            // put decimal part back
1073            if (parts.length > 1) {
1074                output += listdo_listing_opts.money_dec_point + parts[1];
1075            }
1076            return output;
1077        },
1078        listingReview: function() {
1079            if ( $('.comment-form-rating').length > 0 ) {
1080                $('.comment-form-rating .rating-inner').each(function(){
1081                    var e_this = $(this);
1082                    var $star = e_this.find('.review-stars');
1083                    var $review = e_this.find('input.rating');
1084                    $star.find('li').on('mouseover',
1085                        function () {
1086                            $(this).nextAll().find('span').removeClass('active');
1087                            $(this).prevAll().find('span').removeClass('active').addClass('active');
1088                            $(this).find('span').removeClass('active').addClass('active');
1089                            var key = $(this).data('key');
1090                            e_this.find('.review-label').html( listdo_listing_opts.reviews[key] );
1091                            //$review.val($(this).index() + 1);
1092                        }
1093                    );
1094                    $star.on('mouseout', function(){
1095                        var current = $review.val() - 1;
1096                        var current_e = $star.find('li').eq(current);
1097
1098                        current_e.nextAll().find('span').removeClass('active');
1099                        current_e.prevAll().find('span').removeClass('active').addClass('active');
1100                        current_e.find('span').removeClass('active').addClass('active');
1101                        var key = current_e.data('key');
1102                        e_this.find('.review-label').html( listdo_listing_opts.reviews[key] );
1103                    });
1104
1105                    $star.find('li').on('click', function () {
1106                        $(this).nextAll().find('span').removeClass('active');
1107                        $(this).prevAll().find('span').removeClass('active').addClass('active');
1108                        $(this).find('span').removeClass('active').addClass('active');
1109                        
1110                        var key = $(this).data('key');
1111                        e_this.find('.review-label').html( listdo_listing_opts.reviews[key] );
1112                        $review.val($(this).index() + 1);
1113                    } );
1114
1115
1116                    var val = $review.val() - 1;
1117                    var key = $star.find('li').eq(val).data('key');
1118                    e_this.find('.review-label').html( listdo_listing_opts.reviews[key] );
1119                });
1120            }
1121
1122        },
1123        bookmarkInit: function() {
1124            var self = this;
1125            // bookmark
1126            $( "body" ).on( "click", ".apus-bookmark-add", function( e ) {
1127                e.preventDefault();
1128
1129                var post_id = $(this).data('id');
1130                var url = listdo_listing_opts.ajaxurl + '?action=listdo_add_bookmark&post_id=' + post_id + '&security=' + listdo_listing_opts.ajax_nonce;
1131                var $self = $(this);
1132                $self.addClass('loading');
1133                $.ajax({
1134                    url: url,
1135                    type:'POST',
1136                    dataType: 'json',
1137                }).done(function(reponse) {
1138                    if (reponse.status === 'success') {
1139                        $self.addClass('apus-bookmark-added').removeClass('apus-bookmark-add');
1140                    }
1141                    $self.removeClass('loading');
1142                    self.showMessage(reponse.msg, reponse.status);
1143                });
1144            });
1145            $(document).on('click', '.apus-bookmark-not-login', function(e){
1146                e.preventDefault();
1147                
1148                $('.apus-user-login').trigger('click');
1149                return false;
1150            });
1151
1152            // bookmark remove
1153            $( "body" ).on( "click", ".apus-bookmark-added", function( e ) {
1154                e.preventDefault();
1155
1156                var post_id = $(this).data('id');
1157                var url = listdo_listing_opts.ajaxurl + '?action=listdo_remove_bookmark&post_id=' + post_id + '&security=' + listdo_listing_opts.ajax_nonce;
1158                var $self = $(this);
1159                $self.addClass('loading');
1160                $.ajax({
1161                    url: url,
1162                    type:'POST',
1163                    dataType: 'json',
1164                }).done(function(reponse) {
1165                    if (reponse.status === 'success') {
1166                        $self.removeClass('apus-bookmark-added').addClass('apus-bookmark-add');
1167                    }
1168                    $self.removeClass('loading');
1169                    self.showMessage(reponse.msg, reponse.status);
1170                });
1171            });
1172            $( "body" ).on( "click", ".apus-bookmark-remove", function( e ) {
1173                e.preventDefault();
1174
1175                var post_id = $(this).data('id');
1176                var url = listdo_listing_opts.ajaxurl + '?action=listdo_remove_bookmark&post_id=' + post_id + '&security=' + listdo_listing_opts.ajax_nonce;
1177                $(this).addClass('loading');
1178                $.ajax({
1179                    url: url,
1180                    type:'POST',
1181                    dataType: 'json',
1182                }).done(function(reponse) {
1183                    if (reponse.status === 'success') {
1184                        var parent = $('#bookmark-listing-' + post_id).parent();
1185                        if ( $('.my-listing-item-wrapper', parent).length <= 1 ) {
1186                            location.reload();
1187                        } else {
1188                            $('#bookmark-listing-' + post_id).remove();
1189                        }
1190                    }
1191                    self.showMessage(reponse.msg, reponse.status);
1192                });
1193            });
1194        },
1195        showMessage: function(msg, status) {
1196            console.log(msg);
1197            if ( msg ) {
1198                var classes = 'alert alert-warning';
1199                if ( status == 'success' ) {
1200                    classes = 'alert alert-info';
1201                }
1202                var $html = '<div id="listdo-popup-message" class="animated fadeInRight"><div class="message-inner '+ classes +'">'+ msg +'</div></div>';
1203                $('body').find('#listdo-popup-message').remove();
1204                $('body').append($html).fadeIn(500);
1205                setTimeout(function() {
1206                    $('body').find('#listdo-popup-message').removeClass('fadeInRight').addClass('delay-1s fadeOutRight');
1207                }, 2500);
1208            }
1209        },
1210        searchInit: function() {
1211            var self = this;
1212            // widget search jobs
1213            $(".search_jobs .show-more-filter").on('click', function(e){
1214                e.preventDefault();
1215                $(".search_jobs .tags-wrap").toggle('500');
1216                if($(this).find('i').hasClass('fa-plus')){
1217                    $(this).find('i').removeClass('fa-plus');
1218                    $(this).find('i').addClass('fa-minus');
1219                } else {
1220                    $(this).find('i').removeClass('fa-minus');
1221                    $(this).find('i').addClass('fa-plus');
1222                }
1223            });
1224            $('.job_search_form .has-suggestion').on('click', function(e) {
1225                e.stopPropagation();
1226            });
1227            $(".job_search_form .has-suggestion").on('click', function(){
1228                var search_val = $(this).find('input[name=search_keywords]').val();
1229                if ( search_val === '' ) {
1230                    $(this).toggleClass("active");
1231                } else {
1232                    $(this).removeClass("active");
1233                }
1234                //alert(search_val);
1235            });
1236            $('body').on('click', function() {
1237                if ($('.job_search_form .has-suggestion').hasClass('active')) {
1238                    $('.job_search_form .has-suggestion').removeClass('active');
1239                }
1240            });
1241
1242            $('.navbar-collapse-suggestions').perfectScrollbar();
1243
1244            // fix map
1245            if ($('#apus-listing-map').is('.fix-map')) {
1246                setTimeout(function(){
1247                    self.changePaddingTopContent();    
1248                }, 50);
1249                $(window).resize(function(){
1250                    self.changePaddingTopContent();
1251                });
1252            }
1253        },
1254        changePaddingTopContent: function() {
1255            if ($(window).width() >= 1200) {
1256                var header_h = $('#apus-header').outerHeight();
1257            } else {
1258                var header_h = $('#apus-header-mobile').outerHeight();
1259            }
1260            $('#apus-listing-map').css({ 'top': header_h });
1261            $('#apus-listing-map').css({ 'height': 'calc(100vh - ' + header_h+ 'px)' });
1262            
1263            $('.listings-filter-wrapper').css({ 'top': header_h });
1264            $('.listings-filter-wrapper').css({ 'height': 'calc(100% - ' + header_h+ 'px)' });
1265
1266        },
1267        getListings: function() {
1268            var self = this;
1269            if ( $('.widget-listing-maps .apus-listing-map').length ) {
1270                $('.widget-listing-maps .apus-listing-map').each(function(e){
1271                    var $this = $(this);
1272                    
1273                    $this.addClass('loading');
1274                    var $settings = $(this).data('settings');
1275                    $.ajax({
1276                        url: listdo_listing_opts.ajaxurl,
1277                        type:'POST',
1278                        dataType: 'html',
1279                        data: {
1280                            action: 'listdo_get_ajax_listings',
1281                            settings: $settings,
1282                        }
1283                    }).done(function(data) {
1284                        $this.removeClass('loading');
1285                        $this.closest('.widget-listing-maps').find('.job_listings_cards').html(data);
1286                        setTimeout(function(){
1287                            self.updateMakerCards();
1288                        });
1289                    });
1290                });
1291            }
1292        },
1293        mapInit: function() {
1294            var self = this;
1295            //
1296            self.initStreetView();
1297
1298            var $window = $(window);
1299            if ($('.no_job_listings_found').length) {
1300                $('<div class="results">' + listdo_listing_opts.strings['no_job_listings_found'] + '</div>').prependTo('.showing_jobs, .listing-search-result');
1301            }
1302
1303            if (!$('#apus-listing-map').length) {
1304                $('.job_listings').on('updated_results', function(e, result) {
1305                    var target = $( this );
1306                    self.layzyLoadImage();
1307                    self.timerCountdown();
1308                    self.previewInit();
1309
1310                    if ( true === target.data( 'show_pagination' ) ) {
1311                        target.find('.job-manager-pagination').remove();
1312
1313                        if ( result.pagination ) {
1314                            target.find('.main-results').append( result.pagination );
1315                        }
1316                    }
1317                    self.updateMakerCards(result.total_found, result);
1318                    $('[data-toggle="tooltip"]').tooltip(); 
1319                });
1320                return;
1321            }
1322
1323            map = L.map('apus-listing-map', {
1324                scrollWheelZoom: false
1325            });
1326
1327            markers = new L.MarkerClusterGroup({
1328                showCoverageOnHover: false
1329            });
1330
1331            CustomHtmlIcon = L.HtmlIcon.extend({
1332                options: {
1333                    html: "<div class='map-popup'></div>",
1334                    iconSize: [42, 42],
1335                    iconAnchor: [22, 42],
1336                    popupAnchor: [0, -42]
1337                }
1338            });
1339
1340            $window.on('pxg:refreshmap', function() {
1341                map._onResize();
1342                setTimeout(function() {
1343                    if(markerArray.length > 0 ){
1344                        group = L.featureGroup(markerArray);
1345                        map.fitBounds(group.getBounds()); 
1346                    }
1347                }, 100);
1348            });
1349
1350            $window.on('pxg:simplerefreshmap', function() {
1351                map._onResize();
1352            });
1353
1354            if ( listdo_listing_opts.map_service == 'mapbox' ) {
1355                var tileLayer = L.tileLayer('https://api.mapbox.com/styles/v1/mapbox/'+listdo_listing_opts.mapbox_style+'/tiles/{z}/{x}/{y}?access_token='+ listdo_listing_opts.mapbox_token, {
1356                    attribution: " &copy;  <a href='https://www.mapbox.com/about/maps/'>Mapbox</a> &copy;  <a href='http://www.openstreetmap.org/copyright'>OpenStreetMap</a> <strong><a href='https://www.mapbox.com/map-feedback/' target='_blank'>Improve this map</a></strong>",
1357                    maxZoom: 18,
1358                });
1359            } else if( listdo_listing_opts.map_service == 'openstreetmap' ) {
1360                var tileLayer = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
1361                    attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
1362                }).addTo(map);
1363
1364            } else {
1365                if ( listdo_listing_opts.custom_style != '' ) {
1366                    try {
1367                        var custom_style = $.parseJSON(listdo_listing_opts.custom_style);
1368                        var tileLayer = L.gridLayer.googleMutant({
1369                            type: 'roadmap',
1370                            styles: custom_style
1371                        });
1372
1373                    } catch(err) {
1374                        var tileLayer = L.gridLayer.googleMutant({
1375                            type: 'roadmap'
1376                        });
1377                    }
1378                } else {
1379                    var tileLayer = L.gridLayer.googleMutant({
1380                        type: 'roadmap'
1381                    });
1382                }
1383                $('#apus-listing-map').addClass('map--google');
1384            }
1385
1386            map.addLayer(tileLayer);
1387            
1388
1389            // check home/archive/single page
1390            if ( $('#apus-listing-map').is('.apus-homepage-listing-map') ) {
1391                self.updateMakerCards();
1392            } else {
1393                if ( !$('#apus-listing-map').is('.apus-single-listing-map') ) {
1394
1395                    $('.job_listings').on('updated_results', function(e, result) {
1396                        var target = $( this );
1397                        self.layzyLoadImage();
1398                        self.timerCountdown();
1399                        self.previewInit();
1400                        if ( true === target.data( 'show_pagination' ) ) {
1401                            target.find('.job-manager-pagination').remove();
1402                            if ( result.pagination ) {
1403                                target.find('.main-results').append( result.pagination );
1404                            }
1405                        }
1406                        self.updateMakerCards(result.total_found, result);
1407                        $('[data-toggle="tooltip"]').tooltip(); 
1408                    });
1409                    // FacetWP
1410                    $(document).on('facetwp-loaded', function(e, result) {
1411                        self.updateMakerCards();
1412                    });
1413                } else {
1414                    var $item = $('.apus-single-listing-wrapper');
1415                    
1416                    if ( $item.data('latitude') !== "" && $item.data('latitude') !== "" ) {
1417                        var zoom = (typeof MapWidgetZoom !== "undefined") ? MapWidgetZoom : 15;
1418                        self.addMakerToMap($item);
1419                        map.addLayer(markers);
1420                        map.setView([$item.data('latitude'), $item.data('longitude')], zoom);
1421                        // $(window).on('update:map', function() {
1422                        //     map.setView([$item.data('latitude'), $item.data('longitude')], zoom);
1423                        // });
1424                        
1425                        $('.top-nav-map').on('click', function(e){
1426                            e.preventDefault();
1427                            $('#apus-listing-map-street-view').hide();
1428                            $('#apus-listing-map').show();
1429                            $('.top-nav-street-view').removeClass('active');
1430                            $('.top-nav-map').removeClass('active').addClass('active');
1431                            map._onResize();
1432                        });
1433                    } else {
1434                        $('#apus-listing-map').hide();
1435                        $('.listing-address').css('marginTop', 0);
1436                    }
1437                }
1438            }
1439        },
1440        mapSidebarInit: function() {
1441            var self = this;
1442
1443            var $window = $(window);
1444            var markersSidebar;
1445            if (!$('#apus-listing-map-sidebar').length) {
1446                return;
1447            }
1448
1449            mapSidebar = L.map('apus-listing-map-sidebar', {
1450                scrollWheelZoom: false
1451            });
1452
1453            markersSidebar = new L.MarkerClusterGroup({
1454                showCoverageOnHover: false
1455            });
1456
1457            CustomHtmlIcon = L.HtmlIcon.extend({
1458                options: {
1459                    html: "<div class='map-popup'></div>",
1460                    iconSize: [48, 59],
1461                    iconAnchor: [24, 59],
1462                    popupAnchor: [0, -59]
1463                }
1464            });
1465
1466            $window.on('pxg:refreshmap', function() {
1467                mapSidebar._onResize();
1468            });
1469
1470            $window.on('pxg:simplerefreshmap', function() {
1471                mapSidebar._onResize();
1472            });
1473
1474            if ( listdo_listing_opts.map_service == 'mapbox' ) {
1475                var tileLayer = L.tileLayer('https://api.mapbox.com/styles/v1/mapbox/'+listdo_listing_opts.mapbox_style+'/tiles/{z}/{x}/{y}?access_token='+ listdo_listing_opts.mapbox_token, {
1476                    attribution: " &copy;  <a href='https://www.mapbox.com/about/maps/'>Mapbox</a> &copy;  <a href='http://www.openstreetmap.org/copyright'>OpenStreetMap</a> <strong><a href='https://www.mapbox.com/map-feedback/' target='_blank'>Improve this map</a></strong>",
1477                    maxZoom: 18,
1478                });
1479            } else {
1480                if ( listdo_listing_opts.custom_style != '' ) {
1481                    try {
1482                        var custom_style = $.parseJSON(listdo_listing_opts.custom_style);
1483                        var tileLayer = L.gridLayer.googleMutant({
1484                            type: 'roadmap',
1485                            styles: custom_style
1486                        });
1487
1488                    } catch(err) {
1489                        var tileLayer = L.gridLayer.googleMutant({
1490                            type: 'roadmap'
1491                        });
1492                    }
1493                } else {
1494                    var tileLayer = L.gridLayer.googleMutant({
1495                        type: 'roadmap'
1496                    });
1497                }
1498                $('#apus-listing-map').addClass('map--google');
1499            }
1500            
1501            mapSidebar.addLayer(tileLayer);
1502
1503            var $item = $('.apus-single-listing-wrapper');
1504            
1505            if ( $item.data('latitude') !== "" && $item.data('latitude') !== "" ) {
1506                var zoom = (typeof MapWidgetZoom !== "undefined") ? MapWidgetZoom : 15;
1507
1508                if ( $item.data('latitude') == "" || $item.data('longitude') == "") {
1509                    return;
1510                }
1511                var logo_wrapper = $item.find('.listing-logo img'), marker;
1512                var mapPinHTML = "<div class='map-popup map-popup-empty'><div class='icon-wrapper'><div class='icon-cat'>!</div></div></div>";
1513
1514                if (logo_wrapper.length) {
1515                    var img = logo_wrapper.data('src');
1516                    if ( typeof img === 'undefined' ) {
1517                        img = logo_wrapper.attr('src');
1518                    }
1519                    mapPinHTML = "<div class='map-popup'><div class='icon-cat'><img src='" + img + "' alt=''></div></div>";
1520                } else if ( $item.data('thumb') ) {
1521                    mapPinHTML = "<div class='map-popup'><div class='icon-cat'><img src='" + $item.data('thumb') + "' alt=''></div></div>";
1522                }
1523
1524                marker = L.marker([$item.data('latitude'), $item.data('longitude')], {
1525                    icon: new CustomHtmlIcon({ html: mapPinHTML })
1526                });
1527                markersSidebar.addLayer(marker);
1528
1529                mapSidebar.addLayer(markersSidebar);
1530
1531                mapSidebar.setView([$item.data('latitude'), $item.data('longitude')], zoom);
1532
1533            } else {
1534                $('#apus-listing-map-sidebar').hide();
1535                $('.listing-address').css('marginTop', 0);
1536            }
1537        },
1538        initStreetView: function() {
1539            var panorama = null;
1540            
1541            $('.top-nav-street-view').on('click', function(e){
1542                e.preventDefault();
1543                $('#apus-listing-map-street-view').show();
1544                $('#apus-listing-map').hide();
1545                $('.top-nav-street-view').removeClass('active').addClass('active');
1546                $('.top-nav-map').removeClass('active');
1547
1548                var $item = $('.apus-single-listing-wrapper');
1549
1550                if ( $item.data('latitude') !== "" && $item.data('longitude') !== "") {
1551                    var zoom = (typeof MapWidgetZoom !== "undefined") ? MapWidgetZoom : 15;
1552                    
1553                    if ( panorama == null ) {
1554
1555                        var fenway = new google.maps.LatLng($item.data('latitude'),$item.data('longitude'));
1556                        var panoramaOptions = {
1557                            position: fenway,
1558                            pov: {
1559                                heading: 34,
1560                                pitch: 10
1561                            }
1562                        };
1563                        panorama = new  google.maps.StreetViewPanorama(document.getElementById('apus-listing-map-street-view'),panoramaOptions);
1564                    }
1565                }
1566            });
1567        },
1568        updateMakerCards: function($total_found, $result) {
1569            var self = this;
1570            var $items = $('.job_listings_cards .job_listing');
1571            
1572            $('.showing_jobs .results, .listing-search-result .results, .listing-search-result-filter .results').remove();
1573
1574            var result_str = '<div class="results"><span class="results-no">';
1575
1576            if (typeof $result !== 'undefined' && typeof $result.found !== 'undefined') {
1577                result_str += '<span class="results-no">' + $result.found + '</span> ';
1578            }
1579
1580            result_str += listdo_listing_opts.strings['results-no'];
1581
1582            if (typeof $result !== 'undefined' && typeof $result.str_found !== 'undefined') {
1583                result_str = result_str + $result.str_found;
1584            }
1585            
1586            result_str = result_str + '</div>';
1587
1588            $(result_str).prependTo('.showing_jobs, .listing-search-result');
1589
1590            if (typeof $result !== 'undefined' && $result.showing !== '' && $result.showing_links !== '') {
1591                $('<div class="results">' +
1592                    $result.showing + ' ' +
1593                    $result.showing_links +
1594                    '</div>').prependTo('.listing-search-result-filter');
1595            }
1596            
1597
1598            if ($('#apus-listing-map').length && typeof map !== "undefined") {
1599                
1600                if (!$items.length) {
1601                    map.setView([listdo_listing_opts.default_latitude, listdo_listing_opts.default_longitude], 12);
1602                    return;
1603                }
1604                
1605                map.removeLayer(markers);
1606                markers = new L.MarkerClusterGroup({
1607                    showCoverageOnHover: false
1608                });
1609                $items.each(function(i, obj) {
1610                    self.addMakerToMap($(obj), true);
1611                });
1612
1613                map.addLayer(markers);
1614
1615                if ( markerArray.length > 0 ) {
1616                    group = L.featureGroup(markerArray);
1617                    map.fitBounds(group.getBounds());
1618                    if ( markerArray.length == 1 ) {
1619                        map.setZoom(16);
1620                    }
1621                }
1622            }
1623        },
1624        addMakerToMap: function($item, archive) {
1625            var self = this;
1626            var logo_wrapper = $item.find('.listing-logo img'), marker;
1627
1628            if ( $item.data('latitude') == "" || $item.data('longitude') == "") {
1629                return;
1630            }
1631
1632            var mapPinHTML = "<div class='map-popup map-popup-empty'><div class='icon-wrapper'><div class='icon-cat'>!</div></div></div>";
1633
1634            if (logo_wrapper.length) {
1635                var img = logo_wrapper.data('src');
1636                if ( typeof img === 'undefined' ) {
1637                    img = logo_wrapper.attr('src');
1638                }
1639                mapPinHTML = "<div class='map-popup'><div class='icon-cat'><img src='" + img + "' alt=''></div></div>";
1640            } else if ( $item.data('thumb') ) {
1641                mapPinHTML = "<div class='map-popup'><div class='icon-cat'><img src='" + $item.data('thumb') + "' alt=''></div></div>";
1642            }
1643
1644            marker = L.marker([$item.data('latitude'), $item.data('longitude')], {
1645                icon: new CustomHtmlIcon({ html: mapPinHTML })
1646            });
1647
1648            if (typeof archive !== "undefined") {
1649
1650                $item.on('hover', function() {
1651                    $(marker._icon).find('.map-popup').addClass('map-popup-selected');
1652                }, function() {
1653                    $(marker._icon).find('.map-popup').removeClass('map-popup-selected');
1654                });
1655                var price_html = '';
1656                if ( $item.find('.price-range').length ) {
1657                    //price_html = "<div class='listing-price'>" + $item.find('.price-range').html() + "</div>";
1658                }
1659                var title_html = '';
1660                if ( $item.find('.listing-title').length ) {
1661                    title_html = "<div class='listing-title'>" + $item.find('.listing-title').html() + "</div>";
1662                }
1663                var address_html = '';
1664                if ( $item.find('.listing-address').length ) {
1665                    address_html = "<div class='listing-address'>" + $item.find('.listing-address').html() + "</div>";
1666                }
1667                var phone_html = '';
1668                if ( $item.find('.listing-phone').length ) {
1669                    phone_html = "<div class='listing-phone'>" + $item.find('.listing-phone').clone().wrap('<div>').parent().html() + "</div>";
1670                }
1671                var review_html = '';
1672                if ( $item.find('.wrapper-star-average-rating').length ) {
1673                    review_html = "<div class='wrapper-star-average-rating'>" + $item.find('.wrapper-star-average-rating').html() + "</div>";
1674                }
1675                var content_botom = '';
1676                if ( $item.find('.listing-content-bottom').length ) {
1677                    content_botom = "<div class='listing-content-bottom'>" + $item.find('.listing-content-bottom').html() + "</div>";
1678                }
1679                var time_html = '';
1680
1681                marker.bindPopup(
1682                    "<div class='job-grid-style job_listing'>" +
1683                        "<div class='listing-image'>" +
1684                            "<div class='image-wrapper image-loaded'>" +
1685                                "<a class='map-popup-url' href='" + $item.data('permalink') + "'>" +
1686                                "<img src='" + $item.data('img') + "' alt=''>" +
1687                                "</a>" + time_html +
1688                            "</div>" + price_html +
1689                            "<div class='listing-title-wrapper'>" + review_html + title_html + address_html + phone_html + "</div>" +
1690                        "</div>" + content_botom + 
1691                    "</div>").openPopup();
1692            }
1693
1694            markers.addLayer(marker);
1695            markerArray.push(L.marker([$item.data('latitude'), $item.data('longitude')]));
1696
1697            self.layzyLoadImage();
1698            self.timerCountdown();
1699        },
1700        previewMap: function() {
1701            var self = this;
1702            var $window = $(window);
1703            map = L.map('apus-preview-listing-map', {
1704                scrollWheelZoom: false
1705            });
1706
1707            markers = new L.MarkerClusterGroup({
1708                showCoverageOnHover: false
1709            });
1710
1711            CustomHtmlIcon = L.HtmlIcon.extend({
1712                options: {
1713                    html: "<div class='map-popup'></div>",
1714                    iconSize: [42, 42],
1715                    iconAnchor: [22, 42],
1716                    popupAnchor: [0, -42]
1717                }
1718            });
1719
1720            $window.on('pxg:refreshmap', function() {
1721                map._onResize();
1722            });
1723
1724            $window.on('pxg:simplerefreshmap', function() {
1725                map._onResize();
1726            });
1727
1728            if ( listdo_listing_opts.map_service == 'mapbox' ) {
1729                var tileLayer = L.tileLayer('https://api.mapbox.com/styles/v1/mapbox/'+listdo_listing_opts.mapbox_style+'/tiles/{z}/{x}/{y}?access_token='+ listdo_listing_opts.mapbox_token, {
1730                    attribution: " &copy;  <a href='https://www.mapbox.com/about/maps/'>Mapbox</a> &copy;  <a href='http://www.openstreetmap.org/copyright'>OpenStreetMap</a> <strong><a href='https://www.mapbox.com/map-feedback/' target='_blank'>Improve this map</a></strong>",
1731                    maxZoom: 18,
1732                });
1733            } else {
1734                if ( listdo_listing_opts.custom_style != '' ) {
1735                    try {
1736                        var custom_style = $.parseJSON(listdo_listing_opts.custom_style);
1737                        var tileLayer = L.gridLayer.googleMutant({
1738                            type: 'roadmap',
1739                            styles: custom_style
1740                        });
1741
1742                    } catch(err) {
1743                        var tileLayer = L.gridLayer.googleMutant({
1744                            type: 'roadmap'
1745                        });
1746                    }
1747                } else {
1748                    var tileLayer = L.gridLayer.googleMutant({
1749                        type: 'roadmap'
1750                    });
1751                }
1752                $('#apus-listing-map').addClass('map--google');
1753            }
1754            
1755            map.addLayer(tileLayer);
1756
1757            // check home/archive/single page
1758            
1759            var $item = $('.quickview-wrapper');
1760            if ( $item.data('latitude') !== "" &&  $item.data('longitude') !== "") {
1761                var zoom = (typeof MapWidgetZoom !== "undefined") ? MapWidgetZoom : 15;
1762                self.addMakerToMap($item);
1763                map.addLayer(markers);
1764
1765                map.setView([$item.data('latitude'), $item.data('longitude')], zoom);
1766                $(window).on('update:map', function() {
1767                    map.setView([$item.data('latitude'), $item.data('longitude')], zoom);
1768                });
1769            } else {
1770                $('#apus-preview-listing-map').hide();
1771                $('.listing-address').css('marginTop', 0);
1772            }
1773        },
1774        previewInit: function() {
1775            var self = this;
1776            $('a.listing-preview').on('click', function (e) {
1777                e.preventDefault();
1778                var $self = $(this);
1779                $self.addClass('loading');
1780                var listing_id = $(this).data('id');
1781                var url = listdo_listing_opts.ajaxurl + '?action=listdo_preview_listing&listing_id=' + listing_id + '&security=' + listdo_listing_opts.ajax_nonce;
1782                
1783                $.get(url,function(data,status){
1784                    $.magnificPopup.open({
1785                        mainClass: 'apus-mfp-zoom-in apus-preview-listing',
1786                        items : {
1787                            src : data,
1788                            type: 'inline'
1789                        }
1790                    });
1791                    
1792                    $('.preview-content-inner').perfectScrollbar();
1793                    self.layzyLoadImage();
1794                    self.previewMap();
1795                    self.bookmarkInit();
1796
1797                    self.initSlick($(".quickview-slick"));
1798
1799                    $self.removeClass('loading');
1800                });
1801            });
1802        },
1803        submitForm: function() {
1804            var self = this;
1805            // menu price section
1806            $('.add-new-section-menu-price').on('click', function(e){
1807                e.preventDefault();
1808                var length = $('.menu-prices-field-wrapper .menu-prices-section-item').length;
1809                var html = $('.menu-prices-field-wrapper .menu-prices-section-item').eq(0).clone(true);
1810                html.find('.input-section-title').attr('name', "_job_menu_prices["+length+"][section_title]");
1811                html.find('.input-section-item-title').attr('name', "_job_menu_prices["+length+"][title][]");
1812                html.find('.input-section-item-price').attr('name', "_job_menu_prices["+length+"][price][]");
1813                html.find('.input-section-item-description').attr('name', "_job_menu_prices["+length+"][description][]");
1814
1815                html.find('.menu-prices-section-item-title span').text( length + 1 );
1816
1817                $('.menu-prices-field-wrapper').append(html);
1818            });
1819
1820            $('.remove-section-menu-price').on('click', function(e) {
1821                e.preventDefault();
1822                var index = $('.menu-prices-field-wrapper .menu-prices-section-item').last().index();
1823                if ( index > 0 ) {
1824                    $('.menu-prices-field-wrapper .menu-prices-section-item').eq(index).remove();
1825                }
1826            });
1827            
1828            // menu price section item
1829            $('body').on('click', '.add-new-menu-price', function(e){
1830                e.preventDefault();
1831                var parent = $(this).parent();
1832                var length = $('.menu-prices-section-item-wrapper .menu-prices-item', parent).length;
1833                var html = $('.menu-prices-item', parent).eq(0).clone(true);
1834                html.find('.group-field-item-title span').text( length + 1 );
1835
1836                parent.find('.menu-prices-section-item-wrapper').append( html );
1837            });
1838            $('body').on('click', '.remove-menu-price', function(e){
1839                e.preventDefault();
1840                var parent = $(this).parent();
1841
1842                var index = $('.menu-prices-item', parent).last().index();
1843                if ( index > 0 ) {
1844                    $('.menu-prices-item', parent).eq(index).remove();
1845                }
1846            });
1847
1848            var number_increment = 0;
1849            $( ".repeate_field_add_row" ).on('click', function(){
1850
1851                var $wrap     = $(this).closest('.wc-job-manager-repeater-rows');
1852                var max_index = 0;
1853                $wrap.find('input.repeater-row-index').each(function(){
1854                    if ( parseInt( $(this).val() ) > max_index ) {
1855                        max_index = parseInt( $(this).val() );
1856                    }
1857                });
1858                var html = $(this).data('row').replace( /%%repeater-row-index%%/g, max_index + 1 );
1859
1860                var html_e = $(html);
1861
1862
1863                $(this).closest('.wc-job-manager-repeater-rows').find('.repeater-fields-rows').append( html_e );
1864
1865                if (isAdvancedUpload) {
1866
1867                    var droppedFiles = false;
1868                    $(this).closest('.wc-job-manager-repeater-rows').find('.label-can-drag', ).each(function(){
1869                        var label_self = $(this);
1870                        label_self.on('drag dragstart dragend dragover dragenter dragleave drop', function(e) {
1871                            e.preventDefault();
1872                            e.stopPropagation();
1873                        }).on('dragover dragenter', function() {
1874                            label_self.addClass('is-dragover');
1875                        }).on('dragleave dragend drop', function() {
1876                            label_self.removeClass('is-dragover');
1877                        }).on('drop', function(e) {
1878                            droppedFiles = e.originalEvent.dataTransfer.files;
1879                            label_self.parent().find('input[type="file"]').prop('files', droppedFiles).trigger('change');
1880                        });
1881                    });
1882                }
1883
1884                $(this).closest('.wc-job-manager-repeater-rows').find('input[type="file"]').on('change', function() {
1885                    var preview = $(this).closest('.field').find('.job-manager-uploaded-files');
1886                    preview.html('<span class="job-manager-uploaded-file-preview"></span>');
1887                    var image_parent = preview.find('.job-manager-uploaded-file-preview');
1888                    self.imagesPreview(this, image_parent);
1889                    image_parent.append('<a class="job-manager-remove-uploaded-file-logo" href="#"><i class="fa fa-close" aria-hidden="true"></i></a>');
1890                    $(preview).css("display","block");
1891                });
1892                
1893                number_increment = number_increment + 1;
1894                return false;
1895            });
1896
1897
1898            $(document).on('click', '.delete-repeat-row', function(e) {
1899                e.preventDefault();
1900                $(this).closest('.repeater-field').remove();
1901            } );
1902
1903
1904            // hours operation
1905            $('.add-new-hour').on('click', function(e){
1906                e.preventDefault();
1907                var parent = $(this).closest('.enter-hours-content');
1908                var length = parent.find('.enter-hours-item-inner').length;
1909                var html = parent.find('.enter-hours-item-inner').eq(0).clone(true);
1910                
1911
1912                parent.find('.enter-hours-wrapper').append(html);
1913            });
1914
1915            $('.remove-hour').on('click', function(e) {
1916                e.preventDefault();
1917                var parent = $(this).closest('.enter-hours-content');
1918                var index = parent.find('.enter-hours-item-inner').last().index();
1919                if ( index > 0 ) {
1920                    parent.find('.enter-hours-item-inner').eq(index).remove();
1921                }
1922            });
1923            
1924
1925            // Regions
1926            $('body').on('change', 'select.select-field-region', function(){
1927                var val = $(this).val();
1928                var next = $(this).data('next');
1929                var main_select = 'select.select-field-region' + next;
1930                if ( $(main_select).length > 0 ) {
1931                    $(main_select).parent().addClass('loading');
1932                    $(main_select).prop('disabled', true);
1933                    $( main_select ).val('');
1934                    $(main_select).trigger('change');
1935
1936                    var parent = $(main_select).parent();
1937                    var name = $(this).attr('name');
1938                    var placeholder = $('.select-field-region'+next).data('placeholder');
1939
1940                    if ( val ) {
1941                        $.ajax({
1942                            url: listdo_listing_opts.ajaxurl,
1943                            type:'POST',
1944                            dataType: 'html',
1945                            data:{
1946                                'action': 'listdo_process_change_region',
1947                                'region_parent': val,
1948                                'next': next,
1949                                'name': name,
1950                                'security': listdo_listing_opts.ajax_nonce,
1951                                'placeholder': placeholder,
1952                            }
1953                        }).done(function(data) {
1954                            $(main_select).parent().removeClass('loading');
1955                            
1956                            parent.html(data);
1957                            if ( $.isFunction( $.fn.select2 ) ) {
1958                                
1959                                var select2_args = job_manager_select2_args;
1960                                select2_args['allowClear']              = true;
1961                                select2_args['minimumResultsForSearch'] = 10;
1962                                $( main_select ).select2(select2_args);
1963                            }
1964                            
1965                        });
1966                    } else {
1967                        var html = '';
1968                        if ( name == '_job_regions[]' || name == 'job_regions[]' ) {
1969                            html += '<label>' + listdo_listing_opts.region_labels[next] +'</label>';
1970                        }
1971                        
1972                        html += '<select class="select-field-region select-field-region'+next+'" data-next="'+ (next + 1)+'" autocomplete="off" name="'+name+'" data-placeholder="'+placeholder+'">';
1973                        html += '<option value="">'+placeholder+'</option>';
1974                        html += '</select>';
1975                        parent.html(html);
1976                        $(main_select).parent().removeClass('loading');
1977                        
1978                        if ( $.isFunction( $.fn.select2 ) ) {
1979                            var select2_args = job_manager_select2_args;
1980                            select2_args['allowClear']              = true;
1981                            select2_args['minimumResultsForSearch'] = 10;
1982                            $( main_select ).select2(select2_args);
1983                        }
1984                    }
1985                }
1986            });
1987
1988            // Category
1989            $('body').on('change', 'select#job_c_category', function(){
1990                if ( $('#job_c_type').length > 0 ) {
1991                    var main_select = $('#job_c_type');
1992                    var val = $(this).val();
1993                    var main_con = main_select.parent();
1994                    $(main_con).addClass('loading');
1995
1996                    var placeholder = '';
1997                    if ( main_select.data('placeholder') !== 'undefined' ) {
1998                        placeholder = main_select.data('placeholder');
1999                    }
2000                    $.ajax({
2001                        url: listdo_listing_opts.ajaxurl,
2002                        type:'POST',
2003                        dataType: 'html',
2004                        data:{
2005                            'action': 'listdo_process_change_category',
2006                            'category_parent': val,
2007                            'security': listdo_listing_opts.ajax_nonce,
2008                            'name': main_select.attr('name'),
2009                            'id': main_select.attr('id'),
2010                            'placeholder': placeholder,
2011                        }
2012                    }).done(function(data) {
2013                        $(main_con).removeClass('loading');
2014                        if ( $.isFunction( $.fn.select2 ) ) {
2015                            main_con.find('#job_c_type').select2("close");
2016                        }
2017                        main_con.html(data);
2018                        if ( $.isFunction( $.fn.select2 ) ) {
2019                            var select2_args = job_manager_select2_args;
2020                            select2_args['allowClear']              = true;
2021                            select2_args['minimumResultsForSearch'] = 10;
2022                            main_con.find('#job_c_type').select2(select2_args);
2023                        }
2024                        
2025                    });
2026                }
2027            });
2028
2029            // Category
2030            $('body').on('change', 'select#job_category', function(){
2031                if ( $('.fieldset-job_amenities').length > 0 ) {
2032                    var val = $(this).val();
2033                    change_category_amenities($(this), val);
2034                }
2035            });
2036            $('body').on('change', '.job-manager-term-checklist-job_category input[name^=job_category]', function(){
2037                if ( $('.fieldset-job_amenities').length > 0 ) {
2038                    var val = [];
2039                    $.each($(".job-manager-term-checklist-job_category input[name^=job_category]:checked"), function(){            
2040                        val.push($(this).val());
2041                    });
2042                    change_category_amenities($(this), val);
2043                }
2044            });
2045            var change_category_amenities = function($this, val) {
2046                var main_select = $('.fieldset-job_amenities');
2047                var job_id = $this.closest('form').find('input[name=job_id]').val();
2048                $(main_select).addClass('loading');
2049
2050                $.ajax({
2051                    url: listdo_listing_opts.ajaxurl,
2052                    type:'POST',
2053                    dataType: 'html',
2054                    data:{
2055                        'action': 'listdo_process_change_category_amenity',
2056                        'category_parent': val,
2057                        'job_id': job_id,
2058                        'security': listdo_listing_opts.ajax_nonce,
2059                    }
2060                }).done(function(data) {
2061                    $(main_select).removeClass('loading');
2062                    
2063                    if ( $.isFunction( $.fn.select2 ) ) {
2064                        main_select.find('select').select2("close");
2065                    }
2066
2067                    main_select.find('div.field').replaceWith(data);
2068                    
2069                    if ( $.isFunction( $.fn.select2 ) ) {
2070                        var select2_args = job_manager_select2_args;
2071                        select2_args['allowClear']              = true;
2072                        select2_args['minimumResultsForSearch'] = 10;
2073                        main_select.find('select').select2(select2_args);
2074                    }
2075
2076                });
2077            }
2078
2079            var isAdvancedUpload = function() {
2080                var div = document.createElement('div');
2081                return (('draggable' in div) || ('ondragstart' in div && 'ondrop' in div)) && 'FormData' in window && 'FileReader' in window;
2082            }();
2083
2084            if (isAdvancedUpload) {
2085
2086                var droppedFiles = false;
2087                $('.label-can-drag').each(function(){
2088                    var label_self = $(this);
2089                    label_self.on('drag dragstart dragend dragover dragenter dragleave drop', function(e) {
2090                        e.preventDefault();
2091                        e.stopPropagation();
2092                    }).on('dragover dragenter', function() {
2093                        label_self.addClass('is-dragover');
2094                    }).on('dragleave dragend drop', function() {
2095                        label_self.removeClass('is-dragover');
2096                    }).on('drop', function(e) {
2097                        droppedFiles = e.originalEvent.dataTransfer.files;
2098                        label_self.parent().find('input[type="file"]').prop('files', droppedFiles).trigger('change');
2099                    });
2100                });
2101            }
2102
2103
2104            // file attachments
2105            $('label.file-logo').on('click', function(){
2106                $(this).closest('.upload-logo').find('input[type="file"]').trigger('click');
2107            });
2108            $('.upload-logo input[type="file"]').on('change', function() {
2109                var preview = $(this).parent().parent().find('.job-manager-uploaded-files');
2110                preview.html('');
2111                self.imagesPreview(this, preview);
2112                preview.append('<a class="job-manager-remove-uploaded-file-logo" href="#"><i class="fa fa-close" aria-hidden="true"></i></a>');
2113                $(preview).css("display","block");
2114            });
2115            $(document).on('click', '.job-manager-remove-uploaded-file-logo', function(e) {
2116                e.preventDefault();
2117                $(this).closest('.job-manager-uploaded-files').html('');
2118                $(this).closest('.job-manager-uploaded-files').parent().find('.upload-logo input[type="file"]').val(null);
2119            });
2120
2121            if (isAdvancedUpload) {
2122
2123                var droppedFiles = false;
2124                $('.upload-logo').each(function(){
2125                    var label_self = $(this);
2126                    label_self.on('drag dragstart dragend dragover dragenter dragleave drop', function(e) {
2127                        e.preventDefault();
2128                        e.stopPropagation();
2129                    }).on('dragover dragenter', function() {
2130                        label_self.addClass('is-dragover');
2131                    }).on('dragleave dragend drop', function() {
2132                        label_self.removeClass('is-dragover');
2133                    }).on('drop', function(e) {
2134                        droppedFiles = e.originalEvent.dataTransfer.files;
2135                        label_self.find('input[type="file"]').prop('files', droppedFiles).trigger('change');
2136                    });
2137                });
2138            }
2139        },
2140        editProfile: function() {
2141            var self = this;
2142            // user profile edit
2143            if ( $('#change-profile-form-birthday').length > 0 && $.isFunction( $.fn.datetimepicker )) {
2144                $('#change-profile-form-birthday').datetimepicker({
2145                    timepicker: false,
2146                    format: listdo_listing_opts.date_format,
2147                    'scrollInput': false
2148                });
2149            }
2150            $('form.change-profile-form').on('submit', function(e){
2151                e.preventDefault();
2152                var self_form = $(this);
2153                self_form.addClass('loading');
2154                $.ajax({
2155                    url: listdo_listing_opts.ajaxurl,
2156                    type:'POST',
2157                    dataType: 'json',
2158                    data:  self_form.serialize() + "&action=listdo_process_change_profile_form"
2159                }).done(function(data) {
2160                    self_form.removeClass('loading');
2161                    self_form.find('.msg').html(data.msg);
2162                });
2163            });
2164            // user change pass
2165            $('form.change-password-form').on('submit', function(e){
2166                e.preventDefault();
2167                var self_form = $(this);
2168                self_form.addClass('loading');
2169                $.ajax({
2170                    url: listdo_listing_opts.ajaxurl,
2171                    type:'POST',
2172                    dataType: 'json',
2173                    data:  self_form.serialize() + "&action=listdo_process_change_password"
2174                }).done(function(data) {
2175                    self_form.removeClass('loading');
2176                    self_form.find('.msg').html(data.msg);
2177                });
2178            });
2179
2180            
2181            $( document.body ).on( 'click', '.job-manager-remove-uploaded-file', function() {
2182                $(this).closest( '.job-manager-uploaded-file' ).remove();
2183                return false;
2184            });
2185        }
2186    });
2187
2188    $.apusThemeExtensions.listing = $.apusThemeCore.listing_init;
2189
2190    jQuery(document).ready(function($){
2191        if ( $( 'div.job_listings' ).length > 0 ) {
2192            $( 'div.job_listings' ).triggerHandler( 'update_results', [ 1, false ] );
2193        }
2194    });
2195    
2196})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.