Probably this is a basic stuff, but better learn now then later.
What i’m doing :
I ‘m implementing a gallery that is getting a xml, and then build me using some javascript code. the problem i tried to call twice gallery.init like :
$(document).ready(function(){
galleryXML.init({
xmlPath : "data/gallery.xml",
imgPath : "images",
perView : 4,
id: "#gallery1"
});
galleryXML.init({
xmlPath : "data/gallery.xml",
imgPath : "images",
perView : 4,
id: "#gallery"
});
})
I expected to have one in #gallery1 other in #gallery. Can someone tell me what the problem?
The rest of the code is here only need to download, unrar and execute the index.html (Working just in firefox, not sure why too)
Thanks in advance.
UPDATE
This is a minimal example for now, not sure if represent well the problem.
http://jsfiddle.net/PSYCKIC/rpNab/2/ -> UPDATED
I think your problem can be that you are using the same variable
_Pfor (what you expect to be) 2 different instances of the galleryXML.The
_Pvariable is created and initialized when the javascript code is parsed, because of the()after thevar galleryXML = function() {...}.So I guess your problem is going to be solved if you just put the variable inside the init of galleryXML. You can see the code here: jsfiddle.net/rpNab/3/ (notice that now each
liis inside each gallery, instead of bothliin the last gallery)EDIT: And I realize that now with my modification the galleryXML module seems ugly (because it only has one method and no variables), so I made a minor refactoring in order to have more methods inside that class, but the methods now must receive the parameter because the class itself continue to be “static”, but the parameters can make it act for different contexts. Hope it helps: jsfiddle.net/rpNab/4/