From 07994a3ecd5b4c6fb8a13e2e926edb830d03b8a5 Mon Sep 17 00:00:00 2001 From: Nikita Khomyakov Date: Sun, 13 Mar 2016 02:16:21 +0000 Subject: [PATCH 01/17] Use UMD (Universal Module Definition) pattern Use returnExportsGlobal variation of universal module definition This commit adds support in backward compatible manner, so the module is still available as a property of global `window` object Details about this approach: https://github.com/umdjs/umd Closes https://github.com/TalAter/annyang/issues/174 --- annyang.js | 47 +++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/annyang.js b/annyang.js index 5c9ddab..7b25fd4 100644 --- a/annyang.js +++ b/annyang.js @@ -3,8 +3,19 @@ //! author : Tal Ater @TalAter //! license : MIT //! https://www.TalAter.com/annyang/ - -(function(undefined) { +(function (root, factory) { + // istanbul ignore next + // jshint strict: false + if (typeof define === 'function' && define.amd) { // AMD + define([], function () { + return (root.annyang = factory(root, undefined)); + }); + } else if (typeof module === 'object' && module.exports) { // CommonJS + module.exports = factory(root, undefined); + } else { // Browser globals + root.annyang = factory(root, undefined); + } +}(typeof window !== 'undefined' ? window : this, function (root, undefined) { "use strict"; /** @@ -17,8 +28,7 @@ * # API Reference */ - // Save a reference to the global object (window in the browser) - var root = this; + var annyang = {}; // Get the SpeechRecognition object, while handling browser prefixes var SpeechRecognition = root.SpeechRecognition || @@ -30,7 +40,6 @@ // Check browser support // This is done as early as possible, to make it as fast as possible for unsupported browsers if (!SpeechRecognition) { - root.annyang = null; return undefined; } @@ -75,18 +84,18 @@ var initIfNeeded = function() { if (!isInitialized()) { - root.annyang.init({}, false); + annyang.init({}, false); } }; var registerCommand = function(command, cb, phrase) { commandsList.push({ command: command, callback: cb, originalPhrase: phrase }); if (debugState) { - root.console.log('Command successfully loaded: %c'+phrase, debugStyle); + console.log('Command successfully loaded: %c'+phrase, debugStyle); } }; - root.annyang = { + annyang = { /** * Initialize annyang with a list of commands to recognize. @@ -169,9 +178,9 @@ // play nicely with the browser, and never restart annyang automatically more than once per second var timeSinceLastStart = new Date().getTime()-lastStartedAt; if (timeSinceLastStart < 1000) { - setTimeout(root.annyang.start, 1000-timeSinceLastStart); + setTimeout(annyang.start, 1000-timeSinceLastStart); } else { - root.annyang.start(); + annyang.start(); } } }; @@ -179,7 +188,7 @@ recognition.onresult = function(event) { if(pauseListening) { if (debugState) { - root.console.log('Speech heard, but annyang is paused'); + console.log('Speech heard, but annyang is paused'); } return false; } @@ -198,7 +207,7 @@ // the text recognized commandText = results[i].trim(); if (debugState) { - root.console.log('Speech recognized: %c'+commandText, debugStyle); + console.log('Speech recognized: %c'+commandText, debugStyle); } // try and match recognized text to one of the commands on the list @@ -208,9 +217,9 @@ if (result) { var parameters = result.slice(1); if (debugState) { - root.console.log('command matched: %c'+currentCommand.originalPhrase, debugStyle); + console.log('command matched: %c'+currentCommand.originalPhrase, debugStyle); if (parameters.length) { - root.console.log('with parameters', parameters); + console.log('with parameters', parameters); } } // execute the matched command @@ -270,7 +279,7 @@ recognition.start(); } catch(e) { if (debugState) { - root.console.log(e.message); + console.log(e.message); } } }, @@ -309,7 +318,7 @@ * @method resume */ resume: function() { - root.annyang.start(); + annyang.start(); }, /** @@ -371,7 +380,7 @@ registerCommand(new RegExp(cb.regexp.source, 'i'), cb.callback, phrase); } else { if (debugState) { - root.console.log('Can not register command: %c'+phrase, debugStyle); + console.log('Can not register command: %c'+phrase, debugStyle); } continue; } @@ -544,7 +553,9 @@ } }; -}).call(this); + return annyang; + +})); /** * # Good to Know From cbd9dc5ba9320aebbe412155efc5ed4b29984417 Mon Sep 17 00:00:00 2001 From: Nikita Khomyakov Date: Sun, 13 Mar 2016 02:19:58 +0000 Subject: [PATCH 02/17] Add dev dependency `grunt-template-jasmine-requirejs` --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index d31c13a..59dc4af 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "grunt-contrib-watch": "^0.6.1", "grunt-contrib-jasmine": "^1.0.0", "grunt-template-jasmine-istanbul": "^0.4.0", + "grunt-template-jasmine-requirejs": "^0.2.3", "grunt-markdox": "^1.2.1" } } From 659b40be3f99bc3a8edb47972c522599acaac7c4 Mon Sep 17 00:00:00 2001 From: Nikita Khomyakov Date: Sun, 13 Mar 2016 02:20:42 +0000 Subject: [PATCH 03/17] Use `grunt-template-jasmine-requirejs` for testing AMD definition --- Gruntfile.js | 14 ++++++++++++++ test/spec/BasicSpec.js | 13 +++++++++++-- test/vendor/corti.js | 20 ++++++++++++++------ 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 125e052..b954126 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -99,6 +99,20 @@ module.exports = function(grunt) { } } } + }, + browserAMD: { + src: ['annyang.js'], + options: { + specs: 'test/spec/*Spec.js', + outfile: 'test/SpecRunner.html', + vendor: ['test/vendor/corti.js', 'test/init_corti.js'], // https://github.com/cloudchen/grunt-template-jasmine-requirejs/issues/72 + template: require('grunt-template-jasmine-requirejs'), + templateOptions: { + requireConfig: { + baseUrl: '../' + } + } + } } } }); diff --git a/test/spec/BasicSpec.js b/test/spec/BasicSpec.js index 193910e..08c7761 100644 --- a/test/spec/BasicSpec.js +++ b/test/spec/BasicSpec.js @@ -1,4 +1,13 @@ -(function() { +(function (root, factory) { + // jshint strict: false + if (typeof module === 'object' && module.exports) { // CommonJS + factory(require('../../annyang')); + } else if (typeof define === 'function' && define.amd) { // AMD + define(['annyang'], factory); + } else { // Browser globals + factory(root.annyang); + } +}(typeof window !== 'undefined' ? window : this, function factory(annyang) { "use strict"; describe('annyang', function() { @@ -1172,4 +1181,4 @@ }); -})(); +})); diff --git a/test/vendor/corti.js b/test/vendor/corti.js index 81560f4..7c84662 100644 --- a/test/vendor/corti.js +++ b/test/vendor/corti.js @@ -4,12 +4,20 @@ //! license : MIT //! https://github.com/TalAter/SpeechKITT/test/corti.js -(function (undefined) { +(function (root, factory) { + // jshint strict: false + if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. + define([], function () { + return (root.Corti = factory(root, undefined)); + }); + } else if (typeof module === 'object' && module.exports) { // CommonJS + module.exports = factory(root, undefined); + } else { // Browser globals + root.Corti = factory(root, undefined); + } +}(typeof window !== 'undefined' ? window : this, function (_root, undefined) { "use strict"; - // Save a reference to the global object (window in the browser) - var _root = this; - // Holds the browser's implementation var _productionVersion = false; @@ -164,7 +172,7 @@ }; // Expose functionality - _root.Corti = { + return { patch: function() { if (_productionVersion === false) { _productionVersion = _root.SpeechRecognition || @@ -181,4 +189,4 @@ } }; -}).call(this); +})); From b1d2c0302365e535efb3beff8b56a1dbc9cec843 Mon Sep 17 00:00:00 2001 From: Nikita Khomyakov Date: Sun, 13 Mar 2016 02:21:23 +0000 Subject: [PATCH 04/17] Update JSHint rules Allow global variable `define`, which is used in AMD (RequireJS) --- .jshintrc | 7 +++++-- test/spec/.jshintrc | 5 +++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.jshintrc b/.jshintrc index e2896df..f78d858 100644 --- a/.jshintrc +++ b/.jshintrc @@ -23,5 +23,8 @@ "sub" : true, "strict" : true, "white" : false, - "indent" : 2 -} \ No newline at end of file + "indent" : 2, + "globals" : { + "define" : false + } +} diff --git a/test/spec/.jshintrc b/test/spec/.jshintrc index a7d2470..80d322c 100644 --- a/test/spec/.jshintrc +++ b/test/spec/.jshintrc @@ -34,6 +34,7 @@ "spyOn": false, "it": false, "xit": false, - "annyang": false + "annyang": false, + "define": false } -} \ No newline at end of file +} From 311805303e5d2c567ab93b61806f724f0a0a0d34 Mon Sep 17 00:00:00 2001 From: Tal Ater Date: Thu, 31 Mar 2016 14:14:23 +0300 Subject: [PATCH 05/17] Rebuilt files from new code --- annyang.min.js | 2 +- docs/README.md | 2 ++ sites/facebook.min.js | 2 +- sites/geektime.min.js | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/annyang.min.js b/annyang.min.js index 776a369..06fe632 100644 --- a/annyang.min.js +++ b/annyang.min.js @@ -3,4 +3,4 @@ //! author : Tal Ater @TalAter //! license : MIT //! https://www.TalAter.com/annyang/ -(function(a){"use strict";var b=this,c=b.SpeechRecognition||b.webkitSpeechRecognition||b.mozSpeechRecognition||b.msSpeechRecognition||b.oSpeechRecognition;if(!c)return b.annyang=null,a;var d,e,f=[],g={start:[],error:[],end:[],result:[],resultMatch:[],resultNoMatch:[],errorNetwork:[],errorPermissionBlocked:[],errorPermissionDenied:[]},h=0,i=!1,j="font-weight: bold; color: #00f;",k=!1,l=!1,m=/\s*\((.*?)\)\s*/g,n=/(\(\?:[^)]+\))\?/g,o=/(\(\?)?:\w+/g,p=/\*\w+/g,q=/[\-{}\[\]+?.,\\\^$|#]/g,r=function(a){return a=a.replace(q,"\\$&").replace(m,"(?:$1)?").replace(o,function(a,b){return b?a:"([^\\s]+)"}).replace(p,"(.*?)").replace(n,"\\s*$1?\\s*"),new RegExp("^"+a+"$","i")},s=function(a){var b=Array.prototype.slice.call(arguments,1);a.forEach(function(a){a.callback.apply(a.context,b)})},t=function(){return d!==a},u=function(){t()||b.annyang.init({},!1)},v=function(a,c,d){f.push({command:a,callback:c,originalPhrase:d}),i&&b.console.log("Command successfully loaded: %c"+d,j)};b.annyang={init:function(m,n){n=n===a?!0:!!n,d&&d.abort&&d.abort(),d=new c,d.maxAlternatives=5,d.continuous="http:"===b.location.protocol,d.lang="en-US",d.onstart=function(){l=!0,s(g.start)},d.onerror=function(a){switch(s(g.error),a.error){case"network":s(g.errorNetwork);break;case"not-allowed":case"service-not-allowed":e=!1,s((new Date).getTime()-h<200?g.errorPermissionBlocked:g.errorPermissionDenied)}},d.onend=function(){if(l=!1,s(g.end),e){var a=(new Date).getTime()-h;1e3>a?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(k)return i&&b.console.log("Speech heard, but annyang is paused"),!1;for(var c=a.results[a.resultIndex],d=[],e=0;em;m++){var o=f[m],p=o.command.exec(h);if(p){var q=p.slice(1);return i&&(b.console.log("command matched: %c"+o.originalPhrase,j),q.length&&b.console.log("with parameters",q)),o.callback.apply(this,q),s(g.resultMatch,h,o.originalPhrase,d),!0}}}return s(g.resultNoMatch,d),!1},n&&(f=[]),m.length&&this.addCommands(m)},start:function(c){k=!1,u(),c=c||{},e=c.autoRestart!==a?!!c.autoRestart:!0,c.continuous!==a&&(d.continuous=!!c.continuous),h=(new Date).getTime();try{d.start()}catch(f){i&&b.console.log(f.message)}},abort:function(){e=!1,t()&&d.abort()},pause:function(){k=!0},resume:function(){b.annyang.start()},debug:function(a){i=arguments.length>0?!!a:!0},setLanguage:function(a){u(),d.lang=a},addCommands:function(a){var c;u();for(var d in a)if(a.hasOwnProperty(d))if(c=b[a[d]]||a[d],"function"==typeof c)v(r(d),c,d);else{if(!("object"==typeof c&&c.regexp instanceof RegExp)){i&&b.console.log("Can not register command: %c"+d,j);continue}v(new RegExp(c.regexp.source,"i"),c.callback,d)}},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;ca?setTimeout(c.start,1e3-a):c.start()}},e.onresult=function(a){if(l)return j&&console.log("Speech heard, but annyang is paused"),!1;for(var b=a.results[a.resultIndex],c=[],d=0;di;i++){var n=g[i],o=n.command.exec(e);if(o){var p=o.slice(1);return j&&(console.log("command matched: %c"+n.originalPhrase,k),p.length&&console.log("with parameters",p)),n.callback.apply(this,p),t(h.resultMatch,e,n.originalPhrase,c),!0}}}return t(h.resultNoMatch,c),!1},o&&(g=[]),n.length&&this.addCommands(n)},start:function(a){l=!1,v(),a=a||{},f=a.autoRestart!==b?!!a.autoRestart:!0,a.continuous!==b&&(e.continuous=!!a.continuous),i=(new Date).getTime();try{e.start()}catch(c){j&&console.log(c.message)}},abort:function(){f=!1,u()&&e.abort()},pause:function(){l=!0},resume:function(){c.start()},debug:function(a){j=arguments.length>0?!!a:!0},setLanguage:function(a){v(),e.lang=a},addCommands:function(b){var c;v();for(var d in b)if(b.hasOwnProperty(d))if(c=a[b[d]]||b[d],"function"==typeof c)w(s(d),c,d);else{if(!("object"==typeof c&&c.regexp instanceof RegExp)){j&&console.log("Can not register command: %c"+d,k);continue}w(new RegExp(c.regexp.source,"i"),c.callback,d)}},removeCommands:function(a){return a===b?void(g=[]):(a=Array.isArray(a)?a:[a],void(g=g.filter(function(b){for(var c=0;c +## annyang + # Quick Tutorial, Intro and Demos The quickest way to get started is to visit the [annyang homepage](https://www.talater.com/annyang/). diff --git a/sites/facebook.min.js b/sites/facebook.min.js index 2c6647b..fcf9c3b 100644 --- a/sites/facebook.min.js +++ b/sites/facebook.min.js @@ -3,7 +3,7 @@ //! author : Tal Ater @TalAter //! license : MIT //! https://www.TalAter.com/annyang/ -(function(a){"use strict";var b=this,c=b.SpeechRecognition||b.webkitSpeechRecognition||b.mozSpeechRecognition||b.msSpeechRecognition||b.oSpeechRecognition;if(!c)return b.annyang=null,a;var d,e,f=[],g={start:[],error:[],end:[],result:[],resultMatch:[],resultNoMatch:[],errorNetwork:[],errorPermissionBlocked:[],errorPermissionDenied:[]},h=0,i=!1,j="font-weight: bold; color: #00f;",k=!1,l=!1,m=/\s*\((.*?)\)\s*/g,n=/(\(\?:[^)]+\))\?/g,o=/(\(\?)?:\w+/g,p=/\*\w+/g,q=/[\-{}\[\]+?.,\\\^$|#]/g,r=function(a){return a=a.replace(q,"\\$&").replace(m,"(?:$1)?").replace(o,function(a,b){return b?a:"([^\\s]+)"}).replace(p,"(.*?)").replace(n,"\\s*$1?\\s*"),new RegExp("^"+a+"$","i")},s=function(a){var b=Array.prototype.slice.call(arguments,1);a.forEach(function(a){a.callback.apply(a.context,b)})},t=function(){return d!==a},u=function(){t()||b.annyang.init({},!1)},v=function(a,c,d){f.push({command:a,callback:c,originalPhrase:d}),i&&b.console.log("Command successfully loaded: %c"+d,j)};b.annyang={init:function(m,n){n=n===a?!0:!!n,d&&d.abort&&d.abort(),d=new c,d.maxAlternatives=5,d.continuous="http:"===b.location.protocol,d.lang="en-US",d.onstart=function(){l=!0,s(g.start)},d.onerror=function(a){switch(s(g.error),a.error){case"network":s(g.errorNetwork);break;case"not-allowed":case"service-not-allowed":e=!1,s((new Date).getTime()-h<200?g.errorPermissionBlocked:g.errorPermissionDenied)}},d.onend=function(){if(l=!1,s(g.end),e){var a=(new Date).getTime()-h;1e3>a?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(k)return i&&b.console.log("Speech heard, but annyang is paused"),!1;for(var c=a.results[a.resultIndex],d=[],e=0;em;m++){var o=f[m],p=o.command.exec(h);if(p){var q=p.slice(1);return i&&(b.console.log("command matched: %c"+o.originalPhrase,j),q.length&&b.console.log("with parameters",q)),o.callback.apply(this,q),s(g.resultMatch,h,o.originalPhrase,d),!0}}}return s(g.resultNoMatch,d),!1},n&&(f=[]),m.length&&this.addCommands(m)},start:function(c){k=!1,u(),c=c||{},e=c.autoRestart!==a?!!c.autoRestart:!0,c.continuous!==a&&(d.continuous=!!c.continuous),h=(new Date).getTime();try{d.start()}catch(f){i&&b.console.log(f.message)}},abort:function(){e=!1,t()&&d.abort()},pause:function(){k=!0},resume:function(){b.annyang.start()},debug:function(a){i=arguments.length>0?!!a:!0},setLanguage:function(a){u(),d.lang=a},addCommands:function(a){var c;u();for(var d in a)if(a.hasOwnProperty(d))if(c=b[a[d]]||a[d],"function"==typeof c)v(r(d),c,d);else{if(!("object"==typeof c&&c.regexp instanceof RegExp)){i&&b.console.log("Can not register command: %c"+d,j);continue}v(new RegExp(c.regexp.source,"i"),c.callback,d)}},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;ca?setTimeout(c.start,1e3-a):c.start()}},e.onresult=function(a){if(l)return j&&console.log("Speech heard, but annyang is paused"),!1;for(var b=a.results[a.resultIndex],c=[],d=0;di;i++){var n=g[i],o=n.command.exec(e);if(o){var p=o.slice(1);return j&&(console.log("command matched: %c"+n.originalPhrase,k),p.length&&console.log("with parameters",p)),n.callback.apply(this,p),t(h.resultMatch,e,n.originalPhrase,c),!0}}}return t(h.resultNoMatch,c),!1},o&&(g=[]),n.length&&this.addCommands(n)},start:function(a){l=!1,v(),a=a||{},f=a.autoRestart!==b?!!a.autoRestart:!0,a.continuous!==b&&(e.continuous=!!a.continuous),i=(new Date).getTime();try{e.start()}catch(c){j&&console.log(c.message)}},abort:function(){f=!1,u()&&e.abort()},pause:function(){l=!0},resume:function(){c.start()},debug:function(a){j=arguments.length>0?!!a:!0},setLanguage:function(a){v(),e.lang=a},addCommands:function(b){var c;v();for(var d in b)if(b.hasOwnProperty(d))if(c=a[b[d]]||b[d],"function"==typeof c)w(s(d),c,d);else{if(!("object"==typeof c&&c.regexp instanceof RegExp)){j&&console.log("Can not register command: %c"+d,k);continue}w(new RegExp(c.regexp.source,"i"),c.callback,d)}},removeCommands:function(a){return a===b?void(g=[]):(a=Array.isArray(a)?a:[a],void(g=g.filter(function(b){for(var c=0;ca?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(k)return i&&b.console.log("Speech heard, but annyang is paused"),!1;for(var c=a.results[a.resultIndex],d=[],e=0;em;m++){var o=f[m],p=o.command.exec(h);if(p){var q=p.slice(1);return i&&(b.console.log("command matched: %c"+o.originalPhrase,j),q.length&&b.console.log("with parameters",q)),o.callback.apply(this,q),s(g.resultMatch,h,o.originalPhrase,d),!0}}}return s(g.resultNoMatch,d),!1},n&&(f=[]),m.length&&this.addCommands(m)},start:function(c){k=!1,u(),c=c||{},e=c.autoRestart!==a?!!c.autoRestart:!0,c.continuous!==a&&(d.continuous=!!c.continuous),h=(new Date).getTime();try{d.start()}catch(f){i&&b.console.log(f.message)}},abort:function(){e=!1,t()&&d.abort()},pause:function(){k=!0},resume:function(){b.annyang.start()},debug:function(a){i=arguments.length>0?!!a:!0},setLanguage:function(a){u(),d.lang=a},addCommands:function(a){var c;u();for(var d in a)if(a.hasOwnProperty(d))if(c=b[a[d]]||a[d],"function"==typeof c)v(r(d),c,d);else{if(!("object"==typeof c&&c.regexp instanceof RegExp)){i&&b.console.log("Can not register command: %c"+d,j);continue}v(new RegExp(c.regexp.source,"i"),c.callback,d)}},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;ca?setTimeout(c.start,1e3-a):c.start()}},e.onresult=function(a){if(l)return j&&console.log("Speech heard, but annyang is paused"),!1;for(var b=a.results[a.resultIndex],c=[],d=0;di;i++){var n=g[i],o=n.command.exec(e);if(o){var p=o.slice(1);return j&&(console.log("command matched: %c"+n.originalPhrase,k),p.length&&console.log("with parameters",p)),n.callback.apply(this,p),t(h.resultMatch,e,n.originalPhrase,c),!0}}}return t(h.resultNoMatch,c),!1},o&&(g=[]),n.length&&this.addCommands(n)},start:function(a){l=!1,v(),a=a||{},f=a.autoRestart!==b?!!a.autoRestart:!0,a.continuous!==b&&(e.continuous=!!a.continuous),i=(new Date).getTime();try{e.start()}catch(c){j&&console.log(c.message)}},abort:function(){f=!1,u()&&e.abort()},pause:function(){l=!0},resume:function(){c.start()},debug:function(a){j=arguments.length>0?!!a:!0},setLanguage:function(a){v(),e.lang=a},addCommands:function(b){var c;v();for(var d in b)if(b.hasOwnProperty(d))if(c=a[b[d]]||b[d],"function"==typeof c)w(s(d),c,d);else{if(!("object"==typeof c&&c.regexp instanceof RegExp)){j&&console.log("Can not register command: %c"+d,k);continue}w(new RegExp(c.regexp.source,"i"),c.callback,d)}},removeCommands:function(a){return a===b?void(g=[]):(a=Array.isArray(a)?a:[a],void(g=g.filter(function(b){for(var c=0;c Date: Thu, 31 Mar 2016 14:14:33 +0300 Subject: [PATCH 06/17] Reordered test suites to run testAndCoverage last --- Gruntfile.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index b954126..4a38d28 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -70,6 +70,20 @@ module.exports = function(grunt) { } }, jasmine: { + browserAMD: { + src: ['annyang.js'], + options: { + specs: 'test/spec/*Spec.js', + outfile: 'test/SpecRunner.html', + vendor: ['test/vendor/corti.js', 'test/init_corti.js'], // https://github.com/cloudchen/grunt-template-jasmine-requirejs/issues/72 + template: require('grunt-template-jasmine-requirejs'), + templateOptions: { + requireConfig: { + baseUrl: '../' + } + } + } + }, testAndCoverage: { src: ['annyang.js'], options: { @@ -99,20 +113,6 @@ module.exports = function(grunt) { } } } - }, - browserAMD: { - src: ['annyang.js'], - options: { - specs: 'test/spec/*Spec.js', - outfile: 'test/SpecRunner.html', - vendor: ['test/vendor/corti.js', 'test/init_corti.js'], // https://github.com/cloudchen/grunt-template-jasmine-requirejs/issues/72 - template: require('grunt-template-jasmine-requirejs'), - templateOptions: { - requireConfig: { - baseUrl: '../' - } - } - } } } }); From 28e6d6512f47b0286b1943f78a3ff310b951e6f2 Mon Sep 17 00:00:00 2001 From: Tal Ater Date: Thu, 31 Mar 2016 14:21:07 +0300 Subject: [PATCH 07/17] Added use strict to UMD block --- annyang.js | 2 +- annyang.min.js | 2 +- sites/facebook.min.js | 2 +- sites/geektime.min.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/annyang.js b/annyang.js index 7b25fd4..028bb64 100644 --- a/annyang.js +++ b/annyang.js @@ -4,8 +4,8 @@ //! license : MIT //! https://www.TalAter.com/annyang/ (function (root, factory) { + "use strict"; // istanbul ignore next - // jshint strict: false if (typeof define === 'function' && define.amd) { // AMD define([], function () { return (root.annyang = factory(root, undefined)); diff --git a/annyang.min.js b/annyang.min.js index 06fe632..a98497f 100644 --- a/annyang.min.js +++ b/annyang.min.js @@ -3,4 +3,4 @@ //! author : Tal Ater @TalAter //! license : MIT //! https://www.TalAter.com/annyang/ -!function(a,b){"function"==typeof define&&define.amd?define([],function(){return a.annyang=b(a,void 0)}):"object"==typeof module&&module.exports?module.exports=b(a,void 0):a.annyang=b(a,void 0)}("undefined"!=typeof window?window:this,function(a,b){"use strict";var c={},d=a.SpeechRecognition||a.webkitSpeechRecognition||a.mozSpeechRecognition||a.msSpeechRecognition||a.oSpeechRecognition;if(!d)return b;var e,f,g=[],h={start:[],error:[],end:[],result:[],resultMatch:[],resultNoMatch:[],errorNetwork:[],errorPermissionBlocked:[],errorPermissionDenied:[]},i=0,j=!1,k="font-weight: bold; color: #00f;",l=!1,m=!1,n=/\s*\((.*?)\)\s*/g,o=/(\(\?:[^)]+\))\?/g,p=/(\(\?)?:\w+/g,q=/\*\w+/g,r=/[\-{}\[\]+?.,\\\^$|#]/g,s=function(a){return a=a.replace(r,"\\$&").replace(n,"(?:$1)?").replace(p,function(a,b){return b?a:"([^\\s]+)"}).replace(q,"(.*?)").replace(o,"\\s*$1?\\s*"),new RegExp("^"+a+"$","i")},t=function(a){var b=Array.prototype.slice.call(arguments,1);a.forEach(function(a){a.callback.apply(a.context,b)})},u=function(){return e!==b},v=function(){u()||c.init({},!1)},w=function(a,b,c){g.push({command:a,callback:b,originalPhrase:c}),j&&console.log("Command successfully loaded: %c"+c,k)};return c={init:function(n,o){o=o===b?!0:!!o,e&&e.abort&&e.abort(),e=new d,e.maxAlternatives=5,e.continuous="http:"===a.location.protocol,e.lang="en-US",e.onstart=function(){m=!0,t(h.start)},e.onerror=function(a){switch(t(h.error),a.error){case"network":t(h.errorNetwork);break;case"not-allowed":case"service-not-allowed":f=!1,t((new Date).getTime()-i<200?h.errorPermissionBlocked:h.errorPermissionDenied)}},e.onend=function(){if(m=!1,t(h.end),f){var a=(new Date).getTime()-i;1e3>a?setTimeout(c.start,1e3-a):c.start()}},e.onresult=function(a){if(l)return j&&console.log("Speech heard, but annyang is paused"),!1;for(var b=a.results[a.resultIndex],c=[],d=0;di;i++){var n=g[i],o=n.command.exec(e);if(o){var p=o.slice(1);return j&&(console.log("command matched: %c"+n.originalPhrase,k),p.length&&console.log("with parameters",p)),n.callback.apply(this,p),t(h.resultMatch,e,n.originalPhrase,c),!0}}}return t(h.resultNoMatch,c),!1},o&&(g=[]),n.length&&this.addCommands(n)},start:function(a){l=!1,v(),a=a||{},f=a.autoRestart!==b?!!a.autoRestart:!0,a.continuous!==b&&(e.continuous=!!a.continuous),i=(new Date).getTime();try{e.start()}catch(c){j&&console.log(c.message)}},abort:function(){f=!1,u()&&e.abort()},pause:function(){l=!0},resume:function(){c.start()},debug:function(a){j=arguments.length>0?!!a:!0},setLanguage:function(a){v(),e.lang=a},addCommands:function(b){var c;v();for(var d in b)if(b.hasOwnProperty(d))if(c=a[b[d]]||b[d],"function"==typeof c)w(s(d),c,d);else{if(!("object"==typeof c&&c.regexp instanceof RegExp)){j&&console.log("Can not register command: %c"+d,k);continue}w(new RegExp(c.regexp.source,"i"),c.callback,d)}},removeCommands:function(a){return a===b?void(g=[]):(a=Array.isArray(a)?a:[a],void(g=g.filter(function(b){for(var c=0;ca?setTimeout(c.start,1e3-a):c.start()}},e.onresult=function(a){if(l)return j&&console.log("Speech heard, but annyang is paused"),!1;for(var b=a.results[a.resultIndex],c=[],d=0;di;i++){var n=g[i],o=n.command.exec(e);if(o){var p=o.slice(1);return j&&(console.log("command matched: %c"+n.originalPhrase,k),p.length&&console.log("with parameters",p)),n.callback.apply(this,p),t(h.resultMatch,e,n.originalPhrase,c),!0}}}return t(h.resultNoMatch,c),!1},o&&(g=[]),n.length&&this.addCommands(n)},start:function(a){l=!1,v(),a=a||{},f=a.autoRestart!==b?!!a.autoRestart:!0,a.continuous!==b&&(e.continuous=!!a.continuous),i=(new Date).getTime();try{e.start()}catch(c){j&&console.log(c.message)}},abort:function(){f=!1,u()&&e.abort()},pause:function(){l=!0},resume:function(){c.start()},debug:function(a){j=arguments.length>0?!!a:!0},setLanguage:function(a){v(),e.lang=a},addCommands:function(b){var c;v();for(var d in b)if(b.hasOwnProperty(d))if(c=a[b[d]]||b[d],"function"==typeof c)w(s(d),c,d);else{if(!("object"==typeof c&&c.regexp instanceof RegExp)){j&&console.log("Can not register command: %c"+d,k);continue}w(new RegExp(c.regexp.source,"i"),c.callback,d)}},removeCommands:function(a){return a===b?void(g=[]):(a=Array.isArray(a)?a:[a],void(g=g.filter(function(b){for(var c=0;ca?setTimeout(c.start,1e3-a):c.start()}},e.onresult=function(a){if(l)return j&&console.log("Speech heard, but annyang is paused"),!1;for(var b=a.results[a.resultIndex],c=[],d=0;di;i++){var n=g[i],o=n.command.exec(e);if(o){var p=o.slice(1);return j&&(console.log("command matched: %c"+n.originalPhrase,k),p.length&&console.log("with parameters",p)),n.callback.apply(this,p),t(h.resultMatch,e,n.originalPhrase,c),!0}}}return t(h.resultNoMatch,c),!1},o&&(g=[]),n.length&&this.addCommands(n)},start:function(a){l=!1,v(),a=a||{},f=a.autoRestart!==b?!!a.autoRestart:!0,a.continuous!==b&&(e.continuous=!!a.continuous),i=(new Date).getTime();try{e.start()}catch(c){j&&console.log(c.message)}},abort:function(){f=!1,u()&&e.abort()},pause:function(){l=!0},resume:function(){c.start()},debug:function(a){j=arguments.length>0?!!a:!0},setLanguage:function(a){v(),e.lang=a},addCommands:function(b){var c;v();for(var d in b)if(b.hasOwnProperty(d))if(c=a[b[d]]||b[d],"function"==typeof c)w(s(d),c,d);else{if(!("object"==typeof c&&c.regexp instanceof RegExp)){j&&console.log("Can not register command: %c"+d,k);continue}w(new RegExp(c.regexp.source,"i"),c.callback,d)}},removeCommands:function(a){return a===b?void(g=[]):(a=Array.isArray(a)?a:[a],void(g=g.filter(function(b){for(var c=0;ca?setTimeout(c.start,1e3-a):c.start()}},e.onresult=function(a){if(l)return j&&console.log("Speech heard, but annyang is paused"),!1;for(var b=a.results[a.resultIndex],c=[],d=0;di;i++){var n=g[i],o=n.command.exec(e);if(o){var p=o.slice(1);return j&&(console.log("command matched: %c"+n.originalPhrase,k),p.length&&console.log("with parameters",p)),n.callback.apply(this,p),t(h.resultMatch,e,n.originalPhrase,c),!0}}}return t(h.resultNoMatch,c),!1},o&&(g=[]),n.length&&this.addCommands(n)},start:function(a){l=!1,v(),a=a||{},f=a.autoRestart!==b?!!a.autoRestart:!0,a.continuous!==b&&(e.continuous=!!a.continuous),i=(new Date).getTime();try{e.start()}catch(c){j&&console.log(c.message)}},abort:function(){f=!1,u()&&e.abort()},pause:function(){l=!0},resume:function(){c.start()},debug:function(a){j=arguments.length>0?!!a:!0},setLanguage:function(a){v(),e.lang=a},addCommands:function(b){var c;v();for(var d in b)if(b.hasOwnProperty(d))if(c=a[b[d]]||b[d],"function"==typeof c)w(s(d),c,d);else{if(!("object"==typeof c&&c.regexp instanceof RegExp)){j&&console.log("Can not register command: %c"+d,k);continue}w(new RegExp(c.regexp.source,"i"),c.callback,d)}},removeCommands:function(a){return a===b?void(g=[]):(a=Array.isArray(a)?a:[a],void(g=g.filter(function(b){for(var c=0;ca?setTimeout(c.start,1e3-a):c.start()}},e.onresult=function(a){if(l)return j&&console.log("Speech heard, but annyang is paused"),!1;for(var b=a.results[a.resultIndex],c=[],d=0;di;i++){var n=g[i],o=n.command.exec(e);if(o){var p=o.slice(1);return j&&(console.log("command matched: %c"+n.originalPhrase,k),p.length&&console.log("with parameters",p)),n.callback.apply(this,p),t(h.resultMatch,e,n.originalPhrase,c),!0}}}return t(h.resultNoMatch,c),!1},o&&(g=[]),n.length&&this.addCommands(n)},start:function(a){l=!1,v(),a=a||{},f=a.autoRestart!==b?!!a.autoRestart:!0,a.continuous!==b&&(e.continuous=!!a.continuous),i=(new Date).getTime();try{e.start()}catch(c){j&&console.log(c.message)}},abort:function(){f=!1,u()&&e.abort()},pause:function(){l=!0},resume:function(){c.start()},debug:function(a){j=arguments.length>0?!!a:!0},setLanguage:function(a){v(),e.lang=a},addCommands:function(b){var c;v();for(var d in b)if(b.hasOwnProperty(d))if(c=a[b[d]]||b[d],"function"==typeof c)w(s(d),c,d);else{if(!("object"==typeof c&&c.regexp instanceof RegExp)){j&&console.log("Can not register command: %c"+d,k);continue}w(new RegExp(c.regexp.source,"i"),c.callback,d)}},removeCommands:function(a){return a===b?void(g=[]):(a=Array.isArray(a)?a:[a],void(g=g.filter(function(b){for(var c=0;ca?setTimeout(c.start,1e3-a):c.start()}},e.onresult=function(a){if(l)return j&&console.log("Speech heard, but annyang is paused"),!1;for(var b=a.results[a.resultIndex],c=[],d=0;di;i++){var n=g[i],o=n.command.exec(e);if(o){var p=o.slice(1);return j&&(console.log("command matched: %c"+n.originalPhrase,k),p.length&&console.log("with parameters",p)),n.callback.apply(this,p),t(h.resultMatch,e,n.originalPhrase,c),!0}}}return t(h.resultNoMatch,c),!1},o&&(g=[]),n.length&&this.addCommands(n)},start:function(a){l=!1,v(),a=a||{},f=a.autoRestart!==b?!!a.autoRestart:!0,a.continuous!==b&&(e.continuous=!!a.continuous),i=(new Date).getTime();try{e.start()}catch(c){j&&console.log(c.message)}},abort:function(){f=!1,u()&&e.abort()},pause:function(){l=!0},resume:function(){c.start()},debug:function(a){j=arguments.length>0?!!a:!0},setLanguage:function(a){v(),e.lang=a},addCommands:function(b){var c;v();for(var d in b)if(b.hasOwnProperty(d))if(c=a[b[d]]||b[d],"function"==typeof c)w(s(d),c,d);else{if(!("object"==typeof c&&c.regexp instanceof RegExp)){j&&console.log("Can not register command: %c"+d,k);continue}w(new RegExp(c.regexp.source,"i"),c.callback,d)}},removeCommands:function(a){return a===b?void(g=[]):(a=Array.isArray(a)?a:[a],void(g=g.filter(function(b){for(var c=0;c Date: Thu, 31 Mar 2016 14:24:27 +0300 Subject: [PATCH 08/17] Updated Jasmine configuration: Moved Corti from `polyfills` to `vendor` Due to a [bug in grunt-template-jasmine-requirejs](https://github.com/cloudchen/grunt-tem plate-jasmine-requirejs/issues/72) --- Gruntfile.js | 4 ++-- test/SpecRunner.html | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 4a38d28..cd9c922 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -75,7 +75,7 @@ module.exports = function(grunt) { options: { specs: 'test/spec/*Spec.js', outfile: 'test/SpecRunner.html', - vendor: ['test/vendor/corti.js', 'test/init_corti.js'], // https://github.com/cloudchen/grunt-template-jasmine-requirejs/issues/72 + vendor: ['test/vendor/corti.js', 'test/init_corti.js'], template: require('grunt-template-jasmine-requirejs'), templateOptions: { requireConfig: { @@ -89,7 +89,7 @@ module.exports = function(grunt) { options: { specs: ['test/spec/*Spec.js'], outfile: 'test/SpecRunner.html', - polyfills: ['test/vendor/corti.js', 'test/init_corti.js'], + vendor: ['test/vendor/corti.js', 'test/init_corti.js'], keepRunner: true, template: require('grunt-template-jasmine-istanbul'), templateOptions: { diff --git a/test/SpecRunner.html b/test/SpecRunner.html index 4f86792..1e9b987 100644 --- a/test/SpecRunner.html +++ b/test/SpecRunner.html @@ -14,10 +14,6 @@ - - - - @@ -26,6 +22,10 @@ + + + + From 79ea2c02dba52255fcb37d85c0aa245654b3ddc1 Mon Sep 17 00:00:00 2001 From: Tal Ater Date: Thu, 31 Mar 2016 14:27:47 +0300 Subject: [PATCH 09/17] Updated Jasmine:browserAMD config to keep spec runner --- Gruntfile.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Gruntfile.js b/Gruntfile.js index cd9c922..59e613a 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -76,6 +76,7 @@ module.exports = function(grunt) { specs: 'test/spec/*Spec.js', outfile: 'test/SpecRunner.html', vendor: ['test/vendor/corti.js', 'test/init_corti.js'], + keepRunner: true, template: require('grunt-template-jasmine-requirejs'), templateOptions: { requireConfig: { From 4d1698e5039e9bcfc5a3f836445ee6dbf232620f Mon Sep 17 00:00:00 2001 From: Tal Ater Date: Thu, 31 Mar 2016 14:28:10 +0300 Subject: [PATCH 10/17] Updated jasmine:testAndCoverage branches threshold --- Gruntfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gruntfile.js b/Gruntfile.js index 59e613a..33aaf0c 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -108,7 +108,7 @@ module.exports = function(grunt) { ], thresholds: { statements: 80, - branches: 65, + branches: 70, functions: 95, lines: 80 } From b24ef1edc3b23e5e5df357788bad9294f4103ddb Mon Sep 17 00:00:00 2001 From: Tal Ater Date: Thu, 31 Mar 2016 14:47:04 +0300 Subject: [PATCH 11/17] No need to pass undefined to factory function --- annyang.js | 6 +++--- annyang.min.js | 2 +- sites/facebook.min.js | 2 +- sites/geektime.min.js | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/annyang.js b/annyang.js index 028bb64..0f5dfa6 100644 --- a/annyang.js +++ b/annyang.js @@ -8,12 +8,12 @@ // istanbul ignore next if (typeof define === 'function' && define.amd) { // AMD define([], function () { - return (root.annyang = factory(root, undefined)); + return (root.annyang = factory(root)); }); } else if (typeof module === 'object' && module.exports) { // CommonJS - module.exports = factory(root, undefined); + module.exports = factory(root); } else { // Browser globals - root.annyang = factory(root, undefined); + root.annyang = factory(root); } }(typeof window !== 'undefined' ? window : this, function (root, undefined) { "use strict"; diff --git a/annyang.min.js b/annyang.min.js index a98497f..2d48b68 100644 --- a/annyang.min.js +++ b/annyang.min.js @@ -3,4 +3,4 @@ //! author : Tal Ater @TalAter //! license : MIT //! https://www.TalAter.com/annyang/ -!function(a,b){"use strict";"function"==typeof define&&define.amd?define([],function(){return a.annyang=b(a,void 0)}):"object"==typeof module&&module.exports?module.exports=b(a,void 0):a.annyang=b(a,void 0)}("undefined"!=typeof window?window:this,function(a,b){"use strict";var c={},d=a.SpeechRecognition||a.webkitSpeechRecognition||a.mozSpeechRecognition||a.msSpeechRecognition||a.oSpeechRecognition;if(!d)return b;var e,f,g=[],h={start:[],error:[],end:[],result:[],resultMatch:[],resultNoMatch:[],errorNetwork:[],errorPermissionBlocked:[],errorPermissionDenied:[]},i=0,j=!1,k="font-weight: bold; color: #00f;",l=!1,m=!1,n=/\s*\((.*?)\)\s*/g,o=/(\(\?:[^)]+\))\?/g,p=/(\(\?)?:\w+/g,q=/\*\w+/g,r=/[\-{}\[\]+?.,\\\^$|#]/g,s=function(a){return a=a.replace(r,"\\$&").replace(n,"(?:$1)?").replace(p,function(a,b){return b?a:"([^\\s]+)"}).replace(q,"(.*?)").replace(o,"\\s*$1?\\s*"),new RegExp("^"+a+"$","i")},t=function(a){var b=Array.prototype.slice.call(arguments,1);a.forEach(function(a){a.callback.apply(a.context,b)})},u=function(){return e!==b},v=function(){u()||c.init({},!1)},w=function(a,b,c){g.push({command:a,callback:b,originalPhrase:c}),j&&console.log("Command successfully loaded: %c"+c,k)};return c={init:function(n,o){o=o===b?!0:!!o,e&&e.abort&&e.abort(),e=new d,e.maxAlternatives=5,e.continuous="http:"===a.location.protocol,e.lang="en-US",e.onstart=function(){m=!0,t(h.start)},e.onerror=function(a){switch(t(h.error),a.error){case"network":t(h.errorNetwork);break;case"not-allowed":case"service-not-allowed":f=!1,t((new Date).getTime()-i<200?h.errorPermissionBlocked:h.errorPermissionDenied)}},e.onend=function(){if(m=!1,t(h.end),f){var a=(new Date).getTime()-i;1e3>a?setTimeout(c.start,1e3-a):c.start()}},e.onresult=function(a){if(l)return j&&console.log("Speech heard, but annyang is paused"),!1;for(var b=a.results[a.resultIndex],c=[],d=0;di;i++){var n=g[i],o=n.command.exec(e);if(o){var p=o.slice(1);return j&&(console.log("command matched: %c"+n.originalPhrase,k),p.length&&console.log("with parameters",p)),n.callback.apply(this,p),t(h.resultMatch,e,n.originalPhrase,c),!0}}}return t(h.resultNoMatch,c),!1},o&&(g=[]),n.length&&this.addCommands(n)},start:function(a){l=!1,v(),a=a||{},f=a.autoRestart!==b?!!a.autoRestart:!0,a.continuous!==b&&(e.continuous=!!a.continuous),i=(new Date).getTime();try{e.start()}catch(c){j&&console.log(c.message)}},abort:function(){f=!1,u()&&e.abort()},pause:function(){l=!0},resume:function(){c.start()},debug:function(a){j=arguments.length>0?!!a:!0},setLanguage:function(a){v(),e.lang=a},addCommands:function(b){var c;v();for(var d in b)if(b.hasOwnProperty(d))if(c=a[b[d]]||b[d],"function"==typeof c)w(s(d),c,d);else{if(!("object"==typeof c&&c.regexp instanceof RegExp)){j&&console.log("Can not register command: %c"+d,k);continue}w(new RegExp(c.regexp.source,"i"),c.callback,d)}},removeCommands:function(a){return a===b?void(g=[]):(a=Array.isArray(a)?a:[a],void(g=g.filter(function(b){for(var c=0;ca?setTimeout(c.start,1e3-a):c.start()}},e.onresult=function(a){if(l)return j&&console.log("Speech heard, but annyang is paused"),!1;for(var b=a.results[a.resultIndex],c=[],d=0;di;i++){var n=g[i],o=n.command.exec(e);if(o){var p=o.slice(1);return j&&(console.log("command matched: %c"+n.originalPhrase,k),p.length&&console.log("with parameters",p)),n.callback.apply(this,p),t(h.resultMatch,e,n.originalPhrase,c),!0}}}return t(h.resultNoMatch,c),!1},o&&(g=[]),n.length&&this.addCommands(n)},start:function(a){l=!1,v(),a=a||{},f=a.autoRestart!==b?!!a.autoRestart:!0,a.continuous!==b&&(e.continuous=!!a.continuous),i=(new Date).getTime();try{e.start()}catch(c){j&&console.log(c.message)}},abort:function(){f=!1,u()&&e.abort()},pause:function(){l=!0},resume:function(){c.start()},debug:function(a){j=arguments.length>0?!!a:!0},setLanguage:function(a){v(),e.lang=a},addCommands:function(b){var c;v();for(var d in b)if(b.hasOwnProperty(d))if(c=a[b[d]]||b[d],"function"==typeof c)w(s(d),c,d);else{if(!("object"==typeof c&&c.regexp instanceof RegExp)){j&&console.log("Can not register command: %c"+d,k);continue}w(new RegExp(c.regexp.source,"i"),c.callback,d)}},removeCommands:function(a){return a===b?void(g=[]):(a=Array.isArray(a)?a:[a],void(g=g.filter(function(b){for(var c=0;ca?setTimeout(c.start,1e3-a):c.start()}},e.onresult=function(a){if(l)return j&&console.log("Speech heard, but annyang is paused"),!1;for(var b=a.results[a.resultIndex],c=[],d=0;di;i++){var n=g[i],o=n.command.exec(e);if(o){var p=o.slice(1);return j&&(console.log("command matched: %c"+n.originalPhrase,k),p.length&&console.log("with parameters",p)),n.callback.apply(this,p),t(h.resultMatch,e,n.originalPhrase,c),!0}}}return t(h.resultNoMatch,c),!1},o&&(g=[]),n.length&&this.addCommands(n)},start:function(a){l=!1,v(),a=a||{},f=a.autoRestart!==b?!!a.autoRestart:!0,a.continuous!==b&&(e.continuous=!!a.continuous),i=(new Date).getTime();try{e.start()}catch(c){j&&console.log(c.message)}},abort:function(){f=!1,u()&&e.abort()},pause:function(){l=!0},resume:function(){c.start()},debug:function(a){j=arguments.length>0?!!a:!0},setLanguage:function(a){v(),e.lang=a},addCommands:function(b){var c;v();for(var d in b)if(b.hasOwnProperty(d))if(c=a[b[d]]||b[d],"function"==typeof c)w(s(d),c,d);else{if(!("object"==typeof c&&c.regexp instanceof RegExp)){j&&console.log("Can not register command: %c"+d,k);continue}w(new RegExp(c.regexp.source,"i"),c.callback,d)}},removeCommands:function(a){return a===b?void(g=[]):(a=Array.isArray(a)?a:[a],void(g=g.filter(function(b){for(var c=0;ca?setTimeout(c.start,1e3-a):c.start()}},e.onresult=function(a){if(l)return j&&console.log("Speech heard, but annyang is paused"),!1;for(var b=a.results[a.resultIndex],c=[],d=0;di;i++){var n=g[i],o=n.command.exec(e);if(o){var p=o.slice(1);return j&&(console.log("command matched: %c"+n.originalPhrase,k),p.length&&console.log("with parameters",p)),n.callback.apply(this,p),t(h.resultMatch,e,n.originalPhrase,c),!0}}}return t(h.resultNoMatch,c),!1},o&&(g=[]),n.length&&this.addCommands(n)},start:function(a){l=!1,v(),a=a||{},f=a.autoRestart!==b?!!a.autoRestart:!0,a.continuous!==b&&(e.continuous=!!a.continuous),i=(new Date).getTime();try{e.start()}catch(c){j&&console.log(c.message)}},abort:function(){f=!1,u()&&e.abort()},pause:function(){l=!0},resume:function(){c.start()},debug:function(a){j=arguments.length>0?!!a:!0},setLanguage:function(a){v(),e.lang=a},addCommands:function(b){var c;v();for(var d in b)if(b.hasOwnProperty(d))if(c=a[b[d]]||b[d],"function"==typeof c)w(s(d),c,d);else{if(!("object"==typeof c&&c.regexp instanceof RegExp)){j&&console.log("Can not register command: %c"+d,k);continue}w(new RegExp(c.regexp.source,"i"),c.callback,d)}},removeCommands:function(a){return a===b?void(g=[]):(a=Array.isArray(a)?a:[a],void(g=g.filter(function(b){for(var c=0;ca?setTimeout(c.start,1e3-a):c.start()}},e.onresult=function(a){if(l)return j&&console.log("Speech heard, but annyang is paused"),!1;for(var b=a.results[a.resultIndex],c=[],d=0;di;i++){var n=g[i],o=n.command.exec(e);if(o){var p=o.slice(1);return j&&(console.log("command matched: %c"+n.originalPhrase,k),p.length&&console.log("with parameters",p)),n.callback.apply(this,p),t(h.resultMatch,e,n.originalPhrase,c),!0}}}return t(h.resultNoMatch,c),!1},o&&(g=[]),n.length&&this.addCommands(n)},start:function(a){l=!1,v(),a=a||{},f=a.autoRestart!==b?!!a.autoRestart:!0,a.continuous!==b&&(e.continuous=!!a.continuous),i=(new Date).getTime();try{e.start()}catch(c){j&&console.log(c.message)}},abort:function(){f=!1,u()&&e.abort()},pause:function(){l=!0},resume:function(){c.start()},debug:function(a){j=arguments.length>0?!!a:!0},setLanguage:function(a){v(),e.lang=a},addCommands:function(b){var c;v();for(var d in b)if(b.hasOwnProperty(d))if(c=a[b[d]]||b[d],"function"==typeof c)w(s(d),c,d);else{if(!("object"==typeof c&&c.regexp instanceof RegExp)){j&&console.log("Can not register command: %c"+d,k);continue}w(new RegExp(c.regexp.source,"i"),c.callback,d)}},removeCommands:function(a){return a===b?void(g=[]):(a=Array.isArray(a)?a:[a],void(g=g.filter(function(b){for(var c=0;ca?setTimeout(c.start,1e3-a):c.start()}},e.onresult=function(a){if(l)return j&&console.log("Speech heard, but annyang is paused"),!1;for(var b=a.results[a.resultIndex],c=[],d=0;di;i++){var n=g[i],o=n.command.exec(e);if(o){var p=o.slice(1);return j&&(console.log("command matched: %c"+n.originalPhrase,k),p.length&&console.log("with parameters",p)),n.callback.apply(this,p),t(h.resultMatch,e,n.originalPhrase,c),!0}}}return t(h.resultNoMatch,c),!1},o&&(g=[]),n.length&&this.addCommands(n)},start:function(a){l=!1,v(),a=a||{},f=a.autoRestart!==b?!!a.autoRestart:!0,a.continuous!==b&&(e.continuous=!!a.continuous),i=(new Date).getTime();try{e.start()}catch(c){j&&console.log(c.message)}},abort:function(){f=!1,u()&&e.abort()},pause:function(){l=!0},resume:function(){c.start()},debug:function(a){j=arguments.length>0?!!a:!0},setLanguage:function(a){v(),e.lang=a},addCommands:function(b){var c;v();for(var d in b)if(b.hasOwnProperty(d))if(c=a[b[d]]||b[d],"function"==typeof c)w(s(d),c,d);else{if(!("object"==typeof c&&c.regexp instanceof RegExp)){j&&console.log("Can not register command: %c"+d,k);continue}w(new RegExp(c.regexp.source,"i"),c.callback,d)}},removeCommands:function(a){return a===b?void(g=[]):(a=Array.isArray(a)?a:[a],void(g=g.filter(function(b){for(var c=0;c Date: Thu, 31 Mar 2016 14:52:58 +0300 Subject: [PATCH 12/17] No need to create object in annyang variable twice --- annyang.js | 2 +- annyang.min.js | 2 +- docs/README.md | 2 -- sites/facebook.min.js | 2 +- sites/geektime.min.js | 2 +- 5 files changed, 4 insertions(+), 6 deletions(-) diff --git a/annyang.js b/annyang.js index 0f5dfa6..26b18e8 100644 --- a/annyang.js +++ b/annyang.js @@ -28,7 +28,7 @@ * # API Reference */ - var annyang = {}; + var annyang; // Get the SpeechRecognition object, while handling browser prefixes var SpeechRecognition = root.SpeechRecognition || diff --git a/annyang.min.js b/annyang.min.js index 2d48b68..cde7e54 100644 --- a/annyang.min.js +++ b/annyang.min.js @@ -3,4 +3,4 @@ //! author : Tal Ater @TalAter //! license : MIT //! https://www.TalAter.com/annyang/ -!function(a,b){"use strict";"function"==typeof define&&define.amd?define([],function(){return a.annyang=b(a)}):"object"==typeof module&&module.exports?module.exports=b(a):a.annyang=b(a)}("undefined"!=typeof window?window:this,function(a,b){"use strict";var c={},d=a.SpeechRecognition||a.webkitSpeechRecognition||a.mozSpeechRecognition||a.msSpeechRecognition||a.oSpeechRecognition;if(!d)return b;var e,f,g=[],h={start:[],error:[],end:[],result:[],resultMatch:[],resultNoMatch:[],errorNetwork:[],errorPermissionBlocked:[],errorPermissionDenied:[]},i=0,j=!1,k="font-weight: bold; color: #00f;",l=!1,m=!1,n=/\s*\((.*?)\)\s*/g,o=/(\(\?:[^)]+\))\?/g,p=/(\(\?)?:\w+/g,q=/\*\w+/g,r=/[\-{}\[\]+?.,\\\^$|#]/g,s=function(a){return a=a.replace(r,"\\$&").replace(n,"(?:$1)?").replace(p,function(a,b){return b?a:"([^\\s]+)"}).replace(q,"(.*?)").replace(o,"\\s*$1?\\s*"),new RegExp("^"+a+"$","i")},t=function(a){var b=Array.prototype.slice.call(arguments,1);a.forEach(function(a){a.callback.apply(a.context,b)})},u=function(){return e!==b},v=function(){u()||c.init({},!1)},w=function(a,b,c){g.push({command:a,callback:b,originalPhrase:c}),j&&console.log("Command successfully loaded: %c"+c,k)};return c={init:function(n,o){o=o===b?!0:!!o,e&&e.abort&&e.abort(),e=new d,e.maxAlternatives=5,e.continuous="http:"===a.location.protocol,e.lang="en-US",e.onstart=function(){m=!0,t(h.start)},e.onerror=function(a){switch(t(h.error),a.error){case"network":t(h.errorNetwork);break;case"not-allowed":case"service-not-allowed":f=!1,t((new Date).getTime()-i<200?h.errorPermissionBlocked:h.errorPermissionDenied)}},e.onend=function(){if(m=!1,t(h.end),f){var a=(new Date).getTime()-i;1e3>a?setTimeout(c.start,1e3-a):c.start()}},e.onresult=function(a){if(l)return j&&console.log("Speech heard, but annyang is paused"),!1;for(var b=a.results[a.resultIndex],c=[],d=0;di;i++){var n=g[i],o=n.command.exec(e);if(o){var p=o.slice(1);return j&&(console.log("command matched: %c"+n.originalPhrase,k),p.length&&console.log("with parameters",p)),n.callback.apply(this,p),t(h.resultMatch,e,n.originalPhrase,c),!0}}}return t(h.resultNoMatch,c),!1},o&&(g=[]),n.length&&this.addCommands(n)},start:function(a){l=!1,v(),a=a||{},f=a.autoRestart!==b?!!a.autoRestart:!0,a.continuous!==b&&(e.continuous=!!a.continuous),i=(new Date).getTime();try{e.start()}catch(c){j&&console.log(c.message)}},abort:function(){f=!1,u()&&e.abort()},pause:function(){l=!0},resume:function(){c.start()},debug:function(a){j=arguments.length>0?!!a:!0},setLanguage:function(a){v(),e.lang=a},addCommands:function(b){var c;v();for(var d in b)if(b.hasOwnProperty(d))if(c=a[b[d]]||b[d],"function"==typeof c)w(s(d),c,d);else{if(!("object"==typeof c&&c.regexp instanceof RegExp)){j&&console.log("Can not register command: %c"+d,k);continue}w(new RegExp(c.regexp.source,"i"),c.callback,d)}},removeCommands:function(a){return a===b?void(g=[]):(a=Array.isArray(a)?a:[a],void(g=g.filter(function(b){for(var c=0;ca?setTimeout(c.start,1e3-a):c.start()}},e.onresult=function(a){if(l)return j&&console.log("Speech heard, but annyang is paused"),!1;for(var b=a.results[a.resultIndex],c=[],d=0;di;i++){var n=g[i],o=n.command.exec(e);if(o){var p=o.slice(1);return j&&(console.log("command matched: %c"+n.originalPhrase,k),p.length&&console.log("with parameters",p)),n.callback.apply(this,p),t(h.resultMatch,e,n.originalPhrase,c),!0}}}return t(h.resultNoMatch,c),!1},o&&(g=[]),n.length&&this.addCommands(n)},start:function(a){l=!1,v(),a=a||{},f=a.autoRestart!==b?!!a.autoRestart:!0,a.continuous!==b&&(e.continuous=!!a.continuous),i=(new Date).getTime();try{e.start()}catch(c){j&&console.log(c.message)}},abort:function(){f=!1,u()&&e.abort()},pause:function(){l=!0},resume:function(){c.start()},debug:function(a){j=arguments.length>0?!!a:!0},setLanguage:function(a){v(),e.lang=a},addCommands:function(b){var c;v();for(var d in b)if(b.hasOwnProperty(d))if(c=a[b[d]]||b[d],"function"==typeof c)w(s(d),c,d);else{if(!("object"==typeof c&&c.regexp instanceof RegExp)){j&&console.log("Can not register command: %c"+d,k);continue}w(new RegExp(c.regexp.source,"i"),c.callback,d)}},removeCommands:function(a){return a===b?void(g=[]):(a=Array.isArray(a)?a:[a],void(g=g.filter(function(b){for(var c=0;c -## annyang - # Quick Tutorial, Intro and Demos The quickest way to get started is to visit the [annyang homepage](https://www.talater.com/annyang/). diff --git a/sites/facebook.min.js b/sites/facebook.min.js index 914ee9f..2458055 100644 --- a/sites/facebook.min.js +++ b/sites/facebook.min.js @@ -3,7 +3,7 @@ //! author : Tal Ater @TalAter //! license : MIT //! https://www.TalAter.com/annyang/ -!function(a,b){"use strict";"function"==typeof define&&define.amd?define([],function(){return a.annyang=b(a)}):"object"==typeof module&&module.exports?module.exports=b(a):a.annyang=b(a)}("undefined"!=typeof window?window:this,function(a,b){"use strict";var c={},d=a.SpeechRecognition||a.webkitSpeechRecognition||a.mozSpeechRecognition||a.msSpeechRecognition||a.oSpeechRecognition;if(!d)return b;var e,f,g=[],h={start:[],error:[],end:[],result:[],resultMatch:[],resultNoMatch:[],errorNetwork:[],errorPermissionBlocked:[],errorPermissionDenied:[]},i=0,j=!1,k="font-weight: bold; color: #00f;",l=!1,m=!1,n=/\s*\((.*?)\)\s*/g,o=/(\(\?:[^)]+\))\?/g,p=/(\(\?)?:\w+/g,q=/\*\w+/g,r=/[\-{}\[\]+?.,\\\^$|#]/g,s=function(a){return a=a.replace(r,"\\$&").replace(n,"(?:$1)?").replace(p,function(a,b){return b?a:"([^\\s]+)"}).replace(q,"(.*?)").replace(o,"\\s*$1?\\s*"),new RegExp("^"+a+"$","i")},t=function(a){var b=Array.prototype.slice.call(arguments,1);a.forEach(function(a){a.callback.apply(a.context,b)})},u=function(){return e!==b},v=function(){u()||c.init({},!1)},w=function(a,b,c){g.push({command:a,callback:b,originalPhrase:c}),j&&console.log("Command successfully loaded: %c"+c,k)};return c={init:function(n,o){o=o===b?!0:!!o,e&&e.abort&&e.abort(),e=new d,e.maxAlternatives=5,e.continuous="http:"===a.location.protocol,e.lang="en-US",e.onstart=function(){m=!0,t(h.start)},e.onerror=function(a){switch(t(h.error),a.error){case"network":t(h.errorNetwork);break;case"not-allowed":case"service-not-allowed":f=!1,t((new Date).getTime()-i<200?h.errorPermissionBlocked:h.errorPermissionDenied)}},e.onend=function(){if(m=!1,t(h.end),f){var a=(new Date).getTime()-i;1e3>a?setTimeout(c.start,1e3-a):c.start()}},e.onresult=function(a){if(l)return j&&console.log("Speech heard, but annyang is paused"),!1;for(var b=a.results[a.resultIndex],c=[],d=0;di;i++){var n=g[i],o=n.command.exec(e);if(o){var p=o.slice(1);return j&&(console.log("command matched: %c"+n.originalPhrase,k),p.length&&console.log("with parameters",p)),n.callback.apply(this,p),t(h.resultMatch,e,n.originalPhrase,c),!0}}}return t(h.resultNoMatch,c),!1},o&&(g=[]),n.length&&this.addCommands(n)},start:function(a){l=!1,v(),a=a||{},f=a.autoRestart!==b?!!a.autoRestart:!0,a.continuous!==b&&(e.continuous=!!a.continuous),i=(new Date).getTime();try{e.start()}catch(c){j&&console.log(c.message)}},abort:function(){f=!1,u()&&e.abort()},pause:function(){l=!0},resume:function(){c.start()},debug:function(a){j=arguments.length>0?!!a:!0},setLanguage:function(a){v(),e.lang=a},addCommands:function(b){var c;v();for(var d in b)if(b.hasOwnProperty(d))if(c=a[b[d]]||b[d],"function"==typeof c)w(s(d),c,d);else{if(!("object"==typeof c&&c.regexp instanceof RegExp)){j&&console.log("Can not register command: %c"+d,k);continue}w(new RegExp(c.regexp.source,"i"),c.callback,d)}},removeCommands:function(a){return a===b?void(g=[]):(a=Array.isArray(a)?a:[a],void(g=g.filter(function(b){for(var c=0;ca?setTimeout(c.start,1e3-a):c.start()}},e.onresult=function(a){if(l)return j&&console.log("Speech heard, but annyang is paused"),!1;for(var b=a.results[a.resultIndex],c=[],d=0;di;i++){var n=g[i],o=n.command.exec(e);if(o){var p=o.slice(1);return j&&(console.log("command matched: %c"+n.originalPhrase,k),p.length&&console.log("with parameters",p)),n.callback.apply(this,p),t(h.resultMatch,e,n.originalPhrase,c),!0}}}return t(h.resultNoMatch,c),!1},o&&(g=[]),n.length&&this.addCommands(n)},start:function(a){l=!1,v(),a=a||{},f=a.autoRestart!==b?!!a.autoRestart:!0,a.continuous!==b&&(e.continuous=!!a.continuous),i=(new Date).getTime();try{e.start()}catch(c){j&&console.log(c.message)}},abort:function(){f=!1,u()&&e.abort()},pause:function(){l=!0},resume:function(){c.start()},debug:function(a){j=arguments.length>0?!!a:!0},setLanguage:function(a){v(),e.lang=a},addCommands:function(b){var c;v();for(var d in b)if(b.hasOwnProperty(d))if(c=a[b[d]]||b[d],"function"==typeof c)w(s(d),c,d);else{if(!("object"==typeof c&&c.regexp instanceof RegExp)){j&&console.log("Can not register command: %c"+d,k);continue}w(new RegExp(c.regexp.source,"i"),c.callback,d)}},removeCommands:function(a){return a===b?void(g=[]):(a=Array.isArray(a)?a:[a],void(g=g.filter(function(b){for(var c=0;ca?setTimeout(c.start,1e3-a):c.start()}},e.onresult=function(a){if(l)return j&&console.log("Speech heard, but annyang is paused"),!1;for(var b=a.results[a.resultIndex],c=[],d=0;di;i++){var n=g[i],o=n.command.exec(e);if(o){var p=o.slice(1);return j&&(console.log("command matched: %c"+n.originalPhrase,k),p.length&&console.log("with parameters",p)),n.callback.apply(this,p),t(h.resultMatch,e,n.originalPhrase,c),!0}}}return t(h.resultNoMatch,c),!1},o&&(g=[]),n.length&&this.addCommands(n)},start:function(a){l=!1,v(),a=a||{},f=a.autoRestart!==b?!!a.autoRestart:!0,a.continuous!==b&&(e.continuous=!!a.continuous),i=(new Date).getTime();try{e.start()}catch(c){j&&console.log(c.message)}},abort:function(){f=!1,u()&&e.abort()},pause:function(){l=!0},resume:function(){c.start()},debug:function(a){j=arguments.length>0?!!a:!0},setLanguage:function(a){v(),e.lang=a},addCommands:function(b){var c;v();for(var d in b)if(b.hasOwnProperty(d))if(c=a[b[d]]||b[d],"function"==typeof c)w(s(d),c,d);else{if(!("object"==typeof c&&c.regexp instanceof RegExp)){j&&console.log("Can not register command: %c"+d,k);continue}w(new RegExp(c.regexp.source,"i"),c.callback,d)}},removeCommands:function(a){return a===b?void(g=[]):(a=Array.isArray(a)?a:[a],void(g=g.filter(function(b){for(var c=0;ca?setTimeout(c.start,1e3-a):c.start()}},e.onresult=function(a){if(l)return j&&console.log("Speech heard, but annyang is paused"),!1;for(var b=a.results[a.resultIndex],c=[],d=0;di;i++){var n=g[i],o=n.command.exec(e);if(o){var p=o.slice(1);return j&&(console.log("command matched: %c"+n.originalPhrase,k),p.length&&console.log("with parameters",p)),n.callback.apply(this,p),t(h.resultMatch,e,n.originalPhrase,c),!0}}}return t(h.resultNoMatch,c),!1},o&&(g=[]),n.length&&this.addCommands(n)},start:function(a){l=!1,v(),a=a||{},f=a.autoRestart!==b?!!a.autoRestart:!0,a.continuous!==b&&(e.continuous=!!a.continuous),i=(new Date).getTime();try{e.start()}catch(c){j&&console.log(c.message)}},abort:function(){f=!1,u()&&e.abort()},pause:function(){l=!0},resume:function(){c.start()},debug:function(a){j=arguments.length>0?!!a:!0},setLanguage:function(a){v(),e.lang=a},addCommands:function(b){var c;v();for(var d in b)if(b.hasOwnProperty(d))if(c=a[b[d]]||b[d],"function"==typeof c)w(s(d),c,d);else{if(!("object"==typeof c&&c.regexp instanceof RegExp)){j&&console.log("Can not register command: %c"+d,k);continue}w(new RegExp(c.regexp.source,"i"),c.callback,d)}},removeCommands:function(a){return a===b?void(g=[]):(a=Array.isArray(a)?a:[a],void(g=g.filter(function(b){for(var c=0;c Date: Thu, 31 Mar 2016 14:57:40 +0300 Subject: [PATCH 13/17] Removed code coverage ignore command from UMD block and lowered thresholds Unfortunate that we have lower coverage, but there is no reason we should not strive to test this code as well --- Gruntfile.js | 4 ++-- annyang.js | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 33aaf0c..0b9dc63 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -108,8 +108,8 @@ module.exports = function(grunt) { ], thresholds: { statements: 80, - branches: 70, - functions: 95, + branches: 65, + functions: 90, lines: 80 } } diff --git a/annyang.js b/annyang.js index 26b18e8..c4bf1c7 100644 --- a/annyang.js +++ b/annyang.js @@ -5,7 +5,6 @@ //! https://www.TalAter.com/annyang/ (function (root, factory) { "use strict"; - // istanbul ignore next if (typeof define === 'function' && define.amd) { // AMD define([], function () { return (root.annyang = factory(root)); From 1bcb00142e4f531a910da50924cbb1ec439c68b0 Mon Sep 17 00:00:00 2001 From: Tal Ater Date: Thu, 31 Mar 2016 15:05:17 +0300 Subject: [PATCH 14/17] Expanded comment for AMD export --- annyang.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/annyang.js b/annyang.js index c4bf1c7..f0b402e 100644 --- a/annyang.js +++ b/annyang.js @@ -5,7 +5,7 @@ //! https://www.TalAter.com/annyang/ (function (root, factory) { "use strict"; - if (typeof define === 'function' && define.amd) { // AMD + if (typeof define === 'function' && define.amd) { // AMD + global define([], function () { return (root.annyang = factory(root)); }); From b3f56614a52081977f5bb17bc3a1b382013fe6c2 Mon Sep 17 00:00:00 2001 From: Tal Ater Date: Thu, 31 Mar 2016 15:07:53 +0300 Subject: [PATCH 15/17] Changed annyang to equal null when Speech Recognition is not available Maintains backward compatibility with existing annyang API. --- annyang.js | 2 +- annyang.min.js | 2 +- sites/facebook.min.js | 2 +- sites/geektime.min.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/annyang.js b/annyang.js index f0b402e..bb7d631 100644 --- a/annyang.js +++ b/annyang.js @@ -39,7 +39,7 @@ // Check browser support // This is done as early as possible, to make it as fast as possible for unsupported browsers if (!SpeechRecognition) { - return undefined; + return null; } var commandsList = []; diff --git a/annyang.min.js b/annyang.min.js index cde7e54..aa1110e 100644 --- a/annyang.min.js +++ b/annyang.min.js @@ -3,4 +3,4 @@ //! author : Tal Ater @TalAter //! license : MIT //! https://www.TalAter.com/annyang/ -!function(a,b){"use strict";"function"==typeof define&&define.amd?define([],function(){return a.annyang=b(a)}):"object"==typeof module&&module.exports?module.exports=b(a):a.annyang=b(a)}("undefined"!=typeof window?window:this,function(a,b){"use strict";var c,d=a.SpeechRecognition||a.webkitSpeechRecognition||a.mozSpeechRecognition||a.msSpeechRecognition||a.oSpeechRecognition;if(!d)return b;var e,f,g=[],h={start:[],error:[],end:[],result:[],resultMatch:[],resultNoMatch:[],errorNetwork:[],errorPermissionBlocked:[],errorPermissionDenied:[]},i=0,j=!1,k="font-weight: bold; color: #00f;",l=!1,m=!1,n=/\s*\((.*?)\)\s*/g,o=/(\(\?:[^)]+\))\?/g,p=/(\(\?)?:\w+/g,q=/\*\w+/g,r=/[\-{}\[\]+?.,\\\^$|#]/g,s=function(a){return a=a.replace(r,"\\$&").replace(n,"(?:$1)?").replace(p,function(a,b){return b?a:"([^\\s]+)"}).replace(q,"(.*?)").replace(o,"\\s*$1?\\s*"),new RegExp("^"+a+"$","i")},t=function(a){var b=Array.prototype.slice.call(arguments,1);a.forEach(function(a){a.callback.apply(a.context,b)})},u=function(){return e!==b},v=function(){u()||c.init({},!1)},w=function(a,b,c){g.push({command:a,callback:b,originalPhrase:c}),j&&console.log("Command successfully loaded: %c"+c,k)};return c={init:function(n,o){o=o===b?!0:!!o,e&&e.abort&&e.abort(),e=new d,e.maxAlternatives=5,e.continuous="http:"===a.location.protocol,e.lang="en-US",e.onstart=function(){m=!0,t(h.start)},e.onerror=function(a){switch(t(h.error),a.error){case"network":t(h.errorNetwork);break;case"not-allowed":case"service-not-allowed":f=!1,t((new Date).getTime()-i<200?h.errorPermissionBlocked:h.errorPermissionDenied)}},e.onend=function(){if(m=!1,t(h.end),f){var a=(new Date).getTime()-i;1e3>a?setTimeout(c.start,1e3-a):c.start()}},e.onresult=function(a){if(l)return j&&console.log("Speech heard, but annyang is paused"),!1;for(var b=a.results[a.resultIndex],c=[],d=0;di;i++){var n=g[i],o=n.command.exec(e);if(o){var p=o.slice(1);return j&&(console.log("command matched: %c"+n.originalPhrase,k),p.length&&console.log("with parameters",p)),n.callback.apply(this,p),t(h.resultMatch,e,n.originalPhrase,c),!0}}}return t(h.resultNoMatch,c),!1},o&&(g=[]),n.length&&this.addCommands(n)},start:function(a){l=!1,v(),a=a||{},f=a.autoRestart!==b?!!a.autoRestart:!0,a.continuous!==b&&(e.continuous=!!a.continuous),i=(new Date).getTime();try{e.start()}catch(c){j&&console.log(c.message)}},abort:function(){f=!1,u()&&e.abort()},pause:function(){l=!0},resume:function(){c.start()},debug:function(a){j=arguments.length>0?!!a:!0},setLanguage:function(a){v(),e.lang=a},addCommands:function(b){var c;v();for(var d in b)if(b.hasOwnProperty(d))if(c=a[b[d]]||b[d],"function"==typeof c)w(s(d),c,d);else{if(!("object"==typeof c&&c.regexp instanceof RegExp)){j&&console.log("Can not register command: %c"+d,k);continue}w(new RegExp(c.regexp.source,"i"),c.callback,d)}},removeCommands:function(a){return a===b?void(g=[]):(a=Array.isArray(a)?a:[a],void(g=g.filter(function(b){for(var c=0;ca?setTimeout(c.start,1e3-a):c.start()}},e.onresult=function(a){if(l)return j&&console.log("Speech heard, but annyang is paused"),!1;for(var b=a.results[a.resultIndex],c=[],d=0;di;i++){var n=g[i],o=n.command.exec(e);if(o){var p=o.slice(1);return j&&(console.log("command matched: %c"+n.originalPhrase,k),p.length&&console.log("with parameters",p)),n.callback.apply(this,p),t(h.resultMatch,e,n.originalPhrase,c),!0}}}return t(h.resultNoMatch,c),!1},o&&(g=[]),n.length&&this.addCommands(n)},start:function(a){l=!1,v(),a=a||{},f=a.autoRestart!==b?!!a.autoRestart:!0,a.continuous!==b&&(e.continuous=!!a.continuous),i=(new Date).getTime();try{e.start()}catch(c){j&&console.log(c.message)}},abort:function(){f=!1,u()&&e.abort()},pause:function(){l=!0},resume:function(){c.start()},debug:function(a){j=arguments.length>0?!!a:!0},setLanguage:function(a){v(),e.lang=a},addCommands:function(b){var c;v();for(var d in b)if(b.hasOwnProperty(d))if(c=a[b[d]]||b[d],"function"==typeof c)w(s(d),c,d);else{if(!("object"==typeof c&&c.regexp instanceof RegExp)){j&&console.log("Can not register command: %c"+d,k);continue}w(new RegExp(c.regexp.source,"i"),c.callback,d)}},removeCommands:function(a){return a===b?void(g=[]):(a=Array.isArray(a)?a:[a],void(g=g.filter(function(b){for(var c=0;ca?setTimeout(c.start,1e3-a):c.start()}},e.onresult=function(a){if(l)return j&&console.log("Speech heard, but annyang is paused"),!1;for(var b=a.results[a.resultIndex],c=[],d=0;di;i++){var n=g[i],o=n.command.exec(e);if(o){var p=o.slice(1);return j&&(console.log("command matched: %c"+n.originalPhrase,k),p.length&&console.log("with parameters",p)),n.callback.apply(this,p),t(h.resultMatch,e,n.originalPhrase,c),!0}}}return t(h.resultNoMatch,c),!1},o&&(g=[]),n.length&&this.addCommands(n)},start:function(a){l=!1,v(),a=a||{},f=a.autoRestart!==b?!!a.autoRestart:!0,a.continuous!==b&&(e.continuous=!!a.continuous),i=(new Date).getTime();try{e.start()}catch(c){j&&console.log(c.message)}},abort:function(){f=!1,u()&&e.abort()},pause:function(){l=!0},resume:function(){c.start()},debug:function(a){j=arguments.length>0?!!a:!0},setLanguage:function(a){v(),e.lang=a},addCommands:function(b){var c;v();for(var d in b)if(b.hasOwnProperty(d))if(c=a[b[d]]||b[d],"function"==typeof c)w(s(d),c,d);else{if(!("object"==typeof c&&c.regexp instanceof RegExp)){j&&console.log("Can not register command: %c"+d,k);continue}w(new RegExp(c.regexp.source,"i"),c.callback,d)}},removeCommands:function(a){return a===b?void(g=[]):(a=Array.isArray(a)?a:[a],void(g=g.filter(function(b){for(var c=0;ca?setTimeout(c.start,1e3-a):c.start()}},e.onresult=function(a){if(l)return j&&console.log("Speech heard, but annyang is paused"),!1;for(var b=a.results[a.resultIndex],c=[],d=0;di;i++){var n=g[i],o=n.command.exec(e);if(o){var p=o.slice(1);return j&&(console.log("command matched: %c"+n.originalPhrase,k),p.length&&console.log("with parameters",p)),n.callback.apply(this,p),t(h.resultMatch,e,n.originalPhrase,c),!0}}}return t(h.resultNoMatch,c),!1},o&&(g=[]),n.length&&this.addCommands(n)},start:function(a){l=!1,v(),a=a||{},f=a.autoRestart!==b?!!a.autoRestart:!0,a.continuous!==b&&(e.continuous=!!a.continuous),i=(new Date).getTime();try{e.start()}catch(c){j&&console.log(c.message)}},abort:function(){f=!1,u()&&e.abort()},pause:function(){l=!0},resume:function(){c.start()},debug:function(a){j=arguments.length>0?!!a:!0},setLanguage:function(a){v(),e.lang=a},addCommands:function(b){var c;v();for(var d in b)if(b.hasOwnProperty(d))if(c=a[b[d]]||b[d],"function"==typeof c)w(s(d),c,d);else{if(!("object"==typeof c&&c.regexp instanceof RegExp)){j&&console.log("Can not register command: %c"+d,k);continue}w(new RegExp(c.regexp.source,"i"),c.callback,d)}},removeCommands:function(a){return a===b?void(g=[]):(a=Array.isArray(a)?a:[a],void(g=g.filter(function(b){for(var c=0;ca?setTimeout(c.start,1e3-a):c.start()}},e.onresult=function(a){if(l)return j&&console.log("Speech heard, but annyang is paused"),!1;for(var b=a.results[a.resultIndex],c=[],d=0;di;i++){var n=g[i],o=n.command.exec(e);if(o){var p=o.slice(1);return j&&(console.log("command matched: %c"+n.originalPhrase,k),p.length&&console.log("with parameters",p)),n.callback.apply(this,p),t(h.resultMatch,e,n.originalPhrase,c),!0}}}return t(h.resultNoMatch,c),!1},o&&(g=[]),n.length&&this.addCommands(n)},start:function(a){l=!1,v(),a=a||{},f=a.autoRestart!==b?!!a.autoRestart:!0,a.continuous!==b&&(e.continuous=!!a.continuous),i=(new Date).getTime();try{e.start()}catch(c){j&&console.log(c.message)}},abort:function(){f=!1,u()&&e.abort()},pause:function(){l=!0},resume:function(){c.start()},debug:function(a){j=arguments.length>0?!!a:!0},setLanguage:function(a){v(),e.lang=a},addCommands:function(b){var c;v();for(var d in b)if(b.hasOwnProperty(d))if(c=a[b[d]]||b[d],"function"==typeof c)w(s(d),c,d);else{if(!("object"==typeof c&&c.regexp instanceof RegExp)){j&&console.log("Can not register command: %c"+d,k);continue}w(new RegExp(c.regexp.source,"i"),c.callback,d)}},removeCommands:function(a){return a===b?void(g=[]):(a=Array.isArray(a)?a:[a],void(g=g.filter(function(b){for(var c=0;ca?setTimeout(c.start,1e3-a):c.start()}},e.onresult=function(a){if(l)return j&&console.log("Speech heard, but annyang is paused"),!1;for(var b=a.results[a.resultIndex],c=[],d=0;di;i++){var n=g[i],o=n.command.exec(e);if(o){var p=o.slice(1);return j&&(console.log("command matched: %c"+n.originalPhrase,k),p.length&&console.log("with parameters",p)),n.callback.apply(this,p),t(h.resultMatch,e,n.originalPhrase,c),!0}}}return t(h.resultNoMatch,c),!1},o&&(g=[]),n.length&&this.addCommands(n)},start:function(a){l=!1,v(),a=a||{},f=a.autoRestart!==b?!!a.autoRestart:!0,a.continuous!==b&&(e.continuous=!!a.continuous),i=(new Date).getTime();try{e.start()}catch(c){j&&console.log(c.message)}},abort:function(){f=!1,u()&&e.abort()},pause:function(){l=!0},resume:function(){c.start()},debug:function(a){j=arguments.length>0?!!a:!0},setLanguage:function(a){v(),e.lang=a},addCommands:function(b){var c;v();for(var d in b)if(b.hasOwnProperty(d))if(c=a[b[d]]||b[d],"function"==typeof c)w(s(d),c,d);else{if(!("object"==typeof c&&c.regexp instanceof RegExp)){j&&console.log("Can not register command: %c"+d,k);continue}w(new RegExp(c.regexp.source,"i"),c.callback,d)}},removeCommands:function(a){return a===b?void(g=[]):(a=Array.isArray(a)?a:[a],void(g=g.filter(function(b){for(var c=0;c Date: Thu, 31 Mar 2016 15:30:13 +0300 Subject: [PATCH 16/17] Updated Corti Added use strict Changed AMD comment Removed explicit undefined from factory call. --- test/vendor/corti.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/vendor/corti.js b/test/vendor/corti.js index 7c84662..f5ca6c6 100644 --- a/test/vendor/corti.js +++ b/test/vendor/corti.js @@ -5,15 +5,15 @@ //! https://github.com/TalAter/SpeechKITT/test/corti.js (function (root, factory) { - // jshint strict: false - if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. + "use strict"; + if (typeof define === 'function' && define.amd) { // AMD + global define([], function () { - return (root.Corti = factory(root, undefined)); + return (root.Corti = factory(root)); }); } else if (typeof module === 'object' && module.exports) { // CommonJS - module.exports = factory(root, undefined); + module.exports = factory(root); } else { // Browser globals - root.Corti = factory(root, undefined); + root.Corti = factory(root); } }(typeof window !== 'undefined' ? window : this, function (_root, undefined) { "use strict"; From c7cc9b6575ecbc3f6ad154b620b2270b0339185e Mon Sep 17 00:00:00 2001 From: Tal Ater Date: Thu, 31 Mar 2016 16:02:43 +0300 Subject: [PATCH 17/17] Reverted Corti back to v0.2.1 Changes should be done in original Corti. See https://github.com/TalAter/Corti/issues/7 --- test/vendor/corti.js | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/test/vendor/corti.js b/test/vendor/corti.js index f5ca6c6..fcdb07c 100644 --- a/test/vendor/corti.js +++ b/test/vendor/corti.js @@ -4,20 +4,12 @@ //! license : MIT //! https://github.com/TalAter/SpeechKITT/test/corti.js -(function (root, factory) { - "use strict"; - if (typeof define === 'function' && define.amd) { // AMD + global - define([], function () { - return (root.Corti = factory(root)); - }); - } else if (typeof module === 'object' && module.exports) { // CommonJS - module.exports = factory(root); - } else { // Browser globals - root.Corti = factory(root); - } -}(typeof window !== 'undefined' ? window : this, function (_root, undefined) { +(function (undefined) { "use strict"; + // Save a reference to the global object (window in the browser) + var _root = this; + // Holds the browser's implementation var _productionVersion = false; @@ -172,7 +164,7 @@ }; // Expose functionality - return { + _root.Corti = { patch: function() { if (_productionVersion === false) { _productionVersion = _root.SpeechRecognition || @@ -189,4 +181,4 @@ } }; -})); +}).call(this); \ No newline at end of file