Skip to content

Instantly share code, notes, and snippets.

View lpaulger's full-sized avatar

Lucas Paulger lpaulger

View GitHub Profile
@lpaulger
lpaulger / quantity.js
Created September 7, 2013 15:20
A simple quantity spinner for angular
angular.module('__directives').directive('__Quantity', [
function() {
return {
restrict: "E",
scope: {
quantity: '='
},
replace: true,
templateUrl: 'templates/quantitySpinner.html',
link: function(scope, element, attrs) {
'use strict';
angular.module('fontSize',[]).directive('adjustSizeToWidth',[function(){
var valueToAdjustFor, container, textSpan, originalFontSize;
return function(scope, elm, attr) {
originalFontSize = attr.vwOriginalFontSize;
valueToAdjustFor = attr.vwAdjustSizeToWidth;
scope.$watch(valueToAdjustFor, function(){
container = elm;
textSpan = elm.children()[0];
(function(undefined){
// (0, eval)('this') is a robust way of getting a reference to the global object
// For details, see http://stackoverflow.com/questions/14119988/return-this-0-evalthis/14120023#14120023
var window = this || (0, eval)('this'),
document = window['document'],
navigator = window['navigator'],
jQueryInstance = window["jQuery"],
JSON = window["JSON"];
(function(factory) {
@lpaulger
lpaulger / namepsace-example.js
Created April 18, 2016 08:49
and example of how to reference module code in old legacy (namespace) javascript code
window.MyCompany.Utilities = {
foo: window.MyModule.foo,
bar: window.MyModule.bar
}
@lpaulger
lpaulger / package.json
Created April 18, 2016 08:55
example pacakge.json with module reference
{
"name": "MyCompany",
"description": "example package.json",
"version": "0.0.1",
"scripts": {
"start": "grunt watch",
"build": "grunt build",
"test": "grunt test",
"analysis": "grunt analysis"
},
@lpaulger
lpaulger / uglify.js
Created April 18, 2016 08:58
grunt uglify build configuration
module.exports = {
options: {
...
},
build: {
files: {
'dist/MyCompanyModules.js': [
...,
'node_modules/MyModule/build/MyModule.js'
...
@lpaulger
lpaulger / MyModule.js
Last active April 18, 2016 09:06
example UMD module
;(function(root, factory) {
if (typeof define === 'function' && define.amd) {
define(['jquery'], factory);
} else if (typeof exports === 'object') {
module.exports = factory(require('jquery'));
} else {
root.MyModule = factory(root.jQuery);
}
}(this, function($) {
'use strict'
@lpaulger
lpaulger / MyModule.js
Last active April 18, 2016 09:04
example module before it's been UMDified
'use strict'
var MyModule = {
foo: function() {
//content with external dependency
return $.doSomething();
},
bar: function() {
//content
@lpaulger
lpaulger / ThingViewModel.test.js
Last active June 17, 2016 12:22
example first test for legacy code
describe('when creating a ThingViewModel', function () {
it('should return an object', function () {
var thingViewModel = new ThingViewModel();
expect(typeof thingViewModel).toBe('object');
});
});
@lpaulger
lpaulger / ThingViewModel.test.js
Created June 17, 2016 12:31
example test with constructor arguments
describe('when creating a ThingViewModel', function () {
var ctorArgs;
beforeEach(function(){
ctorArgs = {
ThingApi: {
getThings: function(){}
},
ThingUtility: {}
}
});