1/* Part of SWI-Prolog 2 3 Author: Jan Wielemaker 4 E-mail: J.Wielemaker@vu.nl 5 WWW: http://www.swi-prolog.org 6 Copyright (c) 2017-2025, VU University Amsterdam 7 SWI-Prolog Solutions b.v. 8 All rights reserved. 9 10 Redistribution and use in source and binary forms, with or without 11 modification, are permitted provided that the following conditions 12 are met: 13 14 1. Redistributions of source code must retain the above copyright 15 notice, this list of conditions and the following disclaimer. 16 17 2. Redistributions in binary form must reproduce the above copyright 18 notice, this list of conditions and the following disclaimer in 19 the documentation and/or other materials provided with the 20 distribution. 21 22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 POSSIBILITY OF SUCH DAMAGE. 34*/ 35 36:- module(jquery, []). 37:- use_module(library(http/html_head)). 38:- use_module(library(http/http_server_files), []). 39:- use_module(library(settings)). 40:- use_module(library(broadcast)). 41 42:- setting(version, atom, 'jquery-3.6.0.min.js', 43 'File name for jquery.js, served as HTML resource "jquery"').
73jquery_dir('web/js'). 74 75global_jquery :- 76 jquery_dir(JQuery), 77 is_absolute_file_name(JQuery). 78 79:- if(global_jquery). 80:- multifile user:file_search_path/2. 81user:file_search_path(js, Dir) :- 82 jquery_dir(Dir). 83:- endif. 84 85ensure_jquery :- 86 html_current_resource(jquery), 87 !. 88ensure_jquery :- 89 register_jquery. 90 91register_jquery :- 92 setting(version, JQuery), 93 html_resource(jquery, 94 [ virtual(true), 95 requires([ js(JQuery) 96 ]) 97 ]). 98 99:- initialization ensure_jquery. 100:- listen(settings(changed(jquery:version, _, _)), 101 register_jquery).
Provide JQuery
This module provides the HTML resource
jquery
. To get the default version of jquery included in a web page, make sure this file is loaded and include the following into the HTML generation DCG.The file served is determined by the setting
jquery:version
and loaded from the file search pathjs
, the default for which is provided by library(http/http_server_files).Note that including jquery into the HTTP infrastructure is not ideal. However, components, such as PlDoc and Pengines as well as user applications require jquery, causing this JavaScript to be installed in many places. That is even worse.
Using your own copy
To use your own copy of jquery, add your jquery file to a directory in the
js
file search path (see file_search_path/2 and absolute_file_name/3) and setjquery:version
to the file version you provided. Alternatively, you can define the html resourcejquery
before loading this file. */