UNPKG

14.1 kBJavaScriptView Raw
1(function webpackUniversalModuleDefinition(root, factory) {
2 if(typeof exports === 'object' && typeof module === 'object')
3 module.exports = factory(require("./foundation.core"), require("jquery"));
4 else if(typeof define === 'function' && define.amd)
5 define(["./foundation.core", "jquery"], factory);
6 else if(typeof exports === 'object')
7 exports["foundation.util.keyboard"] = factory(require("./foundation.core"), require("jquery"));
8 else
9 root["__FOUNDATION_EXTERNAL__"] = root["__FOUNDATION_EXTERNAL__"] || {}, root["__FOUNDATION_EXTERNAL__"]["foundation.util.keyboard"] = factory(root["__FOUNDATION_EXTERNAL__"]["foundation.core"], root["jQuery"]);
10})(window, function(__WEBPACK_EXTERNAL_MODULE__foundation_core__, __WEBPACK_EXTERNAL_MODULE_jquery__) {
11return /******/ (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 = 23);
95/******/ })
96/************************************************************************/
97/******/ ({
98
99/***/ "./foundation.core":
100/*!****************************************************************************************************************************************************************!*\
101 !*** external {"root":["__FOUNDATION_EXTERNAL__","foundation.core"],"amd":"./foundation.core","commonjs":"./foundation.core","commonjs2":"./foundation.core"} ***!
102 \****************************************************************************************************************************************************************/
103/*! no static exports found */
104/***/ (function(module, exports) {
105
106module.exports = __WEBPACK_EXTERNAL_MODULE__foundation_core__;
107
108/***/ }),
109
110/***/ "./js/entries/plugins/foundation.util.keyboard.js":
111/*!********************************************************!*\
112 !*** ./js/entries/plugins/foundation.util.keyboard.js ***!
113 \********************************************************/
114/*! exports provided: Foundation, Keyboard */
115/***/ (function(module, __webpack_exports__, __webpack_require__) {
116
117"use strict";
118__webpack_require__.r(__webpack_exports__);
119/* harmony import */ var _foundation_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./foundation.core */ "./foundation.core");
120/* harmony import */ var _foundation_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_foundation_core__WEBPACK_IMPORTED_MODULE_0__);
121/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Foundation", function() { return _foundation_core__WEBPACK_IMPORTED_MODULE_0__["Foundation"]; });
122
123/* harmony import */ var _foundation_util_keyboard__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../foundation.util.keyboard */ "./js/foundation.util.keyboard.js");
124/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Keyboard", function() { return _foundation_util_keyboard__WEBPACK_IMPORTED_MODULE_1__["Keyboard"]; });
125
126
127
128_foundation_core__WEBPACK_IMPORTED_MODULE_0__["Foundation"].Keyboard = _foundation_util_keyboard__WEBPACK_IMPORTED_MODULE_1__["Keyboard"];
129
130
131/***/ }),
132
133/***/ "./js/foundation.util.keyboard.js":
134/*!****************************************!*\
135 !*** ./js/foundation.util.keyboard.js ***!
136 \****************************************/
137/*! exports provided: Keyboard */
138/***/ (function(module, __webpack_exports__, __webpack_require__) {
139
140"use strict";
141__webpack_require__.r(__webpack_exports__);
142/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Keyboard", function() { return Keyboard; });
143/* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! jquery */ "jquery");
144/* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(jquery__WEBPACK_IMPORTED_MODULE_0__);
145/* harmony import */ var _foundation_core_utils__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./foundation.core.utils */ "./foundation.core");
146/* harmony import */ var _foundation_core_utils__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_foundation_core_utils__WEBPACK_IMPORTED_MODULE_1__);
147/*******************************************
148 * *
149 * This util was created by Marius Olbertz *
150 * Please thank Marius on GitHub /owlbertz *
151 * or the web http://www.mariusolbertz.de/ *
152 * *
153 ******************************************/
154
155
156
157
158var keyCodes = {
159 9: 'TAB',
160 13: 'ENTER',
161 27: 'ESCAPE',
162 32: 'SPACE',
163 35: 'END',
164 36: 'HOME',
165 37: 'ARROW_LEFT',
166 38: 'ARROW_UP',
167 39: 'ARROW_RIGHT',
168 40: 'ARROW_DOWN'
169};
170var commands = {}; // Functions pulled out to be referenceable from internals
171
172function findFocusable($element) {
173 if (!$element) {
174 return false;
175 }
176
177 return $element.find('a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, object, embed, *[tabindex], *[contenteditable]').filter(function () {
178 if (!jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).is(':visible') || jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).attr('tabindex') < 0) {
179 return false;
180 } //only have visible elements and those that have a tabindex greater or equal 0
181
182
183 return true;
184 });
185}
186
187function parseKey(event) {
188 var key = keyCodes[event.which || event.keyCode] || String.fromCharCode(event.which).toUpperCase(); // Remove un-printable characters, e.g. for `fromCharCode` calls for CTRL only events
189
190 key = key.replace(/\W+/, '');
191 if (event.shiftKey) key = "SHIFT_".concat(key);
192 if (event.ctrlKey) key = "CTRL_".concat(key);
193 if (event.altKey) key = "ALT_".concat(key); // Remove trailing underscore, in case only modifiers were used (e.g. only `CTRL_ALT`)
194
195 key = key.replace(/_$/, '');
196 return key;
197}
198
199var Keyboard = {
200 keys: getKeyCodes(keyCodes),
201
202 /**
203 * Parses the (keyboard) event and returns a String that represents its key
204 * Can be used like Foundation.parseKey(event) === Foundation.keys.SPACE
205 * @param {Event} event - the event generated by the event handler
206 * @return String key - String that represents the key pressed
207 */
208 parseKey: parseKey,
209
210 /**
211 * Handles the given (keyboard) event
212 * @param {Event} event - the event generated by the event handler
213 * @param {String} component - Foundation component's name, e.g. Slider or Reveal
214 * @param {Objects} functions - collection of functions that are to be executed
215 */
216 handleKey: function handleKey(event, component, functions) {
217 var commandList = commands[component],
218 keyCode = this.parseKey(event),
219 cmds,
220 command,
221 fn;
222 if (!commandList) return console.warn('Component not defined!'); // Ignore the event if it was already handled
223
224 if (event.zfIsKeyHandled === true) return; // This component does not differentiate between ltr and rtl
225
226 if (typeof commandList.ltr === 'undefined') {
227 cmds = commandList; // use plain list
228 } else {
229 // merge ltr and rtl: if document is rtl, rtl overwrites ltr and vice versa
230 if (Object(_foundation_core_utils__WEBPACK_IMPORTED_MODULE_1__["rtl"])()) cmds = jquery__WEBPACK_IMPORTED_MODULE_0___default.a.extend({}, commandList.ltr, commandList.rtl);else cmds = jquery__WEBPACK_IMPORTED_MODULE_0___default.a.extend({}, commandList.rtl, commandList.ltr);
231 }
232
233 command = cmds[keyCode];
234 fn = functions[command]; // Execute the handler if found
235
236 if (fn && typeof fn === 'function') {
237 var returnValue = fn.apply(); // Mark the event as "handled" to prevent future handlings
238
239 event.zfIsKeyHandled = true; // Execute function when event was handled
240
241 if (functions.handled || typeof functions.handled === 'function') {
242 functions.handled(returnValue);
243 }
244 } else {
245 // Execute function when event was not handled
246 if (functions.unhandled || typeof functions.unhandled === 'function') {
247 functions.unhandled();
248 }
249 }
250 },
251
252 /**
253 * Finds all focusable elements within the given `$element`
254 * @param {jQuery} $element - jQuery object to search within
255 * @return {jQuery} $focusable - all focusable elements within `$element`
256 */
257 findFocusable: findFocusable,
258
259 /**
260 * Returns the component name name
261 * @param {Object} component - Foundation component, e.g. Slider or Reveal
262 * @return String componentName
263 */
264 register: function register(componentName, cmds) {
265 commands[componentName] = cmds;
266 },
267 // TODO9438: These references to Keyboard need to not require global. Will 'this' work in this context?
268 //
269
270 /**
271 * Traps the focus in the given element.
272 * @param {jQuery} $element jQuery object to trap the foucs into.
273 */
274 trapFocus: function trapFocus($element) {
275 var $focusable = findFocusable($element),
276 $firstFocusable = $focusable.eq(0),
277 $lastFocusable = $focusable.eq(-1);
278 $element.on('keydown.zf.trapfocus', function (event) {
279 if (event.target === $lastFocusable[0] && parseKey(event) === 'TAB') {
280 event.preventDefault();
281 $firstFocusable.focus();
282 } else if (event.target === $firstFocusable[0] && parseKey(event) === 'SHIFT_TAB') {
283 event.preventDefault();
284 $lastFocusable.focus();
285 }
286 });
287 },
288
289 /**
290 * Releases the trapped focus from the given element.
291 * @param {jQuery} $element jQuery object to release the focus for.
292 */
293 releaseFocus: function releaseFocus($element) {
294 $element.off('keydown.zf.trapfocus');
295 }
296};
297/*
298 * Constants for easier comparing.
299 * Can be used like Foundation.parseKey(event) === Foundation.keys.SPACE
300 */
301
302function getKeyCodes(kcs) {
303 var k = {};
304
305 for (var kc in kcs) {
306 k[kcs[kc]] = kcs[kc];
307 }
308
309 return k;
310}
311
312
313
314/***/ }),
315
316/***/ 23:
317/*!**************************************************************!*\
318 !*** multi ./js/entries/plugins/foundation.util.keyboard.js ***!
319 \**************************************************************/
320/*! no static exports found */
321/***/ (function(module, exports, __webpack_require__) {
322
323module.exports = __webpack_require__(/*! /Users/joeworkman/Development/foundation-sites/js/entries/plugins/foundation.util.keyboard.js */"./js/entries/plugins/foundation.util.keyboard.js");
324
325
326/***/ }),
327
328/***/ "jquery":
329/*!********************************************************************************************!*\
330 !*** external {"root":["jQuery"],"amd":"jquery","commonjs":"jquery","commonjs2":"jquery"} ***!
331 \********************************************************************************************/
332/*! no static exports found */
333/***/ (function(module, exports) {
334
335module.exports = __WEBPACK_EXTERNAL_MODULE_jquery__;
336
337/***/ })
338
339/******/ });
340});
341//# sourceMappingURL=foundation.util.keyboard.js.map
\No newline at end of file