View source with raw comments or as raw
   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)  2015, VU University Amsterdam
   7    All rights reserved.
   8
   9    Redistribution and use in source and binary forms, with or without
  10    modification, are permitted provided that the following conditions
  11    are met:
  12
  13    1. Redistributions of source code must retain the above copyright
  14       notice, this list of conditions and the following disclaimer.
  15
  16    2. Redistributions in binary form must reproduce the above copyright
  17       notice, this list of conditions and the following disclaimer in
  18       the documentation and/or other materials provided with the
  19       distribution.
  20
  21    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25    COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  28    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32    POSSIBILITY OF SUCH DAMAGE.
  33*/
  34
  35:- module(jquery, []).
  36:- use_module(library(http/html_head)).
  37:- use_module(library(http/http_server_files)).
  38:- use_module(library(settings)).
  39:- use_module(library(broadcast)).
  40
  41:- setting(version, atom, '1.11.3.min',
  42           'Version of jquery served by the html resource "jquery"').
  43
  44/** <module> Provide JQuery
  45
  46This module provides the HTML  resource   `jquery`.  To  get the default
  47version of jquery included in a web page,  make sure this file is loaded
  48and include the following into the HTML generation DCG.
  49
  50  ==
  51    html_requires(jquery),
  52  ==
  53
  54The file served is determined by the setting `jquery:version` and loaded
  55from the file search path `js`,  the   default  for which is provided by
  56library(http/http_server_files).
  57
  58Note that including jquery into the   HTTP  infrastructure is not ideal.
  59However, components, such  as  PlDoc  and   Pengines  as  well  as  user
  60applications require jquery, causing this JavaScript  to be installed in
  61many places. That is even worse.
  62
  63# Using your own copy
  64
  65To use your own copy of jquery, add   your jquery file to a directory in
  66the   `js`   file   search    path     (see    file_search_path/2    and
  67absolute_file_name/3) and set `jquery:version` to   the file version you
  68provided. Alternatively, you  can  define   the  html  resource `jquery`
  69before loading this file.
  70*/
  71
  72register_jquery :-
  73    setting(version, Version),
  74    atomic_list_concat(['jquery-', Version, '.js'], JQuery),
  75    html_resource(jquery,
  76                  [ virtual(true),
  77                    requires([ js(JQuery)
  78                             ])
  79                  ]).
  80
  81:- if(\+html_current_resource(jquery)).
  82:- initialization register_jquery.
  83:- listen(settings(changed(jquery:version, _, _)),
  84          register_jquery).
  85:- endif.