PageSourceSearch

https://www.ashbybears.com/acatalog/recentproductssupport.js?DAYNO=XCAB

js ashbybears.com collected 2026-09-27 07:32:24 UTC 12,592 bytes, 369 lines download raw bytes

1/***********************************************************************
2*
3* Recently viewed product code. V0.02. Uses cookie "ACTINIC_RECENT" of format:
4*
5*	ProductID\tProductName\tProductPrice\tProductThumbNailImage\fProductID\tProductName\t...
6*
7************************************************************************/
8
9//END Configuration variables - alter with care
10
11var nStartPos = -1;		// Start position (-1 means default)
12var bUseTable = false;
13
14/***********************************************************************
15*
16* CreateRecentProduct 	- create Recent Product object
17*
18* Input: sPid		- Product ID
19*	 sPname		- Product Name (Actinic encoded)
20*	 sPprice	- Product Price
21*	 sThumb		- Product Thumbnail Image
22*
23* Returns: object with sPid, sPname, sPprice, sThumb properties
24*
25************************************************************************/
26
27function CreateRecentProduct(sPid, sPname, sPprice, sThumb)
28	{
29	this.sPid = sPid
30	this.sPname = sPname;
31	this.sPprice = sPprice;
32	this.sThumb = sThumb;
33	}
34
35/***********************************************************************
36*
37* GetRecentFromCookie -	gets list of recent products from cookie
38*
39* Input: nothing
40*
41* Returns: array of Recent Product objects
42* Returns: false if no cookie items saved
43*
44************************************************************************/
45
46function GetRecentFromCookie()
47	{
48	var sRecent = getCookie('ACTINIC_RECENT');
49	if ( (sRecent != null) && (sRecent.length > 10) ) 
50		{
51		var aRecentViewed = new Array();
52		var aCookieList = sRecent.split("\f");
53		for ( var i=0; i<aCookieList.length; i++) 
54			{
55			var aCurrentRecent = aCookieList[i].split("\t");
56			aRecentViewed.push(new CreateRecentProduct(aCurrentRecent[0], aCurrentRecent[1], aCurrentRecent[2], aCurrentRecent[3]));
57			}
58		return aRecentViewed;
59		}
60	return false;	
61	}
62
63/***********************************************************************
64*
65* SetRecentToCookie - saves recent products cookie
66*
67* Input: aRecentViewed	- array of Recent Product objects
68*
69* Returns: nothing
70*
71************************************************************************/
72
73function SetRecentToCookie(aRecentViewed)
74	{
75	var sCookie = '';
76	for ( var i=0; i<aRecentViewed.length; i++) sCookie += aRecentViewed[i].sPid + "\t" + aRecentViewed[i].sPname + "\t" + aRecentViewed[i].sPprice + "\t" + aRecentViewed[i].sThumb + "\f";
77	sCookie = sCookie.slice(0, -1);		// lose trailing delimiter
78	var dRecentExpiry = new Date();		// current time
79	dRecentExpiry.setTime(dRecentExpiry.getTime() + (1000 * 60 * 60 * nKeepRecentHours));	// add hours to keep
80	setCookie('ACTINIC_RECENT', sCookie, dRecentExpiry);
81	}
82
83
84/***********************************************************************
85*
86* ReplaceVariables - replace variable markers with content
87*
88* Input: 
89*	sTemplate 	- template
90*	aRecentItem 	- recentitem object
91*
92* Returns: template with replacements
93*
94************************************************************************/
95
96function ReplaceVariables(sTemplate, aRecentItem)
97	{
98	var sImageURL = aRecentItem.sThumb.indexOf("file:///") == 0 ? aRecentItem.sThumb
99		: catalogDir + aRecentItem.sThumb;				//	add catalog path to Image
100	sTemplate = sTemplate.replace(/_PID_/g,   aRecentItem.sPid);			//	_PID_	replaced by ProductID
101	sTemplate = sTemplate.replace(/_ENAME_/g, escape(aRecentItem.sPname));		//	_ENAME_	replaced by Escaped Product Name
102	sTemplate = sTemplate.replace(/_NAME_/g,  aRecentItem.sPname);			//	_NAME_	replaced by Product Name
103	sTemplate = sTemplate.replace(/_PRICE_/g, aRecentItem.sPprice);			//	_PRICE_	replaced by Product Price
104	sTemplate = sTemplate.replace(/_THUMB_/g, sImageURL);				//	_THUMB_	replaced by Image filename
105	sTemplate = sTemplate.replace(/_SSURL_/g, ssURL);				//	_SSURL_	replaced by SearchScript URL
106	sTemplate = sTemplate.replace(/_HREF_/g, 'href');				//	_HREF_	replaced by href (prevents actinic Perl munging it)
107	return sTemplate;
108	}
109
110/***********************************************************************
111*
112* ScrollBackRecent - scroll back list if possible
113*
114* Input: nothing
115*
116* Returns: nothing (affects global nStartPos)
117*
118************************************************************************/
119
120function ScrollBackRecent()
121	{
122	var aRecentViewed = GetRecentFromCookie();
123	if ( aRecentViewed && (aRecentViewed.length > nTrimListTo) ) 	// can scroll back
124			{
125			nStartPos -= nScrollBy;			// scroll back by set length
126			if ( nStartPos < 0 ) nStartPos = 0;
127			document.getElementById('recenthtlist').innerHTML = bUseTable ? RecentProductsListTableHTML() : RecentProductsListHTML();	// redisplay list
128			SetBackForwardButtons ();
129			}
130
131	}	
132
133/***********************************************************************
134*
135* ScrollForwardRecent - scroll forward list if possible
136*
137* Input: nothing
138*
139* Returns: nothing (affects global nStartPos)
140*
141************************************************************************/
142
143function ScrollForwardRecent()
144	{
145	var aRecentViewed = GetRecentFromCookie();
146	if ( aRecentViewed && (aRecentViewed.length > nTrimListTo) ) 	// can scroll forward
147			{
148			if ( nStartPos < 0 ) nStartPos = 0;
149			nStartPos += nScrollBy;			// scroll forward by set count
150			if ( nStartPos > (aRecentViewed.length - nTrimListTo) ) nStartPos = (aRecentViewed.length - nTrimListTo);	// don't go off end off list
151			document.getElementById('recenthtlist').innerHTML = bUseTable ? RecentProductsListTableHTML() : RecentProductsListHTML();
152			SetBackForwardButtons ();
153			}
154	}	
155
156/***********************************************************************
157*
158* SetBackForwardButtons - enable disbale scroll buttons
159*
160* Input: nothing
161*
162* Returns: nothing
163*
164************************************************************************/
165
166function SetBackForwardButtons()
167	{
168	var aRecentViewed = GetRecentFromCookie();
169	if ( aRecentViewed ) 	// can scroll 
170			{
171			var d; if ( d = document.getElementById('scrollbackrecent') ) 
172				{
173				d.disabled = (nStartPos <= 0);
174				d.style.cursor = (nStartPos <= 0) ? 'default' : 'pointer';
175				}
176			if ( d = document.getElementById('scrollforwardrecent') )
177				{
178				d.disabled = (nStartPos >= (aRecentViewed.length - nTrimListTo));
179				d.style.cursor = (nStartPos >= (aRecentViewed.length - nTrimListTo)) ? 'default' : 'pointer';
180				}
181			}
182	}	
183
184/***********************************************************************
185*
186* TrimRecentProductsList - Reduce list to desired number of items
187*
188* Input: aRecentViewed	- array of Recent Product objects
189*
190* Returns: reduced array of Recent Product objects
191*
192************************************************************************/
193
194function TrimRecentProductsList(aRecentViewed)
195	{
196	var nRecentListTotal = aRecentViewed.length;
197	if ( nRecentListTotal <= nTrimListTo ) 		// list doesn't need truncating
198		{
199		nStartPos = 0;
200		return aRecentViewed;
201		}
202	var aRecentSubList = new Array();
203	if ( nStartPos < 0 ) nStartPos = nRecentListTotal - nTrimListTo;
204	if ( nStartPos > (nRecentListTotal - nTrimListTo) ) nStartPos = nRecentListTotal - nTrimListTo;
205	for ( i=0; i<nTrimListTo; i++ )
206		{
207		aRecentSubList.push(aRecentViewed[nStartPos + i]);
208		}
209	return aRecentSubList;
210	}
211
212/***********************************************************************
213*
214* RecentProductsListHTML - generate simple recent products HTML - no navigation
215*
216* Input: nothing - uses cookie
217*
218* Returns: recent products HTML or empty list string
219*
220************************************************************************/
221
222function RecentProductsListHTML()
223	{
224	var aRecentViewed = GetRecentFromCookie();
225	if ( aRecentViewed )
226		{
227		aRecentViewed = TrimRecentProductsList(aRecentViewed); // trim list
228		if ( bDisplayReversed ) aRecentViewed.reverse();		// reverse if required
229		var sHTML = ''
230		for (var i=0; i<aRecentViewed.length; i++)
231			{
232			sHTML += ReplaceVariables(sRecentItem, aRecentViewed[i]);
233			}
234 		if ( sHTML != '' ) return sRecentPrefix + sHTML + sRecentSuffix;
235		}
236	return sRecentEmptyList;		
237	}
238
239/***********************************************************************
240*
241* RecentProductsListTableHTML - generate horizontal table of recent products HTML - use trimmed list
242*
243* Input: nothing - uses cookie
244*
245* Returns: recent products HTML or empty list string
246*
247************************************************************************/
248
249function RecentProductsListTableHTML()
250	{
251	var aRecentViewed = GetRecentFromCookie();
252	if ( aRecentViewed )
253		{
254		aRecentViewed = TrimRecentProductsList(aRecentViewed);		// trim list
255		if ( bDisplayReversed ) aRecentViewed.reverse();		// reverse if required
256		var bHhaveItems = false;
257		var sImageRowHTML = sRecentImageRowPrefix;
258		var sDescRowHTML = sRecentDescRowPrefix;
259		var sPriceRowHTML= sRecentPriceRowPrefix;
260		var sDeleteRowHTML = sRecentDeleteRowPrefix;
261		for (var i=0; i<aRecentViewed.length; i++)
262			{
263			bHaveItems = true;
264			sImageRowHTML += ReplaceVariables(sRecentImageItem, aRecentViewed[i]);
265			sDescRowHTML += ReplaceVariables(sRecentDescItem, aRecentViewed[i]);
266			sPriceRowHTML += ReplaceVariables(sRecentPriceItem, aRecentViewed[i]);
267			sDeleteRowHTML += ReplaceVariables(sRecentDeleteItem, aRecentViewed[i]);
268			}
269 		if ( bHaveItems ) return ( sRecentPrefix 
270 			+ sImageRowHTML + sRecentImageRowSuffix 
271 			+ sDescRowHTML + sRecentDescRowSuffix 
272 			+ sPriceRowHTML + sRecentPriceRowSuffix
273 			+ sDeleteRowHTML + sRecentDeleteRowSuffix
274 			+ sRecentSuffix );
275		}
276	return sRecentEmptyList;		
277	}
278	
279/***********************************************************************
280*
281* DisplayRecentProducts - write recent products HTML to page
282*
283* Input: bTable	- whether to use horizontal table or simple layout
284* 
285* Returns: nothing
286*
287************************************************************************/
288
289function DisplayRecentProducts(bTable)
290	{
291	bUseTable = (bTable === true);
292	if (bTable) 
293		{
294		document.write(RecentProductsListTableHTML());
295		SetBackForwardButtons();
296		}
297	else
298		{	
299		document.write(RecentProductsListHTML());
300		SetBackForwardButtons();
301		}
302	}
303
304/***********************************************************************
305*
306* SaveRecentProduct - called from Product List layout - save product detail to cookie
307*
308* Input: sPid		- Product ID
309*	 sPname		- Product Name (Actinic encoded)
310*	 sPprice	- Product Price
311*	 sThumb		- Product Thumbnail Image
312* 
313* Returns: nothing
314*
315************************************************************************/
316
317function SaveRecentProduct(sPid, sPname, sPprice, sThumb)
318	{
319	if ( sThumb == '' ) return;		// skip items with no thumbnail
320	var aRecentViewed = new Array();
321	var aCurrentRecent = GetRecentFromCookie();
322	if ( aCurrentRecent )
323		{
324		for ( var i=0; i<aCurrentRecent.length; i++) if ( aCurrentRecent[i].sPid != sPid ) aRecentViewed.push(aCurrentRecent[i]);	// remove any identical products from list
325		}	
326	aRecentViewed.push(new CreateRecentProduct(sPid, sPname, sPprice, sThumb));	// save at end of list
327	while ( aRecentViewed.length > nMaxRecent ) aRecentViewed.shift();		// trim excess entries
328	SetRecentToCookie(aRecentViewed);
329	}
330
331/***********************************************************************
332*
333* DeleteRecent - called from Product display - delete selected product from recent products list
334*
335* Input: sPid	- ProductID
336*	 bTable	- Whether to use simple layout or table
337* 
338* Returns: nothing
339*
340************************************************************************/
341
342function DeleteRecent(sPid, bTable)
343	{
344	var aRecentViewed = new Array();
345	var aCurrentRecent = GetRecentFromCookie();
346	if ( aCurrentRecent )
347		{
348		for ( var i=0; i<aCurrentRecent.length; i++) if ( aCurrentRecent[i].sPid != sPid ) aRecentViewed.push(aCurrentRecent[i]);	// remove matching products from list
349		}	
350	SetRecentToCookie(aRecentViewed);
351	if (bTable)
352		{
353		document.getElementById('recenthtlist').innerHTML = RecentProductsListTableHTML();	// redisplay horiz table list
354		}
355	else
356		{
357		var elRecentProductList = document.getElementById('recenthtlist'); 
358		if (elRecentProductList === null)
359			{
360			elRecentProductList = document.getElementById('recentstlist'); 
361			}
362		if (elRecentProductList)
363			{
364			elRecentProductList.innerHTML = RecentProductsListHTML();	// redisplay simple list
365			}
366		}
367	SetBackForwardButtons();
368	}
369// END - Recently viewed product code. 

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.