mirror of
				https://github.com/KevinMidboe/vue-js-modal.git
				synced 2025-10-29 18:00:20 +00:00 
			
		
		
		
	Fixed :draggable not working on the touchscreen, demo improvements
This commit is contained in:
		| @@ -3,6 +3,7 @@ | |||||||
|   <demo-error-modal/> |   <demo-error-modal/> | ||||||
|   <demo-login-modal/> |   <demo-login-modal/> | ||||||
|   <demo-conditional-modal/> |   <demo-conditional-modal/> | ||||||
|  |   <demo-focus-modal/> | ||||||
|  |  | ||||||
|   <modal name="example-modal" |   <modal name="example-modal" | ||||||
|          transition="nice-modal-fade" |          transition="nice-modal-fade" | ||||||
| @@ -39,12 +40,22 @@ | |||||||
|     <button @click="show(false, false, false)">Simple</button> |     <button @click="show(false, false, false)">Simple</button> | ||||||
|     <button @click="show(true, false, false)">Resizable</button> |     <button @click="show(true, false, false)">Resizable</button> | ||||||
|     <button @click="show(false, true, false)">Adaptive</button> |     <button @click="show(false, true, false)">Adaptive</button> | ||||||
|     <button @click="show(true, true, false)">Mixed</button> |  | ||||||
|     <button @click="show(false, false, true)">Draggable</button> |     <button @click="show(false, false, true)">Draggable</button> | ||||||
|     <br> |     <br> | ||||||
|     <button class="green" @click="$modal.show('error-modal')">Demo: Error handling</button> |     <button class="green" | ||||||
|     <button class="green" @click="$modal.show('demo-login')">Demo: Login</button> |             @click="$modal.show('error-modal')"> | ||||||
|     <button :class="canBeShown ? 'green' : 'red'" @click="conditionalShow"> |       Demo: Error handling | ||||||
|  |     </button> | ||||||
|  |     <button class="green" | ||||||
|  |             @click="$modal.show('demo-login')"> | ||||||
|  |       Demo: Login | ||||||
|  |     </button> | ||||||
|  |     <button class="green" | ||||||
|  |             @click="$modal.show('input-focus-modal')"> | ||||||
|  |       Demo: Focus Input | ||||||
|  |     </button> | ||||||
|  |     <button :class="canBeShown ? 'green' : 'red'" | ||||||
|  |             @click="conditionalShow"> | ||||||
|       Can <b v-if="!canBeShown">NOT</b> be shown |       Can <b v-if="!canBeShown">NOT</b> be shown | ||||||
|     </button> |     </button> | ||||||
|   </div> |   </div> | ||||||
| @@ -57,6 +68,7 @@ | |||||||
| import ModesTable           from './components/ModesTable.vue' | import ModesTable           from './components/ModesTable.vue' | ||||||
| import PropsTable           from './components/PropsTable.vue' | import PropsTable           from './components/PropsTable.vue' | ||||||
| import DemoErrorModal       from './components/DemoErrorModal.vue' | import DemoErrorModal       from './components/DemoErrorModal.vue' | ||||||
|  | import DemoFocusModal       from './components/InputFocusModal.vue' | ||||||
| import DemoLoginModal       from './components/DemoLoginModal.vue' | import DemoLoginModal       from './components/DemoLoginModal.vue' | ||||||
| import DemoConditionalModal from './components/ConditionalModal.vue' | import DemoConditionalModal from './components/ConditionalModal.vue' | ||||||
|  |  | ||||||
| @@ -66,6 +78,7 @@ export default { | |||||||
|     ModesTable, |     ModesTable, | ||||||
|     PropsTable, |     PropsTable, | ||||||
|     DemoErrorModal, |     DemoErrorModal, | ||||||
|  |     DemoFocusModal, | ||||||
|     DemoLoginModal, |     DemoLoginModal, | ||||||
|     DemoConditionalModal |     DemoConditionalModal | ||||||
|   }, |   }, | ||||||
|   | |||||||
| @@ -1,6 +1,7 @@ | |||||||
| <template> | <template> | ||||||
|   <modal name="conditional-modal" |   <modal name="conditional-modal" | ||||||
|          :height="200" |          :height="200" | ||||||
|  |          :adaptive="true" | ||||||
|          @before-open="beforeOpen"> |          @before-open="beforeOpen"> | ||||||
|     <div style="padding:30px; text-align: center"> |     <div style="padding:30px; text-align: center"> | ||||||
|       Hello! |       Hello! | ||||||
|   | |||||||
							
								
								
									
										30
									
								
								demo/src/components/InputFocusModal.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								demo/src/components/InputFocusModal.vue
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,30 @@ | |||||||
|  | <template> | ||||||
|  |   <modal name="input-focus-modal" | ||||||
|  |          :height="150" | ||||||
|  |          :adaptive="true" | ||||||
|  |          @opened="opened"> | ||||||
|  |     <div style="padding: 30px; text-align: center"> | ||||||
|  |       <input class="huge-font" type="text" placeholder="email" ref="email"> | ||||||
|  |     </div> | ||||||
|  |   </modal> | ||||||
|  | </template> | ||||||
|  | <script> | ||||||
|  | export default { | ||||||
|  |   name: 'InputFocusModal', | ||||||
|  |   methods: { | ||||||
|  |     opened (event) { | ||||||
|  |       console.log(this.$refs.email) | ||||||
|  |     //  this.$refs.email.focus(); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | </script> | ||||||
|  | <style> | ||||||
|  |   input.huge-font { | ||||||
|  |     font-size: 70px; | ||||||
|  |     font-weight: 100; | ||||||
|  |     text-align: center; | ||||||
|  |     min-width: auto; | ||||||
|  |     width: 100%; | ||||||
|  |   } | ||||||
|  | </style> | ||||||
| @@ -19,9 +19,9 @@ | |||||||
|       </td> |       </td> | ||||||
|     </tr> |     </tr> | ||||||
|     <tr> |     <tr> | ||||||
|       <td><b>Mixed</b></td> |       <td><b>Draggable</b></td> | ||||||
|       <td> |       <td> | ||||||
|         Is resizable, but if the size of the screen is changed - modal will try to adapt to the page size |         Allows to drag modal on the screen | ||||||
|       </td> |       </td> | ||||||
|     </tr> |     </tr> | ||||||
|   </table> |   </table> | ||||||
|   | |||||||
							
								
								
									
										53
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										53
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							| @@ -546,7 +546,7 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true }); | |||||||
|  |  | ||||||
|  |  | ||||||
| /* harmony default export */ __webpack_exports__["default"] = { | /* harmony default export */ __webpack_exports__["default"] = { | ||||||
|   name: 'Modal', |   name: 'VueJsModal', | ||||||
|   props: { |   props: { | ||||||
|     name: { |     name: { | ||||||
|       required: true, |       required: true, | ||||||
| @@ -716,11 +716,18 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true }); | |||||||
|     }, |     }, | ||||||
|     genEventObject: function genEventObject(params) { |     genEventObject: function genEventObject(params) { | ||||||
|       //todo: clean this up (change to ...) |       //todo: clean this up (change to ...) | ||||||
|       return __WEBPACK_IMPORTED_MODULE_0_vue__["a" /* default */].util.extend({ |       var data = { | ||||||
|         name: this.name, |         name: this.name, | ||||||
|  |         timestamp: Date.now(), | ||||||
|  |         canceled: false, | ||||||
|         ref: this.$refs.modal, |         ref: this.$refs.modal, | ||||||
|         timestamp: Date.now() |         stop: function stop() { | ||||||
|       }, params || {}); |           this.canceled = true; | ||||||
|  |         } | ||||||
|  |       }; | ||||||
|  |  | ||||||
|  |       return __WEBPACK_IMPORTED_MODULE_0_vue__["a" /* default */].util.extend(data, params || {}); | ||||||
|  |       //        return event | ||||||
|     }, |     }, | ||||||
|     adaptSize: function adaptSize() { |     adaptSize: function adaptSize() { | ||||||
|       if (this.adaptive) { |       if (this.adaptive) { | ||||||
| @@ -758,6 +765,13 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true }); | |||||||
|         this.$emit(afterEventName, afterEvent); |         this.$emit(afterEventName, afterEvent); | ||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|  |     emitCancelableEvent: function emitCancelableEvent(data) { | ||||||
|  |       var stopEventExecution = false; | ||||||
|  |       var stop = function stop() { | ||||||
|  |         stopEventExecution = true; | ||||||
|  |       }; | ||||||
|  |       var event = this.genEventObject(data); | ||||||
|  |     }, | ||||||
|     getDraggableElement: function getDraggableElement() { |     getDraggableElement: function getDraggableElement() { | ||||||
|       var selector = typeof this.draggable !== 'string' ? '.v--modal-box' : this.draggable; |       var selector = typeof this.draggable !== 'string' ? '.v--modal-box' : this.draggable; | ||||||
|  |  | ||||||
| @@ -784,30 +798,51 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true }); | |||||||
|           var cachedShiftX = 0; |           var cachedShiftX = 0; | ||||||
|           var cachedShiftY = 0; |           var cachedShiftY = 0; | ||||||
|  |  | ||||||
|  |           var getPosition = function getPosition(event) { | ||||||
|  |             return event.touches && event.touches.length > 0 ? event.touches[0] : event; | ||||||
|  |           }; | ||||||
|  |  | ||||||
|           var mousedown = function mousedown(event) { |           var mousedown = function mousedown(event) { | ||||||
|  |             var _getPosition = getPosition(event), | ||||||
|  |                 clientX = _getPosition.clientX, | ||||||
|  |                 clientY = _getPosition.clientY; | ||||||
|  |  | ||||||
|             document.addEventListener('mousemove', mousemove); |             document.addEventListener('mousemove', mousemove); | ||||||
|             document.addEventListener('mouseup', mouseup); |             document.addEventListener('mouseup', mouseup); | ||||||
|  |  | ||||||
|             startX = event.clientX; |             document.addEventListener('touchmove', mousemove); | ||||||
|             startY = event.clientY; |             document.addEventListener('touchend', mouseup); | ||||||
|  |  | ||||||
|  |             startX = clientX; | ||||||
|  |             startY = clientY; | ||||||
|             cachedShiftX = _this3.shift.left; |             cachedShiftX = _this3.shift.left; | ||||||
|             cachedShiftY = _this3.shift.top; |             cachedShiftY = _this3.shift.top; | ||||||
|  |  | ||||||
|             event.preventDefault(); |             event.preventDefault(); | ||||||
|           }; |           }; | ||||||
|  |  | ||||||
|           var mousemove = function mousemove(event) { |           var mousemove = function mousemove(event) { | ||||||
|             _this3.shift.left = cachedShiftX + event.clientX - startX; |             var _getPosition2 = getPosition(event), | ||||||
|             _this3.shift.top = cachedShiftY + event.clientY - startY; |                 clientX = _getPosition2.clientX, | ||||||
|  |                 clientY = _getPosition2.clientY; | ||||||
|  |  | ||||||
|  |             _this3.shift.left = cachedShiftX + clientX - startX; | ||||||
|  |             _this3.shift.top = cachedShiftY + clientY - startY; | ||||||
|             event.preventDefault(); |             event.preventDefault(); | ||||||
|           }; |           }; | ||||||
|  |  | ||||||
|           var mouseup = function mouseup(event) { |           var mouseup = function mouseup(event) { | ||||||
|             document.removeEventListener('mousemove', mousemove); |             document.removeEventListener('mousemove', mousemove); | ||||||
|             document.removeEventListener('mouseup', mouseup); |             document.removeEventListener('mouseup', mouseup); | ||||||
|  |  | ||||||
|  |             document.removeEventListener('touchmove', mousemove); | ||||||
|  |             document.removeEventListener('touchend', mouseup); | ||||||
|  |  | ||||||
|             event.preventDefault(); |             event.preventDefault(); | ||||||
|           }; |           }; | ||||||
|  |  | ||||||
|           dragger.addEventListener('mousedown', mousedown); |           dragger.addEventListener('mousedown', mousedown); | ||||||
|  |           dragger.addEventListener('touchstart', mousedown); | ||||||
|         })(); |         })(); | ||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
| @@ -831,7 +866,7 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true }); | |||||||
|  |  | ||||||
|  |  | ||||||
| /* harmony default export */ __webpack_exports__["default"] = { | /* harmony default export */ __webpack_exports__["default"] = { | ||||||
|   name: 'Resizer', |   name: 'VueJsModalResizer', | ||||||
|   props: { |   props: { | ||||||
|     minHeight: { |     minHeight: { | ||||||
|       type: Number, |       type: Number, | ||||||
|   | |||||||
| @@ -193,11 +193,18 @@ | |||||||
|  |  | ||||||
|       genEventObject (params) { |       genEventObject (params) { | ||||||
|         //todo: clean this up (change to ...) |         //todo: clean this up (change to ...) | ||||||
|         return Vue.util.extend({ |         var data = { | ||||||
|           name: this.name, |           name: this.name, | ||||||
|  |           timestamp: Date.now(), | ||||||
|  |           canceled: false, | ||||||
|           ref: this.$refs.modal, |           ref: this.$refs.modal, | ||||||
|           timestamp: Date.now() |           stop: function() { | ||||||
|         }, params || {}); |             this.canceled = true | ||||||
|  |           } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return Vue.util.extend(data, params || {}); | ||||||
|  | //        return event | ||||||
|       }, |       }, | ||||||
|  |  | ||||||
|       adaptSize () { |       adaptSize () { | ||||||
| @@ -236,6 +243,12 @@ | |||||||
|         } |         } | ||||||
|       }, |       }, | ||||||
|  |  | ||||||
|  |       emitCancelableEvent (data) { | ||||||
|  |         let stopEventExecution = false | ||||||
|  |         let stop = () => { stopEventExecution = true } | ||||||
|  |         let event = this.genEventObject(data) | ||||||
|  |       }, | ||||||
|  |  | ||||||
|       getDraggableElement () { |       getDraggableElement () { | ||||||
|         var selector = typeof this.draggable !== 'string' |         var selector = typeof this.draggable !== 'string' | ||||||
|           ? '.v--modal-box' |           ? '.v--modal-box' | ||||||
| @@ -262,30 +275,49 @@ | |||||||
|           let cachedShiftX = 0 |           let cachedShiftX = 0 | ||||||
|           let cachedShiftY = 0 |           let cachedShiftY = 0 | ||||||
|  |  | ||||||
|  |           let getPosition = (event) => { | ||||||
|  |               return event.touches && event.touches.length > 0 | ||||||
|  |                 ? event.touches[0] | ||||||
|  |                 : event | ||||||
|  |           } | ||||||
|  |  | ||||||
|           let mousedown = (event) => { |           let mousedown = (event) => { | ||||||
|  |             let { clientX, clientY } = getPosition(event) | ||||||
|  |  | ||||||
|             document.addEventListener('mousemove', mousemove) |             document.addEventListener('mousemove', mousemove) | ||||||
|             document.addEventListener('mouseup', mouseup) |             document.addEventListener('mouseup', mouseup) | ||||||
|  |  | ||||||
|             startX = event.clientX |             document.addEventListener('touchmove', mousemove) | ||||||
|             startY = event.clientY |             document.addEventListener('touchend', mouseup) | ||||||
|  |  | ||||||
|  |             startX = clientX | ||||||
|  |             startY = clientY | ||||||
|             cachedShiftX = this.shift.left |             cachedShiftX = this.shift.left | ||||||
|             cachedShiftY = this.shift.top |             cachedShiftY = this.shift.top | ||||||
|  |  | ||||||
|             event.preventDefault() |             event.preventDefault() | ||||||
|           } |           } | ||||||
|  |  | ||||||
|           let mousemove = (event) => { |           let mousemove = (event) => { | ||||||
|             this.shift.left = cachedShiftX + event.clientX - startX |             let { clientX, clientY } = getPosition(event) | ||||||
|             this.shift.top = cachedShiftY + event.clientY - startY |  | ||||||
|  |             this.shift.left = cachedShiftX + clientX - startX | ||||||
|  |             this.shift.top = cachedShiftY + clientY - startY | ||||||
|             event.preventDefault() |             event.preventDefault() | ||||||
|           } |           } | ||||||
|  |  | ||||||
|           let mouseup = (event) => { |           let mouseup = (event) => { | ||||||
|             document.removeEventListener('mousemove', mousemove) |             document.removeEventListener('mousemove', mousemove) | ||||||
|             document.removeEventListener('mouseup', mouseup) |             document.removeEventListener('mouseup', mouseup) | ||||||
|  |  | ||||||
|  |             document.removeEventListener('touchmove', mousemove) | ||||||
|  |             document.removeEventListener('touchend', mouseup) | ||||||
|  |  | ||||||
|             event.preventDefault() |             event.preventDefault() | ||||||
|           } |           } | ||||||
|  |  | ||||||
|           dragger.addEventListener('mousedown', mousedown) |           dragger.addEventListener('mousedown', mousedown) | ||||||
|  |           dragger.addEventListener('touchstart', mousedown) | ||||||
|         } |         } | ||||||
|       }, |       }, | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user