From eac2786173549080d8a0816d8b921f70c97f71c2 Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Wed, 12 Feb 2014 15:46:35 +0000 Subject: [PATCH] Move jQuery plugin out of mkws.js into its own file mkws-jquery.js: see MKWS-120 --- tools/htdocs/mkws-jquery.js | 147 +++++++++++++++++++++++++++++++++++++++++++ tools/htdocs/mkws.js | 139 ---------------------------------------- 2 files changed, 147 insertions(+), 139 deletions(-) create mode 100644 tools/htdocs/mkws-jquery.js diff --git a/tools/htdocs/mkws-jquery.js b/tools/htdocs/mkws-jquery.js new file mode 100644 index 0000000..8123b7d --- /dev/null +++ b/tools/htdocs/mkws-jquery.js @@ -0,0 +1,147 @@ +/*! 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.debug("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) { + 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); + } + } + }); +}; + + +(function (j) { + // enable before page load, so we could call it before mkws() runs + _mkws_jquery_plugin(j); +})(jQuery); diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js index a96fd32..2abcfca 100644 --- a/tools/htdocs/mkws.js +++ b/tools/htdocs/mkws.js @@ -1106,141 +1106,6 @@ function team($, teamName) { }; -/* - * implement jQuery plugin $.pazpar2({}) - */ -function _mkws_jquery_plugin ($) { - function debug (string) { - mkws.debug("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) { - 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); - } - } - }); -}; - - // wrapper to call team() after page load (function (j) { mkws.debug = function (string) { @@ -1262,10 +1127,6 @@ function _mkws_jquery_plugin ($) { var debug = mkws.debug; - // enable before page load, so we could call it before mkws() runs - _mkws_jquery_plugin(j); - - mkws.handle_node_with_team = function(node, callback) { var classes = node.className; var list = classes.split(/\s+/) -- 1.7.10.4