PageSourceSearch

https://ijain.org/lib/pkp/js/lib/jquery/plugins/jquery.pkp.js

js ijain.org collected 2026-10-06 05:05:06 UTC 2,290 bytes, 89 lines download raw bytes

1/**
2 * @defgroup js_lib_jquery_plugins
3 */
4
5/**
6 * @file js/lib/jquery/plugins/jquery.pkp.js
7 *
8 * Copyright (c) 2013-2017 Simon Fraser University
9 * Copyright (c) 2000-2016 John Willinsky
10 * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
11 *
12 * @ingroup js_lib_jquery_plugins
13 *
14 * @brief PKP jQuery extensions.
15 */
16
17/** @param {jQuery} $ jQuery closure. */
18(function($) {
19
20
21	/**
22	 * Handler plug-in.
23	 * @this {jQuery}
24	 * @param {string} handlerName The handler to be instantiated
25	 *  and attached to the target HTML element(s).
26	 * @param {Object=} options Parameters to be passed on
27	 *  to the handler.
28	 * @return {jQuery} Selected HTML elements for chaining.
29	 */
30	$.fn.pkpHandler = function(handlerName, options) {
31		// Go through all selected elements.
32		this.each(function() {
33			var $element = $(this);
34
35			// Instantiate the handler and bind it
36			// to the element.
37			options = options || {};
38			var handler = $.pkp.classes.Helper.objectFactory(
39					handlerName, [$element, options]);
40		});
41
42		// Allow chaining.
43		return this;
44	};
45
46
47	/**
48	 * Re-implementation of jQuery's html() method
49	 * with a remote source.
50	 * @param {string} url the AJAX endpoint from which to
51	 *  retrieve the HTML to be inserted.
52	 * @param {object} callback function to be called on ajax success.
53	 * @return {jQuery} Selected HTML elements for chaining.
54	 */
55	$.fn.pkpAjaxHtml = function(url, callback) {
56		var $element = this.first();
57		// using $.ajax instead of .getJSON to handle failures.
58		// .getJSON does not allow for an error callback
59		// this changes with jQuery 1.5
60		$.ajax({
61			url: url,
62			dataType: 'json',
63			success: function(jsonData) {
64				$element.find('#loading').hide();
65				if (jsonData.status === true) {
66					// Replace the element content with
67					// the remote content.
68					if (jsonData.content) {
69						$element.html(jsonData.content);
70					}
71					if (callback) {
72						callback();
73					}
74				} else {
75					// Alert that the remote call failed.
76					$element.trigger('ajaxHtmlError', jsonData.content)
77					alert(jsonData.content);
78				}
79			},
80			error: function() {
81				alert('Failed Ajax request or invalid JSON returned.');
82			}
83		});
84		$element.html("<div id='loading' class='throbber'></div>");
85		return this;
86	};
87
88
89})(jQuery);

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.