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