From 8fa680e8206cd6ece35f18edf482aaf5b99e78d5 Mon Sep 17 00:00:00 2001 From: Alex MacArthur Date: Tue, 7 Jun 2016 19:34:10 -0500 Subject: [PATCH] Implement strict mode. --- README.md | 4 +- dev/typeit.js | 714 ++++++++++++++++++++++----------------------- dev/typeit.min.js | 2 +- dist/typeit.js | 714 ++++++++++++++++++++++----------------------- dist/typeit.min.js | 2 +- package.json | 2 +- 6 files changed, 719 insertions(+), 719 deletions(-) diff --git a/README.md b/README.md index 1a7472f1..f20a7772 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ To get started, first select a license: Get it from this repo, or from the following sources: -* CDN: Include `https://cdn.jsdelivr.net/jquery.typeit/4.2.1/typeit.min.js` or `https://cdnjs.cloudflare.com/ajax/libs/typeit/4.2.1/typeit.min.js` on your page. +* CDN: Include `https://cdn.jsdelivr.net/jquery.typeit/4.2.2/typeit.min.js` or `https://cdnjs.cloudflare.com/ajax/libs/typeit/4.2.2/typeit.min.js` on your page. * npm: Install with `npm install typeit`. ### Hook It Up @@ -60,7 +60,7 @@ Get it from this repo, or from the following sources: ``` -2. Create an empty HTML element to select. (If you want to have a fallback for users without JavaScript, you can put a string or strings right into this element. For more on that, see the full documentation..) +2. Create an empty HTML element to select. (If you want to have a fallback for users without JavaScript, you can put a string or strings right into this element. For more on that, see the full documentation.) ```html diff --git a/dev/typeit.js b/dev/typeit.js index 2e59c263..82d15649 100644 --- a/dev/typeit.js +++ b/dev/typeit.js @@ -1,17 +1,19 @@ /** * jQuery TypeIt * @author Alex MacArthur (http://macarthur.me) - * @version 4.2.1 + * @version 4.2.2 * @copyright 2016 Alex MacArthur * @description Types out a given string or strings. */ - (function($, undefined){ +(function($, undefined) { + + 'use strict'; var $doc = $(document); - $.fn.typeIt = function(opt){ - return this.each(function(){ + $.fn.typeIt = function(opt) { + return this.each(function() { var $t = $(this); $t.data('typeit', new $.typeIt($t, opt)); }); @@ -32,8 +34,8 @@ loop: false, loopDelay: 750, html: true, - autoStart: true, - callback: function(){} + autoStart: true, + callback: function() {} }; this.queue = []; @@ -43,424 +45,422 @@ this.stringsToDelete = ''; this.style = 'style="display:inline;position:relative;font:inherit;color:inherit;"'; this.s = $.extend({}, this.d, opt); - this.el = el; + this.el = el; this._init(); }; - $.typeIt.prototype = { - - _init : function() { - this.el.find('.ti-container, .ti-cursor, .ti-placeholder').remove(); - this._elCheck(); - this.s.strings = this._toArray(this.s.strings); - this.el.html('.'); - this.tel = this.el.find('span'); - - this.insert = function(c) { - this.tel.append(c); - }; - - if(this.s.startDelete) { - this.tel.html(this.stringsToDelete); - this.queue.push([this.delete]); - } + $.typeIt.prototype = { + + _init: function() { + this.el.find('.ti-container, .ti-cursor, .ti-placeholder').remove(); + this._elCheck(); + this.s.strings = this._toArray(this.s.strings); + this.el.html('.'); + this.tel = this.el.find('span'); + + this.insert = function(c) { + this.tel.append(c); + }; + + if (this.s.startDelete) { + this.tel.html(this.stringsToDelete); + this.queue.push([this.delete]); + } - this._generateQueue(); - this._kickoff(); - }, - - _kickoff : function() { - this._cursor(); - - if(this.s.autoStart) { - this._startQueue(); - } else { - if(this._isVisible()) { - this.hasStarted = true; + this._generateQueue(); + this._kickoff(); + }, + + _kickoff: function() { + this._cursor(); + + if (this.s.autoStart) { this._startQueue(); } else { - $doc.on('scroll', function() { - if(this._isVisible() && !this.hasStarted) { - this.hasStarted = true; - this._startQueue(); - } - }.bind(this)); + if (this._isVisible()) { + this.hasStarted = true; + this._startQueue(); + } else { + $doc.on('scroll', function() { + if (this._isVisible() && !this.hasStarted) { + this.hasStarted = true; + this._startQueue(); + } + }.bind(this)); + } } - } - }, - - _generateQueue : function() { - for(i = 0; i < this.s.strings.length; i++) { - - this.queue.push([this.type, this.s.strings[i]]); - - if(i < (this.s.strings.length - 1)) { - var curPos = this.queue.length; - this.queue.push([this.s.breakLines ? this.break : this.delete]); - - if(this.s.breakLines) { - this.queue.splice(curPos, 0, [this.pause, this.s.breakDelay/2]); - this.queue.splice(curPos + 2, 0, [this.pause, this.s.breakDelay/2]); + }, + + _generateQueue: function() { + for (i = 0; i < this.s.strings.length; i++) { + + this.queue.push([this.type, this.s.strings[i]]); + + if (i < (this.s.strings.length - 1)) { + var curPos = this.queue.length; + this.queue.push([this.s.breakLines ? this.break : this.delete]); + + if (this.s.breakLines) { + this.queue.splice(curPos, 0, [this.pause, this.s.breakDelay / 2]); + this.queue.splice(curPos + 2, 0, [this.pause, this.s.breakDelay / 2]); + } } } - } - }, + }, - _startQueue : function() { - this._to(function() { - this._executeQueue(); - }.bind(this), this.s.startDelay); - }, + _startQueue: function() { + this._to(function() { + this._executeQueue(); + }.bind(this), this.s.startDelay); + }, - /* - Pass in a string, and loop over that string until empty. Then return true. - */ - type : function(string, rake){ + /* + Pass in a string, and loop over that string until empty. Then return true. + */ + type: function(string, rake) { - // set default 'rake' value - rake = typeof rake === 'undefined' ? true : rake; + // set default 'rake' value + rake = typeof rake === 'undefined' ? true : rake; - // convert to array - string = this._toArray(string); + // convert to array + string = this._toArray(string); - // if it's designated, rake that bad boy for HTML tags and stuff - if(rake) { - string = this._rake(string); - string = string[0]; - } + // if it's designated, rake that bad boy for HTML tags and stuff + if (rake) { + string = this._rake(string); + string = string[0]; + } - // do the work that matters - this.tTO = setTimeout(function() { + // do the work that matters + this.tTO = setTimeout(function() { - // randomize the timeout each time, if that's your thing - this._setPace(this); + // randomize the timeout each time, if that's your thing + this._setPace(this); - // "_print" the character - // if an opening HTML tag is found and we're not already pringing inside a tag - if(this.s.html && (string[0].indexOf('<') !== -1 && string[0].indexOf('= 0; i--) { - if(string[i].indexOf('= 0; i--) { + if (string[i].indexOf(''); + this._executeQueue(); + }, - pause : function(time) { - time = time === undefined ? this.s.breakDelay : time; - this._to(function() { + mergeSet: function(s) { + this.s = $.extend({}, this.s, s); this._executeQueue(); - }.bind(this), time); - }, - - break : function() { - this.insert('
'); - this._executeQueue(); - }, - - mergeSet : function(s) { - this.s = $.extend({}, this.s, s); - this._executeQueue(); - }, - - _print : function(chr) { - if(this.inTag) { - $(this.tag, this.el).last().append(chr); - if(this.tagCount < this.tagDuration) { - this.tagCount++; + }, + + _print: function(chr) { + if (this.inTag) { + $(this.tag, this.el).last().append(chr); + if (this.tagCount < this.tagDuration) { + this.tagCount++; + } else { + this.inTag = false; + } } else { - this.inTag = false; + this.insert(chr); } - } else { - this.insert(chr); - } - }, + }, /* If show cursor is enabled, move array starting point for the for loop back one, so that the loop will not find the closing tag and delete the cursor. */ - delete : function(chars) { + delete: function(chars) { - this.dTO = setTimeout(function() { + this.dTO = setTimeout(function() { - this._setPace(); + this._setPace(); - var a = this.tel.html().split(""); + var a = this.tel.html().split(""); - var amount = chars === undefined || chars === null ? a.length-1 : chars + 1; + var amount = chars === undefined || chars === null ? a.length - 1 : chars + 1; - // cut the array by a character - for (var n = a.length-1; n > -1; n--) { + // cut the array by a character + for (var n = a.length - 1; n > -1; n--) { - if((a[n] === '>' || a[n] === ';') && this.s.html) { - for(var o = n; o > -1; o--) { + if ((a[n] === '>' || a[n] === ';') && this.s.html) { + for (var o = n; o > -1; o--) { - if(a.slice(o-3, o+1).join('') === '
') { - a.splice(o-3, 4); - break; - } + if (a.slice(o - 3, o + 1).join('') === '
') { + a.splice(o - 3, 4); + break; + } - if(a[o] === '&') { - a.splice(o, n-o+1); - break; - } + if (a[o] === '&') { + a.splice(o, n - o + 1); + break; + } - if(a[o] === '<') { - if(a[o-1] !== '>') { - if(a[o-1] === ';') { - for(var p = o-1; p > -1; p--) { - if(a[p] === '&') { - a.splice(p, o-p); - break; + if (a[o] === '<') { + if (a[o - 1] !== '>') { + if (a[o - 1] === ';') { + for (var p = o - 1; p > -1; p--) { + if (a[p] === '&') { + a.splice(p, o - p); + break; + } } } - } - a.splice(o-1, 1); - break; + a.splice(o - 1, 1); + break; + } } } + break; + } else { + a.pop(); + break; } - break; + } - else { - a.pop(); - break; + // if we've found an empty set of HTML tags... + if (this.tel.html().indexOf('> -1) { + for (var i = this.tel.html().indexOf('>= 0; i--) { + if (a[i] === '<') { + a.splice(i, a.length - i); + break; + } + } } - } + this.tel.html(a.join('')); - // if we've found an empty set of HTML tags... - if(this.tel.html().indexOf('> -1) { - for (var i = this.tel.html().indexOf('>= 0; i--) { - if(a[i] === '<') { - a.splice(i, a.length-i); - break; - } + // characters still in the string. + if (amount > (chars === undefined ? 0 : 2)) { + this.delete(chars === undefined ? undefined : chars - 1); + } else { + this._executeQueue(); } - } - - this.tel.html(a.join('')); + }.bind(this), this.deletePace); + }, - // characters still in the string. - if (amount > (chars === undefined ? 0 : 2)) { - this.delete(chars === undefined ? undefined : chars-1); - } else { - this._executeQueue(); + _isVisible: function() { + var win = $(window); + + var viewport = { + top: win.scrollTop(), + left: win.scrollLeft() + }; + viewport.right = viewport.left + win.width(); + viewport.bottom = viewport.top + win.height(); + + var height = this.el.outerHeight(); + var width = this.el.outerWidth(); + + if (!width || !height) { + return false; } - }.bind(this), this.deletePace); - }, - - _isVisible : function() { - var win = $(window); - - var viewport = { - top : win.scrollTop(), - left : win.scrollLeft() - }; - viewport.right = viewport.left + win.width(); - viewport.bottom = viewport.top + win.height(); - - var height = this.el.outerHeight(); - var width = this.el.outerWidth(); - - if(!width || !height){ + + var bounds = this.el.offset(); + bounds.right = bounds.left + width; + bounds.bottom = bounds.top + height; + + var visible = (!(viewport.right < bounds.left || viewport.left > bounds.right || viewport.bottom < bounds.top || viewport.top > bounds.bottom)); + + if (!visible) { return false; - } - - var bounds = this.el.offset(); - bounds.right = bounds.left + width; - bounds.bottom = bounds.top + height; - - var visible = (!(viewport.right < bounds.left || viewport.left > bounds.right || viewport.bottom < bounds.top || viewport.top > bounds.bottom)); - - if(!visible){ - return false; - } - - var deltas = { - top : Math.min( 1, ( bounds.bottom - viewport.top ) / height), - bottom : Math.min(1, ( viewport.bottom - bounds.top ) / height), - left : Math.min(1, ( bounds.right - viewport.left ) / width), - right : Math.min(1, ( viewport.right - bounds.left ) / width) - }; - - return (deltas.left * deltas.right) >= 1 && (deltas.top * deltas.bottom) >= 1; - }, + } - /* - Advance the function queue to execute the next function after the previous one has finished. - */ - _executeQueue : function() { - if(this.queueIndex < this.queue.length) { - var thisFunc = this.queue[this.queueIndex]; - this.queueIndex++; - - // delay execution if looping back to the beginning of the queue. - if(this.isLooping && this.queueIndex === 1) { - this._to(function() { + var deltas = { + top: Math.min(1, (bounds.bottom - viewport.top) / height), + bottom: Math.min(1, (viewport.bottom - bounds.top) / height), + left: Math.min(1, (bounds.right - viewport.left) / width), + right: Math.min(1, (viewport.right - bounds.left) / width) + }; + + return (deltas.left * deltas.right) >= 1 && (deltas.top * deltas.bottom) >= 1; + }, + + /* + Advance the function queue to execute the next function after the previous one has finished. + */ + _executeQueue: function() { + if (this.queueIndex < this.queue.length) { + var thisFunc = this.queue[this.queueIndex]; + this.queueIndex++; + + // delay execution if looping back to the beginning of the queue. + if (this.isLooping && this.queueIndex === 1) { + this._to(function() { + thisFunc[0].bind(this)(thisFunc[1]); + }.bind(this), this.s.loopDelay / 2); + } else { thisFunc[0].bind(this)(thisFunc[1]); - }.bind(this), this.s.loopDelay/2); + } } else { - thisFunc[0].bind(this)(thisFunc[1]); + if (this.s.loop) { + this.queueIndex = 0; + this.isLooping = true; + this._to(function() { + this.delete(); + }.bind(this), this.s.loopDelay / 2); + } else { + this.s.callback(); + } } - } else { - if(this.s.loop) { - this.queueIndex = 0; - this.isLooping = true; - this._to(function() { - this.delete(); - }.bind(this), this.s.loopDelay/2); - } else { - this.s.callback(); + }, + + _to: function(fn, time) { + setTimeout(function() { + fn(); + }.bind(this), time); + }, + + _elCheck: function() { + if (!this.s.startDelete && this.el.html().length > 0) { + this.s.strings = this.el.html().trim(); + } else if (this.s.startDelete) { + this.stringsToDelete = this.el.html(); } - } - }, - - _to : function(fn, time) { - setTimeout(function() { - fn(); - }.bind(this), time); - }, - - _elCheck : function() { - if(!this.s.startDelete && this.el.html().length > 0) { - this.s.strings = this.el.html().trim(); - } else if(this.s.startDelete) { - this.stringsToDelete = this.el.html(); - } - }, - - _toArray : function(str) { - return str.constructor === Array ? str.slice(0) : str.split('
'); - }, - - _cursor : function() { - if(this.s.cursor) { - this.el.append('|'); - var s = this.s.cursorSpeed; - var t = this; - (function loop() { - t.el.find('.ti-cursor').fadeTo(s/2, 0).fadeTo(s/2, 1); - t._to(loop, s); - })(); - } - }, - - _setPace : function() { - var typeSpeed = this.s.speed; - var deleteSpeed = this.s.deleteSpeed !== undefined ? this.s.deleteSpeed : this.s.speed/3; - var typeRange = typeSpeed/2; - var deleteRange = deleteSpeed/2; - - this.typePace = this.s.lifeLike ? this._randomInRange(typeSpeed, typeRange) : typeSpeed; - this.deletePace = this.s.lifeLike ? this._randomInRange(deleteSpeed, deleteRange) : deleteSpeed; - }, - - _randomInRange : function(value, range) { - return Math.abs(Math.random() * ((value+range) - (value-range)) + (value-range)); - }, - - /* - Convert each string in the array to a sub-array. While happening, search the subarrays for HTML tags. - When a complete tag is found, slice the subarray to get the complete tag, insert it at the correct index, - and delete the range of indexes where the indexed tag used to be. - */ - _rake : function(array) { - for(var i = 0; i < array.length; i++) { - array[i] = array[i].split(''); - - if(this.s.html) { - this.tPos = []; - var p = this.tPos; - var tag; - var en = false; - for(var j = 0; j < array[i].length; j++) { - - if(array[i][j] === '<' || array[i][j] === '&') { - p[0] = j; - en = array[i][j] === '&' ? true : false; - } + }, + + _toArray: function(str) { + return str.constructor === Array ? str.slice(0) : str.split('
'); + }, + + _cursor: function() { + if (this.s.cursor) { + this.el.append('|'); + var s = this.s.cursorSpeed; + var t = this; + (function loop() { + t.el.find('.ti-cursor').fadeTo(s / 2, 0).fadeTo(s / 2, 1); + t._to(loop, s); + })(); + } + }, + + _setPace: function() { + var typeSpeed = this.s.speed; + var deleteSpeed = this.s.deleteSpeed !== undefined ? this.s.deleteSpeed : this.s.speed / 3; + var typeRange = typeSpeed / 2; + var deleteRange = deleteSpeed / 2; + + this.typePace = this.s.lifeLike ? this._randomInRange(typeSpeed, typeRange) : typeSpeed; + this.deletePace = this.s.lifeLike ? this._randomInRange(deleteSpeed, deleteRange) : deleteSpeed; + }, + + _randomInRange: function(value, range) { + return Math.abs(Math.random() * ((value + range) - (value - range)) + (value - range)); + }, - if(array[i][j] === '>' || (array[i][j] === ';' && en)) { - p[1] = j; - j = 0; - tag = (array[i].slice(p[0], p[1]+1)).join(''); - array[i].splice(p[0], (p[1]-p[0]+1), tag); - en = false; + /* + Convert each string in the array to a sub-array. While happening, search the subarrays for HTML tags. + When a complete tag is found, slice the subarray to get the complete tag, insert it at the correct index, + and delete the range of indexes where the indexed tag used to be. + */ + _rake: function(array) { + for (var i = 0; i < array.length; i++) { + array[i] = array[i].split(''); + + if (this.s.html) { + this.tPos = []; + var p = this.tPos; + var tag; + var en = false; + for (var j = 0; j < array[i].length; j++) { + + if (array[i][j] === '<' || array[i][j] === '&') { + p[0] = j; + en = array[i][j] === '&' ? true : false; + } + + if (array[i][j] === '>' || (array[i][j] === ';' && en)) { + p[1] = j; + j = 0; + tag = (array[i].slice(p[0], p[1] + 1)).join(''); + array[i].splice(p[0], (p[1] - p[0] + 1), tag); + en = false; + } } } } + + return array; + }, + + /* + Get the start & ending positions of the string inside HTML opening & closing angle brackets, + and then create a DOM element of that string/tag name. + */ + _makeNode: function(char) { + this.tag = $($.parseHTML(char)); + this._print(this.tag); + this.inTag = true; } + }; + + $.fn.tiType = function(str) { + var i = $(this).data('typeit'); + if (i === undefined) return $doc; + i.queue.push([i.type, str]); + return this; + }; - return array; - }, + $.fn.tiDelete = function(num) { + var i = $(this).data('typeit'); + if (i === undefined) return $doc; + i.queue.push([i.delete, num]); + return this; + }; - /* - Get the start & ending positions of the string inside HTML opening & closing angle brackets, - and then create a DOM element of that string/tag name. - */ - _makeNode : function(char) { - this.tag = $($.parseHTML(char)); - this._print(this.tag); - this.inTag = true; - } -}; - -$.fn.tiType = function(str){ - var i = $(this).data('typeit'); - if (i === undefined) return $doc; - i.queue.push([i.type, str]); - return this; -}; - -$.fn.tiDelete = function(num){ - var i = $(this).data('typeit'); - if (i === undefined) return $doc; - i.queue.push([i.delete, num]); - return this; -}; - -$.fn.tiPause = function(time){ - var i = $(this).data('typeit'); - if (i === undefined) return $doc; - i.queue.push([i.pause, time]); - return this; -}; - -$.fn.tiBreak = function(){ - var i = $(this).data('typeit'); - if (i === undefined) return $doc; - i.queue.push([i.break]); - return this; -}; - -$.fn.tiSettings = function(settings) { - var i = $(this).data('typeit'); - if (i === undefined) return $doc; - i.queue.push([i.mergeSet, settings]); - return this; -}; - -}(jQuery)); + $.fn.tiPause = function(time) { + var i = $(this).data('typeit'); + if (i === undefined) return $doc; + i.queue.push([i.pause, time]); + return this; + }; + + $.fn.tiBreak = function() { + var i = $(this).data('typeit'); + if (i === undefined) return $doc; + i.queue.push([i.break]); + return this; + }; + + $.fn.tiSettings = function(settings) { + var i = $(this).data('typeit'); + if (i === undefined) return $doc; + i.queue.push([i.mergeSet, settings]); + return this; + }; + +}(jQuery)); \ No newline at end of file diff --git a/dev/typeit.min.js b/dev/typeit.min.js index cddc6a4a..901a0834 100644 --- a/dev/typeit.min.js +++ b/dev/typeit.min.js @@ -1 +1 @@ -!function(t,e){var s=t(document);t.fn.typeIt=function(e){return this.each(function(){var i=t(this);i.data("typeit",new t.typeIt(i,e))})},t.typeIt=function(i,s){this.d={strings:[],speed:100,deleteSpeed:e,lifeLike:!0,cursor:!0,cursorSpeed:1e3,breakLines:!0,breakDelay:750,startDelay:250,startDelete:!1,loop:!1,loopDelay:750,html:!0,autoStart:!0,callback:function(){}},this.queue=[],this.queueIndex=0,this.hasStarted=!1,this.inTag=!1,this.stringsToDelete="",this.style='style="display:inline;position:relative;font:inherit;color:inherit;"',this.s=t.extend({},this.d,s),this.el=i,this._init()},t.typeIt.prototype={_init:function(){this.el.find(".ti-container, .ti-cursor, .ti-placeholder").remove(),this._elCheck(),this.s.strings=this._toArray(this.s.strings),this.el.html('.'),this.tel=this.el.find("span"),this.insert=function(t){this.tel.append(t)},this.s.startDelete&&(this.tel.html(this.stringsToDelete),this.queue.push([this["delete"]])),this._generateQueue(),this._kickoff()},_kickoff:function(){this._cursor(),this.s.autoStart?this._startQueue():this._isVisible()?(this.hasStarted=!0,this._startQueue()):s.on("scroll",function(){this._isVisible()&&!this.hasStarted&&(this.hasStarted=!0,this._startQueue())}.bind(this))},_generateQueue:function(){for(i=0;i=0;e--)-1!==t[e].indexOf(""),this._executeQueue()},mergeSet:function(e){this.s=t.extend({},this.s,e),this._executeQueue()},_print:function(e){this.inTag?(t(this.tag,this.el).last().append(e),this.tagCount-1;h--){if(">"!==i[h]&&";"!==i[h]||!this.s.html){i.pop();break}for(var n=h;n>-1;n--){if("
"===i.slice(n-3,n+1).join("")){i.splice(n-3,4);break}if("&"===i[n]){i.splice(n,h-n+1);break}if("<"===i[n]&&">"!==i[n-1]){if(";"===i[n-1])for(var r=n-1;r>-1;r--)if("&"===i[r]){i.splice(r,n-r);break}i.splice(n-1,1);break}}break}if(this.tel.html().indexOf(">-1)for(var u=this.tel.html().indexOf(">=0;u--)if("<"===i[u]){i.splice(u,i.length-u);break}this.tel.html(i.join("")),s>(t===e?0:2)?this["delete"](t===e?e:t-1):this._executeQueue()}.bind(this),this.deletePace)},_isVisible:function(){var e=t(window),i={top:e.scrollTop(),left:e.scrollLeft()};i.right=i.left+e.width(),i.bottom=i.top+e.height();var s=this.el.outerHeight(),h=this.el.outerWidth();if(!h||!s)return!1;var n=this.el.offset();n.right=n.left+h,n.bottom=n.top+s;var r=!(i.rightn.right||i.bottomn.bottom);if(!r)return!1;var u={top:Math.min(1,(n.bottom-i.top)/s),bottom:Math.min(1,(i.bottom-n.top)/s),left:Math.min(1,(n.right-i.left)/h),right:Math.min(1,(i.right-n.left)/h)};return u.left*u.right>=1&&u.top*u.bottom>=1},_executeQueue:function(){if(this.queueIndex0?this.s.strings=this.el.html().trim():this.s.startDelete&&(this.stringsToDelete=this.el.html())},_toArray:function(t){return t.constructor===Array?t.slice(0):t.split("
")},_cursor:function(){if(this.s.cursor){this.el.append("|');var t=this.s.cursorSpeed,e=this;!function i(){e.el.find(".ti-cursor").fadeTo(t/2,0).fadeTo(t/2,1),e._to(i,t)}()}},_setPace:function(){var t=this.s.speed,i=this.s.deleteSpeed!==e?this.s.deleteSpeed:this.s.speed/3,s=t/2,h=i/2;this.typePace=this.s.lifeLike?this._randomInRange(t,s):t,this.deletePace=this.s.lifeLike?this._randomInRange(i,h):i},_randomInRange:function(t,e){return Math.abs(Math.random()*(t+e-(t-e))+(t-e))},_rake:function(t){for(var e=0;e"===t[e][n]||";"===t[e][n]&&h)&&(s[1]=n,n=0,i=t[e].slice(s[0],s[1]+1).join(""),t[e].splice(s[0],s[1]-s[0]+1,i),h=!1)}return t},_makeNode:function(e){this.tag=t(t.parseHTML(e)),this._print(this.tag),this.inTag=!0}},t.fn.tiType=function(i){var h=t(this).data("typeit");return h===e?s:(h.queue.push([h.type,i]),this)},t.fn.tiDelete=function(i){var h=t(this).data("typeit");return h===e?s:(h.queue.push([h["delete"],i]),this)},t.fn.tiPause=function(i){var h=t(this).data("typeit");return h===e?s:(h.queue.push([h.pause,i]),this)},t.fn.tiBreak=function(){var i=t(this).data("typeit");return i===e?s:(i.queue.push([i["break"]]),this)},t.fn.tiSettings=function(i){var h=t(this).data("typeit");return h===e?s:(h.queue.push([h.mergeSet,i]),this)}}(jQuery); \ No newline at end of file +!function(t,e){"use strict";var s=t(document);t.fn.typeIt=function(e){return this.each(function(){var i=t(this);i.data("typeit",new t.typeIt(i,e))})},t.typeIt=function(i,s){this.d={strings:[],speed:100,deleteSpeed:e,lifeLike:!0,cursor:!0,cursorSpeed:1e3,breakLines:!0,breakDelay:750,startDelay:250,startDelete:!1,loop:!1,loopDelay:750,html:!0,autoStart:!0,callback:function(){}},this.queue=[],this.queueIndex=0,this.hasStarted=!1,this.inTag=!1,this.stringsToDelete="",this.style='style="display:inline;position:relative;font:inherit;color:inherit;"',this.s=t.extend({},this.d,s),this.el=i,this._init()},t.typeIt.prototype={_init:function(){this.el.find(".ti-container, .ti-cursor, .ti-placeholder").remove(),this._elCheck(),this.s.strings=this._toArray(this.s.strings),this.el.html('.'),this.tel=this.el.find("span"),this.insert=function(t){this.tel.append(t)},this.s.startDelete&&(this.tel.html(this.stringsToDelete),this.queue.push([this["delete"]])),this._generateQueue(),this._kickoff()},_kickoff:function(){this._cursor(),this.s.autoStart?this._startQueue():this._isVisible()?(this.hasStarted=!0,this._startQueue()):s.on("scroll",function(){this._isVisible()&&!this.hasStarted&&(this.hasStarted=!0,this._startQueue())}.bind(this))},_generateQueue:function(){for(i=0;i=0;e--)-1!==t[e].indexOf(""),this._executeQueue()},mergeSet:function(e){this.s=t.extend({},this.s,e),this._executeQueue()},_print:function(e){this.inTag?(t(this.tag,this.el).last().append(e),this.tagCount-1;h--){if(">"!==i[h]&&";"!==i[h]||!this.s.html){i.pop();break}for(var n=h;n>-1;n--){if("
"===i.slice(n-3,n+1).join("")){i.splice(n-3,4);break}if("&"===i[n]){i.splice(n,h-n+1);break}if("<"===i[n]&&">"!==i[n-1]){if(";"===i[n-1])for(var r=n-1;r>-1;r--)if("&"===i[r]){i.splice(r,n-r);break}i.splice(n-1,1);break}}break}if(this.tel.html().indexOf(">-1)for(var u=this.tel.html().indexOf(">=0;u--)if("<"===i[u]){i.splice(u,i.length-u);break}this.tel.html(i.join("")),s>(t===e?0:2)?this["delete"](t===e?e:t-1):this._executeQueue()}.bind(this),this.deletePace)},_isVisible:function(){var e=t(window),i={top:e.scrollTop(),left:e.scrollLeft()};i.right=i.left+e.width(),i.bottom=i.top+e.height();var s=this.el.outerHeight(),h=this.el.outerWidth();if(!h||!s)return!1;var n=this.el.offset();n.right=n.left+h,n.bottom=n.top+s;var r=!(i.rightn.right||i.bottomn.bottom);if(!r)return!1;var u={top:Math.min(1,(n.bottom-i.top)/s),bottom:Math.min(1,(i.bottom-n.top)/s),left:Math.min(1,(n.right-i.left)/h),right:Math.min(1,(i.right-n.left)/h)};return u.left*u.right>=1&&u.top*u.bottom>=1},_executeQueue:function(){if(this.queueIndex0?this.s.strings=this.el.html().trim():this.s.startDelete&&(this.stringsToDelete=this.el.html())},_toArray:function(t){return t.constructor===Array?t.slice(0):t.split("
")},_cursor:function(){if(this.s.cursor){this.el.append("|');var t=this.s.cursorSpeed,e=this;!function i(){e.el.find(".ti-cursor").fadeTo(t/2,0).fadeTo(t/2,1),e._to(i,t)}()}},_setPace:function(){var t=this.s.speed,i=this.s.deleteSpeed!==e?this.s.deleteSpeed:this.s.speed/3,s=t/2,h=i/2;this.typePace=this.s.lifeLike?this._randomInRange(t,s):t,this.deletePace=this.s.lifeLike?this._randomInRange(i,h):i},_randomInRange:function(t,e){return Math.abs(Math.random()*(t+e-(t-e))+(t-e))},_rake:function(t){for(var e=0;e"===t[e][n]||";"===t[e][n]&&h)&&(s[1]=n,n=0,i=t[e].slice(s[0],s[1]+1).join(""),t[e].splice(s[0],s[1]-s[0]+1,i),h=!1)}return t},_makeNode:function(e){this.tag=t(t.parseHTML(e)),this._print(this.tag),this.inTag=!0}},t.fn.tiType=function(i){var h=t(this).data("typeit");return h===e?s:(h.queue.push([h.type,i]),this)},t.fn.tiDelete=function(i){var h=t(this).data("typeit");return h===e?s:(h.queue.push([h["delete"],i]),this)},t.fn.tiPause=function(i){var h=t(this).data("typeit");return h===e?s:(h.queue.push([h.pause,i]),this)},t.fn.tiBreak=function(){var i=t(this).data("typeit");return i===e?s:(i.queue.push([i["break"]]),this)},t.fn.tiSettings=function(i){var h=t(this).data("typeit");return h===e?s:(h.queue.push([h.mergeSet,i]),this)}}(jQuery); \ No newline at end of file diff --git a/dist/typeit.js b/dist/typeit.js index 2e59c263..82d15649 100644 --- a/dist/typeit.js +++ b/dist/typeit.js @@ -1,17 +1,19 @@ /** * jQuery TypeIt * @author Alex MacArthur (http://macarthur.me) - * @version 4.2.1 + * @version 4.2.2 * @copyright 2016 Alex MacArthur * @description Types out a given string or strings. */ - (function($, undefined){ +(function($, undefined) { + + 'use strict'; var $doc = $(document); - $.fn.typeIt = function(opt){ - return this.each(function(){ + $.fn.typeIt = function(opt) { + return this.each(function() { var $t = $(this); $t.data('typeit', new $.typeIt($t, opt)); }); @@ -32,8 +34,8 @@ loop: false, loopDelay: 750, html: true, - autoStart: true, - callback: function(){} + autoStart: true, + callback: function() {} }; this.queue = []; @@ -43,424 +45,422 @@ this.stringsToDelete = ''; this.style = 'style="display:inline;position:relative;font:inherit;color:inherit;"'; this.s = $.extend({}, this.d, opt); - this.el = el; + this.el = el; this._init(); }; - $.typeIt.prototype = { - - _init : function() { - this.el.find('.ti-container, .ti-cursor, .ti-placeholder').remove(); - this._elCheck(); - this.s.strings = this._toArray(this.s.strings); - this.el.html('.'); - this.tel = this.el.find('span'); - - this.insert = function(c) { - this.tel.append(c); - }; - - if(this.s.startDelete) { - this.tel.html(this.stringsToDelete); - this.queue.push([this.delete]); - } + $.typeIt.prototype = { + + _init: function() { + this.el.find('.ti-container, .ti-cursor, .ti-placeholder').remove(); + this._elCheck(); + this.s.strings = this._toArray(this.s.strings); + this.el.html('.'); + this.tel = this.el.find('span'); + + this.insert = function(c) { + this.tel.append(c); + }; + + if (this.s.startDelete) { + this.tel.html(this.stringsToDelete); + this.queue.push([this.delete]); + } - this._generateQueue(); - this._kickoff(); - }, - - _kickoff : function() { - this._cursor(); - - if(this.s.autoStart) { - this._startQueue(); - } else { - if(this._isVisible()) { - this.hasStarted = true; + this._generateQueue(); + this._kickoff(); + }, + + _kickoff: function() { + this._cursor(); + + if (this.s.autoStart) { this._startQueue(); } else { - $doc.on('scroll', function() { - if(this._isVisible() && !this.hasStarted) { - this.hasStarted = true; - this._startQueue(); - } - }.bind(this)); + if (this._isVisible()) { + this.hasStarted = true; + this._startQueue(); + } else { + $doc.on('scroll', function() { + if (this._isVisible() && !this.hasStarted) { + this.hasStarted = true; + this._startQueue(); + } + }.bind(this)); + } } - } - }, - - _generateQueue : function() { - for(i = 0; i < this.s.strings.length; i++) { - - this.queue.push([this.type, this.s.strings[i]]); - - if(i < (this.s.strings.length - 1)) { - var curPos = this.queue.length; - this.queue.push([this.s.breakLines ? this.break : this.delete]); - - if(this.s.breakLines) { - this.queue.splice(curPos, 0, [this.pause, this.s.breakDelay/2]); - this.queue.splice(curPos + 2, 0, [this.pause, this.s.breakDelay/2]); + }, + + _generateQueue: function() { + for (i = 0; i < this.s.strings.length; i++) { + + this.queue.push([this.type, this.s.strings[i]]); + + if (i < (this.s.strings.length - 1)) { + var curPos = this.queue.length; + this.queue.push([this.s.breakLines ? this.break : this.delete]); + + if (this.s.breakLines) { + this.queue.splice(curPos, 0, [this.pause, this.s.breakDelay / 2]); + this.queue.splice(curPos + 2, 0, [this.pause, this.s.breakDelay / 2]); + } } } - } - }, + }, - _startQueue : function() { - this._to(function() { - this._executeQueue(); - }.bind(this), this.s.startDelay); - }, + _startQueue: function() { + this._to(function() { + this._executeQueue(); + }.bind(this), this.s.startDelay); + }, - /* - Pass in a string, and loop over that string until empty. Then return true. - */ - type : function(string, rake){ + /* + Pass in a string, and loop over that string until empty. Then return true. + */ + type: function(string, rake) { - // set default 'rake' value - rake = typeof rake === 'undefined' ? true : rake; + // set default 'rake' value + rake = typeof rake === 'undefined' ? true : rake; - // convert to array - string = this._toArray(string); + // convert to array + string = this._toArray(string); - // if it's designated, rake that bad boy for HTML tags and stuff - if(rake) { - string = this._rake(string); - string = string[0]; - } + // if it's designated, rake that bad boy for HTML tags and stuff + if (rake) { + string = this._rake(string); + string = string[0]; + } - // do the work that matters - this.tTO = setTimeout(function() { + // do the work that matters + this.tTO = setTimeout(function() { - // randomize the timeout each time, if that's your thing - this._setPace(this); + // randomize the timeout each time, if that's your thing + this._setPace(this); - // "_print" the character - // if an opening HTML tag is found and we're not already pringing inside a tag - if(this.s.html && (string[0].indexOf('<') !== -1 && string[0].indexOf('= 0; i--) { - if(string[i].indexOf('= 0; i--) { + if (string[i].indexOf(''); + this._executeQueue(); + }, - pause : function(time) { - time = time === undefined ? this.s.breakDelay : time; - this._to(function() { + mergeSet: function(s) { + this.s = $.extend({}, this.s, s); this._executeQueue(); - }.bind(this), time); - }, - - break : function() { - this.insert('
'); - this._executeQueue(); - }, - - mergeSet : function(s) { - this.s = $.extend({}, this.s, s); - this._executeQueue(); - }, - - _print : function(chr) { - if(this.inTag) { - $(this.tag, this.el).last().append(chr); - if(this.tagCount < this.tagDuration) { - this.tagCount++; + }, + + _print: function(chr) { + if (this.inTag) { + $(this.tag, this.el).last().append(chr); + if (this.tagCount < this.tagDuration) { + this.tagCount++; + } else { + this.inTag = false; + } } else { - this.inTag = false; + this.insert(chr); } - } else { - this.insert(chr); - } - }, + }, /* If show cursor is enabled, move array starting point for the for loop back one, so that the loop will not find the closing tag and delete the cursor. */ - delete : function(chars) { + delete: function(chars) { - this.dTO = setTimeout(function() { + this.dTO = setTimeout(function() { - this._setPace(); + this._setPace(); - var a = this.tel.html().split(""); + var a = this.tel.html().split(""); - var amount = chars === undefined || chars === null ? a.length-1 : chars + 1; + var amount = chars === undefined || chars === null ? a.length - 1 : chars + 1; - // cut the array by a character - for (var n = a.length-1; n > -1; n--) { + // cut the array by a character + for (var n = a.length - 1; n > -1; n--) { - if((a[n] === '>' || a[n] === ';') && this.s.html) { - for(var o = n; o > -1; o--) { + if ((a[n] === '>' || a[n] === ';') && this.s.html) { + for (var o = n; o > -1; o--) { - if(a.slice(o-3, o+1).join('') === '
') { - a.splice(o-3, 4); - break; - } + if (a.slice(o - 3, o + 1).join('') === '
') { + a.splice(o - 3, 4); + break; + } - if(a[o] === '&') { - a.splice(o, n-o+1); - break; - } + if (a[o] === '&') { + a.splice(o, n - o + 1); + break; + } - if(a[o] === '<') { - if(a[o-1] !== '>') { - if(a[o-1] === ';') { - for(var p = o-1; p > -1; p--) { - if(a[p] === '&') { - a.splice(p, o-p); - break; + if (a[o] === '<') { + if (a[o - 1] !== '>') { + if (a[o - 1] === ';') { + for (var p = o - 1; p > -1; p--) { + if (a[p] === '&') { + a.splice(p, o - p); + break; + } } } - } - a.splice(o-1, 1); - break; + a.splice(o - 1, 1); + break; + } } } + break; + } else { + a.pop(); + break; } - break; + } - else { - a.pop(); - break; + // if we've found an empty set of HTML tags... + if (this.tel.html().indexOf('> -1) { + for (var i = this.tel.html().indexOf('>= 0; i--) { + if (a[i] === '<') { + a.splice(i, a.length - i); + break; + } + } } - } + this.tel.html(a.join('')); - // if we've found an empty set of HTML tags... - if(this.tel.html().indexOf('> -1) { - for (var i = this.tel.html().indexOf('>= 0; i--) { - if(a[i] === '<') { - a.splice(i, a.length-i); - break; - } + // characters still in the string. + if (amount > (chars === undefined ? 0 : 2)) { + this.delete(chars === undefined ? undefined : chars - 1); + } else { + this._executeQueue(); } - } - - this.tel.html(a.join('')); + }.bind(this), this.deletePace); + }, - // characters still in the string. - if (amount > (chars === undefined ? 0 : 2)) { - this.delete(chars === undefined ? undefined : chars-1); - } else { - this._executeQueue(); + _isVisible: function() { + var win = $(window); + + var viewport = { + top: win.scrollTop(), + left: win.scrollLeft() + }; + viewport.right = viewport.left + win.width(); + viewport.bottom = viewport.top + win.height(); + + var height = this.el.outerHeight(); + var width = this.el.outerWidth(); + + if (!width || !height) { + return false; } - }.bind(this), this.deletePace); - }, - - _isVisible : function() { - var win = $(window); - - var viewport = { - top : win.scrollTop(), - left : win.scrollLeft() - }; - viewport.right = viewport.left + win.width(); - viewport.bottom = viewport.top + win.height(); - - var height = this.el.outerHeight(); - var width = this.el.outerWidth(); - - if(!width || !height){ + + var bounds = this.el.offset(); + bounds.right = bounds.left + width; + bounds.bottom = bounds.top + height; + + var visible = (!(viewport.right < bounds.left || viewport.left > bounds.right || viewport.bottom < bounds.top || viewport.top > bounds.bottom)); + + if (!visible) { return false; - } - - var bounds = this.el.offset(); - bounds.right = bounds.left + width; - bounds.bottom = bounds.top + height; - - var visible = (!(viewport.right < bounds.left || viewport.left > bounds.right || viewport.bottom < bounds.top || viewport.top > bounds.bottom)); - - if(!visible){ - return false; - } - - var deltas = { - top : Math.min( 1, ( bounds.bottom - viewport.top ) / height), - bottom : Math.min(1, ( viewport.bottom - bounds.top ) / height), - left : Math.min(1, ( bounds.right - viewport.left ) / width), - right : Math.min(1, ( viewport.right - bounds.left ) / width) - }; - - return (deltas.left * deltas.right) >= 1 && (deltas.top * deltas.bottom) >= 1; - }, + } - /* - Advance the function queue to execute the next function after the previous one has finished. - */ - _executeQueue : function() { - if(this.queueIndex < this.queue.length) { - var thisFunc = this.queue[this.queueIndex]; - this.queueIndex++; - - // delay execution if looping back to the beginning of the queue. - if(this.isLooping && this.queueIndex === 1) { - this._to(function() { + var deltas = { + top: Math.min(1, (bounds.bottom - viewport.top) / height), + bottom: Math.min(1, (viewport.bottom - bounds.top) / height), + left: Math.min(1, (bounds.right - viewport.left) / width), + right: Math.min(1, (viewport.right - bounds.left) / width) + }; + + return (deltas.left * deltas.right) >= 1 && (deltas.top * deltas.bottom) >= 1; + }, + + /* + Advance the function queue to execute the next function after the previous one has finished. + */ + _executeQueue: function() { + if (this.queueIndex < this.queue.length) { + var thisFunc = this.queue[this.queueIndex]; + this.queueIndex++; + + // delay execution if looping back to the beginning of the queue. + if (this.isLooping && this.queueIndex === 1) { + this._to(function() { + thisFunc[0].bind(this)(thisFunc[1]); + }.bind(this), this.s.loopDelay / 2); + } else { thisFunc[0].bind(this)(thisFunc[1]); - }.bind(this), this.s.loopDelay/2); + } } else { - thisFunc[0].bind(this)(thisFunc[1]); + if (this.s.loop) { + this.queueIndex = 0; + this.isLooping = true; + this._to(function() { + this.delete(); + }.bind(this), this.s.loopDelay / 2); + } else { + this.s.callback(); + } } - } else { - if(this.s.loop) { - this.queueIndex = 0; - this.isLooping = true; - this._to(function() { - this.delete(); - }.bind(this), this.s.loopDelay/2); - } else { - this.s.callback(); + }, + + _to: function(fn, time) { + setTimeout(function() { + fn(); + }.bind(this), time); + }, + + _elCheck: function() { + if (!this.s.startDelete && this.el.html().length > 0) { + this.s.strings = this.el.html().trim(); + } else if (this.s.startDelete) { + this.stringsToDelete = this.el.html(); } - } - }, - - _to : function(fn, time) { - setTimeout(function() { - fn(); - }.bind(this), time); - }, - - _elCheck : function() { - if(!this.s.startDelete && this.el.html().length > 0) { - this.s.strings = this.el.html().trim(); - } else if(this.s.startDelete) { - this.stringsToDelete = this.el.html(); - } - }, - - _toArray : function(str) { - return str.constructor === Array ? str.slice(0) : str.split('
'); - }, - - _cursor : function() { - if(this.s.cursor) { - this.el.append('|'); - var s = this.s.cursorSpeed; - var t = this; - (function loop() { - t.el.find('.ti-cursor').fadeTo(s/2, 0).fadeTo(s/2, 1); - t._to(loop, s); - })(); - } - }, - - _setPace : function() { - var typeSpeed = this.s.speed; - var deleteSpeed = this.s.deleteSpeed !== undefined ? this.s.deleteSpeed : this.s.speed/3; - var typeRange = typeSpeed/2; - var deleteRange = deleteSpeed/2; - - this.typePace = this.s.lifeLike ? this._randomInRange(typeSpeed, typeRange) : typeSpeed; - this.deletePace = this.s.lifeLike ? this._randomInRange(deleteSpeed, deleteRange) : deleteSpeed; - }, - - _randomInRange : function(value, range) { - return Math.abs(Math.random() * ((value+range) - (value-range)) + (value-range)); - }, - - /* - Convert each string in the array to a sub-array. While happening, search the subarrays for HTML tags. - When a complete tag is found, slice the subarray to get the complete tag, insert it at the correct index, - and delete the range of indexes where the indexed tag used to be. - */ - _rake : function(array) { - for(var i = 0; i < array.length; i++) { - array[i] = array[i].split(''); - - if(this.s.html) { - this.tPos = []; - var p = this.tPos; - var tag; - var en = false; - for(var j = 0; j < array[i].length; j++) { - - if(array[i][j] === '<' || array[i][j] === '&') { - p[0] = j; - en = array[i][j] === '&' ? true : false; - } + }, + + _toArray: function(str) { + return str.constructor === Array ? str.slice(0) : str.split('
'); + }, + + _cursor: function() { + if (this.s.cursor) { + this.el.append('|'); + var s = this.s.cursorSpeed; + var t = this; + (function loop() { + t.el.find('.ti-cursor').fadeTo(s / 2, 0).fadeTo(s / 2, 1); + t._to(loop, s); + })(); + } + }, + + _setPace: function() { + var typeSpeed = this.s.speed; + var deleteSpeed = this.s.deleteSpeed !== undefined ? this.s.deleteSpeed : this.s.speed / 3; + var typeRange = typeSpeed / 2; + var deleteRange = deleteSpeed / 2; + + this.typePace = this.s.lifeLike ? this._randomInRange(typeSpeed, typeRange) : typeSpeed; + this.deletePace = this.s.lifeLike ? this._randomInRange(deleteSpeed, deleteRange) : deleteSpeed; + }, + + _randomInRange: function(value, range) { + return Math.abs(Math.random() * ((value + range) - (value - range)) + (value - range)); + }, - if(array[i][j] === '>' || (array[i][j] === ';' && en)) { - p[1] = j; - j = 0; - tag = (array[i].slice(p[0], p[1]+1)).join(''); - array[i].splice(p[0], (p[1]-p[0]+1), tag); - en = false; + /* + Convert each string in the array to a sub-array. While happening, search the subarrays for HTML tags. + When a complete tag is found, slice the subarray to get the complete tag, insert it at the correct index, + and delete the range of indexes where the indexed tag used to be. + */ + _rake: function(array) { + for (var i = 0; i < array.length; i++) { + array[i] = array[i].split(''); + + if (this.s.html) { + this.tPos = []; + var p = this.tPos; + var tag; + var en = false; + for (var j = 0; j < array[i].length; j++) { + + if (array[i][j] === '<' || array[i][j] === '&') { + p[0] = j; + en = array[i][j] === '&' ? true : false; + } + + if (array[i][j] === '>' || (array[i][j] === ';' && en)) { + p[1] = j; + j = 0; + tag = (array[i].slice(p[0], p[1] + 1)).join(''); + array[i].splice(p[0], (p[1] - p[0] + 1), tag); + en = false; + } } } } + + return array; + }, + + /* + Get the start & ending positions of the string inside HTML opening & closing angle brackets, + and then create a DOM element of that string/tag name. + */ + _makeNode: function(char) { + this.tag = $($.parseHTML(char)); + this._print(this.tag); + this.inTag = true; } + }; + + $.fn.tiType = function(str) { + var i = $(this).data('typeit'); + if (i === undefined) return $doc; + i.queue.push([i.type, str]); + return this; + }; - return array; - }, + $.fn.tiDelete = function(num) { + var i = $(this).data('typeit'); + if (i === undefined) return $doc; + i.queue.push([i.delete, num]); + return this; + }; - /* - Get the start & ending positions of the string inside HTML opening & closing angle brackets, - and then create a DOM element of that string/tag name. - */ - _makeNode : function(char) { - this.tag = $($.parseHTML(char)); - this._print(this.tag); - this.inTag = true; - } -}; - -$.fn.tiType = function(str){ - var i = $(this).data('typeit'); - if (i === undefined) return $doc; - i.queue.push([i.type, str]); - return this; -}; - -$.fn.tiDelete = function(num){ - var i = $(this).data('typeit'); - if (i === undefined) return $doc; - i.queue.push([i.delete, num]); - return this; -}; - -$.fn.tiPause = function(time){ - var i = $(this).data('typeit'); - if (i === undefined) return $doc; - i.queue.push([i.pause, time]); - return this; -}; - -$.fn.tiBreak = function(){ - var i = $(this).data('typeit'); - if (i === undefined) return $doc; - i.queue.push([i.break]); - return this; -}; - -$.fn.tiSettings = function(settings) { - var i = $(this).data('typeit'); - if (i === undefined) return $doc; - i.queue.push([i.mergeSet, settings]); - return this; -}; - -}(jQuery)); + $.fn.tiPause = function(time) { + var i = $(this).data('typeit'); + if (i === undefined) return $doc; + i.queue.push([i.pause, time]); + return this; + }; + + $.fn.tiBreak = function() { + var i = $(this).data('typeit'); + if (i === undefined) return $doc; + i.queue.push([i.break]); + return this; + }; + + $.fn.tiSettings = function(settings) { + var i = $(this).data('typeit'); + if (i === undefined) return $doc; + i.queue.push([i.mergeSet, settings]); + return this; + }; + +}(jQuery)); \ No newline at end of file diff --git a/dist/typeit.min.js b/dist/typeit.min.js index cddc6a4a..901a0834 100644 --- a/dist/typeit.min.js +++ b/dist/typeit.min.js @@ -1 +1 @@ -!function(t,e){var s=t(document);t.fn.typeIt=function(e){return this.each(function(){var i=t(this);i.data("typeit",new t.typeIt(i,e))})},t.typeIt=function(i,s){this.d={strings:[],speed:100,deleteSpeed:e,lifeLike:!0,cursor:!0,cursorSpeed:1e3,breakLines:!0,breakDelay:750,startDelay:250,startDelete:!1,loop:!1,loopDelay:750,html:!0,autoStart:!0,callback:function(){}},this.queue=[],this.queueIndex=0,this.hasStarted=!1,this.inTag=!1,this.stringsToDelete="",this.style='style="display:inline;position:relative;font:inherit;color:inherit;"',this.s=t.extend({},this.d,s),this.el=i,this._init()},t.typeIt.prototype={_init:function(){this.el.find(".ti-container, .ti-cursor, .ti-placeholder").remove(),this._elCheck(),this.s.strings=this._toArray(this.s.strings),this.el.html('.'),this.tel=this.el.find("span"),this.insert=function(t){this.tel.append(t)},this.s.startDelete&&(this.tel.html(this.stringsToDelete),this.queue.push([this["delete"]])),this._generateQueue(),this._kickoff()},_kickoff:function(){this._cursor(),this.s.autoStart?this._startQueue():this._isVisible()?(this.hasStarted=!0,this._startQueue()):s.on("scroll",function(){this._isVisible()&&!this.hasStarted&&(this.hasStarted=!0,this._startQueue())}.bind(this))},_generateQueue:function(){for(i=0;i=0;e--)-1!==t[e].indexOf(""),this._executeQueue()},mergeSet:function(e){this.s=t.extend({},this.s,e),this._executeQueue()},_print:function(e){this.inTag?(t(this.tag,this.el).last().append(e),this.tagCount-1;h--){if(">"!==i[h]&&";"!==i[h]||!this.s.html){i.pop();break}for(var n=h;n>-1;n--){if("
"===i.slice(n-3,n+1).join("")){i.splice(n-3,4);break}if("&"===i[n]){i.splice(n,h-n+1);break}if("<"===i[n]&&">"!==i[n-1]){if(";"===i[n-1])for(var r=n-1;r>-1;r--)if("&"===i[r]){i.splice(r,n-r);break}i.splice(n-1,1);break}}break}if(this.tel.html().indexOf(">-1)for(var u=this.tel.html().indexOf(">=0;u--)if("<"===i[u]){i.splice(u,i.length-u);break}this.tel.html(i.join("")),s>(t===e?0:2)?this["delete"](t===e?e:t-1):this._executeQueue()}.bind(this),this.deletePace)},_isVisible:function(){var e=t(window),i={top:e.scrollTop(),left:e.scrollLeft()};i.right=i.left+e.width(),i.bottom=i.top+e.height();var s=this.el.outerHeight(),h=this.el.outerWidth();if(!h||!s)return!1;var n=this.el.offset();n.right=n.left+h,n.bottom=n.top+s;var r=!(i.rightn.right||i.bottomn.bottom);if(!r)return!1;var u={top:Math.min(1,(n.bottom-i.top)/s),bottom:Math.min(1,(i.bottom-n.top)/s),left:Math.min(1,(n.right-i.left)/h),right:Math.min(1,(i.right-n.left)/h)};return u.left*u.right>=1&&u.top*u.bottom>=1},_executeQueue:function(){if(this.queueIndex0?this.s.strings=this.el.html().trim():this.s.startDelete&&(this.stringsToDelete=this.el.html())},_toArray:function(t){return t.constructor===Array?t.slice(0):t.split("
")},_cursor:function(){if(this.s.cursor){this.el.append("|');var t=this.s.cursorSpeed,e=this;!function i(){e.el.find(".ti-cursor").fadeTo(t/2,0).fadeTo(t/2,1),e._to(i,t)}()}},_setPace:function(){var t=this.s.speed,i=this.s.deleteSpeed!==e?this.s.deleteSpeed:this.s.speed/3,s=t/2,h=i/2;this.typePace=this.s.lifeLike?this._randomInRange(t,s):t,this.deletePace=this.s.lifeLike?this._randomInRange(i,h):i},_randomInRange:function(t,e){return Math.abs(Math.random()*(t+e-(t-e))+(t-e))},_rake:function(t){for(var e=0;e"===t[e][n]||";"===t[e][n]&&h)&&(s[1]=n,n=0,i=t[e].slice(s[0],s[1]+1).join(""),t[e].splice(s[0],s[1]-s[0]+1,i),h=!1)}return t},_makeNode:function(e){this.tag=t(t.parseHTML(e)),this._print(this.tag),this.inTag=!0}},t.fn.tiType=function(i){var h=t(this).data("typeit");return h===e?s:(h.queue.push([h.type,i]),this)},t.fn.tiDelete=function(i){var h=t(this).data("typeit");return h===e?s:(h.queue.push([h["delete"],i]),this)},t.fn.tiPause=function(i){var h=t(this).data("typeit");return h===e?s:(h.queue.push([h.pause,i]),this)},t.fn.tiBreak=function(){var i=t(this).data("typeit");return i===e?s:(i.queue.push([i["break"]]),this)},t.fn.tiSettings=function(i){var h=t(this).data("typeit");return h===e?s:(h.queue.push([h.mergeSet,i]),this)}}(jQuery); \ No newline at end of file +!function(t,e){"use strict";var s=t(document);t.fn.typeIt=function(e){return this.each(function(){var i=t(this);i.data("typeit",new t.typeIt(i,e))})},t.typeIt=function(i,s){this.d={strings:[],speed:100,deleteSpeed:e,lifeLike:!0,cursor:!0,cursorSpeed:1e3,breakLines:!0,breakDelay:750,startDelay:250,startDelete:!1,loop:!1,loopDelay:750,html:!0,autoStart:!0,callback:function(){}},this.queue=[],this.queueIndex=0,this.hasStarted=!1,this.inTag=!1,this.stringsToDelete="",this.style='style="display:inline;position:relative;font:inherit;color:inherit;"',this.s=t.extend({},this.d,s),this.el=i,this._init()},t.typeIt.prototype={_init:function(){this.el.find(".ti-container, .ti-cursor, .ti-placeholder").remove(),this._elCheck(),this.s.strings=this._toArray(this.s.strings),this.el.html('.'),this.tel=this.el.find("span"),this.insert=function(t){this.tel.append(t)},this.s.startDelete&&(this.tel.html(this.stringsToDelete),this.queue.push([this["delete"]])),this._generateQueue(),this._kickoff()},_kickoff:function(){this._cursor(),this.s.autoStart?this._startQueue():this._isVisible()?(this.hasStarted=!0,this._startQueue()):s.on("scroll",function(){this._isVisible()&&!this.hasStarted&&(this.hasStarted=!0,this._startQueue())}.bind(this))},_generateQueue:function(){for(i=0;i=0;e--)-1!==t[e].indexOf(""),this._executeQueue()},mergeSet:function(e){this.s=t.extend({},this.s,e),this._executeQueue()},_print:function(e){this.inTag?(t(this.tag,this.el).last().append(e),this.tagCount-1;h--){if(">"!==i[h]&&";"!==i[h]||!this.s.html){i.pop();break}for(var n=h;n>-1;n--){if("
"===i.slice(n-3,n+1).join("")){i.splice(n-3,4);break}if("&"===i[n]){i.splice(n,h-n+1);break}if("<"===i[n]&&">"!==i[n-1]){if(";"===i[n-1])for(var r=n-1;r>-1;r--)if("&"===i[r]){i.splice(r,n-r);break}i.splice(n-1,1);break}}break}if(this.tel.html().indexOf(">-1)for(var u=this.tel.html().indexOf(">=0;u--)if("<"===i[u]){i.splice(u,i.length-u);break}this.tel.html(i.join("")),s>(t===e?0:2)?this["delete"](t===e?e:t-1):this._executeQueue()}.bind(this),this.deletePace)},_isVisible:function(){var e=t(window),i={top:e.scrollTop(),left:e.scrollLeft()};i.right=i.left+e.width(),i.bottom=i.top+e.height();var s=this.el.outerHeight(),h=this.el.outerWidth();if(!h||!s)return!1;var n=this.el.offset();n.right=n.left+h,n.bottom=n.top+s;var r=!(i.rightn.right||i.bottomn.bottom);if(!r)return!1;var u={top:Math.min(1,(n.bottom-i.top)/s),bottom:Math.min(1,(i.bottom-n.top)/s),left:Math.min(1,(n.right-i.left)/h),right:Math.min(1,(i.right-n.left)/h)};return u.left*u.right>=1&&u.top*u.bottom>=1},_executeQueue:function(){if(this.queueIndex0?this.s.strings=this.el.html().trim():this.s.startDelete&&(this.stringsToDelete=this.el.html())},_toArray:function(t){return t.constructor===Array?t.slice(0):t.split("
")},_cursor:function(){if(this.s.cursor){this.el.append("|');var t=this.s.cursorSpeed,e=this;!function i(){e.el.find(".ti-cursor").fadeTo(t/2,0).fadeTo(t/2,1),e._to(i,t)}()}},_setPace:function(){var t=this.s.speed,i=this.s.deleteSpeed!==e?this.s.deleteSpeed:this.s.speed/3,s=t/2,h=i/2;this.typePace=this.s.lifeLike?this._randomInRange(t,s):t,this.deletePace=this.s.lifeLike?this._randomInRange(i,h):i},_randomInRange:function(t,e){return Math.abs(Math.random()*(t+e-(t-e))+(t-e))},_rake:function(t){for(var e=0;e"===t[e][n]||";"===t[e][n]&&h)&&(s[1]=n,n=0,i=t[e].slice(s[0],s[1]+1).join(""),t[e].splice(s[0],s[1]-s[0]+1,i),h=!1)}return t},_makeNode:function(e){this.tag=t(t.parseHTML(e)),this._print(this.tag),this.inTag=!0}},t.fn.tiType=function(i){var h=t(this).data("typeit");return h===e?s:(h.queue.push([h.type,i]),this)},t.fn.tiDelete=function(i){var h=t(this).data("typeit");return h===e?s:(h.queue.push([h["delete"],i]),this)},t.fn.tiPause=function(i){var h=t(this).data("typeit");return h===e?s:(h.queue.push([h.pause,i]),this)},t.fn.tiBreak=function(){var i=t(this).data("typeit");return i===e?s:(i.queue.push([i["break"]]),this)},t.fn.tiSettings=function(i){var h=t(this).data("typeit");return h===e?s:(h.queue.push([h.mergeSet,i]),this)}}(jQuery); \ No newline at end of file diff --git a/package.json b/package.json index 7802249d..2cebccb0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "typeit", - "version": "4.2.1", + "version": "4.2.2", "license": "GPL-2.0", "author": "Alex MacArthur ", "description": "The most versatile jQuery animated typing plugin on the planet.",