PageSourceSearch

https://redinstead.com.au/shopblog25/wp-content/plugins/decorator-…/storefrog/assets/js/storefrog.js?ver=1.0.4

js redinstead.com.au collected 2026-10-03 21:38:00 UTC 2,899 bytes, 119 lines download raw bytes

1/**
2 *  Storefrog connector script.
3 *
4 *  @package Storefrog_Connector
5 *  @since 2.0.0
6 */
7
8/* Create global `storefrogDataObject` from localized data. */
9window.storefrogDataObject = wbte_sf_script_params.storefrogDataObject;
10
11/* Create an object to store cart changes */
12var wbteSfDataObject = {
13	"cart": {
14		"items": {},
15		"hash": window.storefrogDataObject.cart.hash
16	},
17	"user": window.storefrogDataObject.user
18};
19
20/* Fetch data object via ajax. And update it to  */
21function getStorefrogDataObject( forceLoadTable = false ) {
22	jQuery.ajax(
23		{
24			url: wbte_sf_script_params.home_url + '/?wc-ajax=get_storefrog_data_object&nonce=' + wbte_sf_script_params.nonce,
25			type:'GET',
26			dataType:'json',
27			success:function (data) {
28				if (data.success) {
29					wbteSfDataObject = data.data;
30					wbteSfDataObjectUpdate(forceLoadTable);
31				}
32			}
33		}
34	);
35}
36
37/* Populate the cart updates to global object */
38function wbteSfDataObjectUpdate(forceLoadTable = false) {
39
40	let tempObj = null;
41	if (forceLoadTable) {
42		tempObj = window.storefrogDataObject;
43		tempObj.cart.table = wbteSfDataObject.cart.table;
44	}else{
45		/* Create a deep copy of the original object. */
46		 tempObj = JSON.parse(JSON.stringify(wbteSfDataObject));
47	}
48
49	/* Clear the array keys. */
50	tempObj.cart.items = Object.values( tempObj.cart.items );
51
52	/* Add this object to the local storage for other tabs. */
53	localStorage.setItem( 'wbteSfDataObject', JSON.stringify( tempObj ) );
54
55	/* Update to global object for current tab. */
56	window.storefrogDataObject = tempObj;
57}
58
59
60/* For block cart and checkout pages. */
61document.addEventListener(
62	'DOMContentLoaded',
63	function () {
64		const registerCheckoutFilters = window?.wc?.blocksCheckout?.registerCheckoutFilters;
65
66		if (typeof registerCheckoutFilters !== "function") {
67            return;
68        }
69
70		var wbteDataObjectUpdateTmr = null;
71
72		registerCheckoutFilters(
73			'wbte-storefrog',
74			{
75				cartItemPrice: (value, extensions, args) => {
76
77					clearTimeout( wbteDataObjectUpdateTmr );
78					wbteDataObjectUpdateTmr = setTimeout(
79						function () {
80							wbteDataObjectUpdateTmr = null;
81							getStorefrogDataObject();
82						},
83						2000
84					);
85
86				return value;
87				}
88			}
89		);
90
91	}
92);
93
94
95/* For classic cart and checkout pages. */
96jQuery( document ).ready(
97	function () {
98		/* Watch cart change */
99		jQuery( 'body' ).on(
100			'updated_wc_div updated_checkout added_to_cart removed_from_cart wc-blocks_added_to_cart',
101			function () {
102				getStorefrogDataObject();
103			}
104		);
105	}
106);
107
108
109/* Watch storage change for non active browser tabs. This section is used to sync the data between tabs */
110window.addEventListener(
111	'storage',
112	( event ) => {
113		if ( 'wbteSfDataObject' === event.key ) {
114			window.storefrogDataObject = JSON.parse( event.newValue );
115		} else if ( event.key.indexOf( 'wc_cart_hash_' ) === 0 ) {
116			window.storefrogDataObject.cart.hash = event.newValue;
117		}
118	}
119);

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.