]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
Factor out core utilities into standalone module
authorKevin Ball <kmball11@gmail.com>
Mon, 9 Jan 2017 23:59:35 +0000 (15:59 -0800)
committerKevin Ball <kmball11@gmail.com>
Tue, 18 Apr 2017 16:41:13 +0000 (09:41 -0700)
18 files changed:
gulp/config.js
js/foundation.accordion.js
js/foundation.accordionMenu.js
js/foundation.core.js
js/foundation.dropdown.js
js/foundation.dropdownMenu.js
js/foundation.equalizer.js
js/foundation.magellan.js
js/foundation.offcanvas.js
js/foundation.orbit.js
js/foundation.responsiveMenu.js
js/foundation.slider.js
js/foundation.sticky.js
js/foundation.tooltip.js
js/foundation.util.box.js
js/foundation.util.core.js [new file with mode: 0644]
js/foundation.util.keyboard.js
js/foundation.zf.responsiveAccordionTabs.js

index e6b06b92100cf32f080dff0e849b537a0445a0a5..b9c1adf9dc1655ddfba7bfb644da4db81772903e 100644 (file)
@@ -3,6 +3,7 @@ module.exports = {
   // Javascript
   JS_FILES: [
   'js/foundation.core.js',
+  'js/foundation.util.core.js',
   'js/foundation.util.*.js',
   'js/*.js'
   ],
index 19fcd0898d97c507555d88911290612622421988..ef83300a9776a3fc3cf89e249c02ae93e6cc8a41 100644 (file)
@@ -3,7 +3,7 @@
 !function($) {
 
   let Keyboard    = Foundation.Keyboard; // import Keyboard from 'foundation.util.keyboard'
-  let GetYoDigits = Foundation.GetYoDigits; // currently part of foundation.core. Refactor?
+  let GetYoDigits = Foundation.GetYoDigits; // import { GetYoDigits } from 'foundation.util.core'
 
 /**
  * Accordion module.
index 05fdbcb8caccf742724455fdfbad6f553b900e27..a620846e35108c3388eb30340711f06f664d943a 100644 (file)
@@ -4,7 +4,7 @@
 
   let Keyboard    = Foundation.Keyboard; // import Keyboard from "foundation.util.keyboard"
   let Nest        = Foundation.Nest; // import Nest from "foundation.util.nest"
-  let GetYoDigits = Foundation.GetYoDigits; // add import after refactor
+  let GetYoDigits = Foundation.GetYoDigits; //import { GetYoDigits } from "foundation.util.core"
 
 /**
  * AccordionMenu module.
index dd37db2e3714ddd6b6e6d5b0cb853219ae4a5ee4..3a3fce6ad3c02862edf3813fa7f88d60eab62a6e 100644 (file)
@@ -19,12 +19,6 @@ var Foundation = {
    */
   _uuids: [],
 
-  /**
-   * Returns a boolean for RTL support
-   */
-  rtl: function(){
-    return $('html').attr('dir') === 'rtl';
-  },
   /**
    * Defines a Foundation plugin, adding it to the `Foundation` namespace and the list of plugins to initialize when reflowing.
    * @param {Object} plugin - The constructor of the plugin.
@@ -129,18 +123,6 @@ var Foundation = {
      }
    },
 
-  /**
-   * returns a random base-36 uid with namespacing
-   * @function
-   * @param {Number} length - number of random base-36 digits desired. Increase for more random strings.
-   * @param {String} namespace - name of plugin to be incorporated in uid, optional.
-   * @default {String} '' - if no plugin name is provided, nothing is appended to the uid.
-   * @returns {String} - unique id
-   */
-  GetYoDigits: function(length, namespace){
-    length = length || 6;
-    return Math.round((Math.pow(36, length + 1) - Math.random() * Math.pow(36, length))).toString(36).slice(1) + (namespace ? `-${namespace}` : '');
-  },
   /**
    * Initialize plugins on any elements within `elem` (and `elem` itself) that aren't already initialized.
    * @param {Object} elem - jQuery object containing the element to check inside. Also checks the element itself, unless it's the `document` object.
@@ -194,30 +176,6 @@ var Foundation = {
     });
   },
   getFnName: functionName,
-  transitionend: function($elem){
-    var transitions = {
-      'transition': 'transitionend',
-      'WebkitTransition': 'webkitTransitionEnd',
-      'MozTransition': 'transitionend',
-      'OTransition': 'otransitionend'
-    };
-    var elem = document.createElement('div'),
-        end;
-
-    for (var t in transitions){
-      if (typeof elem.style[t] !== 'undefined'){
-        end = transitions[t];
-      }
-    }
-    if(end){
-      return end;
-    }else{
-      end = setTimeout(function(){
-        $elem.triggerHandler('transitionend', [$elem]);
-      }, 1);
-      return 'transitionend';
-    }
-  }
 };
 
 Foundation.util = {
index ed71969e489f92940208bf36b283c3c1e2f698d0..53a8deb8cb70c97ca8d2b2051d1a95e43a6dc8f2 100644 (file)
@@ -4,7 +4,7 @@
 
   let Keyboard    = Foundation.Keyboard; // import Keyboard from "foundation.util.keyboard";
   let Box         = Foundation.Box; // import Box from "foundation.util.box";
-  let GetYoDigits = Foundation.GetYoDigits; // figure out import after refactor
+  let GetYoDigits = Foundation.GetYoDigits; // import { GetYoDigits } from "foundation.util.core";
 
   // import "foundation.util.triggers.js";
   // TODO: Figure out what a triggers import "means", since triggers are always accessed indirectly.
index c803f2a5d8b7cad4dcbb346ecb7a229d502d2536..f5f530d3b575f1cc9d5418fdf028c9c4bc3ec6a7 100644 (file)
@@ -5,7 +5,7 @@
   let Keyboard = Foundation.Keyboard; // import Keyboard from "foundation.util.keyboard";
   let Nest     = Foundation.Nest; // import Nest from "foundation.util.nest";
   let Box      = Foundation.Box; // import Box from "foundation.util.box";
-  let Rtl      = Foundation.rtl; // Figure out import after refactor
+  let Rtl      = Foundation.rtl; // import { rtl } from "foundation.util.core";
 
 /**
  * DropdownMenu module.
index 70b94db5aa0e81864c7918277406b7fbf06b6a6d..1f08a490ba12cc183c1b7fe93e82c629cd7db763 100644 (file)
@@ -4,7 +4,7 @@
 
   let MediaQuery     = Foundation.MediaQuery; // import MediaQuery from "foundation.util.mediaQuery";
   let onImagesLoaded = Foundation.onImagesLoaded; // import onImagesLoaded from "foundation.util.imageLoader";
-  let GetYoDigits    = Foundation.GetYoDigits; // figure out import after refactor;
+  let GetYoDigits    = Foundation.GetYoDigits; // import { GetYoDigits } from "foundation.util.core"
 
 /**
  * Equalizer module.
index ba854ee86a7b654e71f34eb5d087af04d79f581c..1a1c0992bf8386038ca1b12aa14cdf100c8f932b 100644 (file)
@@ -2,7 +2,7 @@
 
 !function($) {
 
-  let GetYoDigits = Foundation.GetYoDigits; // TODO: Separate this out?
+  let GetYoDigits = Foundation.GetYoDigits; // import { GetYoDigits } from "foundation.util.core";
 
 /**
  * Magellan module.
index 38b195981ad04e534dc470f1b83b5f472c7b3d35..da50f49dd16634dc02df4d29e469b52f75aeb1db 100644 (file)
@@ -5,7 +5,7 @@
   let Keyboard      = Foundation.Keyboard; // import Keyboard from "foundation.util.keyboard";
   let MediaQuery    = Foundation.MediaQuery; // import MediaQuery from "foundation.util.mediaQuery";
 
-  let transitionend = Foundation.transitionend; // Should transitionend be refactored into it's own module?
+  let transitionend = Foundation.transitionend; // import { transitionend } from "foundation.util.core";
 
   // import "foundation.util.triggers.js";
   // TODO: Figure out what triggers import should actually do, given how indirect their use is
index 2c299ac1ad143901a11ff770086552839ba04127..4c60d12be7da00552d370b3f057b0d832f486ecc 100644 (file)
@@ -4,10 +4,10 @@
 
 
   let Keyboard       = Foundation.Keyboard; // import Keyboard from "foundation.util.keyboard";
-  let Motion         = Foundation.Motion; // import { Motion } from "foundation.util.move"
-  let Timer          = Foundation.Timer; // import Timer from "foundation.util.timer"
-  let onImagesLoaded = Foundation.onImagesLoaded; // import onImagesLoaded from "foundation.util.imageLoader"
-  let GetYoDigits    = Foundation.GetYoDigits; // Add import after refactor
+  let Motion         = Foundation.Motion; // import { Motion } from "foundation.util.move";
+  let Timer          = Foundation.Timer; // import Timer from "foundation.util.timer";
+  let onImagesLoaded = Foundation.onImagesLoaded; // import onImagesLoaded from "foundation.util.imageLoader";
+  let GetYoDigits    = Foundation.GetYoDigits; // import { GetYoDigits } from "foundation.util.core";
 
   // import "foundation.util.touch.js"
   // TODO:  Figure out what a touch import should really do.
index a4e49c60feb3427bef09eb3ab924a14bc1b06659..2d5f2815d3900812240967a4b3b1b38ccf27a9e6 100644 (file)
@@ -3,7 +3,7 @@
 !function($) {
 
   let MediaQuery  = Foundation.MediaQuery; // import MediaQuery from "foundation.util.mediaQuery";
-  let GetYoDigits = Foundation.GetYoDigits; // separate out GetYoDigits into util
+  let GetYoDigits = Foundation.GetYoDigits; // import { GetYoDigits } from "foundation.util.core";
 
   // import "foundation.util.triggers.js";
 
index f7aa700d1579bcadc0810432b8b8fa8b14470b46..32119a3ee23d2ead70827a9b5f2d38a796751f11 100644 (file)
@@ -4,8 +4,8 @@
 
   let Keyboard    = Foundation.Keyboard; // import Keyboard from "foundation.util.keyboard";
   let Move        = Foundation.Move; // import { Move } from "foundation.util.motion";
-  let GetYoDigits = Foundation.GetYoDigits; // figure out import after refactor TODO9438
-  let Rtl         = Foundation.rtl; // figure out import/refactor for encapsulation of rtl() TODO9438
+  let GetYoDigits = Foundation.GetYoDigits; // import { GetYoDigits, rtl } from "foundation.util.core";
+  let Rtl         = Foundation.rtl;
 /**
  * Slider module.
  * @module foundation.slider
index 71ed662c034243b3be3dc37d208ff4d2395b5aad..d645bb1ff79c7ff85b364b44ec44860ace4d352b 100644 (file)
@@ -2,7 +2,7 @@
 
 !function($) {
 
-  let GetYoDigits = Foundation.GetYoDigits; // figure out import after refactor TODO9438
+  let GetYoDigits = Foundation.GetYoDigits; // import { GetYoDigits } from "foundation.util.core";
   let MediaQuery  = Foundation.MediaQuery; // import MediaQuery from "foundation.util.mediaQuery";
 /**
  * Sticky module.
index 38681073024234621629edfb037deadd45af9cc5..6ffcdb753adf0f0f34dd0a7b7a4886c12e65d7fb 100644 (file)
@@ -3,7 +3,7 @@
 !function($) {
 
   let Box         = Foundation.Box; // import Box from "foundation.utils.box";
-  let GetYoDigits = Foundation.GetYoDigits; // figure out import after refactor. TODO9438
+  let GetYoDigits = Foundation.GetYoDigits; // import { GetYoDigits } from "foundation.utils.core";
   let MediaQuery  = Foundation.MediaQuery; // import MediaQuery from "foundation.utils.mediaQuery";
 
   // import "foundation.util.triggers";
index 225a3abcf4772a871f1a18a7cde3d7aa90b02ef3..c6791d5f6fedfc6c93dfd72fa90423ce01f7041d 100644 (file)
@@ -2,7 +2,7 @@
 
 !function($) {
 
-  let Rtl = Foundation.rtl; // Figure out imports after refactor
+  let Rtl = Foundation.rtl; // import { rtl } from "foundation.util.core";
 
 Foundation.Box = {
   ImNotTouchingYou: ImNotTouchingYou,
diff --git a/js/foundation.util.core.js b/js/foundation.util.core.js
new file mode 100644 (file)
index 0000000..5ed3eea
--- /dev/null
@@ -0,0 +1,58 @@
+!function($) {
+
+"use strict";
+
+// Core Foundation Utilities, utilized in a number of places.
+
+  /**
+   * Returns a boolean for RTL support
+   */
+function rtl() {
+  return $('html').attr('dir') === 'rtl';
+}
+
+/**
+ * returns a random base-36 uid with namespacing
+ * @function
+ * @param {Number} length - number of random base-36 digits desired. Increase for more random strings.
+ * @param {String} namespace - name of plugin to be incorporated in uid, optional.
+ * @default {String} '' - if no plugin name is provided, nothing is appended to the uid.
+ * @returns {String} - unique id
+ */
+function GetYoDigits(length, namespace){
+  length = length || 6;
+  return Math.round((Math.pow(36, length + 1) - Math.random() * Math.pow(36, length))).toString(36).slice(1) + (namespace ? `-${namespace}` : '');
+}
+
+function transitionend($elem){
+  var transitions = {
+    'transition': 'transitionend',
+    'WebkitTransition': 'webkitTransitionEnd',
+    'MozTransition': 'transitionend',
+    'OTransition': 'otransitionend'
+  };
+  var elem = document.createElement('div'),
+      end;
+
+  for (var t in transitions){
+    if (typeof elem.style[t] !== 'undefined'){
+      end = transitions[t];
+    }
+  }
+  if(end){
+    return end;
+  }else{
+    end = setTimeout(function(){
+      $elem.triggerHandler('transitionend', [$elem]);
+    }, 1);
+    return 'transitionend';
+  }
+}
+
+// export {rtl, GetYoDigits, transitionend}
+
+Foundation.rtl = rtl;
+Foundation.GetYoDigits = GetYoDigits;
+Foundation.transitionend = transitionend;
+
+}(jQuery)
index d1fe08bcb98c4e2b9c9a7f7dd228165be8648a71..197536379184130a253ac10e4cec9127d2e35fbc 100644 (file)
@@ -10,7 +10,7 @@
 
 !function($) {
 
-  let Rtl = Foundation.rtl; // Figure out import after refactor
+  let Rtl = Foundation.rtl; // import { rtl } from "foundation.util.core";
 
 const keyCodes = {
   9: 'TAB',
index 6ddf7534172f76815aeec764fdb8ef179a26601e..0683fcc7121faa17b2785ad52d38f519085be3d1 100644 (file)
@@ -3,7 +3,7 @@
 !function($) {
 
   let MediaQuery  = Foundation.MediaQuery; // import MediaQuery from "foundation.util.mediaQuery";
-  let GetYoDigits = Foundation.GetYoDigits;
+  let GetYoDigits = Foundation.GetYoDigits; // import { GetYoDigits } from "foundation.util.core";
 
 /**
  * ResponsiveAccordionTabs module.