From 53f7cd25dd050b88153761251c2c846aca4fbc72 Mon Sep 17 00:00:00 2001 From: kirillmurashov Date: Wed, 16 May 2018 14:04:10 +0300 Subject: [PATCH] Added props parentW & parentH Added props: parentW & parentH see documentation and demo --- README.md | 24 ++++++++++++++++++++++++ package.json | 2 +- src/components/vue-drag-resize.js | 30 ++++++++++++++++++++++++++++-- src/demo/app.vue | 19 ++++++++++++++++++- 4 files changed, 71 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 122b692..2a95a04 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,30 @@ If the prop is enabled, the component is oriented only to the specified. ``` +#### parentW +Type: `Number`
+Required: `false`
+Default: `0` + +Define the initial width of the parent element. If not specified it calculated automatically. +With this parameter, you can set the bounding area for the component, and also it is used when resizing in real time. + +```html + +``` + +#### parentH +Type: `Number`
+Required: `false`
+Default: `0` + +Define the initial height of the parent element. If not specified it calculated automatically. +With this parameter, you can set the bounding area for the component, and also it is used when resizing in real time. + +```html + +``` + #### isDraggable Type: `Boolean`
Required: `false`
diff --git a/package.json b/package.json index 83e4124..eefc0a6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-drag-resize", - "version": "1.2.0", + "version": "1.2.1", "description": "Vue Component for resize and drag elements", "author": "Kirill Murashov ", "main": "dist/index.js", diff --git a/src/components/vue-drag-resize.js b/src/components/vue-drag-resize.js index 87e5fc3..d067983 100644 --- a/src/components/vue-drag-resize.js +++ b/src/components/vue-drag-resize.js @@ -19,6 +19,20 @@ export default { parentLimitation: { type: Boolean, default: true }, + parentW: { + type: Number, + default: 0, + validator: function (val) { + return val >= 0 + } + }, + parentH: { + type: Number, + default: 0, + validator: function (val) { + return val >= 0 + } + }, w: { type: Number, default: 100, @@ -127,9 +141,9 @@ export default { mounted: function () { this.parentElement = this.$el.parentNode; + this.parentWidth = this.parentW ? this.parentW : this.parentElement.clientWidth; + this.parentHeight = this.parentH ? this.parentH : this.parentElement.clientHeight; - this.parentWidth = this.parentElement.clientWidth; - this.parentHeight = this.parentElement.clientHeight; this.rawRight = this.parentWidth - this.rawWidth - this.rawLeft; this.rawBottom = this.parentHeight - this.rawHeight - this.rawTop; @@ -692,6 +706,18 @@ export default { let delta = this.height- this.h; this.rawBottom = this.bottom + delta; + }, + + parentW(val){ + this.right = val - this.width - this.left; + this.parentWidth = val; + + }, + + parentH(val){ + this.bottom = val - this.height - this.top; + this.parentHeight = val; + } } } \ No newline at end of file diff --git a/src/demo/app.vue b/src/demo/app.vue index a7866c1..f57f0cc 100644 --- a/src/demo/app.vue +++ b/src/demo/app.vue @@ -1,11 +1,13 @@