An Angularjs module that has some common helper functions
###Example ####Javascript
angular.module('st4rtApp',[
'utility_module'
]).controller('AppCtlr', ['Sendgrid', function (Sendgrid){
var self = this;
this.Sendgrid = Sendgrid;
}]);
###Methods
-
.localStorageSize()
- Returns the size of localStorage in KB
-
.log(somethingToLog, titleString)
- Formatted console.log()
-
.debug(anything)
- Print a javascript expression, object, string, etc. in the console. It will also write the into the html as a return
-
.domain()
- Returns the current domain
-
.scroll_to(string)
- Scrolls the page to a specific element id(Angular has issues with anchor tags using hashtags)
-
.trim_text(string, limit)
- Trims the passed text to the passed length. If it is longer than specified, adds an ellipses
-
.parse_json(json)
- Safely returns an object from JSON. If error, returns the supplied json
-
.stringify(object)
- Safely returns a string from an object. If error, returns the supplied object
-
.parse_commas(string)
- Returns an array of a string split by commas
-
.object_length(object)
- Returns the number of properties in an object
-
.object_path(object, string, any)
- Given an object or array and a period delimited string. If the third argument is undefined, the value is returned, otherwise a value is set on the given path
-
.color_luminance(color(string), adjustment(float))
- Adjusts a given color(hex, rgb, rgba, hsl) up or down where 1 is 16 bits. Note 1, 0, -1 equals no change. Returns rgb()
-
.convert_color(color(string), target_type(string))
- Converts a color from one standard to another (hls, rgb, hex)
-
.typeOf(any)
- Returns the type of element, either undefined, null, boolean, number, date, string, array, object, function
-
.is_it(start(object), expression(string), equals(boolean))
- Returns true or false. The first argument is either the starting object, array, string, number. The second argument is the object/array property path if it applies. Lastly, the third argument is what it should equal
-
.to_text(HTML)
- Takes html and converts it to text
-
.url_decode(string)
- Returns decodeURIComponent(string). For use in templates if needed
-
.validate_email(string)
- Checks to see if the passed string is a valid email in that it contains '@' and a domain name
-
.get_time(object{timestamp, hours, minutes, seconds, miliseconds, am_pm, delimiter})
- Returns a formatted time as hour:minute:second:miliseconds AM/PM
-
.format_date(object{date, display(string)})
- Returns a formatted date using these keys:
- year_short
- year_long
- month_number
- month_name_short
- month_name_long
- day_number
- day_name_short
- day_name_long
- hours
- minutes
- seconds
- miliseconds
- am_pm
- Returns a formatted date using these keys:
-
.format_time(number:seconds, boolean})
- Returns a formatted time string.
-
.merge(object, object)
- Merges object2 properties and values into object1
-
.math(method(string), expression(number/string))
- Will perform javascript math functions in a template
-
.is_past(then(date))
- Will compare the current date and time with a supplied date and time to see if it is in the past or not
-
.trust_url(string)
- An angular helper to that declares a safe url to bind to. Only use if you know the source of the url
-
.trust_html(anything)
- An angular helper to that declares safe html to bind to. Only use if you know the source of the html
###Directives
-
ellipsis-bind
-
Limits a body of text by a specified number of lines
-
Attributes
- ellipsis-symbol
- Defaults to "...", can be whatever you want
- ellipsis-lines
- Defaults to "...", can be whatever you want
- ellipsis-watch
- Makes Angular specifically watch the text, in case it's going to change
- ellipsis-bind
- What calls the directive as well as defines what is the text
- ellipsis-symbol
-
-
toggle-parent
-
Adds/removes class on parent element when clicked
-
Attributes
- toggle-parent
- Class to toggle
- toggle-parent
-
-
json-text
- Converts ng-model to display as json but saved as an object
###Use
- Bower - ckc-angularjs-utility
- Add "utility_module" to your app's dependencies
- Add "utility.min.js" to your scripts