mirror of
https://github.com/KevinMidboe/vue-js-modal.git
synced 2025-10-29 18:00:20 +00:00
Fixed min-width, min-height with % w/h
This commit is contained in:
198
dist/index.js
vendored
198
dist/index.js
vendored
File diff suppressed because one or more lines are too long
124
src/Modal.vue
124
src/Modal.vue
@@ -19,7 +19,7 @@
|
|||||||
<resizer v-if="resizable"
|
<resizer v-if="resizable"
|
||||||
:min-width="minWidth"
|
:min-width="minWidth"
|
||||||
:min-height="minHeight"
|
:min-height="minHeight"
|
||||||
@resize="resize"/>
|
@resize="onModalResize"/>
|
||||||
</div>
|
</div>
|
||||||
</transition>
|
</transition>
|
||||||
</div>
|
</div>
|
||||||
@@ -30,6 +30,7 @@
|
|||||||
import Modal from './index'
|
import Modal from './index'
|
||||||
import Resizer from './Resizer.vue'
|
import Resizer from './Resizer.vue'
|
||||||
import { inRange } from './util'
|
import { inRange } from './util'
|
||||||
|
import parseNumber from './parser'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'VueJsModal',
|
name: 'VueJsModal',
|
||||||
@@ -75,49 +76,31 @@
|
|||||||
return value >= 0
|
return value >= 0
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
maxAdaptiveWidth: {
|
|
||||||
type: Number,
|
|
||||||
default: 1
|
|
||||||
// ,
|
|
||||||
// validator (value) {
|
|
||||||
// return value > 0 && value <= 1
|
|
||||||
// }
|
|
||||||
},
|
|
||||||
maxAdaptiveHeight: {
|
|
||||||
type: Number,
|
|
||||||
default: 1
|
|
||||||
// ,
|
|
||||||
// validator (value) {
|
|
||||||
// return value > 0 && value <= 1
|
|
||||||
// }
|
|
||||||
},
|
|
||||||
width: {
|
width: {
|
||||||
type: [Number, String],
|
type: [Number, String],
|
||||||
default: 600,
|
default: 600,
|
||||||
validator (value) {
|
validator (value) {
|
||||||
if (typeof value === 'string') {
|
if (typeof value === 'string') {
|
||||||
return value.charAt(value.length-1) === '%'
|
let width = parseNumber(value)
|
||||||
&& !isNaN(parseFloat(value))
|
return (width.type === '%' || width.type === 'px')
|
||||||
|
&& width.value > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof value === 'number') {
|
|
||||||
return value >= 0
|
return value >= 0
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
height: {
|
height: {
|
||||||
type: [Number, String],
|
type: [Number, String],
|
||||||
default: 300,
|
default: 300,
|
||||||
validator (value) {
|
validator (value) {
|
||||||
if (typeof value === 'string') {
|
if (typeof value === 'string') {
|
||||||
return (value.charAt(value.length-1) === '%'
|
let height = parseNumber(value)
|
||||||
&& !isNaN(parseFloat(value)))
|
return (height.type === '%' || height.type === 'px')
|
||||||
|
&& height.value > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof value === 'number') {
|
|
||||||
return value >= 0
|
return value >= 0
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
pivotX: {
|
pivotX: {
|
||||||
type: Number,
|
type: Number,
|
||||||
@@ -138,6 +121,11 @@
|
|||||||
Resizer
|
Resizer
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
|
let width = parseNumber(this.width)
|
||||||
|
let height = parseNumber(this.height)
|
||||||
|
|
||||||
|
console.log(width, height)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
visible: false,
|
visible: false,
|
||||||
|
|
||||||
@@ -152,23 +140,26 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
modal: {
|
modal: {
|
||||||
width: this.width,
|
widthInit: 0,
|
||||||
height: this.height
|
width: width.value,
|
||||||
|
widthType: width.type,
|
||||||
|
|
||||||
|
heightInit: 0,
|
||||||
|
height: height.value,
|
||||||
|
heightType: height.type
|
||||||
},
|
},
|
||||||
|
|
||||||
window: {
|
window: {
|
||||||
width: 0,
|
width: 0,
|
||||||
height: 0
|
height: 0
|
||||||
},
|
}
|
||||||
|
}
|
||||||
draggableElement: false
|
|
||||||
};
|
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
visible (value) {
|
visible (value) {
|
||||||
if (value) {
|
if (value) {
|
||||||
this.visibility.overlay = true
|
this.visibility.overlay = true
|
||||||
this.adaptSize()
|
// this.adaptSize()
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.visibility.modal = true
|
this.visibility.modal = true
|
||||||
@@ -207,13 +198,15 @@
|
|||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
position () {
|
position () {
|
||||||
const {window, modal, shift} = this
|
const { window, modal, shift } = this
|
||||||
|
|
||||||
const maxLeft = window.width - this.trueModalWidth()
|
const maxLeft = window.width - this.trueModalWidth
|
||||||
const maxTop = window.height - this.trueModalHeight()
|
const maxTop = window.height - this.trueModalHeight
|
||||||
|
|
||||||
const left = shift.left + this.pivotX * (window.width - this.trueModalWidth())
|
const left = shift.left +
|
||||||
const top = shift.top + this.pivotY * (window.height - this.trueModalHeight())
|
this.pivotX * (window.width - this.trueModalWidth)
|
||||||
|
const top = shift.top +
|
||||||
|
this.pivotY * (window.height - this.trueModalHeight)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
left: inRange(0, maxLeft, left),
|
left: inRange(0, maxLeft, left),
|
||||||
@@ -221,16 +214,40 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
trueModalWidth () {
|
||||||
|
const { window, modal } = this
|
||||||
|
const value = modal.widthType === '%'
|
||||||
|
? window.width / 100 * modal.width
|
||||||
|
: modal.width
|
||||||
|
|
||||||
|
return this.adaptive
|
||||||
|
? inRange(this.minWidth, this.window.width, value)
|
||||||
|
: value
|
||||||
|
},
|
||||||
|
|
||||||
|
trueModalHeight () {
|
||||||
|
const { window, modal } = this
|
||||||
|
const value = (modal.heightType === '%')
|
||||||
|
? window.height / 100 * modal.height
|
||||||
|
: modal.height
|
||||||
|
|
||||||
|
return this.adaptive
|
||||||
|
? inRange(this.minHeight, this.window.height, value)
|
||||||
|
: value
|
||||||
|
},
|
||||||
|
|
||||||
modalClass () {
|
modalClass () {
|
||||||
return ['v--modal-box', this.classes]
|
return ['v--modal-box', this.classes]
|
||||||
},
|
},
|
||||||
|
|
||||||
modalStyle () {
|
modalStyle () {
|
||||||
|
console.log(this.trueModalWidth, this.trueModalHeight)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
top: this.position.top + 'px',
|
top: this.position.top + 'px',
|
||||||
left: this.position.left + 'px',
|
left: this.position.left + 'px',
|
||||||
width: this.trueModalWidth() + 'px',
|
width: this.trueModalWidth + 'px',
|
||||||
height: this.trueModalHeight() + 'px'
|
height: this.trueModalHeight + 'px'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -238,7 +255,7 @@
|
|||||||
onWindowResize () {
|
onWindowResize () {
|
||||||
this.window.width = window.innerWidth
|
this.window.width = window.innerWidth
|
||||||
this.window.height = window.innerHeight
|
this.window.height = window.innerHeight
|
||||||
this.adaptSize()
|
// this.adaptSize()
|
||||||
},
|
},
|
||||||
|
|
||||||
genEventObject (params) {
|
genEventObject (params) {
|
||||||
@@ -257,29 +274,16 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
adaptSize () {
|
adaptSize () {
|
||||||
if (this.adaptive) {
|
/* if (this.adaptive) {
|
||||||
this.modal.width = inRange(
|
this.modal.width = inRange(this.minWidth, this.window.width,
|
||||||
0,
|
this.trueModalWidth)
|
||||||
this.window.width * this.maxAdaptiveWidth,
|
this.modal.height = inRange(this.minHeight, this.window.height,
|
||||||
this.trueModalWidth())
|
this.trueModalHeight)
|
||||||
this.modal.height = inRange(
|
|
||||||
0,
|
|
||||||
this.window.height * this.maxAdaptiveHeight,
|
|
||||||
this.trueModalHeight())
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
},
|
},
|
||||||
|
|
||||||
trueModalWidth () {
|
onModalResize (event) {
|
||||||
const {window, modal} = this
|
|
||||||
return (typeof modal.width === 'string') ? window.width * parseFloat(modal.width) / 100.0 : modal.width
|
|
||||||
},
|
|
||||||
|
|
||||||
trueModalHeight () {
|
|
||||||
const {window, modal} = this
|
|
||||||
return (typeof modal.height === 'string') ? window.height * parseFloat(modal.height) / 100.0 : modal.height
|
|
||||||
},
|
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ export default {
|
|||||||
size: {}
|
size: {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted () {
|
||||||
this.$el.addEventListener('mousedown', this.start, false)
|
this.$el.addEventListener('mousedown', this.start, false)
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
|||||||
@@ -7,6 +7,10 @@
|
|||||||
var floatRegexp = '[-+]?[0-9]*\.?[0-9]+'
|
var floatRegexp = '[-+]?[0-9]*\.?[0-9]+'
|
||||||
|
|
||||||
var types = [
|
var types = [
|
||||||
|
// {
|
||||||
|
// name: 'rem',
|
||||||
|
// regexp: new RegExp(`^${floatRegexp}rem\$`)
|
||||||
|
// },
|
||||||
{
|
{
|
||||||
name: 'px',
|
name: 'px',
|
||||||
regexp: new RegExp(`^${floatRegexp}px\$`)
|
regexp: new RegExp(`^${floatRegexp}px\$`)
|
||||||
Reference in New Issue
Block a user