support multiple popup widgets, part of MKWS-235
[mkws-moved-to-github.git] / src / mkws-popup.js
index 153425b..48b5059 100644 (file)
@@ -3,7 +3,6 @@
  */
 
 // "use strict";
-
 $(document).ready(function () {
     // mkws.registerWidgetType('PopupWindow', function() {
     var $ = mkws.$;
@@ -15,30 +14,36 @@ $(document).ready(function () {
         return;
     }
 
-    var popup = $(".PopupWindow");
-    if (!popup) {
-        debug("no popup found");
+    var popup_window = $(".PopupWindow");
+    if (!popup_window) {
+        debug("no popup found, skip");
         return;
     } else {
-        debug("found popup windows: " + popup.length);
+        debug("found popup windows: " + popup_window.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");
+    popup_window.each(function (i) {
+        var that = $(this);
+
+        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");
 
-    $(popup).dialog({
-        closeOnEscape: true,
-        autoOpen: autoOpen,
-        height: height,
-        width: width,
-        modal: true,
-        resizable: true,
-        buttons: {
-            Cancel: function () {
-                $(popup).dialog("close");
-            }
-        },
-        close: function () {}
+        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 () {}
+        });
     });
 });