mi sa che è meglio che vi posti tutto il codice
Codice PHP:
function WPGallery(url) {
this.url = url; /* < url for the WPGallery's xml file */
this.length = false; /* < number of images in the WPGallery */
this.$data = new XML(); /* < private var holding the xml data */
this.base = ''; /* < private var for gallery base */
this.thumbnailbase = ''; /* < private var for thumbnail base */
this.largebase = ''; /* < private var for large image base */
this.$data.ignoreWhite = true; /* < set ignore white for the xml */
var self = this; // hacky backref to the WPGallery object
// called when xml is loaded, sets length and call user callback
this.$data.onLoad = function (ok) {
if (ok) {
var i, prop; // counters
var fc = this.firstChild; // firstchild node
// set the length for the gallery
self.length = this.images.childNodes.length;
// copy all gallery attribs into the object
for (i in fc.attributes) {
self[i] = fc.attributes[i];
}
// copy all non-image nodes into the WPGallery object
for (i=0; i<fc.childNodes.length; i++) {
// skip images, add banner, thumbnail, large attributes
switch(fc.childNodes[i].nodeName) {
case 'banner':
case 'thumbnail':
case 'large':
for (prop in fc.childNodes[i].attributes) {
self[fc.childNodes[i].nodeName + prop] = fc.childNodes[i].attributes[prop];
}
break;
case 'images':
break;
default:
self[fc.childNodes[i].nodeName] = fc.childNodes[i].firstChild.nodeValue;
break;
}
}
self.onLoad();
} else {
trace('The XML file was not loaded.');
}
}
}
/**
* load the xml for the WPGallery
*/
WPGallery.prototype.load = function() {
this.$data.load(this.url);
}
/**
* return the image for the given index
* @param: imgnum the index of the image to return
* @return: an object with all properties for this image
*/
WPGallery.prototype.getImage = function(imgnum) {
var src; /** < the xml node for this image */
var img = {}; /** < the parsed image node to return as an object */
img.meta = []; /** < holder for meta data */
src = this.$data.images.childNodes[imgnum];
// add meta.title set as filename (default)
img.meta.title = src.attributes.path;
// get attributes
// escape filename for highbit languages
var basename = src.attributes.path.substring(0, src.attributes.path.indexOf('.jpg'));
basename = escape(basename)+'.jpg';
img.file = basename;
img.largeurl = this.base + this.largebase + basename;
img.largewidth = src.attributes.width;
img.largeheight = src.attributes.height;
// escape thumbname
basename = src.attributes.thumbpath.substring(0, src.attributes.thumbpath.indexOf('.jpg'));
basename = escape(basename)+'.jpg';
img.thumbnailurl = this.base + this.thumbnailbase + basename;
img.thumbnailwidth = src.attributes.thumbwidth;
img.thumbnailheight = src.attributes.thumbheight;
for (var i=0; i<src.childNodes.length; i++) {
// add the url and prepend the image base
if (src.childNodes[i].nodeName == 'meta') {
img.meta[img.meta.length] = {
name:src.childNodes[i].attributes.name,
content: src.childNodes[i].firstChild.nodeValue
}
img.meta[src.childNodes[i].attributes.name] = src.childNodes[i].firstChild.nodeValue;
} else if (src.childNodes[i].nodeName == 'keywords') {
img.meta.keywords = [];
for (var j=0; j<src.childNodes[i].childNodes.length; j++) {
img.meta.keywords.push(src.childNodes[i].childNodes[j].firstChild.nodeValue);
}
}
}
return img;
}
/**
* return an iterator for the gallery
* @return: an WPGalleryIterator object
*/
WPGallery.prototype.iterator = function() {
return new WPGalleryIterator(this);
}
// ------------------------------------------
// iteration functions
// --
/**
* returns an iterator for the gallery
* @param: gallery. The gallery to get an interator for.
* @return: WPGallery Iterator object
*/
function WPGalleryIterator(gallery) {
this.$current = false; /* < private var of the current index */
this.length = gallery.length; /* < number of items in the iterator */
this.parent = gallery; /* < gallery this iterator handles */
}
/**
* returns the next image in the gallery if it is available, otherwise returns false
* @return: an object with all properties for this image
*/
WPGalleryIterator.prototype.next = function() {
if (this.$current === false) {
this.$current = 0;
} else if (this.$current < (this.length-1)) {
++this.$current;
} else {
return false;
}
return this.parent.getImage(this.$current);
}
/**
* returns the last image in the gallery if it is available, otherwise returns false
* @return: an object with all properties for this image
*/
WPGalleryIterator.prototype.prev = function() {
if (this.$current > 0) {
--this.$current;
} else if (this.$current == 0) {
this.$current = this.length-1;
} else {
return false;
}
return this.parent.getImage(this.$current);
}
/**
* reset the gallery for iteration
*/
WPGalleryIterator.prototype.reset = function() {
this.$current = false;
}
/**
* set the internal pointer and return the image there
* @param: i the index to seek to
*/
WPGalleryIterator.prototype.seek = function(i) {
this.$current = i;
return this.parent.getImage(this.$current);
}
/**
* get the current image number
*/
WPGalleryIterator.prototype.getCurrentIndex = function() {
return this.$current;
}
{