PageSourceSearch

https://www.uprrmuseum.org/cs/resources/wcm/sitestudio/wcm.toggle.js

js uprrmuseum.org collected 2026-09-24 09:22:58 UTC 14,611 bytes, 517 lines download raw bytes

1/////////////////////////////////////////////////////////////////////////////
2// 
3// Project   : Web Content Management JavaScript Library (WCM)
4//
5// FileName  : wcm.toggle.js
6// FileType  : JavaScript
7// Created   : June 2007
8// Version   : 11gR1+ (11.1.1.9.0)
9//
10// Comments  : 
11//
12// Copyright : Oracle, Incorporated Confidential and Proprietary
13//
14//             This computer program contains valuable, confidential and proprietary
15//             information. Disclosure, use, or reproduction without the written
16//             authorization of Oracle is prohibited. This unpublished
17//             work by Oracle is protected by the laws of the United States
18//             and other countries. If publication of the computer program should occur,
19//             the following notice shall apply:
20//
21//             Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
22//
23/////////////////////////////////////////////////////////////////////////////
24
25var WCM = WCM || {}; // namespace object
26
27//***************************************************************************
28
29WCM.DHTML = WCM.DHTML || {}; // namespace object
30
31//***************************************************************************
32
33WCM.CONTRIBUTOR = WCM.CONTRIBUTOR || {}; // namespace object
34WCM.DESIGN = WCM.DESIGN || {}; // namespace object
35
36//***************************************************************************
37
38WCM.CONTRIBUTOR.mode = "wcm.contributor.mode";
39WCM.CONTRIBUTOR.sscontributor = "SSContributor";
40
41WCM.DESIGN.mode = "wcm.design.mode";
42WCM.DESIGN.ssdesignmode = "SSDesignMode";
43
44//***************************************************************************
45//***************************************************************************
46//********************************** WCM ************************************
47//***************************************************************************
48//***************************************************************************
49
50WCM.IS_MAC = (navigator.platform.toLowerCase().indexOf('mac') > -1);
51WCM.IS_CHROME = (navigator.userAgent.toLowerCase().indexOf("chrome") > -1);
52WCM.IS_SAFARI = (((navigator.userAgent.toLowerCase().indexOf("applewebkit") > -1) || (navigator.userAgent.toLowerCase().indexOf("apple") > -1)) && !WCM.IS_CHROME);
53
54//***************************************************************************
55
56WCM.IsString = function(obj) { return (typeof obj == 'string'); }
57WCM.IsBoolean = function(obj) { return (typeof obj == 'boolean'); }
58WCM.IsUndefined = function(obj) { return (typeof obj == 'undefined'); }
59WCM.IsNull = function(obj) { return (obj == null); }
60WCM.IsValid = function(obj) { return (!WCM.IsNull(obj) && !WCM.IsUndefined(obj)); }
61WCM.IsFunction = function(obj) { return (typeof obj == 'function'); }
62
63//***************************************************************************
64
65WCM.ToBool = function(obj, def)
66{
67	if (WCM.IsValid(obj))
68	{
69		return ((obj == 1) || (obj == true) || (obj == "1") || (obj.toString().toLowerCase() == "true") || (obj.toString().toLowerCase() == 'yes'));
70	}
71
72	return (WCM.IsBoolean(def) ? def : false);
73};
74
75//***************************************************************************
76
77WCM.GetUrlBase = function(context)
78{
79	context = WCM.IsString(context) ? context : (context || window).location.href;
80	return context.split("?")[0].split("#")[0];
81}
82
83//***************************************************************************
84
85WCM.GetBookmark = function(context)
86{
87	context = WCM.IsString(context) ? context : (context || window).location.href;
88	return (WCM.IsString(context.split("#")[1])) ? "#"+context.split("#")[1] : "";
89}
90
91//***************************************************************************
92
93WCM.GetQueryString = function(context)
94{
95	return WCM.IsString(context) ? ((context.split('?')[1] && '?'+context.split('?')[1].split('#')[0]) || '') : (context || window).location.search;
96}
97
98//***************************************************************************
99
100WCM.GetQueryStringValue = function(name, query)
101{
102	query = WCM.GetQueryString(query);
103
104	if (query.indexOf(name) >= 0)
105	{
106		var q = query.replace(/.*\?/, '');
107
108		if (WCM.IsValid(q) && q.length > 0)
109		{
110			var pairs = q.split("&");
111			for (var i = 0; i < pairs.length; i++)
112			{
113				var p = pairs[i].split("=");
114				if (name == p[0])
115					return decodeURIComponent(p[1]);
116			}
117		}
118	}
119	return null;
120}
121
122//***************************************************************************
123
124WCM.RemoveQueryStringValue = function(name, query)
125{
126	query = WCM.GetQueryString(query);
127
128	if (query.indexOf(name) >= 0)
129	{
130		var q = query.replace(/\?/,'');
131
132		if (WCM.IsValid(q) && q.length > 0)
133		{
134			var tmp = "";
135			var pairs = q.split("&");
136			for (var i = 0; i < pairs.length; i++)
137			{
138				var p = pairs[i].split("=");
139				if (name != p[0])
140					tmp += "&" + p[0] + "=" + p[1];
141			}
142			return tmp.replace(/\&/,'?');
143		}
144	}
145	return query;
146}
147
148//***************************************************************************
149
150WCM.SetQueryStringValue = function(name, value, query)
151{
152	query = WCM.GetQueryString(query);
153	var q = WCM.RemoveQueryStringValue(name, query);
154	var con = (q.length == 0) ? "?" : (q[q.length-1] == "&") ? "" : "&";
155	return q + con + name + "=" + encodeURIComponent(value);
156}
157
158//***************************************************************************
159
160WCM.SetCookie = function(name, value, days)
161{
162	var expires = null;
163	if (days)
164	{
165		var date = new Date();
166		date.setTime(date.getTime()+(days*24*60*60*1000));
167		expires = "; expires=" + date.toGMTString();
168	}
169	else
170		expires = "";
171
172	document.cookie = name+"="+value+expires+"; path=/";
173}
174
175//***************************************************************************
176
177WCM.GetCookie = function(name)
178{
179	var nameEQ = name + "=";
180	var ca = document.cookie.split(';');
181
182	for(var i=0;i < ca.length;i++)
183	{
184		var c = ca[i];
185		while (c.charAt(0)==' ')
186			c = c.substring(1,c.length);
187
188		if (c.indexOf(nameEQ) == 0)
189			return c.substring(nameEQ.length,c.length);
190	}
191	return null;
192}
193
194//***************************************************************************
195
196WCM.ReloadURL = function(url, context)
197{
198	context = context || window;
199	url = url || WCM.GetUrl(context);
200
201	if (context.location.href.toString() != url)
202		context.location = url;
203	else
204		context.location.reload(true);
205}
206
207//***************************************************************************
208
209WCM.GenerateUniqueId = function(prepend, append)
210{
211	return (prepend || '') + (''+Math.random()).replace(/\./, '') + (WCM.Counter++) + (append || '');
212}
213
214//***************************************************************************
215//***************************************************************************
216//******************************* WCM.DHTML *********************************
217//***************************************************************************
218//***************************************************************************
219
220WCM.DHTML.ID = function(id, context)
221{
222	if (WCM.IsValid(id) && WCM.IsString(id))
223		return (context || document).getElementById(id);
224	else
225		return null;
226}
227
228//***************************************************************************
229
230WCM.DHTML.ToObject = function(obj, def)
231{
232	return WCM.DHTML.ID(obj) || def || (!WCM.IsString(obj) && obj) || null;
233}
234
235//***************************************************************************
236
237WCM.DHTML.GetEventObject = function(e) 
238{ 
239	return (e ? e : window.event); 
240}
241
242//***************************************************************************
243
244WCM.DHTML.GetEventCtrlKey = function(e) 
245{ 
246	e = WCM.DHTML.GetEventObject(e); 
247	return e.ctrlKey; 
248}
249
250//***************************************************************************
251
252WCM.DHTML.GetEventShiftKey = function(e) 
253{ 
254	e = WCM.DHTML.GetEventObject(e); 
255	return e.shiftKey; 
256}
257
258//***************************************************************************
259
260WCM.DHTML.GetEventKeyCode = function(e) 
261{ 
262	e = WCM.DHTML.GetEventObject(e); 
263	return e.keyCode; 
264}
265
266//***************************************************************************
267
268WCM.DHTML.CleanUpCache = {};
269
270//***************************************************************************
271
272WCM.DHTML.AddEvent = function(elm, evType, fn, useCapture)
273{
274	elm = WCM.DHTML.ToObject(elm);
275	if (WCM.IsValid(elm))
276	{
277		if (elm.addEventListener)
278		{
279			elm.addEventListener(evType, fn, useCapture);
280			return true;
281		}
282		else if (elm.attachEvent)
283		{
284			var r = elm.attachEvent('on' + evType, fn);
285			return r;
286		}
287		else
288		{
289			elm['on' + evType] = fn;
290		}
291		
292		if (evType != 'unload')
293		{
294			WCM.DHTML.CleanUpCache[WCM.GenerateUniqueId()] = {
295				"elm" : elm,
296				"evType" : evType,
297				"fn" : fn,
298				"useCapture" : useCapture
299			};
300		}
301	}
302}
303
304//***************************************************************************
305
306WCM.DHTML.RemoveEvent = function(elm, evType, fn, useCapture)
307{
308	elm = WCM.DHTML.ToObject(elm);
309
310	if (WCM.IsValid(elm) && WCM.IsString(evType) && WCM.IsFunction(fn))
311	{
312		if (elm.removeEventListener)
313		{
314			elm.removeEventListener(evType, fn, useCapture);
315			return true;
316		}
317		else if (elm.detachEvent)
318		{
319			elm.detachEvent('on' + evType, fn);
320		}
321		else
322		{
323			elm['on' + evType] = null;
324		}
325	}
326}
327
328//***************************************************************************
329
330WCM.DHTML.CleanUpEventHandlers = function()
331{
332	WCM.DHTML.RemoveEvent(window, 'unload', WCM.DHTML.CleanUpEventHandlers);
333	
334	var key = '';
335	var wait = {};
336
337	for (key in WCM.DHTML.CleanUpCache)
338	{
339		var fn = WCM.DHTML.CleanUpCache[key].fn;
340		var elm = WCM.DHTML.CleanUpCache[key].elm;
341		var evType = WCM.DHTML.CleanUpCache[key].evType;
342		var useCapture = WCM.DHTML.CleanUpCache[key].useCapture;
343				
344		if (WCM.IsValid(elm) && WCM.IsFunction(fn) && WCM.IsString(evType))
345		{
346			WCM.DHTML.RemoveEvent(elm, evType, fn, useCapture);
347			
348			fn = null;
349			if (elm.location && elm.self && elm.self.location && elm.self == elm)
350			{
351				wait[WCM.GenerateUniqueId()] = elm;
352			}
353			else
354			{
355				elm = null;
356			}
357		}
358	}
359	
360	key = '';
361	for (key in wait)
362	{
363		wait[key] = null;
364	};
365	
366	WCM.DHTML.CleanUpCache = null;
367	delete WCM.DHTML['CleanUpCache'];
368}
369
370//***************************************************************************
371
372WCM.DHTML.AddEvent(window, 'unload', WCM.DHTML.CleanUpEventHandlers);
373
374//***************************************************************************
375//***************************************************************************
376//**************************** WCM.CONTRIBUTOR ******************************
377//***************************************************************************
378//***************************************************************************
379
380WCM.CONTRIBUTOR.OnKeyUp = WCM.CONTRIBUTOR.OnKeyUp || function(e)
381{
382	if ((WCM.DHTML.GetEventCtrlKey(e)) &&
383	    (WCM.DHTML.GetEventShiftKey(e)) && 
384	    (WCM.DHTML.GetEventKeyCode(e) == 116))
385	{
386		WCM.CONTRIBUTOR.Toggle( 'contributor' );
387	}
388}
389
390//***************************************************************************
391
392WCM.CONTRIBUTOR.IsContributorMode = WCM.CONTRIBUTOR.IsContributorMode || function()
393{
394	var qs = WCM.GetQueryStringValue(WCM.CONTRIBUTOR.mode);
395	var cookie = WCM.GetCookie(WCM.CONTRIBUTOR.mode);
396	
397	if (!WCM.IsNull(qs))
398	{
399		return WCM.ToBool(qs);
400	}
401	else if (WCM.IsValid(SSContributor))
402	{
403		return WCM.ToBool(SSContributor);
404	}
405	else if (!WCM.IsNull(cookie))
406	{
407		return WCM.ToBool(cookie);
408	}
409	
410	return false; 
411}
412
413//***************************************************************************
414
415WCM.CONTRIBUTOR.IsDesignMode = WCM.CONTRIBUTOR.IsDesignMode || function()
416{
417	if (window['g_ssIsDesignMode'] && WCM.ToBool(window['g_ssIsDesignMode']))
418	{
419		return true;
420	}
421
422	return false; 
423}
424
425//***************************************************************************
426
427WCM.CONTRIBUTOR.IsDesignModeAllowed = WCM.CONTRIBUTOR.IsDesignModeAllowed || function ()
428{
429	if(window['g_ssAllowDesignMode'] && WCM.ToBool(window['g_ssAllowDesignMode']))
430	{
431		return true;
432	}
433
434	return false;	
435}
436
437//***************************************************************************
438
439WCM.CONTRIBUTOR.UseUrlParamsToToggle = WCM.CONTRIBUTOR.UseUrlParamsToToggle || function ()
440{
441	return false;	
442}
443
444//***************************************************************************
445
446WCM.CONTRIBUTOR.Toggle = WCM.CONTRIBUTOR.Toggle || function( mode )
447{
448	var hash = WCM.GetBookmark();
449	var query = WCM.GetQueryString();
450
451	mode = mode || 'contributor';
452
453	if( mode == 'design' )
454	{
455		// Clean up query string
456		if (WCM.IsValid(query) && query.length > 0)
457		{
458			query = WCM.RemoveQueryStringValue(WCM.DESIGN.ssdesignmode, query);
459		}
460
461		if (WCM.CONTRIBUTOR.IsDesignMode()) // Disable
462		{
463			WCM.SetCookie(WCM.DESIGN.mode, "false");
464			if( WCM.CONTRIBUTOR.UseUrlParamsToToggle() )
465			{
466				query = WCM.SetQueryStringValue( WCM.DESIGN.ssdesignmode, 'false', query );
467			}
468		}
469		else // Enable
470		{
471			WCM.SetCookie(WCM.DESIGN.mode, "true");
472			if( WCM.CONTRIBUTOR.UseUrlParamsToToggle() )
473			{
474				query = WCM.SetQueryStringValue( WCM.DESIGN.ssdesignmode, 'true', query );
475			}
476		}
477	}
478
479	if( mode == 'contributor' )
480	{
481		// Clean up query string
482		if (WCM.IsValid(query) && query.length > 0)
483		{
484			query = WCM.RemoveQueryStringValue(WCM.CONTRIBUTOR.mode, query);
485			query = WCM.RemoveQueryStringValue(WCM.CONTRIBUTOR.sscontributor, query);
486		}
487
488		if (WCM.CONTRIBUTOR.IsContributorMode()) // Disable
489		{
490			WCM.SetCookie(WCM.CONTRIBUTOR.mode, "false");
491			if( WCM.CONTRIBUTOR.UseUrlParamsToToggle() )
492			{
493				query = WCM.SetQueryStringValue( WCM.CONTRIBUTOR.mode, 'false', query );
494			}
495		}
496		else // Enable
497		{
498			WCM.SetCookie(WCM.CONTRIBUTOR.mode, "true");
499			if( WCM.CONTRIBUTOR.UseUrlParamsToToggle() )
500			{
501				query = WCM.SetQueryStringValue( WCM.CONTRIBUTOR.mode, 'true', query );
502			}
503		}
504	}
505	
506	WCM.ReloadURL(WCM.GetUrlBase() + query + hash);
507}
508
509//***************************************************************************
510
511WCM.DHTML.AddEvent(document, (WCM.IS_MAC && WCM.IS_SAFARI) ? 'keydown' : 'keyup', WCM.CONTRIBUTOR.OnKeyUp);
512
513//***************************************************************************
514
515
516
517

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.