# routeapp/2.4.13/admin/js/routeapp-admin.js

Route ‑ Shipping Protection, version 2.4.13. 220 lines.

- Page: https://pluginprobe.com/plugins/routeapp/2.4.13/code/admin/js/routeapp-admin.js
- Raw: https://pluginprobe.com/plugins/routeapp/2.4.13/raw/admin/js/routeapp-admin.js
- Modified: 2026-07-02T17:11:44+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/routeapp/2.4.13/code/admin/js/routeapp-admin.js#L10-L20`.

```javascript
(function( $ ) {
	'use strict';

	/**
	 * All of the code for your admin-facing JavaScript source
	 * should reside in this file.
	 *
	 * Note: It has been assumed you will write jQuery code here, so the
	 * $ function reference has been prepared for usage within the scope
	 * of this function.
	 *
	 * This enables you to define handlers, for when the DOM is ready:
	 *
	 * $(function() {
	 *
	 * });
	 *
	 * When the window is loaded:
	 *
	 * $( window ).load(function() {
	 *
	 * });
	 *
	 * ...and/or other possibilities.
	 *
	 * Ideally, it is not considered best practise to attach more than a
	 * single DOM-ready or window-load handler for a particular page.
	 * Although scripts in the WordPress core, Plugins and Themes may be
	 * practising this, we should strive to set a better example in our own work.
	 */

	function setRouteCookie(name, value, expire)
	{
		let date = new Date();
		date.setTime(date.getTime() + (expire * 24 * 360000));
		document.cookie = name + "=" + value + "; expires=" + date.toGMTString()+"; path=/";
	}

	function getRouteCookie(cname)
	{
		let name = cname + "=";
		let allCookieArray = document.cookie.split(';');
		for(let i=0; i<allCookieArray.length; i++)
		{
			let temp = allCookieArray[i].trim();
			if (temp.indexOf(name)==0)
				return temp.substring(name.length,temp.length);
		}
		return "";
	}

	function isSaveOrderItemsRequest(settings) {
		if (!settings || !settings.data) {
			return false;
		}

		if (typeof settings.data === 'string') {
			try {
				return new URLSearchParams(settings.data).get('action') === 'woocommerce_save_order_items';
			} catch (e) {
				return settings.data.indexOf('action=woocommerce_save_order_items') !== -1;
			}
		}

		if (typeof settings.data === 'object') {
			return settings.data.action === 'woocommerce_save_order_items';
		}

		return false;
	}

	function refreshRouteFeeButton() {
		if (typeof woocommerce_admin_meta_boxes === 'undefined') {
			return;
		}

		var data = {
			action: 'routeapp_refresh_admin_fee_button',
			security: woocommerce_admin_meta_boxes.order_item_nonce,
			order_id: woocommerce_admin_meta_boxes.post_id
		};

		$.post(
			woocommerce_admin_meta_boxes.ajax_url,
			data,
			function( response ) {
				if (!response.success) {
					return;
				}

				$('#add-route-fee, #remove-route-fee').remove();

				if (response.data && response.data.html) {
					$('.wc-order-bulk-actions .add-items .calculate-action').first().before(response.data.html);
				}
			}
		).fail(function(xhr) {
			console.error('Failed to refresh Route fee button.', xhr);
		});
	}

	$(document).ready(function () {
		$('.routeapp-redirect-countdown').each(function () {
			var $wrap = $(this);
			var mode = $wrap.data('countdown-mode') || 'once';
			var alwaysRun = mode === 'always';

			if (!alwaysRun && getRouteCookie('route_installed')) {
				$wrap.closest('.notice-success').hide();
				return;
			}

			if (!alwaysRun) {
				setRouteCookie('route_installed', 1, 360);
			}

			var $num = $wrap.find('.routeapp-redirect-countdown__num');
			var seconds = parseInt($wrap.data('seconds'), 10);
			if (isNaN(seconds) || seconds < 1) {
				seconds = 5;
			}
			$num.text(seconds);

			var intervalId = setInterval(function () {
				seconds--;
				if (seconds > 0) {
					$num.text(seconds);
				} else {
					clearInterval(intervalId);
					$num.text(0);
					var dest = $wrap.attr('data-redirect-src');
					if (dest) {
						window.location.href = dest;
					}
				}
			}, 1000);
		});

		$(document).on('click', '#add-route-fee', function (e) {
			e.preventDefault();

			var data = {
				action: 'routeapp_add_admin_fee',
				security: woocommerce_admin_meta_boxes.order_item_nonce,
				order_id: woocommerce_admin_meta_boxes.post_id
			};

			$.post(
				woocommerce_admin_meta_boxes.ajax_url,
				data,
				function( response )
				{
					console.log(response);
					// Errors
					if( !response.success )
					{
						// No data came back, maybe a security error
						if( !response.data )
							console.log( 'AJAX ERROR: no response' );
						// Error from PHP
						else
							console.log( 'Response Error: ' + response.data.error );
					}
					// Success
					else {
            $('.calculate-action').click();
            console.log( 'Response Success: ' + response.data );
          }
				}
			);

		});

		$(document).on('click', '#remove-route-fee', function (e) {
			e.preventDefault();

			var data = {
				action: 'routeapp_remove_admin_fee',
				security: woocommerce_admin_meta_boxes.order_item_nonce,
				order_id: woocommerce_admin_meta_boxes.post_id
			};

			$.post(
				woocommerce_admin_meta_boxes.ajax_url,
				data,
				function( response )
				{
					console.log(response);
					// Errors
					if( !response.success )
					{
						// No data came back, maybe a security error
						if( !response.data )
							console.log( 'AJAX ERROR: no response' );
						// Error from PHP
						else
							console.log( 'Response Error: ' + response.data.error );
					}
					// Success
					else {
            $('.calculate-action').click();
            console.log( 'Response Success: ' + response.data );
          }
				}
			);

		});

		$(document.body).on('order-totals-recalculate-success', refreshRouteFeeButton);

		$(document).ajaxSuccess(function(event, xhr, settings) {
			if (isSaveOrderItemsRequest(settings)) {
				refreshRouteFeeButton();
			}
		});

	})

})( jQuery );

```
