From 769a3783133ce220ad9876badb96829476c2df2d Mon Sep 17 00:00:00 2001 From: Gabin Date: Wed, 25 Feb 2015 21:32:12 +0100 Subject: [PATCH] updating to v1.3.2 --- CONTRIBUTING.md | 2 +- LICENSE | 2 +- bower.json | 2 +- build/theater.js | 2 +- build/theater.min.js | 2 +- package.json | 2 +- src/theater.js | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8ac45ecd..bb3f88de 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -42,4 +42,4 @@ So adding support for the `fr` locale (`azerty` keyboard) would be as simple as (function (w) { w.TheaterJS.prototype.keyboards.fr = ["azertyuiop", "qsdfghjklm", "wxcvbn"]; })(window); -``` +``` \ No newline at end of file diff --git a/LICENSE b/LICENSE index 9e67f1d7..6b203ee4 100644 --- a/LICENSE +++ b/LICENSE @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. +THE SOFTWARE. \ No newline at end of file diff --git a/bower.json b/bower.json index 1d59a01d..beef6a2d 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "TheaterJS", - "version": "1.3.1", + "version": "1.3.2", "main": "build/theater.js", "license": "MIT", "ignore": [ diff --git a/build/theater.js b/build/theater.js index 0ee4f771..8735949f 100644 --- a/build/theater.js +++ b/build/theater.js @@ -53,7 +53,7 @@ TheaterJS.prototype = { constructor: TheaterJS, - version: "1.3.1", + version: "1.3.2", keyboards: {}, diff --git a/build/theater.min.js b/build/theater.min.js index f0e89899..97298293 100644 --- a/build/theater.min.js +++ b/build/theater.min.js @@ -1 +1 @@ -!function(t,e){function r(t){var e=this,r={autoplay:!0,erase:!0,locale:"detect",minSpeed:50,maxSpeed:600};e.options=e.utils.merge(r,t||{}),"detect"===e.options.locale&&(e.options.locale=(window.navigator.languages||["en"])[0].split("-")[0]),e.keyboards[e.options.locale]||(e.options.locale="en"),e.utils.keyboard=e.keyboards[e.options.locale],e.events={},e.scene=-1,e.scenario=[],e.casting={},e.current={},e.state="ready"}r.prototype={constructor:r,version:"1.3.1",keyboards:{},set:function(t,e){var r=this,n=r.current.voice,i=r.current.html||[];return r.utils.isArray(e)||(e=[]),r.current.model=e[0]=r.utils.injectHTML(t,i),r.utils.isFunction(n)?n.apply(r,e):n.innerHTML=r.current.model,r},getSayingSpeed:function(t){var e=this;e.utils.isNumber(t)||(t=0);var r=e.current.speed+t;r>1&&(r=1);var n=e.utils.randomFloat(r,1);return e.utils.getPercentageBetween(e.options.maxSpeed,e.options.minSpeed,n)},recover:function(t){var e=this,r=e.maxMistakes();return t>=r||e.utils.randomFloat(0,1)<=e.current.accuracy},maxMistakes:function(){var t=this,e=.8-t.current.accuracy;return 0>=e?1:10*e},isMistaking:function(){var t=this;return t.utils.randomFloat(0,.8)>t.current.accuracy},utils:{keyboard:{},copy:function(t){var e,r={};for(e in t)t.hasOwnProperty(e)&&(r[e]=t[e]);return r},isArray:function(t){return t instanceof Array},isFunction:function(t){return"function"==typeof t},isString:function(t){return"string"==typeof t},isNumber:function(t){return"number"==typeof t},isObject:function(t){return t instanceof Object},stripHTML:function(t){return t.replace(/(<([^>]+)>)/gi,"")},mapHTML:function(t){for(var e,r,n=/<[^>]+>/gi,i=[],a=[];e=n.exec(t);)r={tagName:e[0],position:e.index},"/"===r.tagName.charAt(1)?r.opener=a.pop():"/"!==r.tagName.charAt(r.tagName.length-2)&&a.push(r),i.push(r);return i},injectHTML:function(t,e){for(var r,n=0,i=e.length;i>n;n++)r=e[n],r.positionn;n++){e=t[n];for(var a=0,s=e.length;s>a;a++)r[e[a]]={x:a,y:n}}return r},merge:function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);return t},getPercentageBetween:function(t,e,r){return t-t*r+e*r},randomCharNear:function(t){var e=this,r=e.mapKeyboard(e.keyboard),n=1,i=[],a=!!t.match(/[A-Z]/);t=t.toLowerCase();var s,o,c=r[t]||[];for(s in r)r.hasOwnProperty(s)&&s!==t&&(o=r[s],Math.abs(c.x-o.x)<=n&&Math.abs(c.y-o.y)<=n&&i.push(s));var u=i.length>0?i[e.randomNumber(0,i.length-1)]:e.randomChar();return a?u.toUpperCase():u},randomChar:function(){var t=this,e=t.keyboard.join("");return e.charAt(t.randomNumber(0,e.length-1))},randomNumber:function(t,e){return Math.floor(Math.random()*(e-t+1))+t},randomFloat:function(t,e){return Math.round(10*(Math.random()*(e-t)+t))/10},hasClass:function(t,e){return t.classList?t.classList.contains(e):new RegExp("(^| )"+e+"( |$)","gi").test(t.className)},addClass:function(t,e){t.classList?t.classList.add(e):t.className+=" "+e},removeClass:function(t,e){t.classList?t.classList.remove(e):t.className=t.className.replace(new RegExp("(^|\\b)"+e.split(" ").join("|")+"(\\b|$)","gi")," ")}},train:function(t){var e=this,r={experience:.6,voice:function(t){console.log(t)},model:""};return t=e.utils.merge(r,t),e.utils.isNumber(t.speed)||(t.speed=t.experience),e.utils.isNumber(t.accuracy)||(t.accuracy=t.experience),e.utils.isNumber(t.invincibility)||(t.invincibility=10*t.accuracy),t},describe:function(t,r,n){var i=this,a={name:t};return i.utils.isNumber(r)?a.experience=r:i.utils.isObject(r)&&(a=i.utils.merge(a,r)),void 0!==n&&(a.voice=i.utils.isString(n)?e.querySelector(n):n),i.casting[t]=i.train(a),i},write:function(){for(var t,e=this,r=Array.prototype.splice.apply(arguments,[0]),n=0,i=r.length;i>n;n++)if(t=r[n],e.utils.isString(t)){var a=t.split(":"),s=a.length>1&&"\\"!==a[0].charAt(a[0].length-1),o=s?a.shift().trim():null,c=a.join(":").replace(/\\:/g,":");s&&e.write({name:"actor",args:[o]}),e.options.erase&&s&&e.write({name:"erase"}),e.write({name:"say",args:[c,!s]})}else"number"==typeof t?e.write(0>t?{name:"erase",args:[t]}:{name:"wait",args:[t]}):"function"==typeof t?e.write({name:"call",args:[t]}):t instanceof Object&&e.scenario.push(t);return e.options.autoplay&&e.play(),e},play:function(t){var e=this;return"playing"!==e.state&&(t===!0&&(e.scene=-1),e.state="ready",e.next()),e},stop:function(){var t=this;return t.state="stopped",t},on:function(t,e){var r=this;t=t.split(",");for(var n,i=0,a=t.length;a>i;i++)n=t[i]=t[i].trim(),(r.events[n]||(r.events[n]=[])).push(e);return r},emit:function(t,e,r){var n=this;n.utils.isString(e)?void 0!==e&&void 0===r&&(r=e):e=void 0;var i=t+(e?":"+e:"");return n.trigger(i,r).trigger("*",[i].concat(r)),n},trigger:function(t,e){var r=this,n=r.events[t]||[];e instanceof Array||(e=[e]);for(var i=0,a=n.length;a>i;i++)n[i].apply(r,[t].concat(e));return r},call:function(t,e){var r=this;return t.apply(r),e?r:r.next()},next:function(){var t=this,e=t.scenario[t.scene];if(e&&t.emit(e.name,"end",[e.name].concat(e.args)),"stopped"===t.state||t.scene+1>=t.scenario.length)t.state="ready";else{t.state="playing";var r=t.scenario[++t.scene];t.emit(r.name,"start",[r.name].concat(r.args)),t[r.name].apply(t,r.args)}return t},actor:function(t){var e=this;return e.current=e.casting[t],e.next()},say:function(t,e){var r,n,i=this,a=0,s=!1,o=i.current.invincibility;i.current.html=i.utils.mapHTML(t),t=i.utils.stripHTML(t),e?(n=i.current.model,r=i.current.model.length-1,t=n+t):(n=i.current.model="",r=-1);var c=setTimeout(function u(){var e,l,p=n.charAt(r);a>0&&(r>=t.length||s||i.recover(a))?(o=i.current.invincibility,s=!0,e=null,l=n=n.substr(0,r),a--,r--):(s=!1,r++,e=t.charAt(r),r0)&&a++,l=n+=e),i.set(l,[l,e,p,t]),a>0||rt?n+1+t:0;setTimeout(function a(){var t=r.charAt(n),s=r.substr(0,--n);e.set(s,[s,null,t,s]),r=s,n>=i?setTimeout(a,e.getSayingSpeed(.2,!0)):e.next()},e.getSayingSpeed(.2))}return e},wait:function(t){var e=this;return setTimeout(function(){e.next()},t),e}},r.prototype.keyboards.en=["qwertyuiop","asdfghjkl","zxcvbnm"],r.prototype.keyboards.fr=["azertyuiop","qsdfghjklm","wxcvbn"],t.TheaterJS=r}(window,document); \ No newline at end of file +!function(t,e){function r(t){var e=this,r={autoplay:!0,erase:!0,locale:"detect",minSpeed:50,maxSpeed:600};e.options=e.utils.merge(r,t||{}),"detect"===e.options.locale&&(e.options.locale=(window.navigator.languages||["en"])[0].split("-")[0]),e.keyboards[e.options.locale]||(e.options.locale="en"),e.utils.keyboard=e.keyboards[e.options.locale],e.events={},e.scene=-1,e.scenario=[],e.casting={},e.current={},e.state="ready"}r.prototype={constructor:r,version:"1.3.2",keyboards:{},set:function(t,e){var r=this,n=r.current.voice,i=r.current.html||[];return r.utils.isArray(e)||(e=[]),r.current.model=e[0]=r.utils.injectHTML(t,i),r.utils.isFunction(n)?n.apply(r,e):n.innerHTML=r.current.model,r},getSayingSpeed:function(t){var e=this;e.utils.isNumber(t)||(t=0);var r=e.current.speed+t;r>1&&(r=1);var n=e.utils.randomFloat(r,1);return e.utils.getPercentageBetween(e.options.maxSpeed,e.options.minSpeed,n)},recover:function(t){var e=this,r=e.maxMistakes();return t>=r||e.utils.randomFloat(0,1)<=e.current.accuracy},maxMistakes:function(){var t=this,e=.8-t.current.accuracy;return 0>=e?1:10*e},isMistaking:function(){var t=this;return t.utils.randomFloat(0,.8)>t.current.accuracy},utils:{keyboard:{},copy:function(t){var e,r={};for(e in t)t.hasOwnProperty(e)&&(r[e]=t[e]);return r},isArray:function(t){return t instanceof Array},isFunction:function(t){return"function"==typeof t},isString:function(t){return"string"==typeof t},isNumber:function(t){return"number"==typeof t},isObject:function(t){return t instanceof Object},stripHTML:function(t){return t.replace(/(<([^>]+)>)/gi,"")},mapHTML:function(t){for(var e,r,n=/<[^>]+>/gi,i=[],a=[];e=n.exec(t);)r={tagName:e[0],position:e.index},"/"===r.tagName.charAt(1)?r.opener=a.pop():"/"!==r.tagName.charAt(r.tagName.length-2)&&a.push(r),i.push(r);return i},injectHTML:function(t,e){for(var r,n=0,i=e.length;i>n;n++)r=e[n],r.positionn;n++){e=t[n];for(var a=0,s=e.length;s>a;a++)r[e[a]]={x:a,y:n}}return r},merge:function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);return t},getPercentageBetween:function(t,e,r){return t-t*r+e*r},randomCharNear:function(t){var e=this,r=e.mapKeyboard(e.keyboard),n=1,i=[],a=!!t.match(/[A-Z]/);t=t.toLowerCase();var s,o,c=r[t]||[];for(s in r)r.hasOwnProperty(s)&&s!==t&&(o=r[s],Math.abs(c.x-o.x)<=n&&Math.abs(c.y-o.y)<=n&&i.push(s));var u=i.length>0?i[e.randomNumber(0,i.length-1)]:e.randomChar();return a?u.toUpperCase():u},randomChar:function(){var t=this,e=t.keyboard.join("");return e.charAt(t.randomNumber(0,e.length-1))},randomNumber:function(t,e){return Math.floor(Math.random()*(e-t+1))+t},randomFloat:function(t,e){return Math.round(10*(Math.random()*(e-t)+t))/10},hasClass:function(t,e){return t.classList?t.classList.contains(e):new RegExp("(^| )"+e+"( |$)","gi").test(t.className)},addClass:function(t,e){t.classList?t.classList.add(e):t.className+=" "+e},removeClass:function(t,e){t.classList?t.classList.remove(e):t.className=t.className.replace(new RegExp("(^|\\b)"+e.split(" ").join("|")+"(\\b|$)","gi")," ")}},train:function(t){var e=this,r={experience:.6,voice:function(t){console.log(t)},model:""};return t=e.utils.merge(r,t),e.utils.isNumber(t.speed)||(t.speed=t.experience),e.utils.isNumber(t.accuracy)||(t.accuracy=t.experience),e.utils.isNumber(t.invincibility)||(t.invincibility=10*t.accuracy),t},describe:function(t,r,n){var i=this,a={name:t};return i.utils.isNumber(r)?a.experience=r:i.utils.isObject(r)&&(a=i.utils.merge(a,r)),void 0!==n&&(a.voice=i.utils.isString(n)?e.querySelector(n):n),i.casting[t]=i.train(a),i},write:function(){for(var t,e=this,r=Array.prototype.splice.apply(arguments,[0]),n=0,i=r.length;i>n;n++)if(t=r[n],e.utils.isString(t)){var a=t.split(":"),s=a.length>1&&"\\"!==a[0].charAt(a[0].length-1),o=s?a.shift().trim():null,c=a.join(":").replace(/\\:/g,":");s&&e.write({name:"actor",args:[o]}),e.options.erase&&s&&e.write({name:"erase"}),e.write({name:"say",args:[c,!s]})}else"number"==typeof t?e.write(0>t?{name:"erase",args:[t]}:{name:"wait",args:[t]}):"function"==typeof t?e.write({name:"call",args:[t]}):t instanceof Object&&e.scenario.push(t);return e.options.autoplay&&e.play(),e},play:function(t){var e=this;return"playing"!==e.state&&(t===!0&&(e.scene=-1),e.state="ready",e.next()),e},stop:function(){var t=this;return t.state="stopped",t},on:function(t,e){var r=this;t=t.split(",");for(var n,i=0,a=t.length;a>i;i++)n=t[i]=t[i].trim(),(r.events[n]||(r.events[n]=[])).push(e);return r},emit:function(t,e,r){var n=this;n.utils.isString(e)?void 0!==e&&void 0===r&&(r=e):e=void 0;var i=t+(e?":"+e:"");return n.trigger(i,r).trigger("*",[i].concat(r)),n},trigger:function(t,e){var r=this,n=r.events[t]||[];e instanceof Array||(e=[e]);for(var i=0,a=n.length;a>i;i++)n[i].apply(r,[t].concat(e));return r},call:function(t,e){var r=this;return t.apply(r),e?r:r.next()},next:function(){var t=this,e=t.scenario[t.scene];if(e&&t.emit(e.name,"end",[e.name].concat(e.args)),"stopped"===t.state||t.scene+1>=t.scenario.length)t.state="ready";else{t.state="playing";var r=t.scenario[++t.scene];t.emit(r.name,"start",[r.name].concat(r.args)),t[r.name].apply(t,r.args)}return t},actor:function(t){var e=this;return e.current=e.casting[t],e.next()},say:function(t,e){var r,n,i=this,a=0,s=!1,o=i.current.invincibility;i.current.html=i.utils.mapHTML(t),t=i.utils.stripHTML(t),e?(n=i.current.model,r=i.current.model.length-1,t=n+t):(n=i.current.model="",r=-1);var c=setTimeout(function u(){var e,l,p=n.charAt(r);a>0&&(r>=t.length||s||i.recover(a))?(o=i.current.invincibility,s=!0,e=null,l=n=n.substr(0,r),a--,r--):(s=!1,r++,e=t.charAt(r),r0)&&a++,l=n+=e),i.set(l,[l,e,p,t]),a>0||rt?n+1+t:0;setTimeout(function a(){var t=r.charAt(n),s=r.substr(0,--n);e.set(s,[s,null,t,s]),r=s,n>=i?setTimeout(a,e.getSayingSpeed(.2,!0)):e.next()},e.getSayingSpeed(.2))}return e},wait:function(t){var e=this;return setTimeout(function(){e.next()},t),e}},r.prototype.keyboards.en=["qwertyuiop","asdfghjkl","zxcvbnm"],r.prototype.keyboards.fr=["azertyuiop","qsdfghjklm","wxcvbn"],t.TheaterJS=r}(window,document); \ No newline at end of file diff --git a/package.json b/package.json index 472490e9..bea7b3fa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "TheaterJS", - "version": "1.3.1", + "version": "1.3.2", "description": "Typing effect mimicking human behavior.", "repository": { "type": "git", diff --git a/src/theater.js b/src/theater.js index 0ee4f771..8735949f 100644 --- a/src/theater.js +++ b/src/theater.js @@ -53,7 +53,7 @@ TheaterJS.prototype = { constructor: TheaterJS, - version: "1.3.1", + version: "1.3.2", keyboards: {},