From: Mike Taylor Date: Wed, 15 Oct 2014 16:03:49 +0000 (+0100) Subject: Re-add mkws-jquery.js. X-Git-Tag: 1.0.0~192^2~3 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=4a58da8ae4e60a8f786d460148a0ab1270473108;p=mkws-moved-to-github.git Re-add mkws-jquery.js. I'm not sure how this got lost. It was lying around in my tools/htdocs directory and has some git history there, but was also listed in .gitignore and does not exist in head (so is absent from a fresh checkout). We need to maintain it in src (with the rest of the source) and have the Makefile copy it into tools/htdocs. --- diff --git a/src/mkws-jquery.js b/src/mkws-jquery.js new file mode 100644 index 0000000..73bd406 --- /dev/null +++ b/src/mkws-jquery.js @@ -0,0 +1,148 @@ +/*! jQuery plugin for MKWS, the MasterKey Widget Set. + * Copyright (C) 2013-2014 Index Data + * See the file LICENSE for details + */ + +"use strict"; + + +/* + * implement jQuery plugin $.pazpar2({}) + */ +function _mkws_jquery_plugin($) { + function debug(string) { + mkws.log("jQuery.pazpar2: " + string); + } + + function init_popup(obj) { + var config = obj ? obj : {}; + + var height = config.height || 760; + var width = config.width || 880; + var id_button = config.id_button || "input.mkwsButton"; + var id_popup = config.id_popup || ".mkwsPopup"; + + debug("popup height: " + height + ", width: " + width); + + // make sure that jquery-ui was loaded afte jQuery core lib, e.g.: + // + if (!$.ui) { + debug("Error: jquery-ui.js is missing, did you include it after jQuery core in the HTML file?"); + return; + } + + $(id_popup).dialog({ + closeOnEscape: true, + autoOpen: false, + height: height, + width: width, + modal: true, + resizable: true, + buttons: { + Cancel: function() { + $(this).dialog("close"); + } + }, + close: function() { } + }); + + $(id_button) + .button() + .click(function() { + $(id_popup).dialog("open"); + }); + }; + + $.extend({ + + // service-proxy or pazpar2 + pazpar2: function(config) { + if (config == null || typeof config != 'object') { + config = {}; + } + var id_popup = config.id_popup || ".mkwsPopup"; + id_popup = id_popup.replace(/^[#\.]/, ""); + + // simple layout + var div = '\ +
\ +
\ +
\ +
\ +
\ +
'; + + // new table layout + var table = '\ +\ + \ +\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ +
\ +
\ +
\ +
\ +
\ +
\ +
\ +
\ +
\ +
\ +
\ +
\ +
\ +
\ +
\ +
\ +
\ +
\ +
'; + + var popup = '\ +
\ +
\ +
\ +
\ +
\ +
\ +
\ +
' + + if (config && config.layout == 'div') { + debug("jquery plugin layout: div"); + document.write(div); + } else if (config && config.layout == 'popup') { + debug("jquery plugin layout: popup with id: " + id_popup); + document.write(popup); + $(document).ready(function() { init_popup(config); }); + } else { + debug("jquery plugin layout: table"); + document.write(table); + } + } + }); +}; + + +// enable before page load, so we could call it before mkws() runs +_mkws_jquery_plugin(jQuery);