PageSourceSearch

https://thetulsavoice.com/core/media/themes/Respond/js/Respond_ajax_ver=1473876729.js

js thetulsavoice.com collected 2026-10-02 14:54:56 UTC 4,312 bytes, 147 lines download raw bytes

1/**
2 * Respond_ajax.js
3 * 
4 * Useful classes to make frapi calls.  Currently includes:
5 *     AjaxMessages
6 *         get: returns an array of messages
7 *         parse: message parser, if you want to do it yourself
8 * 
9 * DEPENDENCY
10 *     jQuery
11 * 
12 */
13
14
15/**
16 * When submitting a page form, we may want to return some status messages to the
17 * calling page.  Unfortunately, if the page is cached, any message attached to
18 * the page source will also be cached.
19 * A method is provided to store an array of messages in a session variable:
20 *     $_SESSION['ajaxmessages']
21 * 
22 * where each stored message is an object with the format:
23 *     {<unique key>, message}
24 * 
25 */
26var AjaxMessages = (function() {
27	var baseURL = "/core/api/frapi/public/index.php/";
28	var cachebuster = "?sid=" + new Date().getTime();
29
30	function reportFailure(callback) {
31		Console.log('Ajax call failed for AjaxMessages.get');
32		Console.log(arguments);
33		if (callback) {
34			callback();
35		}
36	};
37
38	return {
39		/**
40		 * Parse messages stored and returned through ajax calls.
41		 * Messages have a unique key (usually php time()) and a
42		 * message.
43		 * What is passed in should be an array of message objects.
44		 * A single message object can be passed in, and it is converted
45		 * into an array of message objects before processing.
46		 * 
47		 * Messages are set in the session, and *should* be cleared after
48		 * being read, but don't seem to be.  So... we keep track of
49		 * messages that have been processed by storing processed
50		 * message keys in the "ajaxMessages" cookie.
51		 * 
52		 * This function can keep track of a maximum of 10 messages at
53		 * a time.  In practice, only a single message will probably be
54		 * set each time.
55		 * 
56		 * @param newMessages array of messed objects or single message objectt
57		 *     format message object: {uniqueKey : message}
58		 * 
59		 */
60		parse: function parse(newMessages) {
61			if (typeof newMessages == "undefined" ||
62					newMessages == "" ||
63					!(rjQuery.isArray(newMessages) || rjQuery.isPlainObject(newMessages))) {
64				return [];
65			}
66			if (rjQuery.isPlainObject(newMessages)) {
67				newMessages = [newMessages];
68			}
69
70			// read in keys from ajax messages already seen
71			var messageKeys = RivistaUtils.getCookie("ajaxMessages");
72			if (messageKeys == null) {
73				messageKeys = [];
74			} else {
75				messageKeys = messageKeys.split("|");
76			}
77
78			// loop through ajax messages, determining whether or not
79			// the messages have already been processed
80			var messages = [];
81			var newKeys = [];
82			rjQuery.each(newMessages, function(index, message) {
83				var cookieId = message["msgid"]+"";		// force to string
84				if (rjQuery.inArray(cookieId, messageKeys) == -1) {	// new message
85					if (message["stringid"] != "" && RivistaJSString.get(message["stringid"])) {
86						messages.push(RivistaJSString.get(message["stringid"]));
87					} else {
88						messages.push(message["message"]);
89					}
90					newKeys.push(cookieId);
91				} else {
92//					Console.log("already seen");
93				}
94			});
95
96			// return new messages and store new keys in cookie
97			if (messages.length > 0) {
98				rjQuery.merge(messageKeys, newKeys);
99				while (messageKeys.length > 50) {
100					messageKeys.shift();
101				}
102				RivistaUtils.setCookie("ajaxMessages", messageKeys.join("|"), 0);
103			}
104			return messages;
105		},
106
107		get: function get(callback, params) {
108			params = rjQuery.extend({
109				frapicall: "Pages/CheckAjaxMessages.json",
110				pageid: 0,
111				failureCallback: null
112			},params);
113
114			callback = typeof callback != "undefined" && rjQuery.isFunction(callback) ? callback : null;
115			if (callback == null || params.pageid <= 0) {
116				return;
117			}
118			var failureCallback = (params.failureCallback != null && rjQuery.isFunction(params.failureCallback))
119					? params.failureCallback
120					: null;
121
122			var dataParams = {};
123			dataParams['pageid'] = params.pageid;
124
125			rjQuery.ajax({
126				url: baseURL+params.frapicall+cachebuster,
127				type: "POST",
128				dataType: "json",
129				async: true,
130				data: dataParams,
131				error: function() {
132					reportFailure(failureCallback);
133				},
134				success: function(data) {
135					if (data.status.toLowerCase() == "success") {
136						var messages = AjaxMessages.parse(data.data);
137						callback(messages);
138					} else {
139						reportFailure(failureCallback);
140					}
141				}
142			});
143		}
144
145	};
146
147})();

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.