PageSourceSearch

https://sajim.co.za/lib/pkp/js/functions/general.js

js sajim.co.za collected 2026-10-02 06:00:58 UTC 3,846 bytes, 163 lines download raw bytes

1/**
2 * functions/general.js
3 *
4 * Copyright (c) 2013-2019 Simon Fraser University
5 * Copyright (c) 2000-2019 John Willinsky
6 * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
7 *
8 * Site-wide common JavaScript functions.
9 */
10
11/**
12 * Prompt user for confirmation prior to loading a URL.
13 */
14function confirmAction(url, msg) {
15	if (confirm(msg)) {
16		if (url) {
17			document.location.href=url;
18		}
19		return true;
20	}
21	return false;
22}
23
24/**
25 * Open window displaying help.
26 */
27function openHelp(url) {
28	window.open(url, 'Help', 'width=700,height=600,screenX=100,screenY=100,toolbar=0,scrollbars=1');
29}
30
31/**
32 * Open window displaying comments.
33 */
34function openComments(url) {
35	window.open(url, 'Comments', 'width=700,height=600,screenX=100,screenY=100,toolbar=0,resizable=1,scrollbars=1');
36}
37
38/**
39 * Open window for preview.
40 */
41function openWindow(url) {
42	window.open(url, 'Window', 'width=600,height=550,screenX=100,screenY=100,toolbar=0,resizable=1,scrollbars=1');
43}
44
45/**
46 * Open window for reading tools.
47 */
48function openRTWindow(url) {
49	window.open(url, 'RT', 'width=700,height=500,screenX=100,screenY=100,toolbar=0,resizable=1,scrollbars=1');
50}
51function openRTWindowWithToolbar(url) {
52	window.open(url, 'RT', 'width=700,height=500,screenX=100,screenY=100,toolbar=1,resizable=1,scrollbars=1');
53}
54
55/**
56 * browser object availability detection
57 * @param objectId string of object needed
58 * @param style int (0 or 1) if style object is needed
59 * @return javascript object specific to current browser
60 */
61function getBrowserObject(objectId, style) {
62	var isNE4 = 0;
63	var currObject;
64
65	// browser object for ie5+ and ns6+
66	if (document.getElementById) {
67		currObject = document.getElementById(objectId);
68	// browser object for ie4+
69	} else if (document.all) {
70		currObject = document.all[objectId];
71	// browser object for ne4
72	} else if (document.layers) {
73		currObject = document.layers[objectId];
74		isNE4 = 1;
75	} else {
76		// do nothing
77	}
78
79	// check if style is needed
80	if (style && !isNE4) {
81		currObject = currObject.style;
82	}
83
84	return currObject;
85}
86
87/**
88 * Load a URL.
89 */
90function loadUrl(url) {
91	document.location.href=url;
92}
93
94function createCookie(name,value,days) {
95	if (days) {
96		var date = new Date();
97		date.setTime(date.getTime()+(days*24*60*60*1000));
98		var expires = "; expires="+date.toGMTString();
99	}
100	else expires = "";
101	document.cookie = name+"="+value+expires+"; path=/";
102}
103
104function readCookie(name) {
105	var nameEQ = name + "=";
106	var ca = document.cookie.split(';');
107	for(var i=0;i < ca.length;i++) {
108		var c = ca[i];
109		while (c.charAt(0)==' ') c = c.substring(1,c.length);
110		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
111	}
112	return null;
113}
114
115/**
116 * Asynchronous request functions
117 */
118function makeAsyncRequest(){
119	var req=(window.XMLHttpRequest)?new XMLHttpRequest():new ActiveXObject('Microsoft.XMLHTTP');
120	return req;
121}
122
123function sendAsyncRequest(req, url, data, method) {
124	var header = 'Content-Type:text/html; Charset=utf-8';
125	req.open(method, url, true);
126	req.setRequestHeader(header.split(':')[0],header.split(':')[1]);
127	req.send(data);
128}
129
130
131/**
132 * Change the form action
133 * @param formId string
134 * @param action string
135 */
136function changeFormAction(formId, action) {
137	document.getElementById(formId).action = action;
138	document.getElementById(formId).submit();
139}
140
141/**
142 * Encode a URL parameter
143 * @param s string
144 */
145function urlEncode(s) {
146	return encodeURIComponent( s ).replace( /\%20/g, '+' ).replace( /!/g, '%21' ).replace( /'/g, '%27' ).replace( /\(/g, '%28' ).replace( /\)/g, '%29' ).replace( /\*/g, '%2A' ).replace( /\~/g, '%7E' );
147}
148
149/**
150 * HTML encode a string
151 * @param s string
152 */
153function escapeHTML(s) {
154	return $('<div/>').text(s).html();
155}
156
157/**
158 * HTML decode a string
159 * @param s string
160 */
161function unescapeHTML(s) {
162	return $('<div/>').html(s).text();
163}

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.