-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zhigang.li
committed
Nov 19, 2018
1 parent
228cd68
commit 8552ce1
Showing
5 changed files
with
138 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,9 @@ | ||
import { on } from '@/libs/tools' | ||
import draggable from './module/draggable' | ||
import clipboard from './module/clipboard' | ||
|
||
const directives = { | ||
draggable: { | ||
inserted: (el, binding, vnode) => { | ||
let triggerDom = document.querySelector(binding.value.trigger) | ||
triggerDom.style.cursor = 'move' | ||
let bodyDom = document.querySelector(binding.value.body) | ||
let pageX = 0 | ||
let pageY = 0 | ||
let transformX = 0 | ||
let transformY = 0 | ||
let canMove = false | ||
const handleMousedown = e => { | ||
let transform = /\(.*\)/.exec(bodyDom.style.transform) | ||
if (transform) { | ||
transform = transform[0].slice(1, transform[0].length - 1) | ||
let splitxy = transform.split('px, ') | ||
transformX = parseFloat(splitxy[0]) | ||
transformY = parseFloat(splitxy[1].split('px')[0]) | ||
} | ||
pageX = e.pageX | ||
pageY = e.pageY | ||
canMove = true | ||
} | ||
const handleMousemove = e => { | ||
let xOffset = e.pageX - pageX + transformX | ||
let yOffset = e.pageY - pageY + transformY | ||
if (canMove) bodyDom.style.transform = `translate(${xOffset}px, ${yOffset}px)` | ||
} | ||
const handleMouseup = e => { | ||
canMove = false | ||
} | ||
on(triggerDom, 'mousedown', handleMousedown) | ||
on(document, 'mousemove', handleMousemove) | ||
on(document, 'mouseup', handleMouseup) | ||
}, | ||
update: (el, binding, vnode) => { | ||
if (!binding.value.recover) return | ||
let bodyDom = document.querySelector(binding.value.body) | ||
bodyDom.style.transform = '' | ||
} | ||
} | ||
draggable, | ||
clipboard | ||
} | ||
|
||
export default directives |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import Clipboard from 'clipboard' | ||
export default { | ||
bind: (el, binding) => { | ||
const clipboard = new Clipboard(el, { | ||
text: () => binding.value.value | ||
}) | ||
el.__success_callback__ = binding.value.success | ||
el.__error_callback__ = binding.value.error | ||
clipboard.on('success', e => { | ||
const callback = el.__success_callback__ | ||
callback && callback(e) | ||
}) | ||
clipboard.on('error', e => { | ||
const callback = el.__error_callback__ | ||
callback && callback(e) | ||
}) | ||
el.__clipboard__ = clipboard | ||
}, | ||
update: (el, binding) => { | ||
el.__clipboard__.text = () => binding.value.value | ||
el.__success_callback__ = binding.value.success | ||
el.__error_callback__ = binding.value.error | ||
}, | ||
unbind: (el, binding) => { | ||
delete el.__success_callback__ | ||
delete el.__error_callback__ | ||
el.__clipboard__.destroy() | ||
delete el.__clipboard__ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { on } from '@/libs/tools' | ||
export default { | ||
inserted: (el, binding, vnode) => { | ||
let triggerDom = document.querySelector(binding.value.trigger) | ||
triggerDom.style.cursor = 'move' | ||
let bodyDom = document.querySelector(binding.value.body) | ||
let pageX = 0 | ||
let pageY = 0 | ||
let transformX = 0 | ||
let transformY = 0 | ||
let canMove = false | ||
const handleMousedown = e => { | ||
let transform = /\(.*\)/.exec(bodyDom.style.transform) | ||
if (transform) { | ||
transform = transform[0].slice(1, transform[0].length - 1) | ||
let splitxy = transform.split('px, ') | ||
transformX = parseFloat(splitxy[0]) | ||
transformY = parseFloat(splitxy[1].split('px')[0]) | ||
} | ||
pageX = e.pageX | ||
pageY = e.pageY | ||
canMove = true | ||
} | ||
const handleMousemove = e => { | ||
let xOffset = e.pageX - pageX + transformX | ||
let yOffset = e.pageY - pageY + transformY | ||
if (canMove) bodyDom.style.transform = `translate(${xOffset}px, ${yOffset}px)` | ||
} | ||
const handleMouseup = e => { | ||
canMove = false | ||
} | ||
on(triggerDom, 'mousedown', handleMousedown) | ||
on(document, 'mousemove', handleMousemove) | ||
on(document, 'mouseup', handleMouseup) | ||
}, | ||
update: (el, binding, vnode) => { | ||
if (!binding.value.recover) return | ||
let bodyDom = document.querySelector(binding.value.body) | ||
bodyDom.style.transform = '' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters