6282ceb1ec902edea81d0464346dfd696fb999b7
[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('Popup', 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 = $(this.node); //
18     var popup_window = $(".mkwsPopup");
19     
20     if (!popup_window) {
21         debug("no popup found, skip");
22         return;
23     } else {
24         debug("found popup windows: " + popup_window.length);
25     }
26
27     // more than one widget on a page are possible
28     popup_window.each(function (i) {
29         var that = $(this);
30
31         var width = parseInt(that.attr("popup_width") || "800");
32         var height = parseInt(that.attr("popup_height") || "600");
33         var autoOpen = parseInt(that.attr("popup_autoOpen") || "0");
34         var modal = parseInt(that.attr("popup_modal") || "0");
35
36         debug("Popup parameters: width: " + width + ", height: " + height + ", autoOpen: " + autoOpen);
37         that.dialog({
38             closeOnEscape: true,
39             autoOpen: autoOpen,
40             height: height,
41             width: width,
42             modal: modal ? true : false,
43             resizable: true,
44             buttons: {
45                 Cancel: function () {
46                     that.dialog("close");
47                 }
48             },
49             close: function () {}
50         });
51
52         // open at search query submit
53         var id_botton = that.attr("popup_button");
54         if (id_botton) {
55             $(id_botton).button().click(function () {
56                 that.dialog("open");
57             });
58         }
59     });
60 });