From 200331107d9f00203515c670edbcb5927860ecdb Mon Sep 17 00:00:00 2001 From: Roman Melnyk Date: Tue, 18 Sep 2018 18:09:36 +0300 Subject: [PATCH] Fix bad merge. --- package.json | 2 +- src/utils/index.js | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/utils/index.js diff --git a/package.json b/package.json index 681a043c..20f73b33 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-draggable-resizable", - "version": "2.0.0-beta.0", + "version": "2.0.1", "author": "Maurizio Bonani ", "main": "dist/index.js", "jsnext:main": "src/index.js", diff --git a/src/utils/index.js b/src/utils/index.js new file mode 100644 index 00000000..befa060f --- /dev/null +++ b/src/utils/index.js @@ -0,0 +1,57 @@ +export function isFunction(func) { + return typeof func === "function" || Object.prototype.toString.call(func) === "[object Function]"; +} + +export function matchesSelectorToParentElements(el, selector, baseNode) { + let node = el; + + const matchesSelectorFunc = [ + "matches", + "webkitMatchesSelector", + "mozMatchesSelector", + "msMatchesSelector", + "oMatchesSelector" + ].find(func => isFunction(node[func])); + + if (!isFunction(node[matchesSelectorFunc])) { + return false; + } + + do { + if (node[matchesSelectorFunc](selector)) { + return true; + } + if (node === baseNode) { + return false; + } + node = node.parentNode; + } while (node); + + return false; +} + +export function addEvent(el, event, handler) { + if (!el) { + return false; + } + if (el.attachEvent) { + el.attachEvent("on" + event, handler); + } else if (el.addEventListener) { + el.addEventListener(event, handler, true); + } else { + el["on" + event] = handler; + } +} + +export function removeEvent(el, event, handler) { + if (!el) { + return false; + } + if (el.detachEvent) { + el.detachEvent("on" + event, handler); + } else if (el.removeEventListener) { + el.removeEventListener(event, handler, true); + } else { + el["on" + event] = null; + } +} \ No newline at end of file