Last active
August 29, 2015 14:22
-
-
Save rlogiacco/ed3a407b1e97a0eb7941 to your computer and use it in GitHub Desktop.
AngularJS UI Utils
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module("ui-utils.focus", ['ng']) | |
.directive('focusMe', function($log) { | |
return { | |
link: function(scope, element, attrs) { | |
scope.$watch(attrs.focusMe, function(value) { | |
if(value === true) { | |
$log.debug("value=" + element[0].value); | |
element[0].focus(); | |
scope[attrs.focusMe] = false; | |
} | |
}); | |
} | |
}; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('ui-utils.truncate', ['ng']) | |
.filter('chars', function () { | |
return function (input, chars, breakOnWord) { | |
if (isNaN(chars)) return input; | |
if (chars <= 0) return ''; | |
if (input && input.length > chars) { | |
input = input.substring(0, chars); | |
if (!breakOnWord) { | |
var lastspace = input.lastIndexOf(' '); | |
//get last space | |
if (lastspace !== -1) { | |
input = input.substr(0, lastspace); | |
} | |
} else { | |
while(input.charAt(input.length-1) === ' '){ | |
input = input.substr(0, input.length -1); | |
} | |
} | |
return input + '...'; | |
} | |
return input; | |
}; | |
}) | |
.filter('words', function () { | |
return function (input, words) { | |
if (isNaN(words)) return input; | |
if (words <= 0) return ''; | |
if (input) { | |
var inputWords = input.split(/\s+/); | |
if (inputWords.length > words) { | |
input = inputWords.slice(0, words).join(' ') + '...'; | |
} | |
} | |
return input; | |
}; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module("ui-utils", ["ui-utils.focus","ui-utils.truncate"]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment