In a comment on a previous post I wrote about Enhancing CFWindow with JavaScript, Nathan asked the question:

"I like the center feature but if you want to move the window to a little below center what function do you call to center then move it down 20 px?"

The answer is to use the Ext.BasicDialog.center() function, then get the windows Ext.Element object using the Ext.BasicDialog.getEl() function. The Ext.Element object has the getX() and getY() methods, which will give you access to the windows X and Y coordinates. You can use those, in combination with the Ext.BasicDialog.moveTo() function, to move the window to your desired position relative to the center.

In the example below, I have created a simple JavaScript function that does that. Click here to try it out.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head>
<title>Reposition A CFWindow From Center</title>
   <script language="JavaScript">
   rePositionWindow = function(windowName){
   
   //Get window object    
   myWindow = ColdFusion.Window.getWindowObject(windowName);
   
   //use the centerfunction to center the window.    
   myWindow.center();
   
   //get the Windows Element object    
   winEl = myWindow.getEl();
   
   //move the window down 20 pixels from it's current position    
   myWindow.moveTo(winEl.getX(),winEl.getY()+20);
   }
   </script>
</head>
<body>

<!--- Button to call the function --->
<input type="button" value="reposition" onclick="rePositionWindow('MyWindow');">

<!--- set up the window. --->
<cfwindow
   name="MyWindow"
   center="true"
   closable="false"
   draggable="true"
   height="200"
   initShow="true"
   minHeight="100"
   minWidth="200"
   modal="false"
   refreshOnShow = "false"
   resizable="true"
   title="My Window"
   width="400">

   Click the button to move this window to 20px below the center
   </cfwindow>

</body>
</html>

Related Blog Entries

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
JayB's Gravatar I was looking for some ideas for a "roving cart" for a store I'm building.I had a look at this today and i made a few additions... seems to work nicely. I thought I'd post in case anyone else was looking for similar functionality...

The only thing I haven't got working which I'd like to implement is maintaining state between catalog sections (via session vars?) Haven't quite wrapped my head around that yet...

code follows

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<!---



---- windowContent.cfm ---
<cfoutput>
<script type="text/javascript">
var showCfWin = #url.showCfWin#
if(showCfWin==true){
   setInterval("rePositionWindow('detail')",1000);
   }
</script>
<h3>CartID: #url.vCartID#</h3>

<button onclick="alert('Deleted Itemid1');">X</button> Item 1<br>
<button onclick="alert('Deleted Itemid2');">X</button> Item 2<br>
<button onclick="alert('Deleted Itemid3');">X</button> Item 3<BR>
</cfoutput>
--------------------------

--->
   
<script type="text/javascript" src="http://10.10.10.225/CFIDE/scripts/ajax/ext/package...;

<script language="JavaScript">
var showCfWin = true
function init(){
   //called from ajaxonload
      myWindow = ColdFusion.Window.getWindowObject('detail');
      myWindow.addButton({
      text:"Hide Cart",
      cls:"x-btn-text-icon",
      handler:hideWin
})
}

function hideWin()
   {
      myWindow = ColdFusion.Window.getWindowObject('detail');
      myWindow.hide()
      showCfWin = false
   }
   
   function showWin()
   {   
      showCfWin=true;
      myWindow = ColdFusion.Window.getWindowObject('detail');
       ///hide so first appearance doesn't cause flashing'
    myWindow.hide();
    myWindow.moveTo(910,205);
    myWindow.show();
   }
   
rePositionWindow = function(windowName){
//Get window object
myWindow = ColdFusion.Window.getWindowObject(windowName);
///hide so appearance doesn't cause flashing'
myWindow.hide();
myWindow.center();
//get the Window Element object
winEl = myWindow.getEl();
if (showCfWin==false){
myWindow.hide();
}
else{
   myWindow.hide();
myWindow.moveTo(910,205);
myWindow.show();
}
}
</script>
</head>

