X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=src%2Fmkws-popup.js;h=54ef15218537a620fd6830941e852e390e41ce4b;hb=2bc3efcb19167c0ea34070c8392229f2aa46986e;hp=41456529842ba32caf58e37e46f3414394e20a5a;hpb=0f1ee6d712ecafbae03166f6fda9407d28be4608;p=mkws-moved-to-github.git diff --git a/src/mkws-popup.js b/src/mkws-popup.js index 4145652..54ef152 100644 --- a/src/mkws-popup.js +++ b/src/mkws-popup.js @@ -1,149 +1,60 @@ -/*! jQuery plugin for MKWS, the MasterKey Widget Set. - * Copyright (C) 2013-2014 Index Data - * See the file LICENSE for details +/* generic function to open results in a popup window + * */ -"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); +//"use strict"; +// $(document).ready(function () { +mkws.registerWidgetType('popup', function() { + var $ = mkws.$; + var debug = this.info; + debug("init popup window"); + + var popup_window = $(this.node); + // var popup_window = $(".mkws-popup mkwsPopup"); // $(document).ready() + if (!popup_window) { + debug("no popup found, skip..."); + return; + } else { + debug("number of popup windows found: " + popup_window.length); + } - // 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; + alert("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"); + // more than one widget on a page are possible + popup_window.each(function(i) { + var that = $(this); + + // all atributes are strings, convert them to integers here + var width = parseInt(that.attr("popup_width") || "800"); + var height = parseInt(that.attr("popup_height") || "600"); + var autoOpen = parseInt(that.attr("popup_autoOpen") || "0"); + var modal = parseInt(that.attr("popup_modal") || "0"); + + debug("Popup parameters: width: " + width + ", height: " + height + ", autoOpen: " + autoOpen); + that.dialog({ + closeOnEscape: true, + autoOpen: autoOpen, + height: height, + width: width, + modal: modal ? true : false, + resizable: true, + buttons: { + Cancel: function() { + that.dialog("close"); + } + }, + close: function() {} + }); + + // open at search query submit: "input.mkws-button mkwsButton" + var id_botton = that.attr("popup_button"); + if (id_botton) { + $(id_botton).button().click(function() { + that.dialog("open"); + }); } - }, - 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 = '\ -\ - \ -\ - \ - \ - \ - | \ -
\
- \
- \
- \
- \
- \
- \
- \
- | \
-
\ - | \ - \ -
\ - \ - | \ -