Show last authors
1 {{warning}}
2 This tutorial is a work in progress.
3 {{/warning}}
4
5 {{toc/}}
6
7 {{info}}
8 This is a Javascript widget bundled by default with the XWiki platform.
9 {{/info}}
10
11 =Usage=
12
13 The Modal Popup is a widget used as a base class for different modal widgets in XWiki, like the [[Confirmation Box>>DevGuide.ConfirmationBox]] or the Jump To Page widget. It will not display a dialog box since it should not be used by itself.
14
15 =Constructor fields for the **ModalPopup** Javascript class=
16 ; content
17 : Object that defines the content of the modal dialog.
18 ; shortcuts
19 : Object that defines the shortcuts that will pop up the dialog.
20 ; options
21 : Object that defines the options for the modal dialog: //title//, //displayCloseButton//, //extraClassName//, //screenColor//, //borderColor//, //titleColor//, //backgroundColor//, //screenOpacity//, //verticalPosition// and //horizontalPosition//.
22
23 =Examples=
24
25 The Modal Popup Javascript class could be used as a base class for a widget that loads the content of another page:
26
27 {{code language="javascript"}}
28 // Make sure the XWiki 'namespace' and the ModalPopup class exist.
29 if(typeof(XWiki) == "undefined" || typeof(XWiki.widgets) == "undefined" || typeof(XWiki.widgets.ModalPopup) == "undefined") {
30 if (typeof console != "undefined" && typeof console.warn == "function") {
31 console.warn("[MessageBox widget] Required class missing: XWiki.widgets.ModalPopup");
32 }
33 } else {
34
35 XWiki.widgets.MyModalPopup = Class.create(XWiki.widgets.ModalPopup, {
36 /** Default parameters can be added to the custom class. */
37 defaultInteractionParameters : {
38 },
39 /** Constructor. Registers the key listener that pops up the dialog. */
40 initialize : function($super, interactionParameters) {
41 this.interactionParameters = Object.extend(Object.clone(this.defaultInteractionParameters), interactionParameters || {});
42 // call constructor from ModalPopup with params content, shortcuts, options
43 $super(
44 this.createContent(this.interactionParameters),
45 {
46 "show" : { method : this.showDialog, keys : [] },
47 "close" : { method : this.closeDialog, keys : ['Esc'] }
48 },
49 {
50 displayCloseButton : true,
51 verticalPosition : "top",
52 backgroundColor : "#FFF"
53 }
54 );
55 this.showDialog();
56 this.setClass("my-modal-popup");
57 },
58 /** Get the content of the modal dialog using ajax */
59 createContent : function (data) {
60 var content = new Element('div', {'class': 'modal-popup'});
61 // get page content for the pageURL
62 new Ajax.Request(data.pageURL,
63 {
64 method:'get',
65 onSuccess: function(transport){
66 var response = transport.responseText || "no response text";
67 content.insert(response);
68 },
69 onFailure: function(){ content.insert('Something went wrong...');
70 }
71 });
72
73 return content;
74 }
75 });
76 } // if the parent widget is defined
77 {{/code}}
78
79 Define the URL of the page to be loaded (in this case the [[DevGuide.AutoSuggestWidgetExample]]) and just call the new widget from the wiki page:
80
81 {{code}}
82 #set($pageURL="$xwiki.getURL('DevGuide.AutoSuggestWidgetExample','view','xpage=plain')")
83 <a href="#" onclick="new XWiki.widgets.MyModalPopup({pageURL: '$pageURL'});">
84 {{/code}}
85
86 {{html wiki="false"}}
87 <script type="text/javascript" language="javascript">
88 // Make sure the XWiki 'namespace' and the ModalPopup class exist.
89 if(typeof(XWiki) == "undefined" || typeof(XWiki.widgets) == "undefined" || typeof(XWiki.widgets.ModalPopup) == "undefined") {
90 if (typeof console != "undefined" && typeof console.warn == "function") {
91 console.warn("[MessageBox widget] Required class missing: XWiki.widgets.ModalPopup");
92 }
93 } else {
94
95 XWiki.widgets.MyModalPopup = Class.create(XWiki.widgets.ModalPopup, {
96 /** Default parameters can be added to the custom class. */
97 defaultInteractionParameters : {
98 },
99 /** Constructor. Registers the key listener that pops up the dialog. */
100 initialize : function($super, interactionParameters) {
101 this.interactionParameters = Object.extend(Object.clone(this.defaultInteractionParameters), interactionParameters || {});
102 // call constructor from ModalPopup with params content, shortcuts, options
103 $super(
104 this.createContent(this.interactionParameters),
105 {
106 "show" : { method : this.showDialog, keys : [] },
107 "close" : { method : this.closeDialog, keys : ['Esc'] }
108 },
109 {
110 displayCloseButton : true,
111 extraClassName : 'mydialog-box',
112 verticalPosition : "top",
113 backgroundColor : "#FFF"
114 }
115 );
116 this.showDialog();
117 this.setClass("my-modal-popup");
118 },
119 /** Get the content of the modal dialog using ajax */
120 createContent : function (data) {
121 var content = new Element('div', {'class': 'modal-popup'});
122 // get page content for the pageURL
123 new Ajax.Request(data.pageURL,
124 {
125 method:'get',
126 onSuccess: function(transport){
127 var response = transport.responseText || "no response text";
128 content.insert(response);
129 }.bind(this),
130 onFailure: function(){ content.insert('Something went wrong...');
131 }
132 });
133
134 return content;
135 }
136 });
137 } // if the parent widget is defined
138 </script>
139 {{/html}}
140
141 {{velocity}}
142 {{html wiki="false"}}
143 #set($pageURL="$xwiki.getURL('DevGuide.AutoSuggestWidgetExample','view','xpage=plain')")
144 Check out the example above live: <a href="#" onclick="new XWiki.widgets.MyModalPopup({pageURL: '$pageURL'});">My Modal Popup</a>.
145 {{/html}}
146 {{/velocity}}
147
148 Widgets bundled by default with XWiki build on top of the Model Popup class:
149
150 * [[Confirmation Box>>DevGuide.ConfirmationBox]] widget
151 * {{scm path="xwiki-platform-core/xwiki-platform-web/src/main/webapp/resources/js/xwiki/widgets/jumpToPage.js"}}Jump to page{{/scm}} widget
152 * {{scm path="xwiki-platform-core/xwiki-platform-web/src/main/webapp/resources/uicomponents/widgets/confirmedAjaxRequest.js"}}Confirmed Ajax Request Box{{/scm}}
153
154 =Tips=
155
156 Check out the Javascript code:
157 * for your wiki instance: **{{{http://localhost:8080/xwiki/bin/skin/resources/js/xwiki/widgets/modalPopup.js}}}**
158 * from GitHub: {{scm path="xwiki-platform-core/xwiki-platform-web/src/main/webapp/resources/js/xwiki/widgets/modalPopup.js"/}}.
159
160 Check out the CSS code:
161 * for your wiki instance: **{{{http://localhost:8080/xwiki/bin/skin/resources/js/xwiki/widgets/modalPopup.css}}}**
162 * from GitHub: {{scm path="xwiki-platform-core/xwiki-platform-web/src/main/webapp/resources/js/xwiki/widgets/modalPopup.css"/}}.

Get Connected