<bodY>
<div style="display:block;width:1100px;border:1px dashed;height:190px;padding:50px;">
<h1>Welcome to our store</h1>
This is our lovely banner.
</div>
<div style="width:1100px;">
<div style="float:right;width:198px;border:1px dashed;text-align:center;height:2000px;">
<button onClick="showWin();">Show Cart</button>
</div>

<div style="height:2000px;width:898px;display:block;border:1px dashed;padding:25px;">
   
<h2>Roving Cart</h2>
<p>
By Jay Bigam (aka SidFishes)
May 28, 2009

</p>
   
   
<p>This snippet provides a cfwindow which scrolls with the page. I developed this for a shopping cart.
It allows customers to see what's in their cart while scrolling on long shopping pages.
Requires an additional file called windowContent.cfm (see commented section in head)</p>

<p>
The original rePositionWindow set the vertical position on load and then stopped. By using the
setInterval function in windowContent.cfm, we call rePositionWindow every 1 second. Since rePositionWindow
finds the current Window Element object relative to the viewport, we can apply myWindow.moveTo(X,Y) and it will
also be relative to the viewport. The rest is just getting the window to show and hide as required.
</p><p>
In the example I pass a url variable on creation of the window to get cart information.
The cfwindow would allow you to delete items from the cart via an ajax call (shown as alert()'s in the example
Because of the setInterval call we are not able to offer any input boxes as these lose focus every second, which
makes entry impossible. For my purposes, delete via ajax is fine.</p>

<p>This has been tested in FF3, IE7 and Safari 3.11 (for pc) </p>
<p>
see http://www.danvega.org/blog/index.cfm/2008/3/7/Add... for adding buttons to cfwindow<BR>
see http://www.coldfusionguy.com/ColdFusion/blog/index...
for original rePositionWindow function
</p>
<strong>important:must include the button.js src to access addButton</strong>

<p>I'm looking</p>

</div>
</div>
<cfset vCartID = left(createuuid(), 10)>
<cfwindow closable="true" initShow="false" name="detail" title ="Your Cart"
         source="windowContent.cfm?vcartid=#vCartID#&showCfWin=true"
         Width="190"   
         height="300"
         y="205"   
         x="910"
         >
</cfwindow>   
<cfset ajaxonload("init")>
</bodY>
</html>
# Posted By JayB | 5/28/08 8:07 PM
JayB's Gravatar obviously (perhaps) the script source path for button.js would vary
# Posted By JayB | 5/28/08 8:09 PM
JayB's Gravatar just noticed my throw together divs in the example were a bit out of whack in FF and Safari...If you edit out all the non-div text (all the <P>'s and <H>'s etc) it will layout properly for the example...

you will have to play around with position based on your layout...

additionally, this does not detect browser resolution ...I expect it wouldn't be that hard to dynamically set the moveTo(X,Y) but I didn't go that far. If your site is set for a specific min width, hard coding the values should be fine... (the example is for w=1024)
# Posted By JayB | 5/28/08 8:20 PM
https://www.bababorses.de/Louis-Vuitton-Damier-Ebene-Canvas-Clapton-PM-Bag-N44243-Magnolia-2361-it.html https://www.bababorses.de/Louis-Vuitton-LV-Trainer-Men-s-Sneakers-Top-Quality-15-5322-it.html https://www.bababorses.de/Celine-Small-Cabas-Bag-In-Black-Leather-it-2087 https://www.bababorses.de/Louis-Vuitton-Heel-10cm-Call-Back-Sandals-Nude-6162-it.html https://www.bababorses.de/LOUIS-VUITTON-BREA-MM-Monogram-Vernis-Leather-In-Magenta-4069-it.html https://www.bababorses.de/Louis-Vuitton-Ring-09-557-it.html https://www.bababorses.de/Louis-Vuitton-Monogram-LV-Square-Espadrilles-Slipper-Sandals-Brown-6371-it.html https://www.bababorses.de/Prada-Golden-Saffiano-Calfskin-Leather-Top-Handle-Bag-it-2956 https://www.bababorses.de/Dior-Diorissimo-Small-Bag-Black-Nappa-Leather-Silvery-Hardware-8001-it-22 https://www.bababorses.de/Louis-Vuitton-Idylle-Blossom-Charms-Necklace-Q94360-406-it.html https://www.bababorses.de/Louis-Vuitton-Color-Blossom-BB-Star-Pendant-Necklace-Red-Gold-309-it.html https://www.bababorses.de/Bvlgari-Serpenti-Original-Leather-Framed-Pochette-Sky-Blue-82121-it-1938 https://www.bababorses.de/Louis-Vuitton-Horizon-55-Trolley-Travel-Luggage-Bag-Taiga-Leather-M30331-Red-6892-it.html https://www.bababorses.de/Fendi-By-The-Way-Small-Croc-Satchel-White-it-2731 https://www.bababorses.de/Louis-Vuitton-Monogram-Canvas-and-PVC-Nano-Bag-M61114-3176-it.html https://www.bababorses.de/Louis-Vuitton-Sarah-Multicartes-Wallet-M61273-Hot-Pink-7624-it.html https://www.bababorses.de/louis-vuitton-speedy-30--Damier-Azur-Canvas-n44367-2300-it.html https://www.bababorses.de/Hermes-Birkin-35cm-cattle-skin-vein-Handbags-blue-golden-it-907 https://www.bababorses.de/Saint-Laurent-Baby-Sac-De-Jour-Bag-In-Rose-Grained-Leather-it-3322 https://www.bababorses.de/Louis-Vuitton-Twist-MM-M53531-M53532-2775-it.html https://www.bababorses.de/Louis-Vuitton-Sunglasses-133-978-it.html https://www.bababorses.de/Louis-Vuitton-Neverfull-MM-M54185-Black-2705-it.html https://www.bababorses.de/Prada-Saffiano-East-West-Medium-Tote-Bag-Nero-it-3042 https://www.bababorses.de/Louis-Vuitton-Compact-Wallet-in-Monogram-Canvas-M63041-7399-it.html https://www.bababorses.de/Prada-Mens-Leather-Pouch-3312-Black-it-3099 https://www.bababorses.de/Louis-Vuitton-Women-s-Escale-Lock-It-Flat-Mule-1A7TOX-Pink-5965-it.html https://www.bababorses.de/Fendi-Baguette-Micro-Monster-Bag-Purple-Multi-it-533 https://www.bababorses.de/Louis-Vuitton-LV-Angel-Stud-Earrings-M64293-435-it.html https://www.bababorses.de/Louis-Vuitton-Damier-Ebene-Canvas-Zippy-Wallet-Evasion-M61360-7219-it.html https://www.bababorses.de/LOUIS-VUITTON-CATOGRAM-SQUARE-SCARF-MP2266-4818-it.html https://www.bababorses.de/Louis-Vuitton-Monogram-Empreinte-Triangle-Shaped-Messenger-Bag-M54330-Black-3865-it.html https://www.bababorses.de/Balenciaga-Velo-Anthracite-store-it-1723 https://www.bababorses.de/Chloe-Marcie-Medium-Satchel-Bag-Cobalt-it-2283 https://www.bababorses.de/louis-vuitton-epi-leather-Soufflot-BB-bag-m55613-black-2580-it.html https://www.bababorses.de/Louis-Vuitton-Dauphine-MM-M55735-4512-it.html https://www.bababorses.de/Louis-Vuitton-Crafty-NeoNoe-MM-bag-black-M45497-2980-it.html https://www.bababorses.de/Louis-Vuitton-Men-Box-Bag-Shoulder-Body-Bag-M44157-Brown-3136-it.html https://www.bababorses.de/Prada-Saffiano-Double-Zip-Executive-Tote-Bag-Gray-it-3025 https://www.bababorses.de/Louis-Vuitton-Epi-Leather-NeoNoe-BB-Bucket-Bag-M53610-Indigo-2564-it.html https://www.bababorses.de/Saint-Laurent-Small-Monogram-Tassel-Satchel-In-Red-Crocodile-Leather-it-3158 https://www.bababorses.de/Louis-Vuitton-Iphone-Case-LV18-59-it.html https://www.bababorses.de/LOUIS-VUITTON--CLASSIC-MINI-PACKBACK-2872-it.html https://www.bababorses.de/Balenciaga-Velo-Anthracite-store-it-1723 https://www.bababorses.de/Louis-Vuitton-Monogram-Ebene-Canvas-Pegase-Legere-53-Business-Rolling-Luggage-6950-it.html https://www.bababorses.de/Louis-Vuitton-Crocodilien-Brillant-Capucines-Mini-Bag-N93429-Black-2231-it.html https://www.bababorses.de/Louis-Vuitton-Monogram-Hoodie-Jacket-Black-1526-it.html https://www.bababorses.de/Louis-Vuitton-Monogram-Coated-Canvas-Popincourt-PM-M43462--Raisin-3345-it.html https://www.bababorses.de/Louis-Vuitton-Lockme-Cabas-Tote-M55028-Black-4530-it.html https://www.bababorses.de/Givenchy-Antigona-Small-Leather-Satchel-Bag-Black-it-2432 https://www.bababorses.de/Louis-Vuitton-Monogram-Canvas-Small-Malle-Chain-Bag-3294-it.html https://www.bababorses.de/Louis-Vuitton-Epi-Leather-Zippy-Wallet-M62304-Red-7304-it.html https://www.bababorses.de/Louis-Vuitton-Iphone-Case-LV113-38-it.html https://www.bababorses.de/Louis-Vuitton-Heel-10.5cm-Eyeline-Pumps-Python-Pattern-Suede-Black-5999-it.html https://www.bababorses.de/LOUIS-VUITTON-PEGASE-LEGERE-REGATTA-N41620-MONOGRAM-CANVAS-6974-it.html https://www.bababorses.de/Louis-Vuitton-Kimono-Wallet-M56175-Pink-7437-it.html https://www.bababorses.de/Louis-Vuitton-Monogram-Tapestry-Denim-Bidart-Espadrilles-Blue-5726-it.html https://www.bababorses.de/Louis-Vuitton-Women-s-Escale-Shirtdress-Blue-1709-it.html https://www.bababorses.de/Louis-Vuitton-Montaigne-MM-M41048-Black-4597-it.html https://www.bababorses.de/Louis-Vuitton-Heel-10cm-Crystals-Call-Back-Sandals-Suede-Red-6160-it.html https://www.bababorses.de/Hermes-Bolide-31cm-Togo-Leather-Green-Bag-it-1070 https://www.bababorses.de/Replica-Hermes-Wallet-H001-Wallet-Cow-Leather-Green-it-1558 https://www.bababorses.de/Celine-Medium-Luggage-Tote-Black-Brown-White-Bag-it-2168 https://www.bababorses.de/Louis-Vuitton-Pochette-Voyage-MM-Bag-Damier-Graphite-Canvas-Pixel-N60176-Green-7278-it.html https://www.bababorses.de/Fendi-Black-Snake-Veins-Leather-With-Beige-Ferrari-Leather-Top-handle-Bag-it-469 https://www.bababorses.de/Louis-Vuitton-All-over-Monogram-Sleeveless-Belted-Dress-Navy-1375-it.html https://www.bababorses.de/Louis-Vuitton-Ring-02-560-it.html https://www.bababorses.de/Louis-Vuitton-Iphone-Case-LV32-76-it.html https://www.bababorses.de/Louis-Vuitton-Dauphine-MM-M55071-Blue-4511-it.html https://www.bababorses.de/Louis-Vuitton-Supreme-Iphone-Case-White-Red-212-it.html https://www.bababorses.de/Louis-Vuitton-Epi-Smooth-Leather-Twist-Shoulder-Bag-MM-Pink-Black-2639-it.html https://www.bababorses.de/Louis-Vuitton-Monogram-Empreinte-Leather-Cosmetic-Pouch-Bag-M80502-Bouton-de-Rose-Pink-By-The-Pool-Capsule-Collection-4296-it.html https://www.bababorses.de/Louis-Vuitton-Bracelet-21-271-it.html https://www.bababorses.de/Louis-Vuitton-Heel-9.5-cm-Star-Trail-Ankle-Boots-Black-5511-it.html https://www.bababorses.de/Louis-Vuitton-Geronimos-Belt-Bag-M43502-Black-Epi-Leather-2646-it.html https://www.bababorses.de/Louis-Vuitton-Damier-Ebene-Canvas-Vavin-Chain-Wallet-N60222-Bordeaux-Red-7221-it.html https://www.bababorses.de/Louis-Vuitton-Monogram-Empreinte-Leather-Zippy-Coin-Purse-M80408-Cream-Saffron-By-The-Pool-Capsule-Collection-7741-it.html https://www.bababorses.de/Louis-Vuitton-Vintage-Monogram-Vernis-Bleecker-Box-Top-Handle-Bag-Burgundy-4172-it.html https://www.bababorses.de/Prada-Saffiano-Mini-Galleria-Crossbody-Bag-Beige-it-2708 https://www.bababorses.de/Louis-Vuitton-Sunglasses-39-1042-it.html https://www.bababorses.de/Louis-Vuitton-Monogram-Canvas-Leopard-Print-Onthego-Tote-Bag-M44674-Black-White-3232-it.html https://www.bababorses.de/Louis-Vuitton-Epi-Leather-Twist-PM-Bag-with-Crystal-embellished-Chain-M55412-White-2630-it.html https://www.bababorses.de/Fendi-Chameleon-Red-Cross-Veins-Leather-Tote-Bag-it-488 https://www.bababorses.de/Louis-Vuitton-Monogram-Canvas-Onthego-Tote-Bag-M44571-Kaki-3270-it.html https://www.bababorses.de/Fendi-Earth-Yellow-Leather-with-Multicolor-Striped-Fabric-Shopping-Handbag-it-771 https://www.bababorses.de/Louis-Vuitton-Croco-Pattern-Petite-Boite-Chapeau-Bag-Black-4090-it.html https://www.bababorses.de/Prada-Saffiano-Small-Double-Handle-Tote-Bag-Light-Gray-Pomice-it-2849 https://www.bababorses.de/Louis-Vuitton-Lvxlol-Speedy-BB-M45202-Golden-3125-it.html https://www.bababorses.de/Louis-Vuitton-Gloria-Flat-Open-Back-Loafers-Monogram-Canvas-5798-it.html https://www.bababorses.de/LOUIS-VUITTON-BREA-PM-Monogram-Vernis-leather-IN-MORDORE-4074-it.html https://www.bababorses.de/Replica-Hermes-Steve-H2810-Ladies-Shoulder-Bag-Cow-Leather-it-1428 https://www.bababorses.de/Louis-Vuitton-Noe-bag-M42226-Brown-3496-it.html https://www.bababorses.de/Louis-Vuitton-Damier-Azur-Canvas-I-2260-it.html https://www.bababorses.de/Christian-Dior-Multicolor-PeachYellow-Zipper-Wallet-118-it-223 https://www.bababorses.de/Fendi-By-the-Way-Small-Tricolor-Satchel-Bag-it-2916 https://www.bababorses.de/Prada-Medium-Vitello-Diano-Open-Tote-Bag-Pomice-it-2728 https://www.bababorses.de/Luxury-Hermes-Wallet-H001-Unisex-Wallet-it-1598 https://www.bababorses.de/Louis-Vuitton-Iphone-Case-LV42-104-it.html https://www.bababorses.de/Prada-Saffiano-Small-Gardeners-Tote-Bag-Blue-it-2803 https://www.bababorses.de/Louis-Vuitton-Sac-Tricot-Bag-Epi-Leather-Red-M52805-2736-it.html https://www.bababorses.de/Louis-Vuitton-Crazy-in-Lock-Strass-Bracelet-Silver-316-it.html