Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: [archived] txp->gallery
justin,
that’s exactly my idea of a perfect gallery-plugin on a html/javascript-basis! Go learn some coding ;-)
/Gerrit.
Offline
Re: [archived] txp->gallery
well, looks like I was able to hack my way to my goal:
check out the picture viewer. i’ll be happy to share the code if anyone is interested. it ain’t pretty.
Offline
Re: [archived] txp->gallery
I would love to get the code! It doesn’t need to be pretty, it seems to works alright!! Cool! Thank you! Post it here or send it via e-Mail!
Offline
Re: [archived] txp->gallery
alright, you asked for it…(please, use with caution, there is nothing plug-n-play about this, it’s highly customized for my own site’s needs):
<pre> //——————————————————————————————————————- // Put together by Max Ziebell under GPL // (blog) http://flashrocket.worldoptimizer.com //——————————————————————————————————————- // contribution by Jeremy Keith // checkout his… // (blog) http://adactio.com and his music // (music) http://www.saltercane.com/ ) // (gallery) http://www.alistapart.com/articles/imagegallery/ //——————————————————————————————————————- function gallery($atts) {
$version = “1.21”;
global $pretext,$img_dir; $pfr = $pretext[‘pfr’]; if (is_array($atts)) extract($atts);
//comment this line if you want to prevent gallery to autoload by default $autoload = (empty($autoload)) ? 0 : $autoload;// <————- if (isset($autoload)) $autoload=intval($autoload); if (!isset($break)) $break=’<br />’;
$type = (empty($type)) ? ‘JSPlaceholder’ : $type; $sortby = (empty($sortby)) ? ‘date’ : $sortby; $sortdir = (empty($sortdir)) ? ‘asc’ : $sortdir;
$q = array( “select * from txp_image”, (!empty($author) or !empty($category)) ? ‘where’ : ‘’, (!empty($author)) ? “author=’$author’” : ‘’, (!empty($author) and !empty($category)) ? “and” : ‘’, (!empty($category)) ? “category=’$category’” : ‘’, “order by”, $sortby, $sortdir, (!empty($limit)) ? “limit $limit” : ‘’ );
//jmrhoades additions $out[] = ‘<!— END WORDS —>’; $out[] = ‘</div>’; $out[] = ‘<!— BEGIN IMAGES —>’; $out[] = ‘<div id=“images”>’;
$rs = getRows(join(’ ‘,$q)); if ($rs) { if ($autoload>count($rs) and isset($autoload)) $autoload = count($rs); switch (strtolower($type)) { case “jsplaceholder”: //just generate JS once global $txpGalleryCounter; if (!isset($txpGalleryCounter)) { $script[] = ‘’; $script[] = ‘<!— gallery ‘.$version.’ functions —>’; $script[] = ‘<script type=“text/javascript” language=“javascript”>’; $script[] = ‘<!—’; $script[] = ‘ var imageArray= new Array();’; $script[] = ‘ var captionArray= new Array();’; $script[] = ‘ function push(array, item) {‘; $script[] = ‘ array[array.length] = item;’; $script[] = ‘ };’; foreach ($rs as $a){ extract($a); $url = $pfr.$img_dir.’/’.$id.$ext; $script[] = “push(imageArray, ‘$url’);”; $caption = htmlentities((($label==“caption”) ? $caption:$alt)); $caption = htmlentities($caption); $script[] = “push(captionArray, ‘$caption’);”; }
$script[] = ‘ var numberOfImages=’.count($rs); $script[] = ‘ var currentImageNum = 0;’; $script[] = ‘ function showNewPic (direction) {‘; $script[] = ‘ if (direction==1){‘; $script[] = ‘ currentImageNum++;’; $script[] = ‘ if (currentImageNum>numberOfImages-1){‘; $script[] = ‘ currentImageNum=0;};’; $script[] = ‘ } else {‘; $script[] = ‘ currentImageNum—;’; $script[] = ‘ if (currentImageNum<0){‘; $script[] = ‘ currentImageNum=numberOfImages-1;};’; $script[] = ‘ }’; $script[] = ‘ document.getElementById(“galleryimage”).src = imageArray[currentImageNum];’; $script[] = ‘ document.getElementById(“gallerycaption”).childNodes0.nodeValue = captionArray[currentImageNum];’; $script[] = ‘ document.getElementById(“imagecount”).childNodes0.nodeValue = currentImageNum+1+” of “+numberOfImages;’; $script[] = ‘ return false;’; $script[] = ‘ }’; $script[] = ‘—>’; $script[] = ‘</script>’; // run level support if (isset($runlevel) and function_exists(“run”)){ set(“galleryjavascript”,join(“\n”,$script)); } else { $out = array_merge($out,$script); } }
//inc galleryCounter $txpGalleryCounter++; $default_id_desc = (isset($descID)) ? $descID : ‘gallery_desc’.$txpGalleryCounter; $default_id_image = (isset($imageID)) ? $imageID : ‘gallery_image’.$txpGalleryCounter;
//generate list foreach($rs as $a) { extract($a); $url = $pfr.$img_dir.’/’.$id.$ext; $temp = ‘’; $title = ‘’; $temp .= ‘’; $temp .= ‘’; $list[] = $temp; }
//jmrhoades additions if (count($rs)>1){ $out[] = ‘<ul>’; $out[] = ‘<li><a onclick=“return showNewPic(0)” href=”#” title=“Previous Image” id=“prev”>previous image</a></li>’; $out[] = ‘<li><a onclick=“return showNewPic(1)” href=”#” title=“Next Image” id=“next”>next image</a></li>’; $out[] = ‘</ul>’; $out[] = ‘<span id=“imagecount”> </span>’; $out[] = ‘<div class=“clear”> </div>’; }
//generate autoload
if (isset($autoload)) {
$out[] = ‘<!— gallery autoload=’.$autoload.’ —>’;
$out[] = ‘<script type=“text/javascript” language=“javascript”>’;
$out[] = ‘<!—’;
$out[] = ‘ setTimeout(\‘document.getElementById(“galleryimage”).src = imageArray[currentImageNum];\’,500);’;
$out[] = ‘ setTimeout(\‘document.getElementById(“gallerycaption”).childNodes0.nodeValue = captionArray[currentImageNum];\’,500);’;
$out[] = ‘ setTimeout(\‘document.getElementById(“imagecount”).childNodes0.nodeValue = currentImageNum+1+” of “+numberOfImages;\’,500);’;
$out[] = ‘—>’;
$out[] = ‘</script>’;
}
//insert list
$temp = ‘’;
$out[] = (!empty($wraptag)) ? tag($temp,$wraptag) : $temp;
//insert placeholders if needed
if (!isset($imageID)) {
$out[]=’<div id=“image”>’;
$out[] = ‘<img id=“galleryimage” alt=” “ src=”“ width=“490” height=“368”/>’;
$out[]=’</div>’;
}
if (!isset($descID)) {
$out[] = ‘<p class=“caption” id=“gallerycaption”> </p>’;
$out[]= ‘<!— END IMAGES —></div><div class=“clear”> </div>’;
}
break; }
return (is_array($list)) ? join(n,$out) : ‘<b>no images found…</b>’;
}
return ‘’;
}
</pre>
Offline