Location: PHPKode > projects > Stelib > stelib-1.2.1/stelib_mootools.php
<?php
/**
* @version $Id: stelib_mootols.php 2008-01-04 00:00:00
* @package stelib
* @author Stefano Sangalli
* @copyright Copyright (C) 2007 GCODE Srl. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* stelib is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
//!  mootools(): oggetto per gestione delle librerie mootools.
/*!
	Questo oggetto permette di sfruttare al meglio le potenzialita' delle librerie javaScript mootools.
*/
class mootools extends Page{
	var $SELECTED = -1;
	/// Costruttore
	function mootools() {
		echo "<script type=\"text/javascript\" src=\"".URL_STELIB_PUBLIC."/mootools-release-1.11.js\"></script>";
	}
	/// Crea una lista di oggetti (div) da slittare
	function addSlideList(
		/// Array che contiene l'elenco degli oggetti (div) da slittare
		$objectList,
		/// Array che contiene l'elenco dei nomi degli anchor per i rispettivi div da slittare
		$anchorList,
		/// Azione da compiere: .... Di default toggle
		$action,
		/// Direzione dello slittamento: vertical-horizontal. Di default vertical
		$direction
	) {
		if (!$direction) { $direction="vertical"; }
		echo ("<script type=\"text/javascript\">
					window.addEvent('domready', function(){
		");
		for ($cont=0;$cont<count($objectList);$cont++) {
			echo "	var mySlide$cont = new Fx.Slide('".$objectList[$cont]."', {mode: '".$direction."'});";
			if (str_replace("object","",$objectList[$cont]) <> $this->SELECTED) {
				echo "mySlide$cont.hide();";
			}
			echo "	$('".$anchorList[$cont]."').addEvent('click', function(e$cont){
							e$cont = new Event(e$cont);
							mySlide$cont.toggle();
							e$cont.stop();
						});
			";
		}
		echo ("
				});
			</script>
		");
	}

	/// Crea un link per slittare un anchor
	function addSlideAnchor(
		/// id dell'anchor. Corrisponde alla definizione dell'array anchorList, usato per la costruzione della SlideList
		$id,
		/// Etichetta dell'anchor
		$label,
		/// Classe di stile
		$class,
		/// Parametri di stile aggiuntivi
		$style
	) {
			echo "<a id=\"".$id."\" href=\"#\" class=\"".$class."\" style=\"".$style."\">".$label."<a/>";
	}

	function addSlideDiv(
		/// id del DIV
		$id,
		/// Contenuto del DIV
		$content,
		/// Classe di stile
		$class,
		/// Parametri di stile aggiuntivi
		$style
	) {
		echo "<div id=\"".$id."\" class=\"".$class."\" style=\"".$style."\">";
			echo $contenuto;
			echo "<br /><br/>";
		echo "</div>";
	}

	/// Aggiunge un div per contenere l'help
	function addSlideHelp(
		/// Contenuto dell'Help
		$content,
		/// Classe di stile
		$class,
		/// Parametri di stile aggiuntivi
		$style,
		/// Direzione dello slittamento: vertical-horizontal. Di default vertical
		$direction
	) {
		if (!$direction) { $direction="vertical"; }
		$postfix=rand(1000);
		$this->addSlideList(
			array("objectHelp".$postfix.""),
			array("toggleHelp".$postfix.""),
			"toggle",
			$direction
		);
		//echo "<a id=\"toggleHelp".$postfix."\" href=\"#\" alt=\"Help\" title=\"Help\"><img src=\"".THEME."/images/help.png\" border=\"0\" alt=\"0\" help=\"0\" class=\"reflect\" /></a>";
		echo "<a id=\"toggleHelp".$postfix."\" href=\"#\" alt=\"Help\" title=\"Help\"><img src=\"".THEME."/images/help.png\" border=\"0\" alt=\"0\" help=\"0\" /></a>";
		echo "<div id=\"objectHelp".$postfix."\" class=\"".$class."\" style=\"".$style."\">";
			echo $content;
		echo "</div>";
		return true;
	}

	
	function addKwickList() {
		echo "<script type=\"text/javascript\">
			window.addEvent('domready', function(){
		";
		echo "
			var szNormal = 64, szSmall  = 64, szFull   = 128;
			
			var kwicks = $$(\"#kwicks .kwick\");
			var fx = new Fx.Elements(kwicks, {wait: false, duration: 300, transition: Fx.Transitions.Back.easeOut});
			kwicks.each(function(kwick, i) {
				kwick.addEvent(\"mouseenter\", function(event) {
					var o = {};
					o[i] = {width: [kwick.getStyle(\"width\").toInt(), szFull]}
					kwicks.each(function(other, j) {
						if(i != j) {
							var w = other.getStyle(\"width\").toInt();
							if(w != szSmall) o[j] = {width: [w, szSmall]};
						}
					});
					fx.start(o);
				});
			});
			
			$(\"kwicks\").addEvent(\"mouseleave\", function(event) {
				var o = {};
				kwicks.each(function(kwick, i) {
					o[i] = {width: [kwick.getStyle(\"width\").toInt(), szNormal]}
				});
				fx.start(o);
			})
		";
		echo ("
				});
			</script>
		");
	}
	function addStylesList() {
		echo "<script type=\"text/javascript\">
			window.addEvent('domready', function(){
		";
		echo "
		var list = $$('#idList li');
		list.each(function(element) {
		
			var fx = new Fx.Styles(element, {duration:200, wait:false});
		
			element.addEvent('mouseenter', function(){
				fx.start({
					'margin-left': 2,
					'background-color': '#666',
					'color': '#ff8',
					'height':'20px'
				});
			});
		
			element.addEvent('mouseleave', function(){
				fx.start({
					'margin-left': 0,
					'background-color': '#333',
					'color': '#888',
					'height':'16px'
				});
			});
		
		});
		";
		echo ("
				});
			</script>
		");
	}
}
Return current item: Stelib