PageSourceSearch

https://thompsonpowersystems.com/wp-content/mu-plugins/webpagefx-p…/assets/js/search.js?ver=1702991607

js thompsonpowersystems.com collected 2026-10-07 18:52:33 UTC 4,168 bytes, 157 lines download raw bytes

1var CSE = (function(CSE, $) {
2
3    CSE.form     = '';
4    CSE.loaded   = false;
5    CSE.jqXHR    = false;
6    CSE.current  = [];
7    CSE.previous = [];
8
9    CSE.fetch = function() {
10
11        $('html').addClass('loading');
12        CSE.target.append('<div class="loading-icon">Searching...</div>');
13
14        if (CSE.jqXHR && CSE.jqXHR.readyState !== 4) {
15            CSE.jqXHR.abort();
16        }
17
18        CSE.previous = CSE.current;
19        CSE.current  = CSE.form.serializeArray();
20
21        var postData = {
22            'action': 'equipment_search_refresh',
23            'data': {
24                'current': JSON.stringify(CSE.current),
25                'previous': JSON.stringify(CSE.previous),
26            }
27        };
28
29        CSE.jqXHR = $.post(CSE.ajaxurl, postData, function(response) {
30            var json = $.parseJSON(response);
31            CSE.update_field_options(json);
32            CSE.render(json);
33        });
34    }
35
36
37    CSE.parse_fields = function(json) {
38
39        if (CSE.jqXHR && CSE.jqXHR.readyState !== 4) {
40            CSE.jqXHR.abort();
41        }
42
43        CSE.previous = CSE.current;
44        CSE.current  = CSE.form.serializeArray();
45
46        CSE.jqXHR   = $.post(CSE.ajaxurl, {
47            'action': 'equipment_search_fields',
48            'changed': CSE.changed,
49            'data': {
50                'current': JSON.stringify(CSE.current),
51                'previous': JSON.stringify(CSE.previous),
52            }
53        }, function(response) {
54            var json = $.parseJSON(response);
55
56            CSE.update_field_options(json);
57        });
58    }
59
60
61    CSE.update_field_options = function(json) {
62
63        $.each(json.values, function(name, values) {
64            var $input = CSE.form.find('[name="'+name+'"]');
65            $input.html(values).trigger('update.fs');
66            if ($input.hasClass('selectric-input') && typeof($input.selectric) == 'function') {
67                $input.selectric('refresh');
68            }
69        });
70    }
71
72    CSE.inject = function() {
73
74        $inject = $('#js-equipment-search-inject');
75        if( ! $inject.length )
76            return;
77
78        CSE.form = $inject;
79        var target = CSE.form.find('#target').val();
80        CSE.target = $(target);
81        CSE.changed = $(this).attr('name');
82
83        CSE.fieldStates();
84        CSE.parse_fields();
85        //CSE.fetch();
86    }
87
88
89    CSE.render = function(json) {
90        $(window).trigger('CSE::beforeRender');
91        CSE.target.html(json.template);
92        $(window).trigger('CSE::afterRender');
93
94        $('html').removeClass('loading');
95    }
96
97
98    CSE.fieldStates = function() {
99
100        var fields = CSE.form.find('[data-enabled-field]');
101
102        fields.each(function(){
103            var f = $(this),
104                src = CSE.form.find('[name="'+f.data('enabled-field')+'"]').val(),
105                val = f.data('enabled-value');
106
107            if( src == val ) {
108                f.removeAttr('disabled');
109                f.trigger('enable'); // fancy select
110            } else {
111                f.attr('disabled', 'disabled')
112                f.trigger('disable'); // fancy select
113            }
114        });
115    }
116
117
118
119    // events
120    $(function(){
121
122        // sets the search to the correct form
123        $('.js-equipment-search-form').on('change', 'select, input', function(event) {
124            CSE.form = $(this).closest('.js-equipment-search-form');
125            CSE.changed = $(this).attr('name');
126
127            CSE.fieldStates();
128            CSE.parse_fields();
129        });
130
131
132        $('.js-equipment-search-form').on('submit', function(event) {
133            var $this = $(this),
134                $action = $this.find('#action'),
135                action = $action.length ? $action.val() : '';
136
137            if(action == 'equipment_search_refresh'){
138                event.preventDefault();
139                CSE.fetch();
140            }
141
142        });
143
144        // $('.js-search-equipment__reset').on('click', function(event) {
145        //     event.preventDefault();
146
147        //     CSE.form.find('[name="source"]').val('');
148        //     CSE.update_field_options();
149        // });
150
151        CSE.inject();
152
153    });
154
155    return CSE;
156
157})(CSE || {}, 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.