From ab12b833924aa3f5267c6425be8464ab05261272 Mon Sep 17 00:00:00 2001 From: Stephan Wagner Date: Tue, 2 Mar 2021 22:50:25 +0100 Subject: [PATCH] Fix closing on mobile devices when draggable --- demo/es6/package-lock.json | 8 ++++---- demo/es6/package.json | 2 +- dist/jBox.all.js | 6 ++++-- dist/jBox.all.min.js | 2 +- dist/jBox.js | 6 ++++-- dist/jBox.min.js | 2 +- package-lock.json | 2 +- package.json | 2 +- src/js/jBox.js | 6 ++++-- 9 files changed, 21 insertions(+), 15 deletions(-) diff --git a/demo/es6/package-lock.json b/demo/es6/package-lock.json index 54d7500..1ca3e54 100644 --- a/demo/es6/package-lock.json +++ b/demo/es6/package-lock.json @@ -33,11 +33,11 @@ } }, "jbox": { - "version": "1.2.10", - "resolved": "https://registry.npmjs.org/jbox/-/jbox-1.2.10.tgz", - "integrity": "sha512-lXutv/T1Hj03yNKPWV/VcJ/yUkwOR4IJ6Bu6ACWDMFUlz9mRU1NAxiKJbrVI039XG9R9xAr7DgF6ggtJLjEdvw==", + "version": "1.2.11", + "resolved": "https://registry.npmjs.org/jbox/-/jbox-1.2.11.tgz", + "integrity": "sha512-tVmouUw2tOJO2Pjl65UklgpGGMmyVwzogbnAWF8Tzzx6DF4Z/QhMT/4noXLsdmg3dgqokaLT9iXLclV1WdQ+1g==", "requires": { - "jquery": "^3.5.1" + "jquery": "^3.6.0" } }, "jquery": { diff --git a/demo/es6/package.json b/demo/es6/package.json index 164398b..b055e55 100644 --- a/demo/es6/package.json +++ b/demo/es6/package.json @@ -6,7 +6,7 @@ "license": "ISC", "main": "index.js", "dependencies": { - "jbox": "^1.2.10" + "jbox": "^1.2.11" }, "devDependencies": { "snowpack": "^3.0.11" diff --git a/dist/jBox.all.js b/dist/jBox.all.js index b876252..2fcd8d6 100755 --- a/dist/jBox.all.js +++ b/dist/jBox.all.js @@ -346,7 +346,9 @@ function jBoxWrapper(jQuery) { var handle = this.options.draggable == 'title' ? this.titleContainer : (this.options.draggable instanceof jQuery ? this.options.draggable : (jQuery.type(this.options.draggable) == 'string' ? jQuery(this.options.draggable) : this.wrapper)); // Abort if no handle or if draggable was set already - if (!handle || !(handle instanceof jQuery) || !handle.length || handle.data('jBox-draggable')) return false; + if (!handle || !(handle instanceof jQuery) || !handle.length || handle.data('jBox-draggable')) { + return false; + } // Add mouse events handle.addClass('jBox-draggable').data('jBox-draggable', true).on('touchstart mousedown', function (ev) @@ -481,7 +483,7 @@ function jBoxWrapper(jQuery) { if (this.options.closeButton) { var closeButtonSVG = this._createSVG('svg', [['viewBox', '0 0 24 24']]); closeButtonSVG.appendChild(this._createSVG('path', [['d', 'M22.2,4c0,0,0.5,0.6,0,1.1l-6.8,6.8l6.9,6.9c0.5,0.5,0,1.1,0,1.1L20,22.3c0,0-0.6,0.5-1.1,0L12,15.4l-6.9,6.9c-0.5,0.5-1.1,0-1.1,0L1.7,20c0,0-0.5-0.6,0-1.1L8.6,12L1.7,5.1C1.2,4.6,1.7,4,1.7,4L4,1.7c0,0,0.6-0.5,1.1,0L12,8.5l6.8-6.8c0.5-0.5,1.1,0,1.1,0L22.2,4z']])); - this.closeButton = jQuery('
').on('click tap', function (ev) { this.close({ignoreDelay: true}); }.bind(this)).append(closeButtonSVG); + this.closeButton = jQuery('
').on('click tap', function (ev) { this.close({ignoreDelay: true}); ev.stopPropagation(); }.bind(this)).append(closeButtonSVG); // Add close button to jBox container if (this.options.closeButton == 'box' || (this.options.closeButton === true && !this.options.overlay && !this.options.title && !this.options.getTitle)) { diff --git a/dist/jBox.all.min.js b/dist/jBox.all.min.js index 47ab692..6656ae5 100755 --- a/dist/jBox.all.min.js +++ b/dist/jBox.all.min.js @@ -1 +1 @@ -function jBoxWrapper(b){function h(t,i){return this.options={id:null,width:"auto",height:"auto",minWidth:null,minHeight:null,maxWidth:null,maxHeight:null,responsiveWidth:!0,responsiveHeight:!0,responsiveMinWidth:100,responsiveMinHeight:100,attach:null,trigger:"click",preventDefault:!1,content:null,getContent:null,title:null,getTitle:null,footer:null,isolateScroll:!0,ajax:{url:null,data:"",reload:!1,getURL:"data-url",getData:"data-ajax",setContent:!0,loadingClass:!0,spinner:!0,spinnerDelay:300,spinnerReposition:!0},cancelAjaxOnClose:!0,target:null,position:{x:"center",y:"center"},outside:null,offset:0,attributes:{x:"left",y:"top"},fixed:!1,adjustPosition:!0,adjustTracker:!1,adjustDistance:5,reposition:!0,repositionOnOpen:!0,repositionOnContent:!0,holdPosition:!0,pointer:!1,pointTo:"target",fade:180,animation:null,theme:"Default",addClass:null,overlay:!1,overlayClass:null,zIndex:1e4,delayOpen:0,delayClose:0,closeOnEsc:!1,closeOnClick:!1,closeOnMouseleave:!1,closeButton:!1,appendTo:b("body"),createOnInit:!1,blockScroll:!1,blockScrollAdjust:!0,draggable:!1,dragOver:!0,autoClose:!1,delayOnHover:!1,showCountdown:!1,preloadAudio:!0,audio:null,volume:100,onInit:null,onAttach:null,onPosition:null,onCreated:null,onOpen:null,onClose:null,onCloseComplete:null,onDragStart:null,onDragEnd:null},this._pluginOptions={Tooltip:{getContent:"title",trigger:"mouseenter",position:{x:"center",y:"top"},outside:"y",pointer:!0},Mouse:{responsiveWidth:!1,responsiveHeight:!1,adjustPosition:"flip",target:"mouse",trigger:"mouseenter",position:{x:"right",y:"bottom"},outside:"xy",offset:5},Modal:{target:b(window),fixed:!0,blockScroll:!0,closeOnEsc:!0,closeOnClick:"overlay",closeButton:!0,overlay:!0,animation:"zoomIn"}},this.options=b.extend(!0,this.options,this._pluginOptions[t]||h._pluginOptions[t],i),"string"==b.type(t)&&(this.type=t),this.isTouchDevice=function(){var t=" -webkit- -moz- -o- -ms- ".split(" ");if("ontouchstart"in window||window.DocumentTouch&&document instanceof DocumentTouch)return!0;var i,t=["(",t.join("touch-enabled),("),"heartz",")"].join("");return i=t,window.matchMedia(i).matches}(),this.isTouchDevice&&"mouseenter"===this.options.trigger&&!1===this.options.closeOnClick&&(this.options.closeOnClick="body"),this._fireEvent=function(t,i){this.options["_"+t]&&this.options["_"+t].bind(this)(i),this.options[t]&&this.options[t].bind(this)(i)},null===this.options.id&&(this.options.id="jBox"+h._getUniqueID()),this.id=this.options.id,("center"==this.options.position.x&&"x"==this.options.outside||"center"==this.options.position.y&&"y"==this.options.outside)&&(this.options.outside=null),"target"!=this.options.pointTo||this.options.outside&&"xy"!=this.options.outside||(this.options.pointer=!1),"object"!=b.type(this.options.offset)?this.options.offset={x:this.options.offset,y:this.options.offset}:this.options.offset=b.extend({x:0,y:0},this.options.offset),"object"!=b.type(this.options.adjustDistance)?this.options.adjustDistance={top:this.options.adjustDistance,right:this.options.adjustDistance,bottom:this.options.adjustDistance,left:this.options.adjustDistance}:this.options.adjustDistance=b.extend({top:5,left:5,right:5,bottom:5},this.options.adjustDistance),this.outside=!(!this.options.outside||"xy"==this.options.outside)&&this.options.position[this.options.outside],this.align=this.outside||("center"!=this.options.position.y&&"number"!=b.type(this.options.position.y)?this.options.position.x:"center"!=this.options.position.x&&"number"!=b.type(this.options.position.x)?this.options.position.y:this.options.attributes.x),h.zIndexMax=Math.max(h.zIndexMax||0,"auto"===this.options.zIndex?1e4:this.options.zIndex),"auto"===this.options.zIndex&&(this.adjustZIndexOnOpen=!0,h.zIndexMax+=2,this.options.zIndex=h.zIndexMax,this.trueModal=this.options.overlay),this._getOpp=function(t){return{left:"right",right:"left",top:"bottom",bottom:"top",x:"y",y:"x"}[t]},this._getXY=function(t){return{left:"x",right:"x",top:"y",bottom:"y",center:"x"}[t]},this._getTL=function(t){return{left:"left",right:"left",top:"top",bottom:"top",center:"left",x:"left",y:"top"}[t]},this._getInt=function(t,i){return"auto"==t?"auto":t&&"string"==b.type(t)&&"%"==t.slice(-1)?b(window)["height"==i?"innerHeight":"innerWidth"]()*parseInt(t.replace("%",""))/100:t},this._createSVG=function(t,i){var o=document.createElementNS("http://www.w3.org/2000/svg",t);return b.each(i,function(t,i){o.setAttribute(i[0],i[1]||"")}),o},this._isolateScroll=function(e){e&&e.length&&e.on("DOMMouseScroll.jBoxIsolateScroll mousewheel.jBoxIsolateScroll",function(t){var i=t.wheelDelta||t.originalEvent&&t.originalEvent.wheelDelta||-t.detail,o=0<=this.scrollTop+e.outerHeight()-this.scrollHeight,s=this.scrollTop<=0;(i<0&&o||0",{id:this.id,class:"jBox-wrapper"+(this.type?" jBox-"+this.type:"")+(this.options.theme?" jBox-"+this.options.theme:"")+(this.options.addClass?" "+this.options.addClass:"")}).css({position:this.options.fixed?"fixed":"absolute",display:"none",opacity:0,zIndex:this.options.zIndex}).data("jBox",this),this.options.closeOnMouseleave&&this.wrapper.on("mouseleave",function(t){!this.source||t.relatedTarget!=this.source[0]&&-1===b.inArray(this.source[0],b(t.relatedTarget).parents("*"))&&this.close()}.bind(this)),"box"==this.options.closeOnClick&&this.wrapper.on("click tap",function(){this.close({ignoreDelay:!0})}.bind(this)),this.container=b('
').appendTo(this.wrapper),this.content=b('
').appendTo(this.container),this.options.footer&&(this.footer=b('