]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
adds method for invoking function calls programmatically on Foundation Plugin classes...
authorzurbchris <chris@zurb.com>
Tue, 17 Nov 2015 22:51:43 +0000 (14:51 -0800)
committerzurbchris <chris@zurb.com>
Tue, 17 Nov 2015 22:51:43 +0000 (14:51 -0800)
js/foundation.core.js

index 0ac12502a371f9b98b794e3e9aa61ff5a96e1b66..5fe2c78316bd680db722b1bba91ca574fce796bc 100644 (file)
@@ -230,15 +230,27 @@ var foundation = function(method) {
     $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;
 };