Просмотр исходного кода

Merge pull request #3018 from RaananW/firefox-event.target-fix

srcElement was replaced by target.
David Catuhe 7 лет назад
Родитель
Сommit
b1f0a6b304

+ 19 - 17
src/Cameras/Inputs/babylon.arcRotateCameraPointersInput.ts

@@ -17,7 +17,7 @@ module BABYLON {
         /**
          * pinchDeltaPercentage will be used instead of pinchPrecision if different from 0. 
          * It defines the percentage of current camera.radius to use as delta when pinch zoom is used.
-         */        
+         */
         @serialize()
         public pinchDeltaPercentage = 0;
 
@@ -50,7 +50,7 @@ module BABYLON {
             var previousPinchSquaredDistance = 0;
             var initialDistance = 0;
             var twoFingerActivityCount = 0;
-            var previousMultiTouchPanPosition: { x: number, y: number, isPaning: boolean, isPinching: boolean } = { x: 0, y:0, isPaning: false, isPinching: false };
+            var previousMultiTouchPanPosition: { x: number, y: number, isPaning: boolean, isPinching: boolean } = { x: 0, y: 0, isPaning: false, isPinching: false };
 
             this._pointerInput = (p, s) => {
                 var evt = <PointerEvent>p.event;
@@ -63,9 +63,11 @@ module BABYLON {
                     return;
                 }
 
-                if (p.type === PointerEventTypes.POINTERDOWN && evt.srcElement) {
+                let srcElement = <HTMLElement>(evt.srcElement || evt.target);
+
+                if (p.type === PointerEventTypes.POINTERDOWN && srcElement) {
                     try {
-                        evt.srcElement.setPointerCapture(evt.pointerId);
+                        srcElement.setPointerCapture(evt.pointerId);
                     } catch (e) {
                         //Nothing to do with the error. Execution will continue.
                     }
@@ -85,13 +87,13 @@ module BABYLON {
                         evt.preventDefault();
                         element.focus();
                     }
-                } 
+                }
                 else if (p.type === PointerEventTypes.POINTERDOUBLETAP) {
                     this.camera.restoreState();
                 }
-                else if (p.type === PointerEventTypes.POINTERUP && evt.srcElement) {
+                else if (p.type === PointerEventTypes.POINTERUP && srcElement) {
                     try {
-                        evt.srcElement.releasePointerCapture(evt.pointerId);
+                        srcElement.releasePointerCapture(evt.pointerId);
                     } catch (e) {
                         //Nothing to do with the error.
                     }
@@ -103,7 +105,7 @@ module BABYLON {
                     twoFingerActivityCount = 0;
                     initialDistance = 0;
 
-                    if((<any>p.event).pointerType !== "touch") {
+                    if ((<any>p.event).pointerType !== "touch") {
                         pointB = null; // Mouse and pen are mono pointer
                     }
 
@@ -178,13 +180,13 @@ module BABYLON {
 
                         if (this.multiTouchPanAndZoom) {
                             if (this.pinchDeltaPercentage) {
-                                this.camera.inertialRadiusOffset += ((pinchSquaredDistance - previousPinchSquaredDistance) * 0.001)* this.camera.radius * this.pinchDeltaPercentage; 
+                                this.camera.inertialRadiusOffset += ((pinchSquaredDistance - previousPinchSquaredDistance) * 0.001) * this.camera.radius * this.pinchDeltaPercentage;
                             } else {
                                 this.camera.inertialRadiusOffset += (pinchSquaredDistance - previousPinchSquaredDistance) /
-                                (this.pinchPrecision *
-                                    ((this.angularSensibilityX + this.angularSensibilityY) / 2) *
-                                    direction);
-                                }
+                                    (this.pinchPrecision *
+                                        ((this.angularSensibilityX + this.angularSensibilityY) / 2) *
+                                        direction);
+                            }
 
                             if (this.panningSensibility !== 0) {
                                 var pointersCenterX = (pointA.x + pointB.x) / 2;
@@ -202,14 +204,14 @@ module BABYLON {
                         else {
                             twoFingerActivityCount++;
 
-                            if (previousMultiTouchPanPosition.isPinching || (twoFingerActivityCount < 20 && Math.abs(pinchDistance - initialDistance) > this.camera.pinchToPanMaxDistance)) {                   
+                            if (previousMultiTouchPanPosition.isPinching || (twoFingerActivityCount < 20 && Math.abs(pinchDistance - initialDistance) > this.camera.pinchToPanMaxDistance)) {
                                 if (this.pinchDeltaPercentage) {
                                     this.camera.inertialRadiusOffset += ((pinchSquaredDistance - previousPinchSquaredDistance) * 0.001) * this.camera.radius * this.pinchDeltaPercentage;
                                 } else {
                                     this.camera.inertialRadiusOffset += (pinchSquaredDistance - previousPinchSquaredDistance) /
-                                    (this.pinchPrecision *
-                                        ((this.angularSensibilityX + this.angularSensibilityY) / 2) *
-                                        direction);
+                                        (this.pinchPrecision *
+                                            ((this.angularSensibilityX + this.angularSensibilityY) / 2) *
+                                            direction);
                                 }
                                 previousMultiTouchPanPosition.isPaning = false;
                                 previousMultiTouchPanPosition.isPinching = true;

+ 9 - 7
src/Cameras/Inputs/babylon.freeCameraMouseInput.ts

@@ -15,7 +15,7 @@ module BABYLON {
         private previousPosition: Nullable<{ x: number, y: number }> = null;
 
         constructor(public touchEnabled = true) {
-        }           
+        }
 
         attachControl(element: HTMLElement, noPreventDefault?: boolean) {
             var engine = this.camera.getEngine();
@@ -32,13 +32,15 @@ module BABYLON {
                         return;
                     }
 
-                    if(p.type !== PointerEventTypes.POINTERMOVE && this.buttons.indexOf(evt.button) === -1){
+                    if (p.type !== PointerEventTypes.POINTERMOVE && this.buttons.indexOf(evt.button) === -1) {
                         return;
                     }
 
-                    if (p.type === PointerEventTypes.POINTERDOWN && evt.srcElement) {
+                    let srcElement = <HTMLElement>(evt.srcElement || evt.target);
+
+                    if (p.type === PointerEventTypes.POINTERDOWN && srcElement) {
                         try {
-                            evt.srcElement.setPointerCapture(evt.pointerId);
+                            srcElement.setPointerCapture(evt.pointerId);
                         } catch (e) {
                             //Nothing to do with the error. Execution will continue.
                         }
@@ -53,9 +55,9 @@ module BABYLON {
                             element.focus();
                         }
                     }
-                    else if (p.type === PointerEventTypes.POINTERUP && evt.srcElement) {
+                    else if (p.type === PointerEventTypes.POINTERUP && srcElement) {
                         try {
-                            evt.srcElement.releasePointerCapture(evt.pointerId);
+                            srcElement.releasePointerCapture(evt.pointerId);
                         } catch (e) {
                             //Nothing to do with the error.
                         }
@@ -146,7 +148,7 @@ module BABYLON {
 
         getSimpleName() {
             return "mouse";
-        }      
+        }
     }
 
     (<any>CameraInputTypes)["FreeCameraMouseInput"] = FreeCameraMouseInput;

+ 7 - 6
src/Tools/babylon.database.ts

@@ -11,7 +11,7 @@ module BABYLON {
         private isSupported: boolean;
 
         // Handling various flavors of prefixed version of IndexedDB
-        private idbFactory = <IDBFactory> (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB);
+        private idbFactory = <IDBFactory>(window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB);
 
         static IsUASupportingBlobStorage = true;
         static IDBStorageEnabled = true;
@@ -68,7 +68,7 @@ module BABYLON {
 
             var timeStampUsed = false;
             var manifestURL = this.currentSceneUrl + ".manifest";
-            
+
             var xhr: XMLHttpRequest = new XMLHttpRequest();
 
             if (navigator.onLine) {
@@ -78,7 +78,7 @@ module BABYLON {
             }
             xhr.open("GET", manifestURL, true);
 
-            xhr.addEventListener("load",() => {
+            xhr.addEventListener("load", () => {
                 if (xhr.status === 200 || Tools.ValidateXHRData(xhr, 1)) {
                     try {
                         var manifestFile = JSON.parse(xhr.response);
@@ -278,7 +278,7 @@ module BABYLON {
                     xhr.open("GET", url, true);
                     xhr.responseType = "blob";
 
-                    xhr.addEventListener("load",() => {
+                    xhr.addEventListener("load", () => {
                         if (xhr.status === 200 && this.db) {
                             // Blob as response (XHR2)
                             blob = xhr.response;
@@ -289,7 +289,8 @@ module BABYLON {
                             transaction.onabort = (event) => {
                                 try {
                                     //backwards compatibility with ts 1.0, srcElement doesn't have an "error" according to ts 1.3
-                                    var error = (<any>event.srcElement)['error'];
+                                    let srcElement = <any>(event.srcElement || event.target);
+                                    var error = srcElement.error;
                                     if (error && error.name === "QuotaExceededError") {
                                         this.hasReachedQuota = true;
                                     }
@@ -533,7 +534,7 @@ module BABYLON {
                     xhr.onprogress = progressCallback;
                 }
 
-                xhr.addEventListener("load",() => {
+                xhr.addEventListener("load", () => {
                     if (xhr.status === 200 || Tools.ValidateXHRData(xhr, !useArrayBuffer ? 1 : 6)) {
                         // Blob as response (XHR2)
                         //fileData = xhr.responseText;