Author: mgrigorov
Date: Sun Jul 18 09:44:46 2010
New Revision: 965186

URL: http://svn.apache.org/viewvc?rev=965186&view=rev
Log:
Port from wicket-1.4.x

r931519
Author: jcompagner
Date:   Wed Apr 7 12:21:42 2010 UTC (3 months, 1 week ago)
Changed paths:  2
Log Message:    
open up the api a bit for custom showing and closing


Modified:
    
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/modal/ModalWindow.java
    
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/modal/res/modal.js

Modified: 
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/modal/ModalWindow.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/modal/ModalWindow.java?rev=965186&r1=965185&r2=965186&view=diff
==============================================================================
--- 
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/modal/ModalWindow.java
 (original)
+++ 
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/modal/ModalWindow.java
 Sun Jul 18 09:44:46 2010
@@ -25,6 +25,7 @@ import org.apache.wicket.ajax.AjaxReques
 import org.apache.wicket.ajax.IAjaxCallDecorator;
 import org.apache.wicket.ajax.calldecorator.CancelEventIfNoAjaxDecorator;
 import org.apache.wicket.behavior.HeaderContributor;
+import 
org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow.PageCreator;
 import org.apache.wicket.markup.ComponentTag;
 import org.apache.wicket.markup.html.WebMarkupContainer;
 import org.apache.wicket.markup.html.panel.Panel;
@@ -334,7 +335,7 @@ public class ModalWindow extends Panel
         */
        public static final void closeCurrent(AjaxRequestTarget target)
        {
-               target.appendJavascript(getCloseJavacript());
+               target.appendJavascript(getCloseJavacriptInternal());
        }
 
        /**
@@ -351,9 +352,16 @@ public class ModalWindow extends Panel
        }
 
        /**
-        * @return javascript that closes current modal window
+        * Method that allows alternate script for showing the window.
+        * 
+        * @return the script that actually shows the window.
         */
-       private static String getCloseJavacript()
+       protected CharSequence getShowJavascript()
+       {
+               return "Wicket.Window.create(settings).show();\n";
+       }
+
+       private static String getCloseJavacriptInternal()
        {
                return "var win;\n" //
                        + "try {\n"
@@ -374,6 +382,16 @@ public class ModalWindow extends Panel
        }
 
        /**
+        * Method that allows alternate script for closing the window.
+        * 
+        * @return the script that actually closes the window.
+        */
+       protected String getCloseJavacript()
+       {
+               return getCloseJavacriptInternal();
+       }
+
+       /**
         * Returns the id of content component.
         * 
         * <pre>
@@ -811,7 +829,7 @@ public class ModalWindow extends Panel
         * 
         * @return True if user has added own component to the window, false 
otherwise.
         */
-       private boolean isCustomComponent()
+       protected boolean isCustomComponent()
        {
                return getContent() != empty;
        }
@@ -1052,7 +1070,7 @@ public class ModalWindow extends Panel
 
                postProcessSettings(buffer);
 
-               buffer.append("Wicket.Window.create(settings).show();\n");
+               buffer.append(getShowJavascript());
                return buffer.toString();
        }
 

Modified: 
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/modal/res/modal.js
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/modal/res/modal.js?rev=965186&r1=965185&r2=965186&view=diff
==============================================================================
--- 
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/modal/res/modal.js
 (original)
+++ 
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/modal/res/modal.js
 Sun Jul 18 09:44:46 2010
@@ -631,34 +631,34 @@ Wicket.Window.prototype = { 
        show: function() {                                      
                
                // create the DOM elements
-               this.createDOM();                                               
                
+               this.createDOM();
                
                // set the class of window (blue or silver by default)
-               this.classElement.className = this.settings.className;          
                                                        
+               this.classElement.className = this.settings.className;
                
                // is it an iframe window?
                if (this.isIframe()) {
                        // load the file
-                       this.load();                    
+                       this.load();
                } else {
                        // it's an element content
                        
-                       // is the element specified?                    
+                       // is the element specified?
                        if (this.settings.element == null) {
                                throw "Either src or element must be set.";
-                       }                       
+                       }
                        
                        // reparent the element
                        this.oldParent = this.settings.element.parentNode;
-                       
this.settings.element.parentNode.removeChild(this.settings.element);            
                
+                       
this.settings.element.parentNode.removeChild(this.settings.element);
                        this.content.appendChild(this.settings.element);
                        
                        // set the overflow style so that scrollbars are shown 
when the element is bigger than window
                        this.content.style.overflow="auto";
-               }                                                               
                                                                                
                                                
+               }
                
                // bind the events
-               this.bindInit();                
+               this.bindInit();
 
                // if the title is specified set it
                if (this.settings.title != null)
