.PopupWindow -> .WmkwsPopup
[mkws-moved-to-github.git] / src / mkws-popup.js
1 /* generic function to open results in a popup window
2  *
3  */
4
5 // "use strict";
6 $(document).ready(function () {
7 // mkws.registerWidgetType('WmkwsPopup', function() {
8     var $ = mkws.$;
9     var debug = mkws.log;
10     debug("init popup window");
11
12     if (!$.ui) {
13         alert("Error: jquery-ui.js is missing, did you include it after jQuery core in the HTML file?");
14         return;
15     }
16
17     var popup_window = $(".WmkwsPopup");
18     if (!popup_window) {
19         debug("no popup found, skip");
20         return;
21     } else {
22         debug("found popup windows: " + popup_window.length);
23     }
24
25     // more than one widget on a page are possible
26     popup_window.each(function (i) {
27         var that = $(this);
28
29         var width = parseInt(that.attr("popup_width") || "800");
30         var height = parseInt(that.attr("popup_height") || "600");
31         var autoOpen = parseInt(that.attr("popup_autoOpen") || "0");
32         var modal = parseInt(that.attr("popup_modal") || "0");
33
34         debug("Popup parameters: width: " + width + ", height: " + height + ", autoOpen: " + autoOpen);
35         that.dialog({
36             closeOnEscape: true,
37             autoOpen: autoOpen,
38             height: height,
39             width: width,
40             modal: modal ? true : false,
41             resizable: true,
42             buttons: {
43                 Cancel: function () {
44                     that.dialog("close");
45                 }
46             },
47             close: function () {}
48         });
49
50         // open at search query submit
51         var id_botton = that.attr("popup_button");
52         if (id_botton) {
53             $(id_botton).button().click(function () {
54                 that.dialog("open");
55             });
56         }
57     });
58 });