Skip to content

Instantly share code, notes, and snippets.

View wholypantalones's full-sized avatar

Jason Dare wholypantalones

View GitHub Profile
@wholypantalones
wholypantalones / fadein-fadeout.css
Created December 22, 2014 21:16
Angular Animation CSS
.fadein,
.fadeout {
-webkit-transition:all linear 0.5s;
-moz-transition:all linear 0.5s;
-o-transition:all linear 0.5s;
transition:all linear 0.5s;
}
.fadein.ng-hide-remove,
.fadeout.ng-hide-add.ng-hide-add-active {
opacity: 0;
@wholypantalones
wholypantalones / ac.js
Last active October 31, 2015 16:53
Angular Google Places AutoComplete
/* Usage:
<input type="text" id="address" name="address" placeholder="Start Typing An Address" ng-model="address" details="placeDetails" googleplace />
Fiddle: http://jsfiddle.net/wholypantalones/5qtt1f8g/
*/
//controller
$scope.$watch('placeDetails', function() {
angular.forEach($scope.placeDetails.address_components,function(val,key) {
if(val.types[0] == "locality") {
$scope.city = val.short_name;
}
@wholypantalones
wholypantalones / findIndex.js
Last active August 29, 2015 14:11
Angular find index of variable
/* usage:
$scope.thing = $scope.myObject.thing2[$scope.findIndex($scope.myObject.thing2,'attr',$scope.variable)];
> $scope.thing = $scope.myObject.thing2[i];
*/
$scope.findIndex = function(arr,attr,val) {
for (var i = 0; i < arr.length; i += 1) {
if (arr[i][attr] === val) {
return i;
}
@wholypantalones
wholypantalones / dataService.js
Last active August 29, 2015 14:11
Angular http dataService with response and error messages
/* usage:
dataService.getData("[GET|POST]","[url]",{data:object},{params:object},{timeout:object}).then(function(dataResponse) {
$scope.item = dataResponse.data;
});
*/
/* Service inject 'httpService' as dependency
angular.module('httpService', []).service('dataService', function ($http, $rootScope) {
*/
app.service('dataService', function($http,$rootScope) {
@wholypantalones
wholypantalones / regex.js
Last active October 1, 2015 13:53
A collection of useful regex
//http://plnkr.co/edit/W1sp75P0PyOdZ834xvQu?p=preview
Email: /^[_a-zA-Z0-9]+(\.[_a-zA-Z0-9]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-z]{2,4})$/
Postal Code: /^(\d{5}(-\d{4})?|[A-Z]\d[A-Z] *\d[A-Z]\d)$/
Credit Card: (/^5[1-5]/.test(value)) ? "Mastercard" : (/^4/.test(value)) ? "Visa" : (/^3[47]/.test(value)) ? 'American Express' : (/^6011|65|64[4-9]|622(1(2[6-9]|[3-9]\d)|[2-8]\d{2}|9([01]\d|2[0-5]))/.test(value)) ? 'Discover' : undefined;
Allow Numbers Only: /[^\d]+/g
Replace Whitespace: /[\W_]+/g
@wholypantalones
wholypantalones / gist:d57f642613350c26d1d0
Created September 12, 2014 16:00
Angular Capitalize Input Value
//<input capitalize>
app.directive('capitalize', function() {
return {
require: 'ngModel',
link: function(scope, element, attrs, modelCtrl) {
var capitalize = function(inputValue) {
if(inputValue == undefined) inputValue = '';
var capitalized = inputValue.toUpperCase(); // change to .charAt(0).toUpperCase() for actual capitalize
if(capitalized !== inputValue) {
@wholypantalones
wholypantalones / gist:a45e9368651be4b8ab26
Created August 26, 2014 14:50
angular killcaps directive
/* usage:
<div> {{somedata | killcaps}}</div>
<select ng-model="countryCd" ng-options="c.countryCode as c.countryName | killcaps for c in countries"></select>
*/
app.filter('killcaps', function() {
return function (killcaps) {
var newValue = killcaps.replace(/_/g," ").replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
return newValue;
};
// Given a query string "?to=email&why=because&first=John&Last=smith"
// getUrlVar("to") will return "email"
// getUrlVar("last") will return "smith"
// Slightly more concise and improved version based on http://www.jquery4u.com/snippets/url-parameters-jquery/
function getUrlVar(key){
var result = new RegExp(key + "=([^&]*)", "i").exec(window.location.search);
return result && unescape(result[1]) || "";
}
@wholypantalones
wholypantalones / chosen.js
Last active August 29, 2015 14:05
Chosen jQuery Plugin Blank Option Not Allowed
//this will default to the first option of nothing is selected or the selected option is removed
$("body").on("change", "#chosen-select", function() {
if($(this).val() === null) {
$(this).find("option:first").prop("selected", true).trigger("chosen:updated");
// or $(this).find("option[value=thing]").prop("selected", true).trigger("chosen:updated");
} else {
$(this).find("option:first").prop("selected", false).trigger("chosen:updated");
// or $(this).find("option[value=thing]").prop("selected", false).trigger("chosen:updated");
}
@wholypantalones
wholypantalones / countObjects.js
Created July 22, 2014 17:14
Angular count objects
// usage {{countSeats(table.seats)}}
// fiddle http://jsfiddle.net/wholypantalones/vCMEM/1/
$scope.countSeats = function(seatsObj) {
if(typeof(seatsObj) !== "undefined") {
return Object.keys(seatsObj).length;
} // prevents "Error while interpolating"
}; // in dom
angular.forEach($scope.tables, function(val,key) {