PageSourceSearch

https://news.iu.edu/livewhale/theme/core/scripts/lwcw.js

js iu.edu collected 2026-09-24 06:40:30 UTC 5,043 bytes, 164 lines download raw bytes

1/*global jQuery:true */
2
3(function() {
4	function isValidJQuery() {
5		var result = false;
6		// load jquery and plugin if jquery not loaded, otherwise just load plugin
7		// check for window.jQuery.fn.ajax function excludes jquery slim
8		if ((typeof livewhale === 'object' && livewhale.jQuery)
9				|| (window.jQuery && window.jQuery.fn && window.jQuery.fn.ajax)) {
10
11			var version_parts = parseFloat(window.jQuery.fn.jquery).toString().split('.');
12			var major_version = parseInt(version_parts[0], 10);
13			var minor_version = parseInt(version_parts[1], 10);
14			if (major_version > 1 || (major_version === 1 && minor_version >= 5)) {
15				result = true;
16			}
17		}
18		return result;
19	}
20
21	function getAggregateUrl(host, liveurl_dir, type, resources) {
22		var urls = [];
23		// build aggregate resource url
24		for (var i = 0; i < resources.length; i++) {
25			urls.push( resources[i].replace(/\//g, '%5C') );
26		}
27		return host + liveurl_dir + '/resource/' + type + '/' + urls.join('/');
28	}
29
30	function parseOptions(option_str) {
31		var result = {},
32				pairs;
33		if (option_str && option_str.indexOf('&')) {
34			pairs = option_str.split('&');
35			for (var i = 0; i < pairs.length; i++) {
36				var pair = pairs[i].split("=");
37				result[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
38			}
39		}
40		return result;
41	}
42
43	// dynamically load javascript and execute callback when finished
44	function loadScript(url, callback) {
45		var script = document.createElement("script");
46		script.type = "text/javascript";
47
48		if (script.readyState) { //IE
49			script.onreadystatechange = function() {
50				if (script.readyState === "loaded" || script.readyState === "complete") {
51					script.onreadystatechange = null;
52					callback();
53				}
54			};
55		} else { //Others
56			script.onload = function() {
57				callback();
58			};
59		}
60		script.src = url;
61		document.getElementsByTagName('head')[0].appendChild(script);
62	}
63
64	function loadStylesheet(url) {
65		var link = document.createElement("link");
66		link.rel = "stylesheet";
67		link.type = "text/css";
68		link.href = url;
69		document.getElementsByTagName("head")[0].appendChild(link);
70	}
71
72	function initPlugin($, host) {
73		$(document).ready(function() {
74			// for each widget, parse options in data-options attr (formatted like qstring), and call plugin
75			$('.lwcw').each(function() {
76				var $this			 = $(this);
77				var option_str = $this.attr('data-options');
78
79				// call iframe widget jquery plugin
80				$this.lwWidget( $.extend({ host: host }, parseOptions(option_str)) );
81			});
82		});
83	}
84
85	function init() {
86		var script			= document.getElementById('lw_lwcw'),
87				option_str	= script.getAttribute('data-options'),
88				liveurl_dir = '/live',
89				load_styles = true;
90
91		// use liveurl_dir set in options if it exists there
92		if (option_str) {
93			var opts = parseOptions(option_str);
94			if (opts.liveurl_dir) {
95				liveurl_dir = opts.liveurl_dir;
96			}
97			if (opts.exclude_styles) {
98				load_styles = false;
99			}
100		}
101
102		// return right away if script tag that loads this is not found
103		if (!script || !script.src) return;
104
105		// get host from script tag's src
106		var host = script.src.match(/^\s*https?:\/\/[^/]+/i);
107		if (host.length !== 1) return;
108		host = host[0];
109
110		var scripts = [
111			'/livewhale/scripts/lib/date/formatter.js',
112			'/livewhale/scripts/lib/date/timezone.js',
113			'/livewhale/scripts/lib/date/user.js',
114			'/livewhale/plugins/jquery/jquery.lw-widget.js'
115		];
116		var styles = [
117			'/livewhale/theme/global/styles/widgets.css'
118		];
119		if (!isValidJQuery()) {
120			scripts.unshift('/livewhale/thirdparty/jquery/jquery.no-conflict-footer.js');
121			scripts.unshift('/livewhale/thirdparty/jquery/jquery.js');
122			scripts.unshift('/livewhale/thirdparty/jquery/jquery.no-conflict-header.js');
123		}
124		var url = getAggregateUrl(host, liveurl_dir, 'js', scripts);
125		var css_url = getAggregateUrl(host, liveurl_dir, 'css', styles);
126
127		if (load_styles) {
128			loadStylesheet(css_url);
129		}
130		loadScript(url, function() {
131			var $ = livewhale.jQuery || jQuery;
132			initPlugin(livewhale.jQuery || jQuery, host);
133
134			// load randomize plugin if widget has lw_widget_randomized class
135			$('body').on('widgetLoad.lw', function(e, $widget) {
136				if ($widget.find('.lw_widget_randomized').length) {
137					var randomize_scripts = [
138						'%5Clivewhale%5Cthirdparty%5Cjqueryui%5Cjquery-ui.widget.js',
139						'%5Clivewhale%5Cscripts%5Clwui%5Cjquery.lw-randomize.js'
140					];
141					var url = host + liveurl_dir + '/resource/js/' + randomize_scripts.join('/');
142
143					loadScript(url, function() {
144						// call randomize plugin
145						$widget.find('.lw_widget_randomized').randomize();
146					});
147				}
148			});
149		});
150	}
151
152  // Multiple lwcw.js scripts are sometimes included in a page.
153  // Make sure only one runs
154  if (typeof window.LW_REMOTE_WIDGET_INITIALIZED === 'undefined') {
155    window.LW_REMOTE_WIDGET_INITIALIZED = true;
156
157    // run on document ready so site's existing jQuery, or LW jQuery, loads first
158    if (document.readyState === 'loading') {
159      document.addEventListener('DOMContentLoaded', init);
160    } else {
161      init();
162    }
163  }
164}());

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.