$noJS.removeClass('no-js');
}
- if (type === 'undefined') {
+ if(type === 'undefined'){//needs to initialize the Foundation object, or an individual plugin.
Foundation.MediaQuery._init();
Foundation.reflow(this);
- } else if (type === 'object') {
- Foundation.reflow(this);
- } else if (type === 'string' || type === 'array') {
- Foundation.reflow(this, method);
- }
+ }else if(type === 'string'){//an individual method to invoke on a plugin or group of plugins
+ var args = Array.prototype.slice.call(arguments, 1);//collect all the arguments, if necessary
+ var plugClass = this.data('zfPlugin');//determine the class of plugin
+ if(plugClass !== undefined && plugClass[method] !== undefined){//make sure both the class and method exist
+ if(this.length === 1){//if there's only one, call it directly.
+ plugClass[method].apply(plugClass, args);
+ }else{
+ this.each(function(i, el){//otherwise loop through the jQuery collection and invoke the method on each
+ plugClass[method].apply($(el).data('zfPlugin'), args);
+ });
+ }
+ }else{//error for no class or no method
+ throw new Error("We're sorry, " + method + " is not an available method for " + (plugClass ? functionName(plugClass) : 'this element') + '.');
+ }
+ }else{//error for invalid argument type
+ throw new Error("We're sorry, " + type + " is not a valid argument. You must use a string representing the method you wish to invoke.");
+ }
return this;
};