Skip to content

Instantly share code, notes, and snippets.

@mcranston18
mcranston18 / SampleAngularCtrl
Last active August 29, 2015 14:03
This is a sample Angular controller demonstrating a possible way to organize your CRUD operations.
'use strict';
angular.module('app.photo')
.controller('EditPhotoCtrl', function($scope, $state, $location, $window,
UserService, PhotoService, UtilitiesService) {
/**
* INIT VALUES
*/
'use strict';
angular.module('app.picture')
.directive('pictureList', function() {
return {
restrict: 'E',
scope: {
pictures: '='
@mcranston18
mcranston18 / gist:c14bffa5caa3a5398fa5
Last active August 29, 2015 14:05
Sample Angular Test
'use strict';
describe('PhotoCtrl', function() {
var ctrl, rootScope, scope, q, Mock;
beforeEach(angular.mock.module('app.photo', 'ui.router'));
beforeEach(inject(function($controller, _$rootScope_, _$location_, _$state_, _$q_) {
beforeEach(inject(function(_) {
underScoreService = _;
}));
it('should do something', function () {
expect(underScoreService).toBe(true);
});
var git = require('gulp-git');
var inject = require('inject-string');
var q = require('q');
var getHash = function() {
var deferred = q.defer();
$.git.revParse({args:'--short HEAD'}, function (err, hash) {
deferred.resolve(hash);
});
return deferred.promise;
@mcranston18
mcranston18 / gist:b03514d1030396f24a3b
Last active August 29, 2015 14:21
generic semantic ui directive
/**
* semanticUi - Generic directive for Semantic UI Javascript initialization.
*/
'use strict';
angular.module('cozumo')
.directive('semanticUi', function ($timeout) {
return {
restrict: 'A',
@mcranston18
mcranston18 / flex-grid.scss
Created November 25, 2015 18:00
Foundation V6 Flex Grid
.foundation-mq {
font-family: "small=0em&medium=40em&large=64em&xlarge=75em&xxlarge=90em"; }
/*! normalize.css v3.0.3 | MIT License | github.com/necolas/normalize.css */
/**
* 1. Set default font family to sans-serif.
* 2. Prevent iOS and IE text size adjust after device orientation change,
* without disabling user zoom.
*/
html {
@mcranston18
mcranston18 / directive_isFocused
Last active December 16, 2015 19:19
AngularJS Directive to Validate Field After User Has Left It
App.directive('isFocused', function(){
var isFocused = {
restrict: 'A',
scope: {
model: '=isFocused'
},
link: function(scope, element, attrs) {
scope.model = false;
element.focus(function(){
@mcranston18
mcranston18 / directive_scrollSpy
Created October 30, 2013 15:15
Angular directive for scroll spy
'use strict';
angular.module('AppSuccess')
.directive('scrollSpy', ['$window', function ($window) {
return {
restrict: 'A',
link: function (scope, element) {
// Get offset before scrollSpy activates
// otherwise offset of element would change
@mcranston18
mcranston18 / directive_verticalAlign
Created October 30, 2013 15:20
Directive to vertically align in CSS
app.directive('verticalAlign', function () {
return {
restrict: 'A',
link: function (scope, elm, attrs) {
var childHeight = elm[0].clientHeight;
var parentHeight = elm[0].parentElement.clientHeight;
var offset = (parentHeight - childHeight) / 2;
elm[0].style.paddingTop = offset + 'px';
}
}