@@ -668,73 +668,79 @@ Wicket.Window.prototype = { 
                // initial width and height
                this.window.style.width = this.settings.width + 
(this.settings.resizable ? "px" : this.settings.widthUnit);
                
-               if (this.settings.height != null)               
-                       this.content.style.height = this.settings.height + 
(this.settings.resizable ? "px" : this.settings.heightUnit);                    
     
+               if (this.settings.height != null)
+                       this.content.style.height = this.settings.height + 
(this.settings.resizable ? "px" : this.settings.heightUnit);
 
                // center the window
-               this.center();                          
+               this.center();
                
                // load position from cookie
                this.loadPosition();
 
                var doShow = function() {
-                       // if there is a previous window  
-                       if (this.oldWindow != null) {
-                               // lower it's z-index so that it's moved under 
the mask
-                               this.oldWindow.window.style.zIndex = 
Wicket.Window.Mask.zIndex - 1;
-                       }                       
-                               
+                       this.adjustOpenWindowZIndexesOnShow();
                        this.window.style.visibility="visible";
                        
                }.bind(this);
                                
-               
-               // is there a window displayed already?
-               if (Wicket.Window.current != null) {
-                       // save the reference to it
-                       this.oldWindow = Wicket.Window.current;
-               }
-               // keep reference to this window
-               Wicket.Window.current = this;
-               
-               // show the window              
+               this.adjustOpenWindowsStatusOnShow();
+
+               // show the window
                if (Wicket.Browser.isGecko() && this.isIframe()) {
                        // HACK
                        // gecko flickers when showing the window
-                       // unless the showing is postponed a little             
                
+                       // unless the showing is postponed a little
                        window.setTimeout(function() { doShow(); }, 0);
                } else {
                        doShow();
-               }               
+               }
 
                // if the content supports focus and blur it, which means
-               // that the already focused element will lose it's focus        
                        
+               // that the already focused element will lose it's focus
                if (this.content.focus) {
                        this.content.focus();
                        this.content.blur();
-               }               
+               }
                // preserve old unload hanler
                this.old_onunload = window.onunload;
                
-               // new unload handler - close the window to prevent memory 
leaks in ie          
-               window.onunload = function() {                  
+               // new unload handler - close the window to prevent memory 
leaks in ie
+               window.onunload = function() {
                        this.close(true);
                        if (this.old_onunload != null)
                                return this.old_onunload();
-               }.bind(this);                           
+               }.bind(this);
                
                // preserve old beforeunload handler
                this.old_onbeforeunload = window.onbeforeunload;
                
                if (Wicket.Window.unloadConfirmation == true) {
                        // new beforeunload handler - ask user before reloading 
window
-                       window.onbeforeunload = function() {                    
+                       window.onbeforeunload = function() {
                                return "Reloading this page will cause the 
modal window to disappear.";
-                       }                               
+                       }
                }
                
-               // create the mask that covers the background           
-               this.createMask();      
+               // create the mask that covers the background
+               this.createMask();
+       },
+       
+       adjustOpenWindowZIndexesOnShow: function() {
+               // if there is a previous window
+               if ((this.oldWindow != null) && (typeof(this.oldWindow) != 
"undefined")) {
+                       // lower it's z-index so that it's moved under the mask
+                       this.oldWindow.window.style.zIndex = 
Wicket.Window.Mask.zIndex - 1;
+               }
+       },
+       
+       adjustOpenWindowsStatusOnShow: function() {
+               // is there a window displayed already?
+               if (Wicket.Window.current != null) {
+                       // save the reference to it
+                       this.oldWindow = Wicket.Window.current;
+               }
+               // keep reference to this window
+               Wicket.Window.current = this;
        },
        
        /**
@@ -747,20 +753,20 @@ Wicket.Window.prototype = { 
        /**
         * Prevent user from closing the window if there's another (nested) 
modal window in the iframe. 
         */
