angular-typed
Advanced tools
Comparing version 0.0.2 to 0.0.3
angular.module('angular-typed', []) | ||
.directive('typed', function($log, $timeout, $q) { | ||
.directive('typed', ['$log', '$timeout', '$q', function($log, $timeout, $q) { | ||
@@ -47,6 +47,4 @@ var _scope = { | ||
var endlineWait = attrs.endlineWait || 250; | ||
var removeLast = attrs.removeLast || false; | ||
var endBackspace = attrs.endBackspace || false; | ||
var cursor = angular.element( document.createElement('span') ).addClass('typed-cursor').text( '|' ); | ||
@@ -200,3 +198,3 @@ | ||
// check if last line should be removed | ||
if( endBackspace ) { | ||
if( removeLast ) { | ||
@@ -228,12 +226,5 @@ backspace(text, currPos); | ||
/** | ||
* Run end-line timeout for next line | ||
*/ | ||
$timeout(function() { | ||
currentLine++ | ||
return typeText( strings[currentLine], 0 ) | ||
currentLine++ | ||
return typeText( strings[currentLine], 0 ) | ||
}, endlineWait); | ||
} | ||
@@ -297,2 +288,2 @@ | ||
}) | ||
}]) |
@@ -1,1 +0,1 @@ | ||
angular.module("angular-typed",[]).directive("typed",function($log,$timeout,$q){function _link(scope,elem,attrs){function newLine(first){var line=angular.element(document.createElement("span")).addClass("typed-line");first?elem.prepend(line):elem.append(line),elem=line}function backspace(text,currPos){var delay=Math.round(70*Math.random())+backSpeed;$timeout(function(){if(htmlMode){var curChar=text.substr(currPos).charAt(0);if(">"===curChar||";"===curChar)for(var tag="",endtag=">"===curChar?"<":"&";text.substr(currPos).charAt(0)!==endtag;)tag+=text.substr(currPos).charAt(0),currPos--}if(0==currPos)return currentLine<strings.length-1?(currentLine++,typeText(strings[currentLine],0)):(angular.isFunction(scope.endCallback)&&scope.$apply(scope.endCallback()),loop?startTyping():null);var nextPos=currPos-1,string=text.substr(0,nextPos);htmlMode?elem.html(string):elem.text(string),backspace(text,nextPos)},delay)}function typeText(text,currPos){var delay=Math.round(70*Math.random())+typeSpeed;$timeout(function(){var charPause=0,substr=text.substr(currPos);if("^"===substr.charAt(0)){var skip=1;/^\^\d+/.test(substr)&&(substr=/\d+/.exec(substr)[0],skip+=substr.length,charPause=parseInt(substr)),text=text.substring(0,currPos)+text.substring(currPos+skip)}if(htmlMode){var curChar=text.substr(currPos).charAt(0);if("<"===curChar||"&"===curChar)for(var tag="",endtag="<"===curChar?">":";";text.substr(currPos).charAt(0)!==endtag;)tag+=text.substr(currPos).charAt(0),currPos++}$timeout(function(){if(currPos==text.length)if(currentLine==strings.length-1){if(!endBackspace)return angular.isFunction(scope.endCallback)&&scope.$apply(scope.endCallback()),loop?startTyping():null;backspace(text,currPos)}else removeLine?backspace(text,currPos):$timeout(function(){return currentLine++,typeText(strings[currentLine],0)},endlineWait);else{var nextPos=currPos+1,string=text.substr(0,nextPos);htmlMode?elem.html(string):elem.text(string),typeText(text,nextPos)}},charPause)},delay)}function startTyping(first){$timeout(function(){return first&&angular.isFunction(scope.startCallback)&&(scope.startCallback(),newLine(!0)),currentLine=startLine,typeText(strings[currentLine],0)},startTimeout)}var strings=scope.typeStrings||(elem.text()?[elem.text().trim().replace(/\s+/g," ")]:null);if(!strings)return void $log.info("angular-typed: No strings to type found on element: ",elem[0]);var startLine=attrs.startLine||0,currentLine=startLine,htmlMode="undefined"!=typeof attrs.htmlMode,startTimeout=parseInt(attrs.startTimeout)||0,loop="loop"in attrs&&"false"!=attrs.loop,typeSpeed=parseInt(attrs.typeSpeed)||0,backSpeed=parseInt(attrs.backSpeed)||0,removeLine=attrs.removeLine||!0,endlineWait=attrs.endlineWait||250,endBackspace=attrs.endBackspace||!1,cursor=angular.element(document.createElement("span")).addClass("typed-cursor").text("|");return elem.empty(),elem.append(cursor),startTyping(!0)}var _scope={typeStrings:"=?",startCallback:"&",endCallback:"&"},directive={restrict:"AE",replace:!1,scope:_scope,link:_link};return directive}); | ||
angular.module("angular-typed",[]).directive("typed",["$log","$timeout","$q",function($log,$timeout,$q){function _link(scope,elem,attrs){function newLine(first){var line=angular.element(document.createElement("span")).addClass("typed-line");first?elem.prepend(line):elem.append(line),elem=line}function backspace(text,currPos){var delay=Math.round(70*Math.random())+backSpeed;$timeout(function(){if(htmlMode){var curChar=text.substr(currPos).charAt(0);if(">"===curChar||";"===curChar)for(var tag="",endtag=">"===curChar?"<":"&";text.substr(currPos).charAt(0)!==endtag;)tag+=text.substr(currPos).charAt(0),currPos--}if(0==currPos)return currentLine<strings.length-1?(currentLine++,typeText(strings[currentLine],0)):(angular.isFunction(scope.endCallback)&&scope.$apply(scope.endCallback()),loop?startTyping():null);var nextPos=currPos-1,string=text.substr(0,nextPos);htmlMode?elem.html(string):elem.text(string),backspace(text,nextPos)},delay)}function typeText(text,currPos){var delay=Math.round(70*Math.random())+typeSpeed;$timeout(function(){var charPause=0,substr=text.substr(currPos);if("^"===substr.charAt(0)){var skip=1;/^\^\d+/.test(substr)&&(substr=/\d+/.exec(substr)[0],skip+=substr.length,charPause=parseInt(substr)),text=text.substring(0,currPos)+text.substring(currPos+skip)}if(htmlMode){var curChar=text.substr(currPos).charAt(0);if("<"===curChar||"&"===curChar)for(var tag="",endtag="<"===curChar?">":";";text.substr(currPos).charAt(0)!==endtag;)tag+=text.substr(currPos).charAt(0),currPos++}$timeout(function(){if(currPos==text.length)if(currentLine==strings.length-1){if(!removeLast)return angular.isFunction(scope.endCallback)&&scope.$apply(scope.endCallback()),loop?startTyping():null;backspace(text,currPos)}else{if(!removeLine)return currentLine++,typeText(strings[currentLine],0);backspace(text,currPos)}else{var nextPos=currPos+1,string=text.substr(0,nextPos);htmlMode?elem.html(string):elem.text(string),typeText(text,nextPos)}},charPause)},delay)}function startTyping(first){$timeout(function(){return first&&angular.isFunction(scope.startCallback)&&(scope.startCallback(),newLine(!0)),currentLine=startLine,typeText(strings[currentLine],0)},startTimeout)}var strings=scope.typeStrings||(elem.text()?[elem.text().trim().replace(/\s+/g," ")]:null);if(!strings)return void $log.info("angular-typed: No strings to type found on element: ",elem[0]);var startLine=attrs.startLine||0,currentLine=startLine,htmlMode="undefined"!=typeof attrs.htmlMode,startTimeout=parseInt(attrs.startTimeout)||0,loop="loop"in attrs&&"false"!=attrs.loop,typeSpeed=parseInt(attrs.typeSpeed)||0,backSpeed=parseInt(attrs.backSpeed)||0,removeLine=attrs.removeLine||!0,removeLast=attrs.removeLast||!1,cursor=angular.element(document.createElement("span")).addClass("typed-cursor").text("|");return elem.empty(),elem.append(cursor),startTyping(!0)}var _scope={typeStrings:"=?",startCallback:"&",endCallback:"&"},directive={restrict:"AE",replace:!1,scope:_scope,link:_link};return directive}]); |
@@ -16,2 +16,18 @@ module.exports = function(grunt) { | ||
ngAnnotate: { | ||
options: { | ||
singleQuotes: true, | ||
}, | ||
dist: { | ||
files: { | ||
'dist/<%= pkg.name %>.js': ['dist/<%= pkg.name %>.js'] | ||
} | ||
} | ||
}, | ||
uglify: { | ||
@@ -35,3 +51,3 @@ | ||
files: ['src/*.js'], | ||
tasks: ['concat', 'uglify'] | ||
tasks: ['concat', 'ngAnnotate', 'uglify'] | ||
} | ||
@@ -45,7 +61,8 @@ | ||
grunt.loadNpmTasks('grunt-contrib-uglify'); | ||
grunt.loadNpmTasks('grunt-ng-annotate'); | ||
grunt.loadNpmTasks('grunt-contrib-watch'); | ||
grunt.registerTask('default', ['watch']); | ||
grunt.registerTask('build', ['concat', 'uglify']); | ||
grunt.registerTask('build', ['concat', 'ngAnnotate', 'uglify']); | ||
} |
{ | ||
"name": "angular-typed", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "the angularjs typing tool module, that helps you with typing animation", | ||
@@ -32,3 +32,4 @@ "main": "", | ||
"grunt-contrib-uglify": "^1.0.1", | ||
"grunt-contrib-watch": "^1.0.0" | ||
"grunt-contrib-watch": "^1.0.0", | ||
"grunt-ng-annotate": "^2.0.2" | ||
}, | ||
@@ -35,0 +36,0 @@ "gitHead": "71994a4667483140f3d73d78208cc749152de220", |
# angular-typed | ||
the angularjs typing tool module, that helps you with typing animation | ||
### [DEMO](http://www.codekraft.it/demos/angular-typed/) | ||
### Getting started: | ||
@@ -47,2 +50,16 @@ | ||
### Customizations | ||
You can pass all of this extra attributes in the element that contain the __typed__ directive. | ||
* **type-speed**: The typing animation speed (in millis) // default 0 | ||
* **back-speed**: The backspace animation speed (in millis) // default 0 | ||
* **html-mode**: Enable the html parse mode // default false | ||
* **start-line**: The line to start typing // default 0 | ||
* **start-timeout**: The start timeout delay // default 0 | ||
* **remove-line**: Delete each line after is been typed // default true | ||
* **remove-last**: Delete the last line when the typing animation ends // default false | ||
* **loop**: Enable the loop at the end of the strings // default false | ||
--- | ||
### Development | ||
@@ -49,0 +66,0 @@ |
@@ -45,6 +45,4 @@ .directive('typed', function($log, $timeout, $q) { | ||
var endlineWait = attrs.endlineWait || 250; | ||
var removeLast = attrs.removeLast || false; | ||
var endBackspace = attrs.endBackspace || false; | ||
var cursor = angular.element( document.createElement('span') ).addClass('typed-cursor').text( '|' ); | ||
@@ -198,3 +196,3 @@ | ||
// check if last line should be removed | ||
if( endBackspace ) { | ||
if( removeLast ) { | ||
@@ -226,12 +224,5 @@ backspace(text, currPos); | ||
/** | ||
* Run end-line timeout for next line | ||
*/ | ||
$timeout(function() { | ||
currentLine++ | ||
return typeText( strings[currentLine], 0 ) | ||
currentLine++ | ||
return typeText( strings[currentLine], 0 ) | ||
}, endlineWait); | ||
} | ||
@@ -238,0 +229,0 @@ |
angular.module('angular-typed', []) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
475945
2189
75
5
1