update copyright year
[mkws-moved-to-github.git] / src / mkws-popup.js
index 153425b..54ef152 100644 (file)
@@ -2,43 +2,59 @@
  *
  */
 
-// "use strict";
-
-$(document).ready(function () {
-    // mkws.registerWidgetType('PopupWindow', function() {
+//"use strict";
+// $(document).ready(function () {
+mkws.registerWidgetType('popup', function() {
     var $ = mkws.$;
-    var debug = mkws.log;
+    var debug = this.info;
     debug("init popup window");
 
-    if (!$.ui) {
-        alert("Error: jquery-ui.js is missing, did you include it after jQuery core in the HTML file?");
+    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);
     }
 
-    var popup = $(".PopupWindow");
-    if (!popup) {
-        debug("no popup found");
+    if (!$.ui) {
+        alert("Error: jquery-ui.js is missing, did you include it after jQuery core in the HTML file?");
         return;
-    } else {
-        debug("found popup windows: " + popup.length);
     }
 
-    var width = parseInt($(popup).attr("popup_width") || "800");
-    var height = parseInt($(popup).attr("popup_height") || "600");
-    var autoOpen = parseInt($(popup).attr("popup_autoOpen") || "0");
+    // 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() {}
+        });
 
-    $(popup).dialog({
-        closeOnEscape: true,
-        autoOpen: autoOpen,
-        height: height,
-        width: width,
-        modal: true,
-        resizable: true,
-        buttons: {
-            Cancel: function () {
-                $(popup).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");
+            });
+        }
     });
 });