Skip to content

Instantly share code, notes, and snippets.

angular.module('app', [])
.controller('AppCtrl', function(){
var app = this;
app.names = [
{
"id": "e1",
"firstName": "Alyson",
"lastName": "Valdez"
},
{
@deanapeterson
deanapeterson / SassMeister-input.scss
Created October 2, 2015 18:09
Generated by SassMeister.com.
// ----
// libsass (v3.2.5)
// ----
.columns{border-bottom:1px solid pink}
/**
This scss component assumes foundation is being used.
**/
label.inline-compact,
@deanapeterson
deanapeterson / simple-angular-model.js
Last active August 29, 2015 14:25
Super simple advanced model service for Angular.
angular
.module("app", [])
.factory("MyModel", MyModelFactory)
.controller("AppController", AppController);
function MyModelFactory($http){ //
var url = "/my-service";
var originalData;
var service = {
data : [], //assumes data is a collection of same object
@deanapeterson
deanapeterson / minutesToHours.js
Created February 6, 2015 18:57
convert minutes integer into hour string.
//usage
//minutesToHours(60) = '1:00'
//minutesToHours(45) = '0:45'
//minutesToHours(43) = '0:45' rounds to nearest 15
function minutesToHours(minutes){
var isNegative = (minutes < 0);
var absMinutes = Math.abs(minutes); //if negative convert to positive
var dividedBy60 = (absMinutes / 60);
var roundedHour = Math.floor(dividedBy60);
@deanapeterson
deanapeterson / ui-router-stateChangeRejected.js
Last active November 25, 2016 07:33
Adding "$stateChangeRejected" event to ui-router.
(function(){
"use strict";
/**
* Hijacks the ui-router $state.transitionTo() method to capture it's promise.
* the promise is added to the $state as $promise (may or may not be needed);
* also adds handler for rejection of the $promise.
*/
angular
@deanapeterson
deanapeterson / alternate-ui-router-event-binding.js
Last active August 29, 2015 14:13
Alternate way to bind to UI-Router events
/**
* Similar to the idea of adding 'rules' to a states data object, I add injectible
* handlers keyed to the specific stateChange relationship:
*
* 'onToStateChangeStart/Success' - fired when the state is the destination
* 'onFromStateChangeStart/Success' - fired when the state is the previous
*
* I like this because the we can run all handlers through one event binding
* and make the state definition object for self-contained.
**/
@deanapeterson
deanapeterson / staticInclude.js
Created October 23, 2013 20:51
Include a view/template without creation of a new scope. Refined from snippet provided on this stackoverflow entry: http://stackoverflow.com/questions/12393703/how-to-include-one-partials-into-other-without-creating-a-new-scope#answer-17340138. jsFiddle: http://jsfiddle.net/DeanIconWeb/BVXUe/
module.directive('staticInclude', ["$http", "$templateCache", "$compile", "$parse",function($http, $templateCache, $compile, $parse) {
return function(scope, element, attrs) {
var templatePath = $parse(attrs.staticInclude)(scope);
attrs.$observe("staticInclude", function(value){
scope.$watch(value, function(templatePath){
loadTemplate(templatePath);
});
@deanapeterson
deanapeterson / TestFor Scrollbar
Created July 16, 2013 21:57
Testing for scrollbar in Jasmine/Karma
//Pseudo Code
it(" should have a scrollbar", function(){
var tableWrap, table, tablePosTop, newTablePosTop;
tableWrap = $(".tableWrapper");
table = tableWrap.find("table");
tablePosTop = table.position().top;
tableWrap.animate({scrollTop:100},0);
newTablePosTop = table.position().top;
@deanapeterson
deanapeterson / insert Style
Created July 16, 2013 21:20
Inserting styles into jasmine/karma tests
beforeEach(inject(function( _$document_){
$document = _$document_;
$document.find("head").append(
"<style>\
table{width:100%}\
</style>"
);
}));