Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

move util in a util folder with the sanitizer #28345

Merged
merged 3 commits into from Feb 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.json
Expand Up @@ -130,7 +130,7 @@
"func-call-spacing": "error",
"func-name-matching": "error",
"func-names": "off",
"func-style": ["error", "declaration"],
"func-style": "off",
"id-blacklist": "error",
"id-length": "off",
"id-match": "error",
Expand Down
63 changes: 33 additions & 30 deletions build/build-plugins.js
Expand Up @@ -41,31 +41,35 @@ const bsPlugins = {
ScrollSpy: path.resolve(__dirname, '../js/src/scrollspy.js'),
Tab: path.resolve(__dirname, '../js/src/tab.js'),
Toast: path.resolve(__dirname, '../js/src/toast.js'),
Tooltip: path.resolve(__dirname, '../js/src/tooltip.js'),
Util: path.resolve(__dirname, '../js/src/util.js')
Tooltip: path.resolve(__dirname, '../js/src/tooltip.js')
}
const rootPath = TEST ? '../js/coverage/dist/' : '../js/dist/'

if (TEST) {
bsPlugins.Util = path.resolve(__dirname, '../js/src/util/index.js')
bsPlugins.Sanitizer = path.resolve(__dirname, '../js/src/util/sanitizer.js')
}

const defaultPluginConfig = {
external: [
bsPlugins.Data,
bsPlugins.EventHandler,
bsPlugins.SelectorEngine,
bsPlugins.Util
bsPlugins.SelectorEngine
],
globals: {
[bsPlugins.Data]: 'Data',
[bsPlugins.EventHandler]: 'EventHandler',
[bsPlugins.SelectorEngine]: 'SelectorEngine',
[bsPlugins.Util]: 'Util'
[bsPlugins.SelectorEngine]: 'SelectorEngine'
}
}

