RE: [SMARTY] JavaScript popup

From: Date: Wed, 18 Feb 2004 15:18:15 +0000
Subject: RE: [SMARTY] JavaScript popup
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-10980@lists.php.net to get a copy of this message
Ah, let me guess, you have multiple thumbnail photos on the same page probably. The code I wrote below assumed you have only one $imgwidth and one $imgheight to $smarty->assign. What you'll want to do is instead have $imgwidth and $imgheight become arrays, so you can store multipe widths and heights. It depends on how you have your page setup, if it's hard-coded or outputting the thumbs in a repeat loop. You may want to make a little PHP function 'stripExtension' that lets you pass in the filename 'photo01.jpg' and it returns 'photo01' which would make a nice associative key name... Then you can build your width & height arrays as $imgwidth['photo01'] = 400; $imgwidth['photo02'] = 350; etc. Then in your smarty template do <a href="#" onClick="OpenNewWindow('detail.php?id=12', {$imgwidth.photo01},{$imgheight.photo01});">Click for Larger Version</a> Geoffrey D. Hoffman Lead Web Developer Arizona Interactive Media Group mailto:ghoffman@aztrib.com > -----Original Message----- > From: UpFront Technology [mailto:upfronttechnology@rrohio.com] > Sent: Wednesday, February 18, 2004 6:48 AM > To: Hoffman, Geoffrey > Subject: RE: [SMARTY] JavaScript popup > > > Thanks so much! I used you code and all is well except...the > window will > not re-size based on the size of the photo. i.e. the popup > window is the > same size with every photo. > > Any ideas? > > thanks again. > > Joe > > -----Original Message----- > From: Hoffman, Geoffrey [mailto:ghoffman@aztrib.com] > Sent: Tuesday, February 17, 2004 11:37 AM > To: Smarty general > Cc: j_evans@upfronttechnology.com > Subject: RE: [SMARTY] JavaScript popup > > > 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},{$imghei > ght});">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 > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > >

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