import $ from 'jquery';
import Foundation from '../foundation.core';
+Foundation.addToJquery($);
// Add Foundation Utils to Foundation global namespace for backwards
// compatibility.
// so no // need to add it to Foundation, just init them.
import Touch from '../foundation.util.touch';
-Touch.init();
+Touch.init($);
import Triggers from '../foundation.util.triggers';
Triggers.init(Foundation, $);
import Interchange from '../foundation.interchange';
Foundation.plugin(Interchange, 'Interchange');
+import Magellan from '../foundation.magellan';
+Foundation.plugin(Magellan, 'Magellan');
+
import OffCanvas from '../foundation.offcanvas';
Foundation.plugin(OffCanvas, 'OffCanvas');
+import Orbit from '../foundation.orbit';
+Foundation.plugin(Orbit, 'Orbit');
+
import ResponsiveMenu from '../foundation.responsiveMenu';
Foundation.plugin(ResponsiveMenu, 'ResponsiveMenu');
});
},
getFnName: functionName,
+
+ addToJquery: function($) {
+ // TODO: consider not making this a jQuery function
+ // TODO: need way to reflow vs. re-initialize
+ /**
+ * The Foundation jQuery method.
+ * @param {String|Array} method - An action to perform on the current jQuery object.
+ */
+ var foundation = function(method) {
+ var type = typeof method,
+ $meta = $('meta.foundation-mq'),
+ $noJS = $('.no-js');
+
+ if(!$meta.length){
+ $('<meta class="foundation-mq">').appendTo(document.head);
+ }
+ if($noJS.length){
+ $noJS.removeClass('no-js');
+ }
+
+ if(type === 'undefined'){//needs to initialize the Foundation object, or an individual plugin.
+ Foundation.MediaQuery._init();
+ Foundation.reflow(this);
+ }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 ReferenceError("We're sorry, '" + method + "' is not an available method for " + (plugClass ? functionName(plugClass) : 'this element') + '.');
+ }
+ }else{//error for invalid argument type
+ throw new TypeError(`We're sorry, ${type} is not a valid parameter. You must use a string representing the method you wish to invoke.`);
+ }
+ return this;
+ };
+ $.fn.foundation = foundation;
+ return $;
+ }
};
Foundation.util = {
}
};
-// TODO: consider not making this a jQuery function
-// TODO: need way to reflow vs. re-initialize
-/**
- * The Foundation jQuery method.
- * @param {String|Array} method - An action to perform on the current jQuery object.
- */
-var foundation = function(method) {
- var type = typeof method,
- $meta = $('meta.foundation-mq'),
- $noJS = $('.no-js');
-
- if(!$meta.length){
- $('<meta class="foundation-mq">').appendTo(document.head);
- }
- if($noJS.length){
- $noJS.removeClass('no-js');
- }
-
- if(type === 'undefined'){//needs to initialize the Foundation object, or an individual plugin.
- Foundation.MediaQuery._init();
- Foundation.reflow(this);
- }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 ReferenceError("We're sorry, '" + method + "' is not an available method for " + (plugClass ? functionName(plugClass) : 'this element') + '.');
- }
- }else{//error for invalid argument type
- throw new TypeError(`We're sorry, ${type} is not a valid parameter. You must use a string representing the method you wish to invoke.`);
- }
- return this;
-};
-
window.Foundation = Foundation;
-$.fn.foundation = foundation;
// Polyfill for requestAnimationFrame
(function() {
'use strict';
import $ from 'jquery';
+import { GetYoDigits } from './foundation.util.core';
// Abstract class for providing lifecycle hooks. Expect plugins to define AT LEAST
// {function} _setup (replaces previous constructor),
var pluginName = hyphenate(this.constructor.name);
this.uuid = GetYoDigits(6, pluginName);
- if(!this.$element.attr(`data-${pluginName}`)){ this.$element.attr(`data-${pluginName}`, plugin.uuid); }
+ if(!this.$element.attr(`data-${pluginName}`)){ this.$element.attr(`data-${pluginName}`, this.uuid); }
if(!this.$element.data('zfPlugin')){ this.$element.data('zfPlugin', this); }
/**
* Fires when the plugin has initialized.
}
}
+// Convert PascalCase to kebab-case
+// Thank you: http://stackoverflow.com/a/8955580
+function hyphenate(str) {
+ return str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
+}
+
export default Plugin;