Skip to content
This repository has been archived by the owner on May 5, 2018. It is now read-only.

Commit

Permalink
reformatted all code to use 2 spaces for tabs. moved bootstrap code l…
Browse files Browse the repository at this point in the history
…ib out of modalSpec.js because it's ugly as sin.
  • Loading branch information
Christopher Hiller committed Aug 18, 2012
1 parent 8992f57 commit f5c9f2d
Show file tree
Hide file tree
Showing 44 changed files with 1,299 additions and 1,274 deletions.
14 changes: 7 additions & 7 deletions grunt.js
Original file line number Original file line Diff line number Diff line change
@@ -1,7 +1,7 @@
var testacular = require('testacular'); var testacular = require('testacular');


/*global module:false*/ /*global module:false*/
module.exports = function(grunt) { module.exports = function (grunt) {


grunt.loadNpmTasks('grunt-recess'); grunt.loadNpmTasks('grunt-recess');
grunt.loadNpmTasks('grunt-coffee'); grunt.loadNpmTasks('grunt-coffee');
Expand Down Expand Up @@ -69,22 +69,22 @@ module.exports = function(grunt) {
// Default task. // Default task.
grunt.registerTask('default', 'coffee concat min recess:basic recess:min test'); grunt.registerTask('default', 'coffee concat min recess:basic recess:min test');


grunt.registerTask('server', 'start testacular server', function() { grunt.registerTask('server', 'start testacular server', function () {
//Mark the task as async but never call done, so the server stays up //Mark the task as async but never call done, so the server stays up
var done = this.async(); var done = this.async();
testacular.server.start('test/test-config.js'); testacular.server.start('test/test-config.js');
}); });


grunt.registerTask('test', 'run tests (make sure server task is run first)', function() { grunt.registerTask('test', 'run tests (make sure server task is run first)', function () {
var done = this.async(); var done = this.async();
grunt.utils.spawn({ grunt.utils.spawn({
cmd: process.platform === 'win32' ? 'testacular-run.cmd' : 'testacular-run', cmd: process.platform === 'win32' ? 'testacular-run.cmd' : 'testacular-run',
args: ['test/test-config.js'] args: ['test/test-config.js']
}, function(error, result, code) { }, function (error, result, code) {
if (error) { if (error) {
grunt.warn("Make sure the testacular server is online: run `grunt server`.\n"+ grunt.warn("Make sure the testacular server is online: run `grunt server`.\n" +
"Also make sure you have a browser open to http://localhost:8080/.\n"+ "Also make sure you have a browser open to http://localhost:8080/.\n" +
error.stdout+error.stderr); error.stdout + error.stderr);
//the testacular runner somehow modifies the files if it errors(??). //the testacular runner somehow modifies the files if it errors(??).
//this causes grunt's watch task to re-fire itself constantly, //this causes grunt's watch task to re-fire itself constantly,
//unless we wait for a sec //unless we wait for a sec
Expand Down
10 changes: 5 additions & 5 deletions modules/directives/animate/animate.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* class {string} the CSS class(es) to use. For example, 'ui-hide' might be an excellent alternative class. * class {string} the CSS class(es) to use. For example, 'ui-hide' might be an excellent alternative class.
* @example <li ng-repeat="item in items" ui-animate=" 'ui-hide' ">{{item}}</li> * @example <li ng-repeat="item in items" ui-animate=" 'ui-hide' ">{{item}}</li>
*/ */
angular.module('ui.directives').directive('uiAnimate', ['ui.config', '$timeout', function(uiConfig, $timeout) { angular.module('ui.directives').directive('uiAnimate', ['ui.config', '$timeout', function (uiConfig, $timeout) {
var options = {}; var options = {};
if (angular.isString(uiConfig.animate)) { if (angular.isString(uiConfig.animate)) {
options['class'] = uiConfig.animate; options['class'] = uiConfig.animate;
Expand All @@ -16,18 +16,18 @@ angular.module('ui.directives').directive('uiAnimate', ['ui.config', '$timeout',
} }
return { return {
restrict: 'A', // supports using directive as element, attribute and class restrict: 'A', // supports using directive as element, attribute and class
link: function($scope, element, attrs) { link: function ($scope, element, attrs) {
var opts = {}; var opts = {};
if (attrs.uiAnimate) { if (attrs.uiAnimate) {
opts = $scope.$eval(attrs.uiAnimate); opts = $scope.$eval(attrs.uiAnimate);
if (angular.isString(opts)) { if (angular.isString(opts)) {
opts = {'class': opts}; opts = {'class': opts};
} }
} }
opts = angular.extend({'class': 'ui-animate'}, options, opts); opts = angular.extend({'class': 'ui-animate'}, options, opts);

element.addClass(opts['class']); element.addClass(opts['class']);
$timeout(function(){ $timeout(function () {
element.removeClass(opts['class']); element.removeClass(opts['class']);
}, 20, false); }, 20, false);
} }
Expand Down
44 changes: 22 additions & 22 deletions modules/directives/animate/test/animateSpec.js
Original file line number Original file line Diff line number Diff line change
@@ -1,7 +1,7 @@
/* /*
* sample unit testing for sample templates and implementations * sample unit testing for sample templates and implementations
*/ */
describe('uiAnimate', function() { describe('uiAnimate', function () {


// declare these up here to be global to all tests // declare these up here to be global to all tests
var $rootScope, $compile, $timeout, uiConfig = angular.module('ui.config'); var $rootScope, $compile, $timeout, uiConfig = angular.module('ui.config');
Expand All @@ -10,57 +10,57 @@ describe('uiAnimate', function() {


// inject in angular constructs. Injector knows about leading/trailing underscores and does the right thing // inject in angular constructs. Injector knows about leading/trailing underscores and does the right thing
// otherwise, you would need to inject these into each test // otherwise, you would need to inject these into each test
beforeEach(inject(function(_$rootScope_, _$compile_, _$timeout_) { beforeEach(inject(function (_$rootScope_, _$compile_, _$timeout_) {
$rootScope = _$rootScope_; $rootScope = _$rootScope_;
$compile = _$compile_; $compile = _$compile_;
$timeout = _$timeout_; $timeout = _$timeout_;
})); }));

afterEach(function() { afterEach(function () {
uiConfig.value('ui.config', {}); uiConfig.value('ui.config', {});
}); });

describe('behavior', function() { describe('behavior', function () {
it('should add a ui-animate class when the dom is compiled', function() { it('should add a ui-animate class when the dom is compiled', function () {
var element = $compile('<div ui-animate></div>')($rootScope); var element = $compile('<div ui-animate></div>')($rootScope);
expect(element.hasClass('ui-animate')).toBeTruthy(); expect(element.hasClass('ui-animate')).toBeTruthy();
}); });
it('should remove the ui-animate class immediately after injection', function() { it('should remove the ui-animate class immediately after injection', function () {
var element = $compile('<div ui-animate></div>')($rootScope); var element = $compile('<div ui-animate></div>')($rootScope);
$timeout.flush(); $timeout.flush();
expect(element.hasClass('ui-animate')).toBeFalsy(); expect(element.hasClass('ui-animate')).toBeFalsy();
}); });


}); });

describe('options', function() { describe('options', function () {
describe('passed', function() { describe('passed', function () {

it('should use a string as the class', function() { it('should use a string as the class', function () {
var element = $compile('<div ui-animate=" \'ui-hide\' "></div>')($rootScope); var element = $compile('<div ui-animate=" \'ui-hide\' "></div>')($rootScope);
expect(element.hasClass('ui-hide')).toBeTruthy(); expect(element.hasClass('ui-hide')).toBeTruthy();
}); });
it('should use an object\'s class attribute as the class', function() { it('should use an object\'s class attribute as the class', function () {
var element = $compile('<div ui-animate=" { \'class\' : \'ui-hide\' } "></div>')($rootScope); var element = $compile('<div ui-animate=" { \'class\' : \'ui-hide\' } "></div>')($rootScope);
expect(element.hasClass('ui-hide')).toBeTruthy(); expect(element.hasClass('ui-hide')).toBeTruthy();
}); });

}); });
describe('global', function() { describe('global', function () {


var uiConfig; var uiConfig;
beforeEach(inject(function($injector){ beforeEach(inject(function ($injector) {
uiConfig = $injector.get('ui.config'); uiConfig = $injector.get('ui.config');
})); }));

it('should use a string as the class', function(){ it('should use a string as the class', function () {
uiConfig.animate = 'ui-hide-global'; uiConfig.animate = 'ui-hide-global';
var element = $compile('<div ui-animate></div>')($rootScope); var element = $compile('<div ui-animate></div>')($rootScope);
expect(element.hasClass('ui-hide-global')).toBeTruthy(); expect(element.hasClass('ui-hide-global')).toBeTruthy();
}); });


it('should use an object\'s class attribute as the class', function() { it('should use an object\'s class attribute as the class', function () {
uiConfig.animate = { 'class' : 'ui-hide-global' }; uiConfig.animate = { 'class': 'ui-hide-global' };
var element = $compile('<div ui-animate></div>')($rootScope); var element = $compile('<div ui-animate></div>')($rootScope);
expect(element.hasClass('ui-hide-global')).toBeTruthy(); expect(element.hasClass('ui-hide-global')).toBeTruthy();
}); });
Expand Down
128 changes: 64 additions & 64 deletions modules/directives/codemirror/codemirror.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,76 +3,76 @@
* Binds a CodeMirror widget to a <textarea> element. * Binds a CodeMirror widget to a <textarea> element.
*/ */
angular.module('ui.directives').directive('uiCodemirror', ['ui.config', '$parse', function (uiConfig, $parse) { angular.module('ui.directives').directive('uiCodemirror', ['ui.config', '$parse', function (uiConfig, $parse) {
'use strict'; 'use strict';


uiConfig.codemirror = uiConfig.codemirror || {}; uiConfig.codemirror = uiConfig.codemirror || {};
return { return {
require: 'ngModel', require: 'ngModel',
link: function (scope, elm, attrs, ngModel) { link: function (scope, elm, attrs, ngModel) {
// Only works on textareas // Only works on textareas
if ( !elm.is('textarea') ) { if (!elm.is('textarea')) {
throw new Error('ui-codemirror can only be applied to a textarea element'); throw new Error('ui-codemirror can only be applied to a textarea element');
} }


var codemirror; var codemirror;
// This is the method that we use to get the value of the ui-codemirror attribute expression. // This is the method that we use to get the value of the ui-codemirror attribute expression.
var uiCodemirrorGet = $parse(attrs.uiCodemirror); var uiCodemirrorGet = $parse(attrs.uiCodemirror);
// This method will be called whenever the code mirror widget content changes // This method will be called whenever the code mirror widget content changes
var onChangeHandler = function (ed) { var onChangeHandler = function (ed) {
// We only update the model if the value has changed - this helps get around a little problem where $render triggers a change despite already being inside a $apply loop. // We only update the model if the value has changed - this helps get around a little problem where $render triggers a change despite already being inside a $apply loop.
var newValue = ed.getValue(); var newValue = ed.getValue();
if ( newValue !== ngModel.$viewValue ) { if (newValue !== ngModel.$viewValue) {
ngModel.$setViewValue(newValue); ngModel.$setViewValue(newValue);
scope.$apply(); scope.$apply();
} }
}; };
// Create and wire up a new code mirror widget (unwiring a previous one if necessary) // Create and wire up a new code mirror widget (unwiring a previous one if necessary)
var updateCodeMirror = function(options) { var updateCodeMirror = function (options) {
// Merge together the options from the uiConfig and the attribute itself with the onChange event above. // Merge together the options from the uiConfig and the attribute itself with the onChange event above.
options = angular.extend({}, options, uiConfig.codemirror); options = angular.extend({}, options, uiConfig.codemirror);


// We actually want to run both handlers if the user has provided their own onChange handler. // We actually want to run both handlers if the user has provided their own onChange handler.
var userOnChange = options.onChange; var userOnChange = options.onChange;
if ( userOnChange ) { if (userOnChange) {
options.onChange = function(ed) { options.onChange = function (ed) {
onChangeHandler(ed); onChangeHandler(ed);
userOnChange(ed); userOnChange(ed);
}; };
} else { } else {
options.onChange = onChangeHandler; options.onChange = onChangeHandler;
} }


// If there is a codemirror widget for this element already then we need to unwire if first // If there is a codemirror widget for this element already then we need to unwire if first
if ( codemirror ) { if (codemirror) {
codemirror.toTextArea(); codemirror.toTextArea();
} }
// Create the new codemirror widget // Create the new codemirror widget
codemirror = CodeMirror.fromTextArea(elm[0], options); codemirror = CodeMirror.fromTextArea(elm[0], options);
}; };


// Initialize the code mirror widget // Initialize the code mirror widget
updateCodeMirror(uiCodemirrorGet()); updateCodeMirror(uiCodemirrorGet());


// Now watch to see if the codemirror attribute gets updated // Now watch to see if the codemirror attribute gets updated
scope.$watch(uiCodemirrorGet, updateCodeMirror, true); scope.$watch(uiCodemirrorGet, updateCodeMirror, true);


// CodeMirror expects a string, so make sure it gets one. // CodeMirror expects a string, so make sure it gets one.
// This does not change the model. // This does not change the model.
ngModel.$formatters.push(function(value) { ngModel.$formatters.push(function (value) {
if(angular.isUndefined(value) || value === null) { if (angular.isUndefined(value) || value === null) {
return ''; return '';
} }
else if (angular.isObject(value) || angular.isArray(value)) { else if (angular.isObject(value) || angular.isArray(value)) {
throw new Error('ui-codemirror cannot use an object or an array as a model'); throw new Error('ui-codemirror cannot use an object or an array as a model');
} }
return value; return value;
}); });


// Override the ngModelController $render method, which is what gets called when the model is updated. // Override the ngModelController $render method, which is what gets called when the model is updated.
// This takes care of the synchronizing the codeMirror element with the underlying model, in the case that it is changed by something else. // This takes care of the synchronizing the codeMirror element with the underlying model, in the case that it is changed by something else.
ngModel.$render = function() { ngModel.$render = function () {
codemirror.setValue(ngModel.$viewValue); codemirror.setValue(ngModel.$viewValue);
}; };
} }
}; };
}]); }]);
Loading

0 comments on commit f5c9f2d

Please sign in to comment.