diff --git a/Readme.md b/Readme.md
index d5a35e2..bf0621f 100644
--- a/Readme.md
+++ b/Readme.md
@@ -30,7 +30,7 @@
- [ ] 表单组件-多级联动(`wc-cascadar`)
- [x] 表单组件-开关(`wc-switch`)
- [x] 图标组件(`wc-icon`)
-- [x] 弹层插件(`layer`)
+- [x] 弹层插件(`layer`、`wc-layer`)
- [ ] markdown解析器(`marked`) 待重构...
- [x] md5(`md5`)
- [ ] md文本编辑器(`anot-meditor`) 待重构...
diff --git a/build.dev.js b/build.dev.js
index bc9d81b..6fe4498 100644
--- a/build.dev.js
+++ b/build.dev.js
@@ -49,7 +49,7 @@ function fixImport(str) {
return str
.replace(/import '([\w-/_.]*)'/g, 'import "$1.js"')
.replace(
- /import ([\w\s,{}]*) from '([a-z0-9\/\.\-_]*)'/g,
+ /import ([\w\s,{}$]*) from '([a-z0-9\/\.\-_]*)'/g,
'import $1 from "$2.js"'
)
}
diff --git a/build.prod.js b/build.prod.js
index 4768cfe..c134111 100644
--- a/build.prod.js
+++ b/build.prod.js
@@ -49,7 +49,7 @@ function fixImport(str) {
return str
.replace(/import '([\w-/_.]*)'/g, 'import "$1.js"')
.replace(
- /import ([\w\s,{}]*) from '([a-z0-9\/\.\-_]*)'/g,
+ /import ([\w\s,{}$]*) from '([a-z0-9\/\.\-_]*)'/g,
'import $1 from "$2.js"'
)
}
diff --git a/index.js b/index.js
deleted file mode 100644
index ebaa41c..0000000
--- a/index.js
+++ /dev/null
@@ -1,7 +0,0 @@
-/**
- *
- * @authors yutent (yutent@doui.cc)
- * @date 2017-12-23 14:47:32
- * @version $Id$
- */
-
diff --git a/src/drag/core.js b/src/drag/core.js
index f37e970..7a9d3f6 100644
--- a/src/drag/core.js
+++ b/src/drag/core.js
@@ -6,7 +6,7 @@
'use strict'
-import { bind, unbind } from '../utils'
+import $ from '../utils'
const DEF_OPT = {
axis: '', // x | y | xy 拖拽方向
@@ -41,10 +41,10 @@ export default class Drag {
// 鼠标状态图标
node.style.cursor = 'move'
- this._handleResize = bind(window, 'resize', this._init.bind(this))
+ this._handleResize = $.bind(window, 'resize', this._init.bind(this))
// let
- this._handleMousedown = bind(node, 'mousedown', ev => {
+ this._handleMousedown = $.bind(node, 'mousedown', ev => {
if (this.disabled) {
return
}
@@ -74,7 +74,7 @@ export default class Drag {
limit = [pbcr.top, pbcr.right - tw, pbcr.bottom - th, pbcr.left]
}
- let handleMove = bind(document, 'mousemove', ev => {
+ let handleMove = $.bind(document, 'mousemove', ev => {
// 防止拖动到边缘时导致页面滚动
ev.preventDefault()
@@ -119,7 +119,7 @@ export default class Drag {
this.$elem.style.transform = `translate(${_x}px, ${_y}px)`
})
- let handleUp = bind(document, 'mouseup', ev => {
+ let handleUp = $.bind(document, 'mouseup', ev => {
this.$elem.dispatchEvent(
new CustomEvent('dragged', {
detail: {
@@ -131,8 +131,8 @@ export default class Drag {
}
})
)
- unbind(document, 'mousemove', handleMove)
- unbind(document, 'mouseup', handleUp)
+ $.unbind(document, 'mousemove', handleMove)
+ $.unbind(document, 'mouseup', handleUp)
})
})
@@ -143,16 +143,16 @@ export default class Drag {
if (!name || typeof cb !== 'function') {
return
}
- return bind(this, name, cb)
+ return $.bind(this, name, cb)
}
off(name, cb) {
- unbind(this, name, cb)
+ $.unbind(this, name, cb)
}
destroy() {
- unbind(window, 'resize', this._handleResize)
- unbind(this.$drag, 'mousedown', this._handleMousedown)
+ $.unbind(window, 'resize', this._handleResize)
+ $.unbind(this.$drag, 'mousedown', this._handleMousedown)
delete this.$elem
delete this.$drag
diff --git a/src/form/button.wc b/src/form/button.wc
index 7d0dcb9..03120f4 100644
--- a/src/form/button.wc
+++ b/src/form/button.wc
@@ -249,6 +249,8 @@
diff --git a/src/form/star.wc b/src/form/star.wc
index a60ab7a..79650e8 100644
--- a/src/form/star.wc
+++ b/src/form/star.wc
@@ -87,7 +87,7 @@ label {
diff --git a/src/utils.js b/src/utils.js
index 8ad4c53..53e2303 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -6,108 +6,113 @@
function noop() {}
-/**
- * 异步回调
- */
-export const nextTick = (function() {
- let queue = []
- function callback() {
- let n = queue.length
- for (let i = 0; i < n; i++) {
- queue[i]()
- }
- queue = queue.slice(n)
- }
-
- let node = document.createTextNode('')
- new MutationObserver(callback).observe(node, { characterData: true })
-
- let bool = false
- return function(fn) {
- queue.push(fn)
- bool = !bool
- node.data = bool
- }
-})()
-
-/**
- * 对象/数组遍历
- * 支持跳出
- */
-export const each = function(obj, fn) {
- if (obj) {
- if (Array.isArray(obj)) {
- for (let i = 0, it; (it = obj[i++]); ) {
- if (fn(it, i - 1) === false) {
- break
- }
- }
- } else {
- for (let i in obj) {
- if (obj.hasOwnProperty(i) && fn(obj[i], i) === false) {
- break
- }
+export default {
+ /**
+ * 异步回调
+ */
+ nextTick: (function() {
+ let queue = []
+ function callback() {
+ let n = queue.length
+ for (let i = 0; i < n; i++) {
+ queue[i]()
}
+ queue = queue.slice(n)
}
- }
-}
-/**
- * 事件绑定
- */
-export const bind = function(dom, type, fn = noop, phase = false) {
- let events = type.split(',')
- each(events, function(t) {
- t = t.trim()
- dom.addEventListener(t, fn, phase)
- })
- return fn
-}
+ let node = document.createTextNode('')
+ new MutationObserver(callback).observe(node, { characterData: true })
-/**
- * 事件绑定(默认不冒泡)
- */
-export const ebind = function(dom, type, fn, phase) {
- function fn2(ev) {
- ev.stopPropagation()
- fn && fn(ev)
- }
- return bind(dom, type, fn2, phase)
-}
+ let bool = false
+ return function(fn) {
+ queue.push(fn)
+ bool = !bool
+ node.data = bool
+ }
+ })(),
-/**
- * 解除事件绑定
- */
-export const unbind = function(dom, type, fn = noop, phase = false) {
- let events = type.split(',')
- each(events, function(t) {
- t = t.trim()
- dom.removeEventListener(t, fn, phase)
- })
-}
-
-// 指定节点外点击(最高不能超过body层)
-export const clickOutside = function(dom, fn = noop) {
- return bind(document, 'mousedown', ev => {
- if (ev) {
- if (ev.path) {
- var path = ev.path.concat()
- while (path.length > 3) {
- if (path.shift() === dom) {
- return
+ /**
+ * 对象/数组遍历
+ * 支持跳出
+ */
+ each(obj, fn) {
+ if (obj) {
+ if (Array.isArray(obj)) {
+ for (let i = 0, it; (it = obj[i++]); ) {
+ if (fn(it, i - 1) === false) {
+ break
}
}
} else {
- var target = ev.explicitOriginalTarget || ev.target
- if (
- dom === target ||
- dom.contains(target) ||
- (dom.root && dom.root.contains(target))
- ) {
- return
+ for (let i in obj) {
+ if (obj.hasOwnProperty(i) && fn(obj[i], i) === false) {
+ break
+ }
}
}
}
- fn(ev)
- })
+ },
+
+ /**
+ * 事件绑定
+ */
+ bind(dom, type, fn = noop, phase = false) {
+ let events = type.split(',')
+ this.each(events, function(t) {
+ t = t.trim()
+ dom.addEventListener(t, fn, phase)
+ })
+ return fn
+ },
+
+ /**
+ * 事件绑定(默认不冒泡)
+ */
+ catch(dom, type, fn, phase) {
+ function fn2(ev) {
+ ev.stopPropagation()
+ fn && fn(ev)
+ }
+ return this.bind(dom, type, fn2, phase)
+ },
+
+ /**
+ * 解除事件绑定
+ */
+ unbind(dom, type, fn = noop, phase = false) {
+ let events = type.split(',')
+ this.each(events, function(t) {
+ t = t.trim()
+ dom.removeEventListener(t, fn, phase)
+ })
+ },
+
+ // 指定节点外点击(最高不能超过body层)
+ outside(dom, fn = noop) {
+ return this.bind(document, 'mousedown', ev => {
+ if (ev) {
+ if (ev.path) {
+ var path = ev.path.concat()
+ while (path.length > 3) {
+ if (path.shift() === dom) {
+ return
+ }
+ }
+ } else {
+ var target = ev.explicitOriginalTarget || ev.target
+ if (
+ dom === target ||
+ dom.contains(target) ||
+ (dom.root && dom.root.contains(target))
+ ) {
+ return
+ }
+ }
+ }
+ fn(ev)
+ })
+ },
+ clearOutside(fn = noop) {
+ this.unbind(document, 'mousedown', fn)
+ }
}