ueilà! come va?
sono nuovo mi sono appena iscritto, un saluto a tutti.
ho un problema con javascript e array vari, spero in qualche consiglio, sto modificando un javascript per creare una galleria in ajax, mi funziona tutto per ora ma vorrei fare una modifica che chissà perchè non mi viene, mi starò incartando?
var photoDir = <? $params->get( 'folder' ); ?>// folder della gallery preso da xml (di joomla)
var borderSize = 6; // = 2x CSS border size
// get current photo id from URL
var thisURL = document.location.href;
var splitURL = thisURL.split("#");
var photoId = splitURL[1] - 1;
// if no id in query string then set to 0
photoId = (!photoId)? 0hotoId;
// Define each photo's name, height, width, and caption
var photoArray = new Array(
// Source, Width, Height, Caption
new Array("3.jpg", "500", "280", "Door 3 - Click on the image to view previous or next image"),
new Array("2.jpg", "425", "319", "Door 2 - Click on the image to view previous or next image"),
new Array("1.jpg", "700", "260", "Door 1 - Click on the image to view previous or next image")
);
// Number of photos in this gallery
var photoNum = photoArray.length;
e poi c'è altro codice.
il pezzo che mi interessa è l'array, vorrei che fosse automatico, cioè leggesse tutte le immagini di una cartella senza dover scrivere a mano il nome.
ho provato questa soluzione passando una funzione all'array
<?
$img_dir = $params->get( 'folder' );
Header("content-type: application/x-javascript");
//This function gets the file names of all images in the current directory
//and ouputs them as a JavaScript array
function returnimages($img_dir) {
$pattern="(\.jpg$)|(\.png$)|(\.jpeg$)|(\.gif$)"; //valid image extensions
$files = array();
$curimage=0;
if($handle = opendir($img_dir)) {
while(false !== ($file = readdir($handle))){
if(eregi($pattern, $file)){ //if this file is a valid image
//Output it as a JavaScript array element
echo 'galleryarray['.$curimage.']="'.$file .'";';
$curimage++;
}
}
closedir($handle);
}
return($files);
}
echo 'var photoDir=new Array();'; //Define array in JavaScript
returnimages() //Output the array elements containing the image file names
?>
ma non funziona putroppo
cosa sbaglio?