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