Cleaned up, working on draggable flag

This commit is contained in:
euvl
2017-04-08 08:02:59 +01:00
parent ff173186d0
commit 45bba6dfcd

View File

@@ -83,7 +83,7 @@
components: { components: {
Resizer Resizer
}, },
data() { data () {
return { return {
visible: false, visible: false,
@@ -92,6 +92,11 @@
overlay: false overlay: false
}, },
shift: {
left: 0,
top: 0
},
modal: { modal: {
width: this.width, width: this.width,
height: this.height height: this.height
@@ -107,7 +112,6 @@
}, },
watch: { watch: {
visible (value) { visible (value) {
// if (this.delay > 0) {
if (value) { if (value) {
this.visibility.overlay = true this.visibility.overlay = true
@@ -126,16 +130,8 @@
this.removeDraggableListeners() this.removeDraggableListeners()
}) })
}, this.delay) }, this.delay)
// this.removeDraggableHandlers()
} }
// } else { }
// this.visibility.overlay = value
// this.$nextTick(() => {
// this.visibility.modal = value
// })
// }
},
}, },
created () { created () {
Modal.event.$on('toggle', (name, state, params) => { Modal.event.$on('toggle', (name, state, params) => {
@@ -153,48 +149,49 @@
this.onWindowResize() this.onWindowResize()
}, },
computed: { computed: {
position() { position () {
return { return {
left: Math.max(this.pivotX * (this.window.width - this.modal.width), 0), left: Math.max(this.shift.left + this.pivotX *
top: Math.max(this.pivotY * (this.window.height - this.modal.height), 0) (this.window.width - this.modal.width), 0),
top: Math.max(this.shift.top + this.pivotY *
(this.window.height - this.modal.height), 0)
} }
}, },
modalClass() { modalClass () {
return ['modal', this.classes] return ['modal', this.classes]
}, },
modalStyle() { modalStyle () {
return { return {
top: this.position.top + 'px', top: this.position.top + 'px',
left: this.position.left + 'px', left: this.position.left + 'px',
width: this.modal.width + 'px', width: this.modal.width + 'px',
height: this.modal.height + 'px' height: this.modal.height + 'px'
} }
}, }
}, },
methods: { methods: {
onWindowResize() { onWindowResize () {
this.window.width = window.innerWidth this.window.width = window.innerWidth
this.window.height = window.innerHeight this.window.height = window.innerHeight
if (this.adaptive) { if (this.adaptive) {
let width = Math.min(this.window.width, this.modal.width) let width = Math.min(this.window.width, this.modal.width)
let height = Math.min(this.window.height, this.modal.height) let height = Math.min(this.window.height, this.modal.height)
// Math.max(width, this.minWidth);
this.modal.width = width // Math.max(width, this.minWidth); this.modal.width = width
this.modal.height = height // Math.max(height, this.minHeight); // Math.max(height, this.minHeight);
this.modal.height = height
} }
}, },
genEventObject(params) { genEventObject (params) {
//todo: clean this up //todo: clean this up
return Vue.util.extend( return Vue.util.extend({
{ name: this.name,
name: this.name, ref: this.$refs.modal,
ref: this.$refs.modal, timestamp: Date.now()
timestamp: Date.now() }, params || {});
},
params || {});
}, },
resize(event) { resize (event) {
this.modal.width = event.size.width this.modal.width = event.size.width
this.modal.height = event.size.height this.modal.height = event.size.height
@@ -203,7 +200,7 @@
this.$emit('resize', resizeEvent) this.$emit('resize', resizeEvent)
}, },
toggle(state, params) { toggle (state, params) {
const beforeEventName = this.visible ? 'before-close' : 'before-open' const beforeEventName = this.visible ? 'before-close' : 'before-open'
const afterEventName = this.visible ? 'closed' : 'opened' const afterEventName = this.visible ? 'closed' : 'opened'
@@ -243,6 +240,41 @@
let dragger = this.getDraggableElement() let dragger = this.getDraggableElement()
if (dragger) { if (dragger) {
let startX = 0
let startY = 0
//let shiftX = 0
//let shiftY = 0
let mousedown = (event) => {
document.addEventListener('mousemove', mousemove)
document.addEventListener('mouseup', mouseup)
startX = event.clientX;
startY = event.clientY;
event.preventDefault()
}
let mousemove = (event) => {
this.shift.left = event.clientX - startX
this.shift.top = event.clientY - startY
console.log(this.shift)
event.preventDefault()
}
let mouseup = (event) => {
dragger.removeEventListener('mousedown', mousedown)
document.removeEventListener('mousemove', mousemove)
document.removeEventListener('mouseup', mouseup)
// this.shiftX = shiftX
// this.shiftY = shiftY
// console.log(shiftX, shiftY)
event.preventDefault()
}
dragger.addEventListener('mousedown', mousedown)
console.log(dragger) console.log(dragger)
} }
}, },