Improved the ARSpeechRecognition.js file according to the review suggestions.

Change-Id: If3420dfffd84b7dfbdaf30e15e167b677304a5a7
This commit is contained in:
ijamardo 2017-09-12 12:21:50 -07:00 committed by Iker Jamardo
parent f8931e7e06
commit 3141a0ff46
3 changed files with 47 additions and 17 deletions

39
dist/three.ar.js vendored
View File

@ -1137,16 +1137,33 @@ exports.default = ARReticle;
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
/*
* Copyright 2017 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint-disable */
(function () {
if (window.webarSpeechRecognitionInstance) {
var addEventHandlingToObject = function addEventHandlingToObject(object) {
object.listeners = {};
object.addEventListener = function (eventType, callback) {
if (!callback) return this;
if (!callback) {
return this;
}
var listeners = this.listeners[eventType];
if (!listeners) {
listeners = [];
this.listeners[eventType] = listeners;
this.listeners[eventType] = listeners = [];
}
if (listeners.indexOf(callback) < 0) {
listeners.push(callback);
@ -1154,7 +1171,9 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
return this;
};
object.removeEventListener = function (eventType, callback) {
if (!callback) return this;
if (!callback) {
return this;
}
var listeners = this.listeners[eventType];
if (listeners) {
var i = listeners.indexOf(callback);
@ -1165,8 +1184,12 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
return this;
};
object.callEventListeners = function (eventType, event) {
if (!event) event = { target: this };
if (!event.target) event.target = this;
if (!event) {
event = { target: this };
}
if (!event.target) {
event.target = this;
}
event.type = eventType;
var onEventType = 'on' + eventType;
if (typeof this[onEventType] === 'function') {
@ -1176,9 +1199,9 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
if (listeners) {
for (var i = 0; i < listeners.length; i++) {
var typeofListener = _typeof(listeners[i]);
if (typeofListener === "object") {
if (typeofListener === 'object') {
listeners[i].handleEvent(event);
} else if (typeofListener === "function") {
} else if (typeofListener === 'function') {
listeners[i](event);
}
}

File diff suppressed because one or more lines are too long

View File

@ -20,11 +20,12 @@
function addEventHandlingToObject(object) {
object.listeners = { };
object.addEventListener = function(eventType, callback) {
if (!callback) return this;
if (!callback) {
return this;
}
var listeners = this.listeners[eventType];
if (!listeners) {
listeners = [];
this.listeners[eventType] = listeners;
this.listeners[eventType] = listeners = [];
}
if (listeners.indexOf(callback) < 0) {
listeners.push(callback);
@ -32,7 +33,9 @@
return this;
};
object.removeEventListener = function(eventType, callback) {
if (!callback) return this;
if (!callback) {
return this;
}
var listeners = this.listeners[eventType];
if (listeners) {
var i = listeners.indexOf(callback);
@ -43,8 +46,12 @@
return this;
};
object.callEventListeners = function(eventType, event) {
if (!event) event = { target : this };
if (!event.target) event.target = this;
if (!event) {
event = { target : this };
}
if (!event.target) {
event.target = this;
}
event.type = eventType;
var onEventType = 'on' + eventType;
if (typeof(this[onEventType]) === 'function') {
@ -54,10 +61,10 @@
if (listeners) {
for (var i = 0; i < listeners.length; i++) {
var typeofListener = typeof(listeners[i]);
if (typeofListener === "object") {
if (typeofListener === 'object') {
listeners[i].handleEvent(event);
}
else if (typeofListener === "function") {
else if (typeofListener === 'function') {
listeners[i](event);
}
}