RE: [SMARTY] JavaScript popup

From: Date: Tue, 17 Feb 2004 16:37:23 +0000
Subject: RE: [SMARTY] JavaScript popup
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-10971@lists.php.net to get a copy of this message
Joe, Here's how I did it... ==================================== 1) I made a smarty modifier to insert my JS script tags for me when I pass in the filename of a .js. (It works for cookie handlers, popup windows, any external .js lots of good ones at www.dynamicdrive.com ) Here's the file /SMARTY_DIR/plugins/function.javascript_init.php <?php /* * Smarty plugin * ------------------------------------------------------------- * Type: function * Name: javascript_init * Purpose: write a javascript src (include) tag * ------------------------------------------------------------- */ function smarty_function_javascript_init($params, &$smarty) { if (!empty($params['src'])) { echo "<script type=\"text/javascript\" language=\"JavaScript\" src=\"".$params["src"]."\"></script>\n"; } else { $smarty->trigger_error("javascript_init: missing src parameter."); } } /* vim: set expandtab: */ ?> ==================================== 2) I wrote a javascript popup window controller as a separate .js file, that automatically pads the window when I pass in the image dimensions. //saved as new_window.js relative to web app doc root not Smarty //note change the padding values depending on the design of detail.php, or add additional params as necessary //note remove email linewrap function OpenNewWindow(page,w,h) { OpenWin = this.open( page, "NewWindow", "top=50,left=50,toolbar=yes,height=h+60,width=w+40,location=no,directories=n o,status=no,menubar=yes,scrollbars=yes,resizable=yes"); } ==================================== 3) I then include it in my Smarty.tpl that needs it, inside the <head> like this: {javascript_init src="javascripts/new_window.js"} ==================================== 4) Then links in your app can be written like this. (You can get the 400,500 from php function getimagesize( ) on the fly. http://us4.php.net/manual/en/function.getimagesize.php ) <!-- product.php --> $imageproperties = getimagesize("/full/path/to/image/file.jpg"); $smarty->assign($imgwidth, $imageproperties[0]); $smarty->assign($imgheight, $imageproperties[1]); $smarty->display("product.tpl"); <!-- product.tpl --> <!-- product overview here --> <a href="#" onClick="OpenNewWindow('detail.php?id=12',{$imgwidth},{$imgheight});">Click for Larger Version</a> Hope this works out - some code OTTOMH not tested. Geoffrey D. Hoffman www.salientdigital.com > -----Original Message----- > From: UpFront Technology > Sent: Tuesday, February 17, 2004 8:17 AM > To: Smarty Post > Subject: [SMARTY] JavaScript popup > > > Hello all, > > I am currently using Smarty on a site that incorporates > a small gallery of > items for purchase. I need to have those items display in a > larger window > when the "larger view" link is clicked. I also need > backwards compatibility > for browsers with JavaScript disabled. > > I need to use JavaScript to control the display of the > window (size, > toolbars, etc.). However, I currently have created the > gallery dynamically > (as Smarty and php are so good with) and I need the window to > open with the > photo size (stored in mysql) plus extra room around the photo (for > aesthetics) and also a java "Close Window" button for each new window. > > I have been looking at the popup function, however the > documentation is > limited, and on top of that, my JavaScript knowledge is minimal. > > I would appreciate thoughts and suggestions about how > to get started. > > Thanks > > Joe E. > UpFront Technology

« previous php.smarty.general (#10971) next »