foundation.util.box.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory(require("./foundation.core"));
  4. else if(typeof define === 'function' && define.amd)
  5. define(["./foundation.core"], factory);
  6. else if(typeof exports === 'object')
  7. exports["foundation.util.box"] = factory(require("./foundation.core"));
  8. else
  9. root["__FOUNDATION_EXTERNAL__"] = root["__FOUNDATION_EXTERNAL__"] || {}, root["__FOUNDATION_EXTERNAL__"]["foundation.util.box"] = factory(root["__FOUNDATION_EXTERNAL__"]["foundation.core"]);
  10. })(window, function(__WEBPACK_EXTERNAL_MODULE__foundation_core__) {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/
  15. /******/ // The require function
  16. /******/ function __webpack_require__(moduleId) {
  17. /******/
  18. /******/ // Check if module is in cache
  19. /******/ if(installedModules[moduleId]) {
  20. /******/ return installedModules[moduleId].exports;
  21. /******/ }
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ i: moduleId,
  25. /******/ l: false,
  26. /******/ exports: {}
  27. /******/ };
  28. /******/
  29. /******/ // Execute the module function
  30. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  31. /******/
  32. /******/ // Flag the module as loaded
  33. /******/ module.l = true;
  34. /******/
  35. /******/ // Return the exports of the module
  36. /******/ return module.exports;
  37. /******/ }
  38. /******/
  39. /******/
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/
  43. /******/ // expose the module cache
  44. /******/ __webpack_require__.c = installedModules;
  45. /******/
  46. /******/ // define getter function for harmony exports
  47. /******/ __webpack_require__.d = function(exports, name, getter) {
  48. /******/ if(!__webpack_require__.o(exports, name)) {
  49. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  50. /******/ }
  51. /******/ };
  52. /******/
  53. /******/ // define __esModule on exports
  54. /******/ __webpack_require__.r = function(exports) {
  55. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  56. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  57. /******/ }
  58. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  59. /******/ };
  60. /******/
  61. /******/ // create a fake namespace object
  62. /******/ // mode & 1: value is a module id, require it
  63. /******/ // mode & 2: merge all properties of value into the ns
  64. /******/ // mode & 4: return value when already ns object
  65. /******/ // mode & 8|1: behave like require
  66. /******/ __webpack_require__.t = function(value, mode) {
  67. /******/ if(mode & 1) value = __webpack_require__(value);
  68. /******/ if(mode & 8) return value;
  69. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  70. /******/ var ns = Object.create(null);
  71. /******/ __webpack_require__.r(ns);
  72. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  73. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  74. /******/ return ns;
  75. /******/ };
  76. /******/
  77. /******/ // getDefaultExport function for compatibility with non-harmony modules
  78. /******/ __webpack_require__.n = function(module) {
  79. /******/ var getter = module && module.__esModule ?
  80. /******/ function getDefault() { return module['default']; } :
  81. /******/ function getModuleExports() { return module; };
  82. /******/ __webpack_require__.d(getter, 'a', getter);
  83. /******/ return getter;
  84. /******/ };
  85. /******/
  86. /******/ // Object.prototype.hasOwnProperty.call
  87. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  88. /******/
  89. /******/ // __webpack_public_path__
  90. /******/ __webpack_require__.p = "";
  91. /******/
  92. /******/
  93. /******/ // Load entry module and return exports
  94. /******/ return __webpack_require__(__webpack_require__.s = 21);
  95. /******/ })
  96. /************************************************************************/
  97. /******/ ({
  98. /***/ "./foundation.core":
  99. /*!****************************************************************************************************************************************************************!*\
  100. !*** external {"root":["__FOUNDATION_EXTERNAL__","foundation.core"],"amd":"./foundation.core","commonjs":"./foundation.core","commonjs2":"./foundation.core"} ***!
  101. \****************************************************************************************************************************************************************/
  102. /*! no static exports found */
  103. /***/ (function(module, exports) {
  104. module.exports = __WEBPACK_EXTERNAL_MODULE__foundation_core__;
  105. /***/ }),
  106. /***/ "./js/entries/plugins/foundation.util.box.js":
  107. /*!***************************************************!*\
  108. !*** ./js/entries/plugins/foundation.util.box.js ***!
  109. \***************************************************/
  110. /*! exports provided: Foundation, Box */
  111. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  112. "use strict";
  113. __webpack_require__.r(__webpack_exports__);
  114. /* harmony import */ var _foundation_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./foundation.core */ "./foundation.core");
  115. /* harmony import */ var _foundation_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_foundation_core__WEBPACK_IMPORTED_MODULE_0__);
  116. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Foundation", function() { return _foundation_core__WEBPACK_IMPORTED_MODULE_0__["Foundation"]; });
  117. /* harmony import */ var _foundation_util_box__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../foundation.util.box */ "./js/foundation.util.box.js");
  118. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Box", function() { return _foundation_util_box__WEBPACK_IMPORTED_MODULE_1__["Box"]; });
  119. _foundation_core__WEBPACK_IMPORTED_MODULE_0__["Foundation"].Box = _foundation_util_box__WEBPACK_IMPORTED_MODULE_1__["Box"];
  120. /***/ }),
  121. /***/ "./js/foundation.util.box.js":
  122. /*!***********************************!*\
  123. !*** ./js/foundation.util.box.js ***!
  124. \***********************************/
  125. /*! exports provided: Box */
  126. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  127. "use strict";
  128. __webpack_require__.r(__webpack_exports__);
  129. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Box", function() { return Box; });
  130. var Box = {
  131. ImNotTouchingYou: ImNotTouchingYou,
  132. OverlapArea: OverlapArea,
  133. GetDimensions: GetDimensions,
  134. GetExplicitOffsets: GetExplicitOffsets
  135. /**
  136. * Compares the dimensions of an element to a container and determines collision events with container.
  137. * @function
  138. * @param {jQuery} element - jQuery object to test for collisions.
  139. * @param {jQuery} parent - jQuery object to use as bounding container.
  140. * @param {Boolean} lrOnly - set to true to check left and right values only.
  141. * @param {Boolean} tbOnly - set to true to check top and bottom values only.
  142. * @default if no parent object passed, detects collisions with `window`.
  143. * @returns {Boolean} - true if collision free, false if a collision in any direction.
  144. */
  145. };
  146. function ImNotTouchingYou(element, parent, lrOnly, tbOnly, ignoreBottom) {
  147. return OverlapArea(element, parent, lrOnly, tbOnly, ignoreBottom) === 0;
  148. }
  149. function OverlapArea(element, parent, lrOnly, tbOnly, ignoreBottom) {
  150. var eleDims = GetDimensions(element),
  151. topOver,
  152. bottomOver,
  153. leftOver,
  154. rightOver;
  155. if (parent) {
  156. var parDims = GetDimensions(parent);
  157. bottomOver = parDims.height + parDims.offset.top - (eleDims.offset.top + eleDims.height);
  158. topOver = eleDims.offset.top - parDims.offset.top;
  159. leftOver = eleDims.offset.left - parDims.offset.left;
  160. rightOver = parDims.width + parDims.offset.left - (eleDims.offset.left + eleDims.width);
  161. } else {
  162. bottomOver = eleDims.windowDims.height + eleDims.windowDims.offset.top - (eleDims.offset.top + eleDims.height);
  163. topOver = eleDims.offset.top - eleDims.windowDims.offset.top;
  164. leftOver = eleDims.offset.left - eleDims.windowDims.offset.left;
  165. rightOver = eleDims.windowDims.width - (eleDims.offset.left + eleDims.width);
  166. }
  167. bottomOver = ignoreBottom ? 0 : Math.min(bottomOver, 0);
  168. topOver = Math.min(topOver, 0);
  169. leftOver = Math.min(leftOver, 0);
  170. rightOver = Math.min(rightOver, 0);
  171. if (lrOnly) {
  172. return leftOver + rightOver;
  173. }
  174. if (tbOnly) {
  175. return topOver + bottomOver;
  176. } // use sum of squares b/c we care about overlap area.
  177. return Math.sqrt(topOver * topOver + bottomOver * bottomOver + leftOver * leftOver + rightOver * rightOver);
  178. }
  179. /**
  180. * Uses native methods to return an object of dimension values.
  181. * @function
  182. * @param {jQuery || HTML} element - jQuery object or DOM element for which to get the dimensions. Can be any element other that document or window.
  183. * @returns {Object} - nested object of integer pixel values
  184. * TODO - if element is window, return only those values.
  185. */
  186. function GetDimensions(elem) {
  187. elem = elem.length ? elem[0] : elem;
  188. if (elem === window || elem === document) {
  189. throw new Error("I'm sorry, Dave. I'm afraid I can't do that.");
  190. }
  191. var rect = elem.getBoundingClientRect(),
  192. parRect = elem.parentNode.getBoundingClientRect(),
  193. winRect = document.body.getBoundingClientRect(),
  194. winY = window.pageYOffset,
  195. winX = window.pageXOffset;
  196. return {
  197. width: rect.width,
  198. height: rect.height,
  199. offset: {
  200. top: rect.top + winY,
  201. left: rect.left + winX
  202. },
  203. parentDims: {
  204. width: parRect.width,
  205. height: parRect.height,
  206. offset: {
  207. top: parRect.top + winY,
  208. left: parRect.left + winX
  209. }
  210. },
  211. windowDims: {
  212. width: winRect.width,
  213. height: winRect.height,
  214. offset: {
  215. top: winY,
  216. left: winX
  217. }
  218. }
  219. };
  220. }
  221. /**
  222. * Returns an object of top and left integer pixel values for dynamically rendered elements,
  223. * such as: Tooltip, Reveal, and Dropdown. Maintained for backwards compatibility, and where
  224. * you don't know alignment, but generally from
  225. * 6.4 forward you should use GetExplicitOffsets, as GetOffsets conflates position and alignment.
  226. * @function
  227. * @param {jQuery} element - jQuery object for the element being positioned.
  228. * @param {jQuery} anchor - jQuery object for the element's anchor point.
  229. * @param {String} position - a string relating to the desired position of the element, relative to it's anchor
  230. * @param {Number} vOffset - integer pixel value of desired vertical separation between anchor and element.
  231. * @param {Number} hOffset - integer pixel value of desired horizontal separation between anchor and element.
  232. * @param {Boolean} isOverflow - if a collision event is detected, sets to true to default the element to full width - any desired offset.
  233. * TODO alter/rewrite to work with `em` values as well/instead of pixels
  234. */
  235. function GetExplicitOffsets(element, anchor, position, alignment, vOffset, hOffset, isOverflow) {
  236. var $eleDims = GetDimensions(element),
  237. $anchorDims = anchor ? GetDimensions(anchor) : null;
  238. var topVal, leftVal;
  239. if ($anchorDims !== null) {
  240. // set position related attribute
  241. switch (position) {
  242. case 'top':
  243. topVal = $anchorDims.offset.top - ($eleDims.height + vOffset);
  244. break;
  245. case 'bottom':
  246. topVal = $anchorDims.offset.top + $anchorDims.height + vOffset;
  247. break;
  248. case 'left':
  249. leftVal = $anchorDims.offset.left - ($eleDims.width + hOffset);
  250. break;
  251. case 'right':
  252. leftVal = $anchorDims.offset.left + $anchorDims.width + hOffset;
  253. break;
  254. } // set alignment related attribute
  255. switch (position) {
  256. case 'top':
  257. case 'bottom':
  258. switch (alignment) {
  259. case 'left':
  260. leftVal = $anchorDims.offset.left + hOffset;
  261. break;
  262. case 'right':
  263. leftVal = $anchorDims.offset.left - $eleDims.width + $anchorDims.width - hOffset;
  264. break;
  265. case 'center':
  266. leftVal = isOverflow ? hOffset : $anchorDims.offset.left + $anchorDims.width / 2 - $eleDims.width / 2 + hOffset;
  267. break;
  268. }
  269. break;
  270. case 'right':
  271. case 'left':
  272. switch (alignment) {
  273. case 'bottom':
  274. topVal = $anchorDims.offset.top - vOffset + $anchorDims.height - $eleDims.height;
  275. break;
  276. case 'top':
  277. topVal = $anchorDims.offset.top + vOffset;
  278. break;
  279. case 'center':
  280. topVal = $anchorDims.offset.top + vOffset + $anchorDims.height / 2 - $eleDims.height / 2;
  281. break;
  282. }
  283. break;
  284. }
  285. }
  286. return {
  287. top: topVal,
  288. left: leftVal
  289. };
  290. }
  291. /***/ }),
  292. /***/ 21:
  293. /*!*********************************************************!*\
  294. !*** multi ./js/entries/plugins/foundation.util.box.js ***!
  295. \*********************************************************/
  296. /*! no static exports found */
  297. /***/ (function(module, exports, __webpack_require__) {
  298. module.exports = __webpack_require__(/*! /Users/joeworkman/Development/foundation-sites/js/entries/plugins/foundation.util.box.js */"./js/entries/plugins/foundation.util.box.js");
  299. /***/ })
  300. /******/ });
  301. });
  302. //# sourceMappingURL=foundation.util.box.js.map