-       canCloseInternal: function() {          
+       canCloseInternal: function() {
                try {
-                       if (this.isIframe() == true) {                          
-                               var current = 
this.content.contentWindow.Wicket.Window.current; 
+                       if (this.isIframe() == true) {
+                               var current = 
this.content.contentWindow.Wicket.Window.current;
                                if (typeof(current) != "undefined" && current 
!= null) {
                                        alert('You can\'t close this modal 
window. Close the top-level modal window first.');
                                        return false;
                                }
                        }
                } catch (ignore) {
-               }       
+               }
                return true;
        },
-               
+       
        /**
         * Closes the window.
         * @param {Boolean} force - internal argument 
@@ -814,17 +820,7 @@ Wicket.Window.prototype = { 
                        this.settings.onClose();
                }
 
-               // if there was a window shown before this one
-               if (this.oldWindow != null) {
-                       // set the old as current
-                       Wicket.Window.current = this.oldWindow;
-                       // increase it's z-index so that it's moved above the 
mask
-                       Wicket.Window.current.window.style.zIndex = 
Wicket.Window.Mask.zIndex + 1;
-                       this.oldWindow = null; 
-               } else {
-                       // remove reference to the window
-                       Wicket.Window.current = null;
-               }                                       
+               this.adjustOpenWindowsStatusAndZIndexesOnClose();
                
                if (Wicket.Browser.isIE()) {
                        // There's a strange focus problem in IE that disables 
focus on entire page,
@@ -841,6 +837,20 @@ Wicket.Window.prototype = { 
                }                                               
        },
        
+       adjustOpenWindowsStatusAndZIndexesOnClose: function() {
+               // if there was a window shown before this one
+               if (this.oldWindow != null) {
+                       // set the old as current
+                       Wicket.Window.current = this.oldWindow;
+                       // increase it's z-index so that it's moved above the 
mask
+                       Wicket.Window.current.window.style.zIndex = 
Wicket.Window.Mask.zIndex + 1;
+                       this.oldWindow = null; 
+               } else {
+                       // remove reference to the window
+                       Wicket.Window.current = null;
+               }
+       },
+       
        /**
         * Cleans the internal state of the window
         */
@@ -1251,50 +1261,60 @@ Wicket.Window.Mask.prototype = {
                        this.dontHide = true;                   
                }
                
-               var doc = document;
-               var old = Wicket.Window.current.oldWindow;
-               if (typeof(old) != "undefined" && old != null) {
-                       doc = old.getContentDocument();
-               }
-               
-               this.document = doc;
-               
-               // disable user interaction
-               setTimeout(function() {this.hideSelectBoxes()}.bind(this), 300);
-               setTimeout(function() {this.disableTabs()}.bind(this), 400);
-               setTimeout(function() {this.disableFocus()}.bind(this), 1000);  
                
+               this.disableCoveredContent();
        },
        
        /**
         * Hides the mask.
         */
        hide: function() {                      
-       
+
                // if the mask is visible and we can hide it
                if (typeof(Wicket.Window.Mask.element) != "undefined" && 
typeof(this.dontHide) == "undefined") {
        
                        // remove element from document 
                        document.body.removeChild(this.element);
-                       this.element = null;                                    
        
+                       this.element = null;
                        
                        // restore old handlers
                        window.onscroll = this.old_onscroll;
                        window.onresize = this.old_onresize;
                                                
-                       Wicket.Window.Mask.element = null;                      
-               }       
+                       Wicket.Window.Mask.element = null;
+               }
                
+               this.reenableCoveredContent();
+       },
+       
+       // disable user interaction for content that is covered by the mask
+       disableCoveredContent: function() {
+               var doc = document;
+               var old = Wicket.Window.current.oldWindow;
+               if (typeof(old) != "undefined" && old != null) {
+                       doc = old.getContentDocument();
+               }
+
+               this.doDisable(doc, Wicket.Window.current);
+       },
+       
+       // disable user interaction for content that is covered by the mask 
inside the given document, taking into consideration that this modal window is 
or not in an iframe
+       // and has the given content
+       doDisable: function(doc, win) {
+               setTimeout(function() {this.hideSelectBoxes(doc, 
win)}.bind(this), 300);
+               setTimeout(function() {this.disableTabs(doc, win)}.bind(this), 
400);
+               setTimeout(function() {this.disableFocus(doc, win)}.bind(this), 
1000);
+       },
+       
+       // reenable user interaction for content that was covered by the mask
+       reenableCoveredContent: function() {
                // show old select boxes (ie only)
                this.showSelectBoxes();
-               
+
                // restore tab order
                this.restoreTabs();
-               
+
                // revert onfocus handlers
                this.enableFocus();
-               
-               this.document = null;
-
        },
        
        /**
@@ -1340,12 +1360,10 @@ Wicket.Window.Mask.prototype = {
         * For internet explorer hides the select boxes (because they
         * have always bigger z-order than any other elements).
         */
