PageSourceSearch

https://bmwra.org/wp-content/plugins/business-directory-regions/resources/js/frontend.js?ver=5.4.4

js bmwra.org collected 2026-09-26 02:18:29 UTC 9,975 bytes, 259 lines download raw bytes

1/*global ajaxurl:true */
2if (jQuery !== undefined) {
3
4var WPBDP = jQuery.WPBDP = jQuery.extend({}, jQuery.WPBDP, WPBDP);
5
6(function($, undefined) {
7
8    $.WPBDP.Collapsible = function(element) {
9        this.element = $(element);
10        this.handler = this.element.find('.js-handler').eq(0);
11        this.subject = this.element.find('[data-collapsible]').eq(0);
12        this.setup();
13    };
14
15    $.extend($.WPBDP.Collapsible.prototype, {
16        setup: function() {
17            var self = this;
18
19            self.subject.hide();
20            self.toggleClass();
21
22            self.handler.click(function(event) {
23                self.toggle.apply(self, [event, this]);
24            });
25
26            if ( self.subject.attr('data-collapsible-default-mode') == 'open' ) {
27                self.handler.click();
28            }            
29        },
30
31        toggleClass: function() {
32            if (this.subject.is(':visible')) {
33				this.handler.removeClass('bdopen').addClass('bdclose');
34                this.handler.find('span').removeClass('open').addClass('close');
35            } else {
36				this.handler.removeClass('bdclose').addClass('bdopen');
37                this.handler.find('span').removeClass('close').addClass('open');
38            }
39        },
40
41        toggle: function(event) {
42            event.preventDefault();
43            var self = this;
44            self.subject.slideToggle(function() { self.toggleClass(); });
45        }
46    });
47
48    $.fn.collapsible = function() {
49        return this.each(function() {
50            var obj = new $.WPBDP.Collapsible(this); $.noop(obj);
51        });
52    };
53
54}(jQuery));
55
56(function($, undefined) {
57
58    $.RegionField = function(container) {
59        this.container = container = $(container);
60        this.select = container.find('select');
61        this.form = container.closest('form');
62
63        this.field = parseInt(this.select.attr('id').replace('wpbdp-field-', ''), 10);
64        this.level = parseInt(container.attr('data-region-level'), 10);
65        this.display_context = this.container.attr( 'data-display-context' );
66
67        this.select.change($.proxy(this, 'change'));
68        this.form.bind('wpbdp-region-selected', $.proxy(this, 'update'));
69
70        var loading = '...';
71        if ( ( 'undefined' !== typeof $.RegionsFrontend ) && ( 'undefined' !== typeof $.RegionsFrontend.UILoadingText ) )
72            loading = $.RegionsFrontend.UILoadingText;
73
74        this.select.after($('<span>').addClass('spinner-text').css('display', 'none').text(loading));
75    };
76
77    $.extend($.RegionField.prototype, {
78        change: function() {
79            var self = this, region = self.select.val();
80            self.form.trigger('wpbdp-region-selected', [self.field, self.level, region]);
81        },
82
83        update: function(event, field, level, region) {
84            var self = this, a, b, hidden = self.container.is(':hidden');
85
86            if (region === 0 || self.field === field || self.level < level) {
87                return;
88            }
89
90            // the visible hierarchy is an ascending ordered list of the
91            // levels of the fields that are available in the current view
92            levels = self.form.find('.wpbdp-region-field').map(function() {
93                return parseInt($(this).attr('data-region-level'), 10);
94            }).get().sort();
95
96            updated_field_position = levels.indexOf(level);
97            current_field_position = levels.indexOf(self.level);
98
99            // this should never ever happen!... but we all know it will happen
100            // just to give somebody a reason to laugh at me. If it happens,
101            // I would like to think we have bigger problems than updating this
102            // field's options so I'm just gonna return.
103            if (updated_field_position === -1 || current_field_position === -1) {
104                return;
105            }
106
107            // do not update this field if is hidden and is not the
108            // next field in the visible hierarchy
109            if (updated_field_position + 1 < current_field_position && hidden) {
110                return;
111            }
112            // Get list of Regions and create a dropdown. If no regions
113            // are returned replace the select dropdown with the textfield
114            //this.spinner.show();
115            var $spinner = self.form.find('#wpbdp-field-' + field).siblings('.spinner-text');
116            $spinner.fadeIn('fast');
117
118            $.getJSON(typeof ajaxurl === 'undefined' ? $.RegionsFrontend.ajaxurl : ajaxurl, {
119                action: 'wpbdp-regions-get-regions',
120                field: self.field,
121                parent: region,
122                level: self.level,
123                display_context: self.display_context,
124                category_id: self.form.find( 'input[name="category_id"]' ).val()
125            }, function(response) {
126                if (response.status === 'ok') {
127                    $spinner.fadeOut('fast');
128
129                    var options = $(response.html).find('option');
130                    self.select.find('option').remove();
131                    self.select.append( options ).val( '' );
132
133                    // Fix for #1592
134                    if ( 'undefined' !== typeof( self.select.data( 'selectpicker' ) ) ) {
135                        self.select.selectpicker( 'refresh' );
136                    }
137
138                    if (options.length === 0 || (options.length === 1 && a + 1 < b)) {
139                        self.container.slideUp(function() {
140                            self.container.addClass('wpbdp-regions-hidden');
141                        });
142                    } else if (hidden) {
143                        self.container.slideDown(function() {
144                            self.container.removeClass('wpbdp-regions-hidden');
145                        });
146                    }
147                } else {
148                    // TODO: tell the user an error ocurred
149                }
150
151                self.form.trigger( 'wpbdp-region-selected-after' );
152            });
153        }
154    });
155
156}(jQuery));
157
158(function($, undefined) {
159
160    var regions_init = function() {
161        $('.wpbdp-region-field').each(function() {
162            var field = new $.RegionField(this); $.noop(field);
163        });
164
165        $('.wpbdp-region-selector').collapsible();
166
167        var sidelist = $('.wpbdp-region-sidelist');
168        sidelist.find('.js-handler').closest('li').collapsible();
169        sidelist.find('a[data-url]').each(function() {
170            var element = $(this);
171            element.attr('href', element.attr('data-url'));
172        });
173    };
174
175    $(function() {
176        regions_init();
177    });
178    $(window).on( 'wpbdp_submit_refresh', function( event, submit, section_id ) {
179        if ( 'listing_fields' == section_id ) {
180            regions_init();
181        }
182    } );
183
184}(jQuery));
185
186(function($, undefined) {
187    $(document).ready(function() {
188        $( '.wpbdp-region-sidelist-wrapper .sidelist-menu-toggle' ).click(function() {
189            $('.wpbdp-region-sidelist-wrapper').toggleClass('open');
190        });
191
192        // XXX: hack our way through Regions fields for widgets.
193        $( '.wpbdp-regions-search-widget' ).each(function( i, v ) {
194            var $widget = $(v);
195            var all_fields = $widget.find( '.wpbdp-region-field' );
196            var hidden_fields = all_fields.not( '.wpbdp-regions-hidden' ).toArray();
197
198            hidden_fields.sort(function( a, b ) {
199                return parseInt( $(a).attr( 'data-region-level' ) ) - parseInt( $(b).attr( 'data-region-level' ) );
200            });
201
202            if ( all_fields.length == 0 ) {
203                return;
204            }
205
206            var first_field = all_fields.get(0);
207
208            $( first_field ).removeClass( 'wpbdp-regions-hidden' );
209            $widget.find( '.wpbdp-region-field' ).not( first_field ).addClass( 'wpbdp-regions-hidden' );
210        });
211
212        // FIXME: Yet another hack. See https://github.com/drodenbaugh/BusinessDirectoryPlugin/issues/2773.
213        if ( $( '.wpbdp-region-field.wpbdp-search-filter' ).length > 0 ) {
214            var search_containers = $( '.wpbdp-region-field.wpbdp-search-filter' ).parent();
215            search_containers.each(function() {
216                $( this ).find( '.wpbdp-region-field.wpbdp-search-filter:first' ).removeClass( 'wpbdp-regions-hidden' );
217                $( this ).find( '.wpbdp-region-field.wpbdp-search-filter' ).not( ':first' ).addClass( 'wpbdp-regions-hidden' );
218            });
219
220            $( '.wpbdp-region-field.wpbdp-search-filter' ).closest( 'form' ).bind( 'wpbdp-region-selected-after', function() {
221
222                var all_fields = $(this).find( '.wpbdp-region-field.wpbdp-search-filter' );
223                var level_with_region = 0;
224
225                all_fields.sort(function( a, b ) {
226                    return parseInt( $(a).attr( 'data-region-level' ) ) - parseInt( $(b).attr( 'data-region-level' ) );
227                });
228                all_fields.each(function() {
229                    if ( ! level_with_region && $( this ).find( 'select' ).val() ) {
230                        level_with_region = parseInt( $( this ).attr( 'data-region-level' ) );
231                    }
232                });
233
234                if ( ! level_with_region ) {
235                    all_fields.not( ':first' ).addClass( 'wpbdp-regions-hidden' ).hide();
236                }
237
238            } );
239
240        }
241
242        $( '.wpbdp-region-selector').on( 'wpbdp-region-selected', function ( event, field, level, region ) {
243            var region_vals = [];
244            $( this ).find( '.wpbdp-region-field select' ).each( function () {
245                region_vals.push( $( this ).val() );
246            } );
247
248            if ( ! region_vals[0] ) {
249                $( this ).find( 'input[name="set-location"]' ).prop( 'disabled', 'disabled' ).fadeOut( 'fast' );
250                return;
251            }
252
253            $( this ).find( 'input[name="set-location"]' ).prop( 'disabled', false ).fadeIn( 'slow' );
254
255        } );
256    });
257}(jQuery));
258
259}

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.