PageSourceSearch

https://demo.restropress.com/pizza-shop/wp-content/plugins/restrop…/js/user-dashboard.js?ver=3.4.6.1789221024

js restropress.com collected 2026-09-25 08:59:42 UTC 13,786 bytes, 331 lines download raw bytes

1jQuery('document').ready(function($) {
2    function parseAddressAjaxResponse(response) {
3        if (typeof response === 'string') {
4            try {
5                return JSON.parse(response);
6            } catch (error) {
7                return {};
8            }
9        }
10
11        return response || {};
12    }
13
14    function getUserDashboardMessage(key, fallback) {
15        if (typeof users !== 'undefined' && users[key]) {
16            return users[key];
17        }
18
19        return fallback;
20    }
21
22    if (typeof DataTable !== 'undefined') {
23    new DataTable('#user-orders', {
24        responsive: true,
25        dom: 'frtip',
26        order: [[ 0, 'desc' ]],
27        initComplete: function () {
28            $('#user-orders_filter input').attr('placeholder','Search orders');
29        }
30    });
31}
32    $('body .user-dashboard-wrapper.user-profile ul li').click(function(){
33        $('body .user-dashboard-wrapper.user-profile ul li').removeClass('active');
34        $(this).addClass('active');
35    });
36    $('body .user-dashboard-wrapper.user-profile ul li.user-profile').click(function(){
37        $('body .user-dashboard-wrapper.user-profile #user-profile').show();
38        $('body .user-dashboard-wrapper.user-profile #user-my-address').hide();
39        $('body .user-dashboard-wrapper.user-profile #user-my-orders').hide();
40    });
41    $('body .user-dashboard-wrapper.user-profile ul li.user-my-address').click(function(){
42        $('body .user-dashboard-wrapper.user-profile #user-profile').hide();
43        $('body .user-dashboard-wrapper.user-profile #user-my-address').show();
44        $('body .user-dashboard-wrapper.user-profile #user-my-orders').hide();
45    });
46    $('body .user-dashboard-wrapper.user-profile ul li.user-my-orders').click(function(){
47        $('body .user-dashboard-wrapper.user-profile #user-profile').hide();
48        $('body .user-dashboard-wrapper.user-profile #user-my-address').hide();
49        $('body .user-dashboard-wrapper.user-profile #user-my-orders').show();
50    });
51    $('body .user-profile .delete-address').click(function(e){
52        e.preventDefault();
53
54        if (!window.confirm(getUserDashboardMessage('delete_confirm_text', 'Are you sure you want to delete this address?'))) {
55            return;
56        }
57
58        var index = $(this).data('index');
59        
60        $.ajax({
61            url: users.ajaxurl,
62            type: 'POST',
63            data: {
64                index: index,
65                security: users.address_nonce,
66                action: 'rpress_delete_user_address'
67            },
68            success: function(response){
69                var parsedResponse = parseAddressAjaxResponse(response);
70
71                if (parsedResponse.success) {
72                    alert(getUserDashboardMessage('delete_success_text', 'Address Deleted'));
73                    location.reload();
74                    return;
75                }
76
77                alert(getUserDashboardMessage('delete_failed_text', 'Unable to delete the address. Please try again.'));
78            },
79            error: function(){
80                alert(getUserDashboardMessage('delete_error_text', 'Something went wrong while deleting the address. Please try again.'));
81            }
82        });
83    });
84    $('body .user-profile .default-address').click(function(e) {
85        e.preventDefault();
86        var index = $(this).data('index');
87        
88        $.ajax({
89            url: users.ajaxurl,
90            type: 'POST',
91            data: {
92                index: index,
93                security: users.address_nonce,
94                action: 'rpress_default_user_address'
95            },
96            success: function(response){
97                location.reload();
98            },
99    
100        });
101    });
102    var hasCookiesApi = (typeof Cookies !== 'undefined' && Cookies && typeof Cookies.get === 'function' && typeof Cookies.set === 'function');
103    if (hasCookiesApi) {
104        $('.sidebar-menu li').click(function(){
105            var clickedClass = $(this).attr('class');
106            clickedClass = clickedClass.replace(/\bactive\b/, '').trim();
107            var expirationDate = new Date();
108            expirationDate.setTime(expirationDate.getTime() + (5 * 60 * 1000));
109            Cookies.set('nav_location', clickedClass,{ expires: expirationDate });
110        });
111    }
112    var navLocation = hasCookiesApi ? Cookies.get('nav_location') : '';
113    if (navLocation) {
114        $('body .user-dashboard-wrapper.user-profile ul li').removeClass('active');
115        $('body .user-dashboard-wrapper.user-profile ul li.'+navLocation).addClass('active');
116        if(navLocation == 'user-profile'){
117            $('body .user-dashboard-wrapper.user-profile #user-profile').show();
118            $('body .user-dashboard-wrapper.user-profile #user-my-address').hide();
119            $('body .user-dashboard-wrapper.user-profile #user-my-orders').hide();
120        }
121        else if(navLocation == 'user-my-orders'){
122            $('body .user-dashboard-wrapper.user-profile #user-profile').hide();
123            $('body .user-dashboard-wrapper.user-profile #user-my-address').hide();
124            $('body .user-dashboard-wrapper.user-profile #user-my-orders').show();
125        }             
126        else if(navLocation == 'user-my-address'){
127            $('body .user-dashboard-wrapper.user-profile #user-profile').hide();
128            $('body .user-dashboard-wrapper.user-profile #user-my-address').show();
129            $('body .user-dashboard-wrapper.user-profile #user-my-orders').hide();
130        }
131    }
132
133    function ensureOrderDetailsModal() {
134        var $modal = jQuery('#rpressModal').first();
135
136        if ($modal.length) {
137            return $modal;
138        }
139
140        var modalHtml = [
141            '<div class="modal micromodal-slide" id="rpressModal" aria-hidden="true">',
142            '  <div class="modal__overlay" tabindex="-1" data-micromodal-close>',
143            '    <div class="modal__container modal-content" role="dialog" aria-modal="true">',
144            '      <header class="modal__header modal-header">',
145            '        <h2 class="modal__title modal-title"></h2>',
146            '        <button class="modal__close" aria-label="Close modal" data-micromodal-close></button>',
147            '      </header>',
148            '      <main class="modal__content modal-body"></main>',
149            '    </div>',
150            '  </div>',
151            '</div>'
152        ].join('');
153
154        jQuery('body').append(modalHtml);
155        return jQuery('#rpressModal').first();
156    }
157
158    function openDashboardOrderModal($trigger) {
159        var $modal = ensureOrderDetailsModal();
160        var orderId = $trigger.attr('data-order-id');
161        var ajaxUrl = (typeof rp_scripts !== 'undefined' && rp_scripts.ajaxurl) ? rp_scripts.ajaxurl : users.ajaxurl;
162        var nonce = (typeof rp_scripts !== 'undefined' && rp_scripts.order_details_nonce) ? rp_scripts.order_details_nonce : ((typeof users !== 'undefined' && users.order_details_nonce) ? users.order_details_nonce : '');
163
164        if (!orderId || !ajaxUrl || !nonce) {
165            return;
166        }
167
168        $modal.addClass('show-order-details rpress-order-details-context');
169
170        jQuery.ajax({
171            type: 'POST',
172            url: ajaxUrl,
173            dataType: 'json',
174            data: {
175                action: 'rpress_show_order_details',
176                order_id: orderId,
177                security: nonce
178            },
179            beforeSend: function () {
180                $trigger.addClass('rp-loading');
181                $trigger.find('.rp-ajax-toggle-text').addClass('rp-text-visibility');
182            },
183            complete: function () {
184                $trigger.removeClass('rp-loading');
185                $trigger.find('.rp-ajax-toggle-text').removeClass('rp-text-visibility');
186            },
187            success: function (response) {
188                if (!response || response.success !== true || !response.data || typeof response.data.html !== 'string') {
189                    return;
190                }
191
192                $modal.find('.modal__container').html(response.data.html);
193
194                if (typeof MicroModal !== 'undefined' && typeof MicroModal.show === 'function') {
195                    MicroModal.show('rpressModal', { disableScroll: true });
196                } else {
197                    $modal.addClass('is-open').attr('aria-hidden', 'false');
198                    jQuery('html, body').addClass('modal-open').css('overflow', 'hidden');
199                }
200            },
201            error: function () {
202                $modal.removeClass('show-order-details rpress-order-details-context');
203            }
204        });
205    }
206
207    if (jQuery('.user-dashboard-wrapper, #rpress_user_history').length) {
208        jQuery(document).off('click', '.rpress-view-order-btn');
209        jQuery(document).on('click.rpressDashboardOrderModal', '.user-dashboard-wrapper .rpress-view-order-btn, #rpress_user_history .rpress-view-order-btn', function (e) {
210            e.preventDefault();
211            e.stopImmediatePropagation();
212            openDashboardOrderModal(jQuery(this));
213        });
214
215        jQuery(document).on('click.rpressDashboardOrderModalClose', '#rpressModal.show-order-details [data-micromodal-close], #rpressModal.show-order-details .modal__close', function (e) {
216            e.preventDefault();
217            e.stopImmediatePropagation();
218
219            if (typeof MicroModal !== 'undefined' && typeof MicroModal.close === 'function') {
220                MicroModal.close('rpressModal');
221            } else {
222                jQuery('#rpressModal').removeClass('is-open show-order-details rpress-order-details-context').attr('aria-hidden', 'true');
223                jQuery('html, body').removeClass('modal-open').css('overflow', '');
224            }
225        });
226    }
227});
228function addaddress() {
229    var div = document.getElementById("add-address-bg");
230
231    if (!div) {
232        return;
233    }
234
235    if (div.className === "") {
236        div.className = "active";
237    } else {
238        div.className = "";
239        return;
240    }
241
242    var $form = jQuery('#add-address-bg .profile-form-wrap');
243
244    if ($form.length) {
245        $form[0].reset();
246    }
247
248    jQuery('#add-address-bg .box-header .box-title').text(
249        (typeof users !== 'undefined' && users.add_address_title_text) ? users.add_address_title_text : 'Add Delivery Address'
250    );
251    jQuery('#form_submit_button').val(
252        (typeof users !== 'undefined' && users.save_address_text) ? users.save_address_text : 'Save Address'
253    );
254    jQuery('#edit_user_address_index').val('');
255    jQuery('#default-address-checkboxInput6').prop('checked', false);
256    jQuery('input[name="address_type"]').prop('checked', false);
257    jQuery('input[name="address_type"][value="Home"]').prop('checked', true);
258}
259function editaddress(context) {
260    var $context = jQuery();
261
262    if (context && context.currentTarget) {
263        $context = jQuery(context.currentTarget);
264    } else if (context && context.target) {
265        $context = jQuery(context.target);
266    } else if (context) {
267        $context = jQuery(context);
268    }
269
270    var addressWrap = $context.closest('.address-wrap');
271
272    if (!addressWrap.length) {
273        return;
274    }
275
276    var div = document.getElementById("add-address-bg");
277
278    if (!div) {
279        return;
280    }
281
282    if (div.className === "") {
283        div.className = "active";
284    }
285    
286    // Get the values within the nearest 'address-wrap' element
287    var addressType     = addressWrap.find('.type-of-address').text().trim();
288    var firstname       = addressWrap.find('.user-firstname').text().trim();
289    var lastname        = addressWrap.find('.user-lastname').text().trim();
290    var phone           = addressWrap.find('.user-contact').text().trim();
291    var pincode         = addressWrap.find('.user-pin').text().trim();
292    var city            = addressWrap.find('.user-city').text().trim();
293    var address         = addressWrap.find('.user-street-address').text().trim();
294    var apartment       = addressWrap.find('.user-apt-suite').text().trim();
295    var addressIndex    = addressWrap.find('.user-address-index').text().trim();
296    var defaultIndex    = addressWrap.find('.user-default-address').text().trim();
297    
298    // Example: Update a form with the retrieved values
299    jQuery('#add-address-bg .box-header .box-title').text(
300        (typeof users !== 'undefined' && users.edit_address_title_text) ? users.edit_address_title_text : 'Edit Delivery Address'
301    );
302    jQuery('#form_submit_button').val(
303        (typeof users !== 'undefined' && users.save_changes_text) ? users.save_changes_text : 'Save Changes'
304    );
305    jQuery('#fastNameInput').val(firstname);
306    jQuery('#lastNameInput').val(lastname);
307    jQuery('#phoneInput').val(phone);
308    jQuery('#pincodeInput').val(pincode);
309    jQuery('#cityAddress').val(city);
310    jQuery('#streetaddress').val(address);
311    jQuery('#aptsuite').val(apartment);
312    jQuery('#edit_user_address_index').val(addressIndex);
313    jQuery('#default-address-checkboxInput6').prop('checked', defaultIndex === '1');
314
315    jQuery('input[name="address_type"]').prop('checked', false);
316
317    if (addressType) {
318        jQuery('input[name="address_type"]').filter(function () {
319            return jQuery(this).val().toLowerCase() === addressType.toLowerCase();
320        }).prop('checked', true);
321    }
322
323    if (!jQuery('input[name="address_type"]:checked').length) {
324        jQuery('input[name="address_type"][value="Home"]').prop('checked', true);
325    }
326}
327jQuery(function($) {
328    if (window.location.pathname === '/order-online/') {
329        $('body').addClass('order-online');
330    }
331});

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.