XML filter is applied to non-XML value
OK I'm a little new to the subject of writing new plug-ins from scratch. I'm trying to write a carousel which works slightly different to other carousels. I've got a basic bit of code called carousel.
- /*
Carousel is responsible for loading the XML file (via ajax calls) specified in the configuration
Carousel takes a list of configuration options (optionally) or takes the default init method
Carousel also adds scrolling functionality to the div containing the arrows
*/
(function ($) {
// A list of public methods
var methods = {
init: function (settings) {
// Settings to configure the jQuery lightBox plugin, Defaults can be overwritten if they are passed
settings = jQuery.extend({
// Id of the carousel container to append elements onto
carouselListID: "imageList",
// Id of the picture container
carouselContainer: "CarouselContainer",
// Width in pixels of inner carousel (including all padding and styling)
carouselWidth: 460,
// How Many Carousel Elements per iteration
itemLength: 5,
xmlURL: "Test.xml",
// Don´t alter these variables in any way
imageArray: [],
activeImage: 0
}, settings);
},
returnCarouselArray: function () {
// Method loads an image list from XML file and returns a full array of all the items
// Carousel must first be initialised
alert(settings.xmlURL);
$.ajax({
type: "GET",
url: settings.xmlURL,
dataType: "xml",
success: function (xml) {
$(xml).find('pic').each(function () {
var title = $(this).attr('title');
var tPAdd = $(this).find('tPAdd');
var lPAdd = $(this).find('lPAdd');
var fPAdd = $(this).find('fPAdd');
alert(title);
});
}
});
}
};
$.fn.carousel = function (method) {
// Method calling logic (if a method was passed)
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
}
// If a method wasn't passed or arguments were passed
else if (typeof method === 'object' || !method) {
return methods.init.apply(this, arguments);
}
// If a non existant method was passed and no arguments were passed then flag an error
else {
$.error('Method ' + method + ' does not exist on jQuery.carousel');
}
};
})(jQuery);
What I'm trying to do is instantiate the plugin like so
- $(function () {
$('#imageList').carousel();
$('#imageList').('returnCarouselArray');
});
I'd have thought what I'd just done is instantiate an object with the defaults by extending imageList
Once extended I'd expect to be able to call it's other functions but I am getting the error in the title of this post.
I wasn't sure if I was looking at this completely wrong. Anyone got any ideas what I'm doing wrong?