From: zurbchris Date: Tue, 24 Nov 2015 17:49:44 +0000 (-0800) Subject: adds data-options method to foundation.core, it's back people X-Git-Tag: v6.0.4~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=34d63b0cd197a52944d420415a4667b57389ccf9;p=thirdparty%2Ffoundation%2Ffoundation-sites.git adds data-options method to foundation.core, it's back people --- diff --git a/js/foundation.core.js b/js/foundation.core.js index e6b5e5471..95bc99047 100644 --- a/js/foundation.core.js +++ b/js/foundation.core.js @@ -162,12 +162,21 @@ var Foundation = { // For each plugin found, initialize it $elem.each(function() { + var $el = $(this), + opts = {}; // Don't double-dip on plugins - if ($(this).attr('zf-plugin')) { + if ($el.attr('zf-plugin')) { console.warn("Tried to initialize "+name+" on an element that already has a Foundation plugin."); return; } - $(this).data('zf-plugin', new plugin($(this))); + + if($el.attr('data-options')){ + var thing = $el.attr('data-options').split(';').forEach(function(e, i){ + var opt = e.split(':').map(function(el){ return el.trim(); }); + if(opt[0]) opts[opt[0]] = parseValue(opt[1]); + }); + } + $el.data('zf-plugin', new plugin($(this), opts)); }); }); }, @@ -342,7 +351,12 @@ function functionName(fn) { return fn.prototype.constructor.name; } } - +function parseValue(str){ + if(/true/.test(str)) return true; + else if(/false/.test(str)) return false; + else if(!isNaN(str * 1)/* && typeof (str * 1) === "number"*/) return parseFloat(str); + return str; +} // Convert PascalCase to kebab-case // Thank you: http://stackoverflow.com/a/8955580 function hyphenate(str) {