So all of your friends are on ColdFusion 8 and your jealous of them. I don't blame you at all because CF8 is awesome but like you our production servers are still on 7. One of the cool new things about ColdFusion 8 is all the new Ajax UI stuff. One new feature I really like is cfwindow. CFWindow allows you to create a popup like dialog without actually creating a browser popup window. To me this is a more effective and stylish way of displaying popup content.
If you did not already know this ColdFusion makes use of the http://www.extjs.com JavaScript framework. This means that we can create our own popup windows with just a little bit of JS Knowledge. I am going to walk you through how to create your own popup windows. The first thing you need to do is head over and download the framework at http://extjs.com/download. After you have finished donwloading extract the contents to your project root so you have a structure similair to this.
+project_root
-ext-2.0
-index.cfm
Now that we are all setup go ahead and open our index.cfm page. The first thing we need to do is include the correct JavaScript files. I have to admit when I first got started with ext this would always bother me. I never understood what files were mandatory and what order they needed to go in. This is of course because I did not realize there was INCLUDE_ORDER.txt file right in the root. If you open up this file you will see the following text.
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
All adapter related files below are located in
/adapters/<lib name>/ of this zip file.
Your include order should be:
Ext Stand-alone
-------------------------------------------------------------------
ext-base.js
ext-all.js (or your choice of files)
Yahoo! UI (.12+)
-------------------------------------------------------------------
yui-utilities.js
ext-yui-adapter.js
ext-all.js (or your choice of files)
jQuery (1.1+)
-------------------------------------------------------------------
jquery.js
jquery-plugins.js // required jQuery plugins
ext-jquery-adapter.js
ext-all.js (or your choice of files)
Prototype (1.5+) / Scriptaculous (1.7+)
-------------------------------------------------------------------
prototype.js
scriptaculous.js?load=effects (or whatever you want to load)
ext-prototype-adapter.js
ext-all.js (or your choice of files)
See the examples folders for more examples.
1All adapter related files below are located in
2/adapters/<lib name>/ of this zip file.
3
4Your include order should be:
5
6Ext Stand-alone
7-------------------------------------------------------------------
8ext-base.js
9ext-all.js (or your choice of files)
10
11
12Yahoo! UI (.12+)
13-------------------------------------------------------------------
14yui-utilities.js
15ext-yui-adapter.js
16ext-all.js (or your choice of files)
17
18
19jQuery (1.1+)
20-------------------------------------------------------------------
21jquery.js
22jquery-plugins.js // required jQuery plugins
23ext-jquery-adapter.js
24ext-all.js (or your choice of files)
25
26
27Prototype (1.5+) / Scriptaculous (1.7+)
28-------------------------------------------------------------------
29prototype.js
30scriptaculous.js?load=effects (or whatever you want to load)
31ext-prototype-adapter.js
32ext-all.js (or your choice of files)
33
34
35
36See the examples folders for more examples.
This file explains to us in what order and what files we need to include if we are using ext as a stand alone or using another framework like jquery as an adapter. More or that another time but for now we will just be using ext as a stand alone. In the head of your page use the following code based on our directory setup from above. We are using the base and and ext-all script. If we were moving to production we would probably want to just include the files we needed because all script is fairly large, but for example purposes we can just use that. We also have a link to the css file that provides our look and feel. Again, you can change this to only include what we need later but for testing this is fine.
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
<!-- extjs includes -->
<script type="text/javascript" language="javascript" src="ext-2.0/adapter/ext/ext-base.js"></script>
<script type="text/javascript" language="javascript" src="ext-2.0/ext-all.js"></script>
<link href="ext-2.0/resources/css/ext-all.css" type="text/css" rel="stylesheet"/>
1<!-- extjs includes -->
2<script type="text/javascript" language="javascript" src="ext-2.0/adapter/ext/ext-base.js"></script>
3<script type="text/javascript" language="javascript" src="ext-2.0/ext-all.js"></script>
4<link href="ext-2.0/resources/css/ext-all.css" type="text/css" rel="stylesheet"/>
We are all ready to go, now we can start coding. To create a window we use the Ext.Window() constructor.
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
<script type="text/javascript" language="javascript">
var win = new Ext.Window();
</script>
1<script type="text/javascript" language="javascript">
2 var win = new Ext.Window();
3</script>
While the code above will work it really does not do much. We need to provide our window some attributes. We doing this by passing in an array of configuration options. At the very basic we should give our window a width, height and a title.
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
<script type="text/javascript" language="javascript">
var win = new Ext.Window({
width:400,
height:200,
title:"Ext Window Example"
});
</script>
1<script type="text/javascript" language="javascript">
2 var win = new Ext.Window({
3 width:400,
4 height:200,
5 title:"Ext Window Example"
6 });
7</script>
And that is all there is to it, you have created a window. That is great except the fact that if you ran this example it would not do anything. Nope this example will not produce any output. First we need something to activate our window and we actually need to show our window. To accomplish this I am going to put a button on a page, when you click this button it will call a function showWindow. Inside of showWindow we will create our window and using a method show() our window will become visible. Below is the code to create our basic window as well as a quick demo.
Basic Window Example
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
<html>
<head>
<title>My Window Example</title>
<!-- extjs includes -->
<script type="text/javascript" language="javascript" src="ext-2.0/adapter/ext/ext-base.js"></script>
<script type="text/javascript" language="javascript" src="ext-2.0/ext-all.js"></script>
<link href="ext-2.0/resources/css/ext-all.css" type="text/css" rel="stylesheet"/>
<script type="text/javascript" language="javascript">
function showWindow() {
var win = new Ext.Window({
width:400,
height:200,
title:"Ext Window Example"
});
win.show();
}
</script>
</head>
<body>
<div style="padding:20px;">
<input type="button" id="btnHello" value="Open My Window" onclick="showWindow();">
</div>
</body>
</html>
1<html>
2<head>
3 <title>My Window Example</title>
4 <!-- extjs includes -->
5 <script type="text/javascript" language="javascript" src="ext-2.0/adapter/ext/ext-base.js"></script>
6 <script type="text/javascript" language="javascript" src="ext-2.0/ext-all.js"></script>
7 <link href="ext-2.0/resources/css/ext-all.css" type="text/css" rel="stylesheet"/>
8
9 <script type="text/javascript" language="javascript">
10 function showWindow() {
11 var win = new Ext.Window({
12 width:400,
13 height:200,
14 title:"Ext Window Example"
15 });
16 win.show();
17 }
18 </script>
19</head>
20
21<body>
22
23 <div style="padding:20px;">
24 <input type="button" id="btnHello" value="Open My Window" onclick="showWindow();">
25 </div>
26
27</body>
28</html>
So far so good but we have just scratched the surface on what we can do. If you look at the docs for Window you will see that there are a ton of configuration options that we can use to enhance our window. Here is list of the options I use often.
- autoScroll: True to use overflow:'auto' on the panel's body element and show scroll bars automatically when necessary, false to clip any overflowing content (defaults to false).
- modal: True to make the window modal and mask everything behind it when displayed, false to display it without restricting access to other UI elements (defaults to false).
- html: An HTML fragment, or a DomHelper specification to use as the panel's body content (defaults to '').
- animateTarget: Id or element from which the window should animate while opening (defaults to null with no animation).
- autoLoad: A valid url spec according to the Updater Ext.Updater.update method. If autoLoad is not null, the panel will attempt to load its contents immediately upon render. The URL will become the default URL for this panel's body element, so it may be refreshed at any time.
In our advanced example we will use many of these. The modal option is nice because it really brings focus to the window and does not allow the user to click anywhere else on the page. The html will be the content that the box is going to use. You could load and external url using the autoLoad feature but we will cover that in a later example. Finally the animate target allows us to create a nice animation of the window from an element to the window. This creates a nice fly in affect that is not necessary but sure does look nice. Here is the code to create our advanced example as well as a link to check it out.
Advanced Example
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
<cfsavecontent variable="htmlcontent">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas ante lectus, mollis eget, rutrum sit amet, venenatis quis, quam. Sed posuere massa et leo. Ut sodales arcu at nulla. Cras tempus sagittis ligula. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Aliquam ante urna, vehicula eu, scelerisque ac, aliquam ac, magna. Etiam quis pede at est eleifend dapibus. Integer tristique, tellus sit amet malesuada iaculis, justo urna cursus nisl, a convallis lacus risus eget orci. Etiam elit arcu, pulvinar id, mollis in, mollis in, nibh. Quisque tincidunt. Proin dapibus tellus non nulla. Integer et metus. Praesent viverra, sapien id blandit tempor, est orci viverra diam, in molestie enim eros sed diam. Quisque dolor enim, fermentum sed, egestas eu, semper eget, sapien. Donec in diam. Morbi cursus gravida est. Donec eleifend metus eu purus. Nam mattis nisl ac lorem.</p>
<br /><br />
<p>Nam venenatis, pede vitae commodo tristique, eros diam rhoncus ante, ut porta dolor pede fringilla magna. Proin pretium euismod massa. Integer at dolor. In mollis risus sed arcu. Vestibulum tortor est, lobortis non, imperdiet a, mollis eget, libero. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Vivamus vel sapien. Ut facilisis convallis purus. Nulla facilisi. Quisque non lectus sit amet quam facilisis pharetra. Etiam dolor enim, auctor venenatis, dignissim a, scelerisque feugiat, erat. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>
<br /><br />
<p>Etiam varius eros eu arcu egestas fringilla. Fusce dignissim lorem at felis. Aenean aliquet, tellus in adipiscing laoreet, elit nisl eleifend dui, et interdum turpis leo nec felis. Mauris at arcu vel ante ornare elementum. Ut vehicula arcu sed ligula. Vivamus sollicitudin dui. Nunc nec quam vel tortor molestie rutrum. Suspendisse quis eros ac elit luctus convallis. Cras malesuada. Cras ac orci.</p>
</cfsavecontent>
<html>
<head>
<title>My Window Example</title>
<!-- extjs includes -->
<script type="text/javascript" language="javascript" src="../ext-2.0/adapter/ext/ext-base.js"></script>
<script type="text/javascript" language="javascript" src="../ext-2.0/ext-all.js"></script>
<link href="../ext-2.0/resources/css/ext-all.css" type="text/css" rel="stylesheet"/>
<script type="text/javascript" language="javascript">
<cfoutput>#toScript(htmlcontent,"html")#</cfoutput>
function showWindow() {
var win = new Ext.Window({
width:400,
height:200,
title:"Ext Window Example",
autoScroll:true,
modal:true,
html:html,
animateTarget:"btnHello"
});
win.show();
}
</script>
</head>
<body>
<div style="padding:20px;">
<input type="button" id="btnHello" value="Open My Window" onclick="showWindow();">
</div>
</body>
</html>
1<cfsavecontent variable="htmlcontent">
2<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas ante lectus, mollis eget, rutrum sit amet, venenatis quis, quam. Sed posuere massa et leo. Ut sodales arcu at nulla. Cras tempus sagittis ligula. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Aliquam ante urna, vehicula eu, scelerisque ac, aliquam ac, magna. Etiam quis pede at est eleifend dapibus. Integer tristique, tellus sit amet malesuada iaculis, justo urna cursus nisl, a convallis lacus risus eget orci. Etiam elit arcu, pulvinar id, mollis in, mollis in, nibh. Quisque tincidunt. Proin dapibus tellus non nulla. Integer et metus. Praesent viverra, sapien id blandit tempor, est orci viverra diam, in molestie enim eros sed diam. Quisque dolor enim, fermentum sed, egestas eu, semper eget, sapien. Donec in diam. Morbi cursus gravida est. Donec eleifend metus eu purus. Nam mattis nisl ac lorem.</p>
3<br /><br />
4<p>Nam venenatis, pede vitae commodo tristique, eros diam rhoncus ante, ut porta dolor pede fringilla magna. Proin pretium euismod massa. Integer at dolor. In mollis risus sed arcu. Vestibulum tortor est, lobortis non, imperdiet a, mollis eget, libero. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Vivamus vel sapien. Ut facilisis convallis purus. Nulla facilisi. Quisque non lectus sit amet quam facilisis pharetra. Etiam dolor enim, auctor venenatis, dignissim a, scelerisque feugiat, erat. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>
5<br /><br />
6<p>Etiam varius eros eu arcu egestas fringilla. Fusce dignissim lorem at felis. Aenean aliquet, tellus in adipiscing laoreet, elit nisl eleifend dui, et interdum turpis leo nec felis. Mauris at arcu vel ante ornare elementum. Ut vehicula arcu sed ligula. Vivamus sollicitudin dui. Nunc nec quam vel tortor molestie rutrum. Suspendisse quis eros ac elit luctus convallis. Cras malesuada. Cras ac orci.</p>
7</cfsavecontent>
8
9<html>
10<head>
11 <title>My Window Example</title>
12 <!-- extjs includes -->
13 <script type="text/javascript" language="javascript" src="../ext-2.0/adapter/ext/ext-base.js"></script>
14 <script type="text/javascript" language="javascript" src="../ext-2.0/ext-all.js"></script>
15 <link href="../ext-2.0/resources/css/ext-all.css" type="text/css" rel="stylesheet"/>
16
17 <script type="text/javascript" language="javascript">
18 <cfoutput>#toScript(htmlcontent,"html")#</cfoutput>
19 function showWindow() {
20 var win = new Ext.Window({
21 width:400,
22 height:200,
23 title:"Ext Window Example",
24 autoScroll:true,
25 modal:true,
26 html:html,
27 animateTarget:"btnHello"
28 });
29 win.show();
30 }
31 </script>
32</head>
33
34<body>
35
36 <div style="padding:20px;">
37 <input type="button" id="btnHello" value="Open My Window" onclick="showWindow();">
38 </div>
39
40</body>
41</html>
There it is your very own window and lets be honest this one looks a little better than the default one in ColdFusion8. This may seem like a lot at first but once you understand what is going on here, it is pretty easy. As a side note I am using toScript in the example above, this makes sure our html string is javascript safe. I wrote an example of this today so check the archives. If anyone has any questions or comments I would love to hear them.
This entry was posted on January 6, 2008 at 6:24 PM and has received 32679 views. Comments 17 |
Print this entry.
#1 by ziggy on 1/6/08 - 10:36 PM
#2 by Dam Vega on 1/6/08 - 10:37 PM
#3 by Justin Carter on 1/6/08 - 10:51 PM
#4 by Rey Bango on 1/7/08 - 10:39 AM
#5 by Steve Brownlee on 1/8/08 - 10:40 AM
I posted a brief example on my blog:
<a href="http://www.fusioncube.net/?p=181">Splittin... Ext is good food</a>
#6 by Dan Vega on 1/8/08 - 10:47 AM
*I enjoy your articles Steve, keep up the great work!
#7 by Steve Brownlee on 1/8/08 - 11:08 AM
#8 by Rey Bango on 1/8/08 - 11:39 AM
#9 by Steve Brownlee on 1/8/08 - 12:48 PM
Only when bandwidth is at a real premium would someone need to strip out low-level features such as resizing, moving, icons and the like.
#10 by Hal Helms on 1/28/08 - 3:40 PM
Thanks for the demo.
#11 by Dan Vega on 1/28/08 - 3:44 PM
#12 by Matt on 4/4/08 - 7:28 PM
- fixed size (no need for resize)
- dragable
- clode 'x' button in top right
Thanks :o)
Matt
#13 by Stanley Pasons on 5/18/08 - 8:45 AM
http://www.usbusinesssites.com
#14 by Laron on 3/8/09 - 12:42 PM
I am from Kosovo and learning to speak English, give please true I wrote the following sentence: "As the if you are unsure as to how to remove the drive bracket then see the avs tivo."
Thanks :p. Laron.
#15 by Don on 6/28/09 - 10:59 PM
Have you tried to simulate EXT window like cfwindow in advanced mode, like first load two windows
(one being the main one and the other pop up
and the latter is initially set to hide or show="false", then, upon certain event, pass a value
being it a FORM element or URL parameter to the hidden window and, run some process and display data at the pop up.
Thanks.
Don
#16 by Chris on 3/24/10 - 7:01 PM
I'm trying to just use the CFwindow tag on my page. But when I do that CF automatically includes the ext-all.js and I (seemingly) have no control over that.
You're all mentioning that I can break out just the scripts I need, and that's great, but that doesn't seem to be an option when using the cfwindow tag, as CF determines the scripts to use automatically. And it always just uses ext-all.js, which is far too heavy going.
Also this doean't every seem to get cached, and as a result every page load on my site (which uses popup windows on every page) ends up running like a dog as I'm starting with 500kb per page load before I even get started on the content.
I cannot believe that this would be acceptable to the CF gods. I must be missing something.
Any ideas? Or did I indeed miss something.
#17 by Dan Vega on 3/30/10 - 8:18 AM