-       hideSelectBoxes : function() {                          
+       hideSelectBoxes : function(doc, win) {                          
                if (Wicket.Browser.isIE() && Wicket.Browser.isIE7() == false) {
-                       var win = Wicket.Window.current;                        
                
-                       
                        this.boxes = new Array();
-                       var selects = 
this.document.getElementsByTagName("select");
+                       var selects = doc.getElementsByTagName("select");
                        for (var i = 0; i < selects.length; i++) {              
                
                                var element = selects[i];
                                
@@ -1379,17 +1397,17 @@ Wicket.Window.Mask.prototype = {
        /**
         * Disable focus on element and all it's children.       
         */
-       disableFocusElement: function(element, revertList) {
+       disableFocusElement: function(element, revertList, win) {
                                
-               if (typeof(Wicket.Window.current) != "undefined" &&
-                       Wicket.Window.current != null &&
-                       Wicket.Window.current.window != element) {              
                                                
+               if (typeof(win) != "undefined" &&
+                       win != null &&
+                       win.window != element) {                                
                                
                                
                        revertList.push([element, element.onfocus]);
                        element.onfocus = function() { element.blur(); }        
                
                        
                        for (var i = 0; i < element.childNodes.length; ++i) {
-                               this.disableFocusElement(element.childNodes[i], 
revertList);
+                               this.disableFocusElement(element.childNodes[i], 
revertList, win);
                        }
                }
        },
@@ -1397,14 +1415,14 @@ Wicket.Window.Mask.prototype = {
        /**
         * Disable focus on all elements in document
         */
-       disableFocus: function() {
+       disableFocus: function(doc, win) {
                // explorer doesn't need this, because for IE disableTabs() is 
called.
                // plus in IE this causes problems because it scrolls document  
        );
                if (Wicket.Browser.isIE() == false) {                   
                        this.focusRevertList = new Array();                     
-                       var body = 
this.document.getElementsByTagName("body")[0];                       
+                       var body = doc.getElementsByTagName("body")[0];         
        
                        for (var i = 0; i < body.childNodes.length; ++i) {      
        
-                               this.disableFocusElement(body.childNodes[i], 
this.focusRevertList);
+                               this.disableFocusElement(body.childNodes[i], 
this.focusRevertList, win);
                        }
                }
        },
@@ -1426,44 +1444,39 @@ Wicket.Window.Mask.prototype = {
        /**
         * Disable tab indexes (ie).
         */
-       disableTabs: function () {              
-               this.tabbableTags = new 
Array("A","BUTTON","TEXTAREA","INPUT","IFRAME", "SELECT");
+       disableTabs: function (doc, win) {
+               if (typeof (this.tabbableTags) == "undefined") 
this.tabbableTags = new Array("A","BUTTON","TEXTAREA","INPUT","IFRAME", 
"SELECT");
                if (Wicket.Browser.isIE()) {
-                       var win = Wicket.Window.current;                        
-                       this.tabsAreDisabled = 'true';
+                       this.disabledTabsRevertList = new Array();
                        for (var j = 0; j < this.tabbableTags.length; j++) {
-                               var tagElements = 
this.document.getElementsByTagName(this.tabbableTags[j]);
+                               var tagElements = 
doc.getElementsByTagName(this.tabbableTags[j]);
                                for (var k = 0 ; k < tagElements.length; k++) {
-                                       
                                        // if this is not an iframe window and 
the element is child of window content,
                                        // don't disable tab on it
-                                               if (win.isIframe() == true || 
this.isParent(tagElements[k], win.content) == false) {
+                                       if (win.isIframe() == true || 
this.isParent(tagElements[k], win.content) == false) {
                                                var element = tagElements[k];
                                                element.hiddenTabIndex = 
element.tabIndex;
                                                element.tabIndex="-1";
+                                               
this.disabledTabsRevertList.push(element);
                                        }
                                }
                        }
                }
        },
-       
+
        /**
         * Restore tab indexes if they were disabled.
         */
        restoreTabs: function() {
-               if (typeof(this.tabsAreDisabled) != 'undefined') {
-                       for (var j = 0; j < this.tabbableTags.length; j++) {
-                               var tagElements = 
this.document.getElementsByTagName(this.tabbableTags[j]);
-                               for (var k = 0 ; k < tagElements.length; k++) {
-                                       var element = tagElements[k];
-                                       if (typeof(element.hiddenTabIndex) != 
'undefined') {
-                                               element.tabIndex = 
element.hiddenTabIndex;
-                                               element.hiddenTabIndex = null;
-                                       }
-                                       element.tabEnabled = true;
+               if (typeof (this.disabledTabsRevertList) != "undefined" && 
this.disabledTabsRevertList != null) {
+                       for (var i = 0; i < this.disabledTabsRevertList.length; 
++i) {
+                               var element = this.disabledTabsRevertList[i];
+                               if (typeof(element.hiddenTabIndex) != 
'undefined') {
+                                       element.tabIndex = 
element.hiddenTabIndex;
+                                       delete element.hiddenTabIndex;
                                }
                        }
-                       this.tabsAreDisabled = null;
+                       this.disabledTabsRevertList = null;
                }
        }
 
@@ -1536,7 +1549,7 @@ Wicket.Cookie = { 
                                        end = document.cookie.length;
                                }
                                return 
unescape(document.cookie.substring(start,end))
-               }
+                       }
                } else {
                        return null
                }


Reply via email to