function getConfigByPluginKey(pluginKey) {
if (
pluginKey === 'Data' ||
pluginKey === 'Manipulator' ||
pluginKey === 'Util'
pluginKey === 'Polyfill' ||
pluginKey === 'Util' ||
pluginKey === 'Sanitizer'
) {
return {
external: [],
Expand All @@ -76,21 +80,10 @@ function getConfigByPluginKey(pluginKey) {
if (pluginKey === 'EventHandler' || pluginKey === 'SelectorEngine') {
return {
external: [
bsPlugins.Polyfill,
bsPlugins.Util
bsPlugins.Polyfill
],
globals: {
[bsPlugins.Polyfill]: 'Polyfill',
[bsPlugins.Util]: 'Util'
}
}
}

if (pluginKey === 'Polyfill') {
return {
external: [bsPlugins.Util],
globals: {
[bsPlugins.Util]: 'Util'
[bsPlugins.Polyfill]: 'Polyfill'
}
}
}
Expand Down Expand Up @@ -125,14 +118,12 @@ function getConfigByPluginKey(pluginKey) {
external: [
bsPlugins.Data,
bsPlugins.SelectorEngine,
bsPlugins.Tooltip,
bsPlugins.Util
bsPlugins.Tooltip
],
globals: {
[bsPlugins.Data]: 'Data',
[bsPlugins.SelectorEngine]: 'SelectorEngine',
[bsPlugins.Tooltip]: 'Tooltip',
[bsPlugins.Util]: 'Util'
[bsPlugins.Tooltip]: 'Tooltip'
}
}
}
Expand All @@ -142,14 +133,12 @@ function getConfigByPluginKey(pluginKey) {
external: [
bsPlugins.Data,
bsPlugins.EventHandler,
bsPlugins.Manipulator,
bsPlugins.Util
bsPlugins.Manipulator
],
globals: {
[bsPlugins.Data]: 'Data',
[bsPlugins.EventHandler]: 'EventHandler',
[bsPlugins.Manipulator]: 'Manipulator',
[bsPlugins.Util]: 'Util'
[bsPlugins.Manipulator]: 'Manipulator'
}
}
}
Expand All @@ -161,14 +150,28 @@ function build(plugin) {
const config = getConfigByPluginKey(plugin)
const external = config.external
const globals = config.globals
let pluginPath = rootPath

const utilObjects = [
'Util',
'Sanitizer'
]

const pluginPath = [
const domObjects = [
'Data',
'EventHandler',
'Manipulator',
'Polyfill',
'SelectorEngine'
].includes(plugin) ? `${rootPath}/dom/` : rootPath
]

if (utilObjects.includes(plugin)) {
pluginPath = `${rootPath}/util/`
}

if (domObjects.includes(plugin)) {
pluginPath = `${rootPath}/dom/`
}

const pluginFilename = `${plugin.toLowerCase()}.js`

Expand Down
17 changes: 11 additions & 6 deletions js/src/alert.js
Expand Up @@ -5,10 +5,16 @@
* --------------------------------------------------------------------------
*/

import {
jQuery as $,
TRANSITION_END,
emulateTransitionEnd,
getSelectorFromElement,
getTransitionDurationFromElement
} from './util/index'
import Data from './dom/data'
import EventHandler from './dom/eventHandler'
import SelectorEngine from './dom/selectorEngine'
import Util from './util'

/**
* ------------------------------------------------------------------------
Expand Down Expand Up @@ -83,7 +89,7 @@ class Alert {
// Private

_getRootElement(element) {
const selector = Util.getSelectorFromElement(element)
const selector = getSelectorFromElement(element)
let parent = false

if (selector) {
Expand All @@ -109,11 +115,11 @@ class Alert {
return
}

const transitionDuration = Util.getTransitionDurationFromElement(element)
const transitionDuration = getTransitionDurationFromElement(element)

EventHandler
.one(element, Util.TRANSITION_END, (event) => this._destroyElement(element, event))
Util.emulateTransitionEnd(element, transitionDuration)
.one(element, TRANSITION_END, (event) => this._destroyElement(element, event))
emulateTransitionEnd(element, transitionDuration)
}

_destroyElement(element) {
Expand Down Expand Up @@ -170,7 +176,6 @@ EventHandler
* add .alert to jQuery only if jQuery is present
*/

const $ = Util.jQuery
if (typeof $ !== 'undefined') {
const JQUERY_NO_CONFLICT = $.fn[NAME]
$.fn[NAME] = Alert._jQueryInterface
Expand Down
5 changes: 3 additions & 2 deletions js/src/button.js
Expand Up @@ -5,10 +5,12 @@
* --------------------------------------------------------------------------
*/

import {
jQuery as $
} from './util/index'
import Data from './dom/data'
import EventHandler from './dom/eventHandler'
import SelectorEngine from './dom/selectorEngine'
import Util from './util'

/**
* ------------------------------------------------------------------------
Expand Down Expand Up @@ -180,7 +182,6 @@ EventHandler.on(document, Event.BLUR_DATA_API, Selector.DATA_TOGGLE_CARROT, (eve
* add .button to jQuery only if jQuery is present
*/

const $ = Util.jQuery
if (typeof $ !== 'undefined') {
const JQUERY_NO_CONFLICT = $.fn[NAME]
$.fn[NAME] = Button._jQueryInterface
Expand Down
36 changes: 23 additions & 13 deletions js/src/carousel.js
Expand Up @@ -5,11 +5,22 @@
* --------------------------------------------------------------------------
*/

import {
jQuery as $,
TRANSITION_END,
emulateTransitionEnd,
getSelectorFromElement,
getTransitionDurationFromElement,
isVisible,
makeArray,
reflow,
triggerTransitionEnd,
typeCheckConfig
} from './util/index'
import Data from './dom/data'
import EventHandler from './dom/eventHandler'
import Manipulator from './dom/manipulator'
import SelectorEngine from './dom/selectorEngine'
import Util from './util'

/**
* ------------------------------------------------------------------------
Expand Down Expand Up @@ -143,7 +154,7 @@ class Carousel {
nextWhenVisible() {
// Don't call next when the page isn't visible
// or the carousel or its parent isn't visible
if (!document.hidden && Util.isVisible(this._element)) {
if (!document.hidden && isVisible(this._element)) {
this.next()
}
}
Expand All @@ -160,7 +171,7 @@ class Carousel {
}

if (SelectorEngine.findOne(Selector.NEXT_PREV, this._element)) {
Util.triggerTransitionEnd(this._element)
triggerTransitionEnd(this._element)
this.cycle(true)
}

Expand Down Expand Up @@ -233,7 +244,7 @@ class Carousel {
...Default,
...config
}
Util.typeCheckConfig(NAME, config, DefaultType)
typeCheckConfig(NAME, config, DefaultType)
return config
}

Expand Down Expand Up @@ -320,7 +331,7 @@ class Carousel {
}
}

Util.makeArray(SelectorEngine.find(Selector.ITEM_IMG, this._element)).forEach((itemImg) => {
makeArray(SelectorEngine.find(Selector.ITEM_IMG, this._element)).forEach((itemImg) => {
EventHandler.on(itemImg, Event.DRAG_START, (e) => e.preventDefault())
})

Expand Down Expand Up @@ -356,7 +367,7 @@ class Carousel {

_getItemIndex(element) {
this._items = element && element.parentNode
? Util.makeArray(SelectorEngine.find(Selector.ITEM, element.parentNode))
? makeArray(SelectorEngine.find(Selector.ITEM, element.parentNode))
: []

return this._items.indexOf(element)
Expand Down Expand Up @@ -459,7 +470,7 @@ class Carousel {
if (this._element.classList.contains(ClassName.SLIDE)) {
nextElement.classList.add(orderClassName)

Util.reflow(nextElement)
reflow(nextElement)

activeElement.classList.add(directionalClassName)
nextElement.classList.add(directionalClassName)
Expand All @@ -472,10 +483,10 @@ class Carousel {
this._config.interval = this._config.defaultInterval || this._config.interval
}

const transitionDuration = Util.getTransitionDurationFromElement(activeElement)
const transitionDuration = getTransitionDurationFromElement(activeElement)

EventHandler
.one(activeElement, Util.TRANSITION_END, () => {
.one(activeElement, TRANSITION_END, () => {
nextElement.classList.remove(directionalClassName)
nextElement.classList.remove(orderClassName)
nextElement.classList.add(ClassName.ACTIVE)
Expand All @@ -496,7 +507,7 @@ class Carousel {
}, 0)
})

Util.emulateTransitionEnd(activeElement, transitionDuration)
emulateTransitionEnd(activeElement, transitionDuration)
} else {
activeElement.classList.remove(ClassName.ACTIVE)
nextElement.classList.add(ClassName.ACTIVE)
Expand Down Expand Up @@ -557,7 +568,7 @@ class Carousel {
}

static _dataApiClickHandler(event) {
const selector = Util.getSelectorFromElement(this)
const selector = getSelectorFromElement(this)

if (!selector) {
return
Expand Down Expand Up @@ -603,7 +614,7 @@ EventHandler
.on(document, Event.CLICK_DATA_API, Selector.DATA_SLIDE, Carousel._dataApiClickHandler)

EventHandler.on(window, Event.LOAD_DATA_API, () => {
const carousels = Util.makeArray(SelectorEngine.find(Selector.DATA_RIDE))
const carousels = makeArray(SelectorEngine.find(Selector.DATA_RIDE))
for (let i = 0, len = carousels.length; i < len; i++) {
Carousel._carouselInterface(carousels[i], Data.getData(carousels[i], DATA_KEY))
}
Expand All @@ -616,7 +627,6 @@ EventHandler.on(window, Event.LOAD_DATA_API, () => {
* add .carousel to jQuery only if jQuery is present
*/

const $ = Util.jQuery
if (typeof $ !== 'undefined') {
const JQUERY_NO_CONFLICT = $.fn[NAME]
$.fn[NAME] = Carousel._jQueryInterface
Expand Down