Commit 7c1d0a10 authored by Johann-S's avatar Johann-S Committed by XhmikosR
Browse files

Wrap our objects into IIFE

parent bcbea028
5 merge requests!31948Examples/Floating-labels: fix bad behavior with autofill,!30064test,!29779Responsive sizing,!28882fix custom-select-indicator in IE10,!28721Hot test
Showing with 395 additions and 353 deletions
+395 -353
...@@ -5,56 +5,66 @@ ...@@ -5,56 +5,66 @@
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
*/ */
const mapData = (() => { const Data = (() => {
const storeData = {}
let id = 1 /**
return { * ------------------------------------------------------------------------
set(element, key, data) { * Constants
if (typeof element.key === 'undefined') { * ------------------------------------------------------------------------
element.key = { */
key,
id
const mapData = (() => {
const storeData = {}
let id = 1
return {
set(element, key, data) {
if (typeof element.key === 'undefined') {
element.key = {
key,
id
}
} }
}
storeData[id] = data storeData[id] = data
id++ id++
}, },
get(element, key) { get(element, key) {
if (typeof element === 'undefined' || typeof element.key === 'undefined') { if (typeof element === 'undefined' || typeof element.key === 'undefined') {
return null
}
const keyProperties = element.key
if (keyProperties.key === key) {
return storeData[keyProperties.id]
}
return null return null
} },
delete(element, key) {
if (typeof element.key === 'undefined') {
return
}
const keyProperties = element.key const keyProperties = element.key
if (keyProperties.key === key) { if (keyProperties.key === key) {
return storeData[keyProperties.id] delete storeData[keyProperties.id]
} delete element.key
return null }
},
delete(element, key) {
if (typeof element.key === 'undefined') {
return
} }
}
})()
const keyProperties = element.key return {
if (keyProperties.key === key) { setData(instance, key, data) {
delete storeData[keyProperties.id] mapData.set(instance, key, data)
delete element.key },
} getData(instance, key) {
return mapData.get(instance, key)
},
removeData(instance, key) {
mapData.delete(instance, key)
} }
} }
})() })()
const Data = {
setData(instance, key, data) {
mapData.set(instance, key, data)
},
getData(instance, key) {
return mapData.get(instance, key)
},
removeData(instance, key) {
mapData.delete(instance, key)
}
}
export default Data export default Data
This diff is collapsed.
...@@ -5,76 +5,86 @@ ...@@ -5,76 +5,86 @@
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
*/ */
// matches polyfill (see: https://mzl.la/2ikXneG) const SelectorEngine = (() => {
let fnMatches = null
if (!Element.prototype.matches) {
fnMatches =
Element.prototype.msMatchesSelector ||
Element.prototype.webkitMatchesSelector
} else {
fnMatches = Element.prototype.matches
}
// closest polyfill (see: https://mzl.la/2vXggaI)
let fnClosest = null
if (!Element.prototype.closest) {
fnClosest = (element, selector) => {
let ancestor = element
if (!document.documentElement.contains(element)) {
return null
}
do {
if (fnMatches.call(ancestor, selector)) {
return ancestor
}
ancestor = ancestor.parentElement /**
} while (ancestor !== null) * ------------------------------------------------------------------------
* Polyfills
* ------------------------------------------------------------------------
*/
return null // matches polyfill (see: https://mzl.la/2ikXneG)
let fnMatches = null
if (!Element.prototype.matches) {
fnMatches =
Element.prototype.msMatchesSelector ||
Element.prototype.webkitMatchesSelector
} else {
fnMatches = Element.prototype.matches
} }
} else {
// eslint-disable-next-line arrow-body-style
fnClosest = (element, selector) => {
return element.closest(selector)
}
}
const SelectorEngine = { // closest polyfill (see: https://mzl.la/2vXggaI)
matches(element, selector) { let fnClosest = null
return fnMatches.call(element, selector) if (!Element.prototype.closest) {
}, fnClosest = (element, selector) => {
let ancestor = element
if (!document.documentElement.contains(element)) {
return null
}
do {
if (fnMatches.call(ancestor, selector)) {
return ancestor
}
ancestor = ancestor.parentElement
} while (ancestor !== null)
find(selector, element = document) {
if (typeof selector !== 'string') {
return null return null
} }
} else {
if (selector.indexOf('#') === 0) { // eslint-disable-next-line arrow-body-style
return SelectorEngine.findOne(selector, element) fnClosest = (element, selector) => {
return element.closest(selector)
} }
}
return element.querySelectorAll(selector) return {
}, matches(element, selector) {
return fnMatches.call(element, selector)
},
findOne(selector, element = document) { find(selector, element = document) {
if (typeof selector !== 'string') { if (typeof selector !== 'string') {
return null return null
} }
let selectorType = 'querySelector' if (selector.indexOf('#') === 0) {
if (selector.indexOf('#') === 0) { return SelectorEngine.findOne(selector, element)
selectorType = 'getElementById' }
selector = selector.substr(1, selector.length)
} return element.querySelectorAll(selector)
},
return element[selectorType](selector) findOne(selector, element = document) {
}, if (typeof selector !== 'string') {
return null
}
let selectorType = 'querySelector'
if (selector.indexOf('#') === 0) {
selectorType = 'getElementById'
selector = selector.substr(1, selector.length)
}
closest(element, selector) { return element[selectorType](selector)
return fnClosest(element, selector) },
closest(element, selector) {
return fnClosest(element, selector)
}
} }
} })()
export default SelectorEngine export default SelectorEngine
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment