346 lines
11 KiB
JavaScript
346 lines
11 KiB
JavaScript
/*!
|
|
{
|
|
"copywrite": "Copyright (c) 2018-present",
|
|
"date": "2019-01-21T12:39:36.944Z",
|
|
"describe": "",
|
|
"description": "Vue directive to react on clicks outside an element.",
|
|
"file": "v-click-outside-x.js",
|
|
"hash": "092bce160dbfe488bc08",
|
|
"license": "MIT",
|
|
"version": "3.7.1"
|
|
}
|
|
*/
|
|
(function webpackUniversalModuleDefinition(root, factory) {
|
|
if(typeof exports === 'object' && typeof module === 'object')
|
|
module.exports = factory();
|
|
else if(typeof define === 'function' && define.amd)
|
|
define([], factory);
|
|
else if(typeof exports === 'object')
|
|
exports["vClickOutside"] = factory();
|
|
else
|
|
root["vClickOutside"] = factory();
|
|
})((function () {
|
|
'use strict';
|
|
|
|
if (typeof self !== 'undefined') {
|
|
return self;
|
|
}
|
|
|
|
if (typeof window !== 'undefined') {
|
|
return window;
|
|
}
|
|
|
|
if (typeof global !== 'undefined') {
|
|
return global;
|
|
}
|
|
|
|
return Function('return this')();
|
|
}()), function() {
|
|
return /******/ (function(modules) { // webpackBootstrap
|
|
/******/ // The module cache
|
|
/******/ var installedModules = {};
|
|
/******/
|
|
/******/ // The require function
|
|
/******/ function __webpack_require__(moduleId) {
|
|
/******/
|
|
/******/ // Check if module is in cache
|
|
/******/ if(installedModules[moduleId]) {
|
|
/******/ return installedModules[moduleId].exports;
|
|
/******/ }
|
|
/******/ // Create a new module (and put it into the cache)
|
|
/******/ var module = installedModules[moduleId] = {
|
|
/******/ i: moduleId,
|
|
/******/ l: false,
|
|
/******/ exports: {}
|
|
/******/ };
|
|
/******/
|
|
/******/ // Execute the module function
|
|
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
|
/******/
|
|
/******/ // Flag the module as loaded
|
|
/******/ module.l = true;
|
|
/******/
|
|
/******/ // Return the exports of the module
|
|
/******/ return module.exports;
|
|
/******/ }
|
|
/******/
|
|
/******/
|
|
/******/ // expose the modules object (__webpack_modules__)
|
|
/******/ __webpack_require__.m = modules;
|
|
/******/
|
|
/******/ // expose the module cache
|
|
/******/ __webpack_require__.c = installedModules;
|
|
/******/
|
|
/******/ // define getter function for harmony exports
|
|
/******/ __webpack_require__.d = function(exports, name, getter) {
|
|
/******/ if(!__webpack_require__.o(exports, name)) {
|
|
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
|
|
/******/ }
|
|
/******/ };
|
|
/******/
|
|
/******/ // define __esModule on exports
|
|
/******/ __webpack_require__.r = function(exports) {
|
|
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
/******/ }
|
|
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
/******/ };
|
|
/******/
|
|
/******/ // create a fake namespace object
|
|
/******/ // mode & 1: value is a module id, require it
|
|
/******/ // mode & 2: merge all properties of value into the ns
|
|
/******/ // mode & 4: return value when already ns object
|
|
/******/ // mode & 8|1: behave like require
|
|
/******/ __webpack_require__.t = function(value, mode) {
|
|
/******/ if(mode & 1) value = __webpack_require__(value);
|
|
/******/ if(mode & 8) return value;
|
|
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
|
|
/******/ var ns = Object.create(null);
|
|
/******/ __webpack_require__.r(ns);
|
|
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
|
|
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
|
|
/******/ return ns;
|
|
/******/ };
|
|
/******/
|
|
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
|
/******/ __webpack_require__.n = function(module) {
|
|
/******/ var getter = module && module.__esModule ?
|
|
/******/ function getDefault() { return module['default']; } :
|
|
/******/ function getModuleExports() { return module; };
|
|
/******/ __webpack_require__.d(getter, 'a', getter);
|
|
/******/ return getter;
|
|
/******/ };
|
|
/******/
|
|
/******/ // Object.prototype.hasOwnProperty.call
|
|
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
|
/******/
|
|
/******/ // __webpack_public_path__
|
|
/******/ __webpack_require__.p = "";
|
|
/******/
|
|
/******/
|
|
/******/ // Load entry module and return exports
|
|
/******/ return __webpack_require__(__webpack_require__.s = 0);
|
|
/******/ })
|
|
/************************************************************************/
|
|
/******/ ([
|
|
/* 0 */
|
|
/***/ (function(module, exports, __webpack_require__) {
|
|
|
|
"use strict";
|
|
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.install = install;
|
|
exports.directive = void 0;
|
|
|
|
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
|
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
|
|
|
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
|
|
var CLICK = 'click';
|
|
var captureInstances = Object.create(null);
|
|
var nonCaptureInstances = Object.create(null);
|
|
var instancesList = [captureInstances, nonCaptureInstances];
|
|
/**
|
|
* The common event handler for bot capture and non-capture events.
|
|
*
|
|
* @param {!Object} context - The event context.
|
|
* @param {!Object} instances - The capture or non-capture registered instances.
|
|
* @param {Event} event - The event object.
|
|
* @returns {undefined} Default.
|
|
*/
|
|
|
|
var commonHandler = function _onCommonEvent(context, instances, event) {
|
|
var target = event.target;
|
|
|
|
var itemIteratee = function _itemIteratee(item) {
|
|
var el = item.el;
|
|
|
|
if (el !== target && !el.contains(target)) {
|
|
var binding = item.binding;
|
|
|
|
if (binding.modifiers.stop) {
|
|
event.stopPropagation();
|
|
}
|
|
|
|
if (binding.modifiers.prevent) {
|
|
event.preventDefault();
|
|
}
|
|
|
|
binding.value.call(context, event);
|
|
}
|
|
};
|
|
|
|
var keysIteratee = function _keysIteratee(eventName) {
|
|
return instances[eventName].forEach(itemIteratee);
|
|
};
|
|
|
|
Object.keys(instances).forEach(keysIteratee);
|
|
};
|
|
/**
|
|
* Event handler for capture events.
|
|
*
|
|
* @param {Event} event - The event object.
|
|
*/
|
|
|
|
|
|
var captureEventHandler = function onCaptureEvent(event) {
|
|
/* eslint-disable-next-line babel/no-invalid-this */
|
|
commonHandler(this, captureInstances, event);
|
|
};
|
|
/**
|
|
* Event handler for non-capture events.
|
|
*
|
|
* @param {Event} event - The event object.
|
|
*/
|
|
|
|
|
|
var nonCaptureEventHandler = function onNonCaptureEvent(event) {
|
|
/* eslint-disable-next-line babel/no-invalid-this */
|
|
commonHandler(this, nonCaptureInstances, event);
|
|
};
|
|
/**
|
|
* Get the correct event handler: Capture or non-capture.
|
|
*
|
|
* @param {boolean} useCapture - Indicate which handler to use; 'true' to use
|
|
* capture handler or 'false' for non-capture.
|
|
* @returns {Function} - The event handler.
|
|
*/
|
|
|
|
|
|
var getEventHandler = function _getEventHandler(useCapture) {
|
|
return useCapture ? captureEventHandler : nonCaptureEventHandler;
|
|
};
|
|
/**
|
|
* The directive definition.
|
|
* {@link https://vuejs.org/v2/guide/custom-directive.html|Custom directive}
|
|
*
|
|
* @namespace
|
|
* @property {!Object} $_captureInstances - Registered capture instances.
|
|
* @property {!Object} $_nonCaptureInstances - Registered non-capture instances.
|
|
* @property {Function} $_onCaptureEvent - Event handler for capture events.
|
|
* @property {Function} $_onNonCaptureEvent - Event handler for non-capture events.
|
|
* @property {Function} bind - Called only once, when the directive is first
|
|
* bound to the element.
|
|
* @property {Function} unbind - Called only once, when the directive is unbound
|
|
* from the element.
|
|
* @property {string} version - The version number of this release.
|
|
*/
|
|
|
|
|
|
var directive = Object.defineProperties({}, {
|
|
$_captureInstances: {
|
|
value: captureInstances
|
|
},
|
|
$_nonCaptureInstances: {
|
|
value: nonCaptureInstances
|
|
},
|
|
$_onCaptureEvent: {
|
|
value: captureEventHandler
|
|
},
|
|
$_onNonCaptureEvent: {
|
|
value: nonCaptureEventHandler
|
|
},
|
|
bind: {
|
|
value: function bind(el, binding) {
|
|
if (typeof binding.value !== 'function') {
|
|
throw new TypeError('Binding value must be a function.');
|
|
}
|
|
|
|
var arg = binding.arg || CLICK;
|
|
|
|
var normalisedBinding = _objectSpread({}, binding, {
|
|
arg: arg,
|
|
modifiers: _objectSpread({}, {
|
|
capture: false,
|
|
prevent: false,
|
|
stop: false
|
|
}, binding.modifiers)
|
|
});
|
|
|
|
var useCapture = normalisedBinding.modifiers.capture;
|
|
var instances = useCapture ? captureInstances : nonCaptureInstances;
|
|
|
|
if (!Array.isArray(instances[arg])) {
|
|
instances[arg] = [];
|
|
}
|
|
|
|
if (instances[arg].push({
|
|
el: el,
|
|
binding: normalisedBinding
|
|
}) === 1) {
|
|
if ((typeof document === "undefined" ? "undefined" : _typeof(document)) === 'object' && document) {
|
|
document.addEventListener(arg, getEventHandler(useCapture), useCapture);
|
|
}
|
|
}
|
|
}
|
|
},
|
|
unbind: {
|
|
value: function unbind(el) {
|
|
var compareElements = function _compareElements(item) {
|
|
return item.el !== el;
|
|
};
|
|
|
|
var instancesIteratee = function _instancesIteratee(instances) {
|
|
var instanceKeys = Object.keys(instances);
|
|
|
|
if (instanceKeys.length) {
|
|
var useCapture = instances === captureInstances;
|
|
|
|
var keysIteratee = function _keysIteratee(eventName) {
|
|
var newInstance = instances[eventName].filter(compareElements);
|
|
|
|
if (newInstance.length) {
|
|
instances[eventName] = newInstance;
|
|
} else {
|
|
if ((typeof document === "undefined" ? "undefined" : _typeof(document)) === 'object' && document) {
|
|
document.removeEventListener(eventName, getEventHandler(useCapture), useCapture);
|
|
}
|
|
|
|
delete instances[eventName];
|
|
}
|
|
};
|
|
|
|
instanceKeys.forEach(keysIteratee);
|
|
}
|
|
};
|
|
|
|
instancesList.forEach(instancesIteratee);
|
|
}
|
|
},
|
|
|
|
/* Note: This needs to be manually updated to match package.json. */
|
|
version: {
|
|
enumerable: true,
|
|
value: '3.7.1'
|
|
}
|
|
});
|
|
/**
|
|
* @typedef {Function} Vue - The constructor.
|
|
* @property {Function} directive - You can register a global custom directive
|
|
* with the Vue.directive() method, passing in a directiveID followed by a
|
|
* definition object.
|
|
*/
|
|
|
|
/**
|
|
* A Vue.js plugin should expose an install method. The method will be called
|
|
* with the Vue constructor as the first argument, along with possible options.
|
|
* {@link https://vuejs.org/v2/guide/plugins.html#Writing-a-Plugin|Writing a plugin}.
|
|
*
|
|
* @param {Vue} Vue - The Vue function.
|
|
*/
|
|
|
|
exports.directive = directive;
|
|
|
|
function install(Vue) {
|
|
Vue.directive('click-outside', directive);
|
|
}
|
|
|
|
/***/ })
|
|
/******/ ]);
|
|
});
|
|
//# sourceMappingURL=v-click-outside-x.js.map
|