Skip to content

Instantly share code, notes, and snippets.

View ferronrsmith's full-sized avatar
⛱️
Chilling on the beach

Ferron H ferronrsmith

⛱️
Chilling on the beach
View GitHub Profile
@ferronrsmith
ferronrsmith / placeholder.js
Last active December 17, 2015 14:19
The following functionality is a custom-based poly-fill placeholder for AngularJS. For browsers lower than IE 10 the in-built placeholder functionality is used, otherwise the poly-fill is used
/***
* The following functionality is a custom-based poly-fill placeholder for AngularJS
* @example <input id="weight" name="weight" type="number" defaulttext="enter your weight"
* min="50" max="500" required />
* For browsers lower than IE 10 the in-built placeholder functionality is used, otherwise
* the poly-fill is used
*/
app.directive('defaulttext', function($timeout){
if (!$.browser.msie || $.browser.version >= 10) {
return {
@ferronrsmith
ferronrsmith / ngEvent.js
Last active December 17, 2015 14:19
General-purpose Event binding. Bind any event not natively supported by Angular Pass an object with keynames for events to ng-event Allows $event object and $params object to be passed
/**
* General-purpose Event binding. Bind any event not natively supported by
* Angular Pass an object with keynames for events to ng-event Allows $event
* object and $params object to be passed
*
* @example <input ng-event="{ focus : 'counter++', blur : 'someCallback()' }">
* @example <input ng-event="{ myCustomEvent : 'myEventHandler($event,
* $params)'}">
*
* @param ng-event
@ferronrsmith
ferronrsmith / ngValidate.js
Last active December 17, 2015 14:19
General-purpose validator for ngModel. angular.js comes with several built-in validation mechanism for input fields (ngRequired, ngPattern etc.) but using an arbitrary validation function requires creation of a custom formatters and / or parsers. The ng-validate directive makes it easy to use any function(s) defined in scope as a validator funct…
/**
* General-purpose validator for ngModel. angular.js comes with several built-in
* validation mechanism for input fields (ngRequired, ngPattern etc.) but using
* an arbitrary validation function requires creation of a custom formatters and /
* or parsers. The ng-validate directive makes it easy to use any function(s)
* defined in scope as a validator function(s). A validator function will
* trigger validation on both model and input changes.
*
* @example <input ng-validate=" 'myValidatorFunction($value)' ">
* @example <input ng-validate="{ foo : '$value > anotherModel', bar :
@ferronrsmith
ferronrsmith / numeric.js
Created May 22, 2013 20:25
disallow numeric entry in a input field
app.directive('ng-numeric', function($log) {
return {
require: 'ngModel',
link: function (scope, element, attr, ngModelCtrl) {
function fromUser(text) {
var transformedInput = text.replace(/[^0-9]/g, '');
$log.info(transformedInput);
if(transformedInput !== text) {
ngModelCtrl.$setViewValue(transformedInput);
ngModelCtrl.$render();
@ferronrsmith
ferronrsmith / ordinal.js
Created May 22, 2013 20:37
angular ordinal filter
'use strict';
// Ordinal Number Filter
// ---------------------
// This filter takes a number and returns its ordinal value
// i.e. 1 -> 1st, 2 -> 2nd, etc.
// h/t http://ecommerce.shopify.com/c/ecommerce-design/t/ordinal-number-in-javascript-1st-2nd-3rd-4th-29259
angular.module('ordinal', []).filter('ordinal', function() {
@ferronrsmith
ferronrsmith / get_url_vars.js
Last active December 18, 2015 10:39
simple JavaScript function to retrieve variables from the url
var getUrlVars = function () {
var vars = [], hash, $href, hashes, i;
$href = window.location.href;
hashes = $href.slice($href.indexOf('?') + 1).split('&');
for (i = 0; i < hashes.length; i += 1) {
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
@ferronrsmith
ferronrsmith / random_color.js
Last active December 18, 2015 10:39
Simple function to generate a random color in JavaScript
var randomColor = function () {
return '#' + ('00000' + (Math.random() * 16777216 << 0).toString(16)).substr(-6);
};
@ferronrsmith
ferronrsmith / uuid.js
Created June 13, 2013 00:22
Simple function to generate a random mask url
var uuid = function () {
var mask = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
return (function (mask) {
return mask.replace(/[xy]/g, function (c) {
var r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}(mask));
}
/**
* The following function does a top-down recursive decent on a json tree to
* find an element with-in structure
*
* @param value -value to retrieve
* @param jObj -json object to traverse
* @param deep - deep traversal
* @return JsonElement if found or null if element not found
*/
public JsonElement get(String value, JsonObject jObj, boolean deep) {
/**
(c) Ferron Hanse 2012
https://github.com/ferronrsmith/anuglarjs-jasmine-matchers
Released under the MIT license
**/
/*jslint nomen : true*/
/*jslint bitwise : true*/
/*global describe, beforeEach, inject, module, angular, document, it, expect, $, jasmine, toJson */