Skip to content

Instantly share code, notes, and snippets.

View nelsonpecora's full-sized avatar

Nelson Pecora nelsonpecora

View GitHub Profile
@nelsonpecora
nelsonpecora / phonemask.js
Last active December 22, 2015 10:18
Quick and dirty phone number masking directive
app.directive('maskTel', function() {
return {
require: 'ngModel',
link: function(scope, element, attrs, ngModel) {
var maskTel = function(inputValue) {
if(inputValue) {
var masked = null,
s = inputValue.replace(/\D/g, '').slice(0,10);
ngModel.$setValidity('tel', false);
@nelsonpecora
nelsonpecora / select.less
Created September 6, 2013 16:54
Custom select box styling with browser fixes
.custom-select {
background: @white url(/images/dropdown.jpg) right center no-repeat;
border: 1px solid @grey_light_border;
color: @textcolor;
padding: 0 0 0 20px !important;
height: 44px;
line-height: 43px;
overflow: hidden;
select {
background: transparent;
@nelsonpecora
nelsonpecora / empty.js
Last active December 22, 2015 16:18
<input type="text" ng-model="name" empty="{{email}}" required /> <input type="email" ng-model="email" empty="{{name}}" required />
app.directive('empty', function() {
return {
restrict: 'A',
require: '?ngModel',
priority: 0,
link: function(scope, elem, attrs, ngModel) {
if(!ngModel) return; // do nothing if no ng-model
// watch own value and re-validate on change
scope.$watch(attrs.ngModel, function() {
@nelsonpecora
nelsonpecora / proxyFactory.js
Created September 12, 2013 18:43
halfway done.
bolster.factory('Proxy', ['$http', function($http) {
return {
Request: function(verb, action, url, data, ok, error, fault) {
// callback handlers
var handleOk = function(data, ok) {
if(ok) return ok();
//default function
console.log(data);
}
{
request: function(obj) {
// callback handlers
var handleOk = function(response, ok) {
console.log('ok: ', data.data);
return response.data;
}
$http(obj).success(function(response) {
if(response.status === 'ok') handleOk(response, ok);
app.factory('Proxy', ['$http', '$q', function($http, $q) {
return {
errorMessage: null,
request: function(method, action, url, data) {
var deferred = $q.defer(),
me = this;
// core functionality
if(method === 'get') {
var obj = {
var app = angular.module('app', ['ngAnimate', 'ngProgress']);
app.config(['$httpProvider', 'ngProgress', function($httpProvider, ngProgress) {
$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
$httpProvider.defaults.transformRequest = [function(data){ return data != undefined ? $.param(data) : null; }];
$httpProvider.responseInterceptors.push('ProgressBar');
$httpProvider.defaults.transformRequest.push(function(data) {
// start the progress bar
ngProgress.start();
return data;
@nelsonpecora
nelsonpecora / blur.js
Created September 19, 2013 16:59
Angular directive to check validation on blur
var blur = function() {
return {
restrict: 'A',
require: '?ngModel',
link: function (scope, element, attrs, ngModel) {
if(!ngModel) return;
ngModel.$setValidity('blur', true);
var validator = function(value) {
if(ngModel.$invalid) {
@nelsonpecora
nelsonpecora / gist:6671936
Last active December 23, 2015 17:49
Projects.getSummary() method in Projects service
getSummary: function() {
var i = 0,
l = this.data.length,
titles = [];
for(i; i < l; i++) {
var obj = {
id: this.data[i].id,
name: this.data[i].name,
slug: Slugify(this.data[i].name)
@nelsonpecora
nelsonpecora / models.js
Created September 24, 2013 18:27
Services used in the traditional sense, factories used as the models
app.service('Model', ['$q', '$http', function($q, $http) {
this.find = function(id) { // generic method for looking up data in the client-side model
return this.data[id];
}
this.fetch = function(resource, id) { // generic CRUD method
this.data = $http.get(resource, id);
}
}]);
app.factory('Cars', ['Model', function(Model) {