diff --git a/.gitignore b/.gitignore index 6cb1e35b..2e5abdae 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ bower_components/ node_modules/ -.rcs -*.swp \ No newline at end of file +out/ +dist/ + +# don't track generated/copied html demo files +demo/*.html diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 00000000..ad23bccc --- /dev/null +++ b/.jshintrc @@ -0,0 +1,23 @@ +{ + "boss": true, + "browser": true, + "eqnull": true, + "expr": true, + "globalstrict": true, + "immed": true, + "laxbreak": true, + "loopfunc": true, + "newcap": true, + "noarg": true, + "noempty": true, + "nonew": true, + "quotmark": true, + "smarttabs": true, + "sub": true, + "trailing": true, + "undef": true, + "unused": true, + "globals": { + "angular": false + } +} diff --git a/.travis.yml b/.travis.yml index 5437b0ea..8a22e711 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,17 @@ --- language: node_js node_js: -- '0.8' +- '0.10' before_install: - export DISPLAY=:99.0 - sh -e /etc/init.d/xvfb start -- npm install -g bower grunt-cli -- npm install -- bower install -before_script: bower_components/angular-ui-docs/.travis/before_script.sh -after_success: bower_components/angular-ui-docs/.travis/after_success.sh +- npm install -qg bower grunt-cli +- npm install -q +- bower install --force +- bower install --force +after_success: +- "./node_modules/angular-ui-publisher/travis/authentication.sh || exit 0" +- "grunt dist build:gh-pages publish:gh-pages build:bower publish:bower build:subbower publish:subbower" script: grunt env: global: diff --git a/README.md b/README.md index e258f9a9..901c6d70 100644 --- a/README.md +++ b/README.md @@ -1,56 +1,87 @@ -# AngularUI - The companion suite for AngularJS +# UI.Utils [![Build Status](https://travis-ci.org/angular-ui/ui-utils.png?branch=master)](https://travis-ci.org/angular-ui/ui-utils) -*** +The companion suite for AngularJS -[![Build Status](https://travis-ci.org/angular-ui/ui-utils.png?branch=master)](https://travis-ci.org/angular-ui/ui-utils) +## Requirements + +- AngularJS ## Usage -### Requirements -* **AngularJS v1.0.0+** is currently required. -* **jQuery*** Until the refactor is complete, some directives still require jQuery +You can get it from [Bower](http://bower.io/) + +```sh +# All the modules +bower install angular-ui-utils\#bower + +# A specific module +# bower install angular-ui-utils\#bower- +bower install angular-ui-utils\#bower-event +bower install angular-ui-utils\#bower-keypress +... + +# A specific version +bower install angular-ui-utils\#v0.0.4 +# A specific module version +bower install angular-ui-utils\#event-0.0.4 +bower install angular-ui-utils\#keypress-0.0.4 +... + +# If you want the sources with it +bower install angular-ui-utils +# or for a specific source version +bower install angular-ui-utils\#src0.0.4 +``` + +This will copy the UI.Utils files into a `bower_components` folder, along with its dependencies. Load the script files in your application: + +```html + + + -## Installation + + + + +``` Add the specific modules to your dependencies, or add the entire lib by depending on `ui.utils` ```javascript angular.module('myApp', ['ui.keypress', 'ui.event', ...]) // or if ALL modules are loaded along with modules/utils.js -angular.module('myApp', ['ui.utils']) +var myAppModule = angular.module('MyApp', ['ui.utils']); ``` Each directive and filter is now it's own module and will have a relevant README.md in their respective folders ## Development -At this time, we do not have a build script. You must include all `.js` files you wish to work on. -We will likely be adding a `Gruntfile.js` in the near future for this +We use Karma and jshint to ensure the quality of the code. The easiest way to run these checks is to use grunt: -### Requirements +```sh +npm install -g grunt-cli +npm install && bower install +grunt +``` -0. Install [Node.js](http://nodejs.org/) and NPM (should come with) +The karma task will try to open Firefox and Chrome as browser in which to run the tests. Make sure this is available or change the configuration in `test\karma.conf.js` -1. Install global dependencies `grunt-cli`, `bower`, and `karma`: - ```bash - $ npm install -g karma grunt-cli bower - ``` +### Grunt Serve -2. Install local dependencies: +We have one task to serve them all ! - ```bash - $ npm install - $ bower install - ``` +```sh +grunt serve +``` -### Running Tests +It's equal to run separately: -Make sure all tests pass in order for your Pull Request to be accepted +* `grunt connect:server` : giving you a development server at [http://127.0.0.1:8000/](http://127.0.0.1:8000/). -You can choose what browsers to test in: `Chrome,ChromeCanary,Firefox,PhantomJS` +* `grunt karma:server` : giving you a Karma server to run tests (at [http://localhost:9876/](http://localhost:9876/) by default). You can force a test on this server with `grunt karma:unit:run`. -```bash -$ karma start --browsers=Chrome,Firefox test/karma.conf.js --single-run=true -``` +* `grunt watch` : will automatically test your code and build your demo. You can demo generation with `grunt build:gh-pages`. diff --git a/bower.json b/bower.json index 6a640708..6808aee0 100644 --- a/bower.json +++ b/bower.json @@ -10,7 +10,6 @@ }, "devDependencies": { "angular-mocks": "~1.0.5", - "jquery": ">=1.6", - "angular-ui-docs": "angular-ui/angular-ui-docs" + "jquery": ">=1.6" } } diff --git a/demo/demo.js b/demo/demo.js index 567f32b1..4d5686e6 100644 --- a/demo/demo.js +++ b/demo/demo.js @@ -1,15 +1,16 @@ +'use strict'; angular.module('doc.ui-utils', ['ui.utils', 'prettifyDirective' ]); angular.module('ui.scroll') .factory('datasource', [ - '$log', '$timeout', '$rootScope', function(console, $timeout, $rootScope) { + '$log', '$timeout', function(console, $timeout) { var get = function(index, count, success) { return $timeout(function() { var i, result, _i, _ref; result = []; for (i = _i = index, _ref = index + count - 1; index <= _ref ? _i <= _ref : _i >= _ref; i = index <= _ref ? ++_i : --_i) { - result.push("item #" + i); + result.push('item #' + i); } return success(result); }, 100); diff --git a/gruntFile.js b/gruntFile.js index d7c20010..78f41086 100644 --- a/gruntFile.js +++ b/gruntFile.js @@ -1,39 +1,67 @@ -module.exports = function (grunt) { +'use strict'; - var initConfig; +module.exports = function (grunt) { // Loading external tasks - grunt.loadNpmTasks('grunt-contrib-watch'); - grunt.loadNpmTasks('grunt-contrib-uglify'); - grunt.loadNpmTasks('grunt-contrib-concat'); - grunt.loadNpmTasks('grunt-contrib-clean'); - grunt.loadNpmTasks('grunt-contrib-jshint'); - grunt.loadNpmTasks('grunt-contrib-copy'); - grunt.loadNpmTasks('grunt-karma'); - - - /** - * Custom task to inline a generated file at a certain moment... - */ - grunt.registerTask('UGF', 'Use Generated Files.', function() { - initConfig.meta.view.demoHTML= grunt.file.read( grunt.template.process("<%= dist %>/demos.html")); - }); + require('load-grunt-tasks')(grunt); // Default task. grunt.registerTask('default', ['jshint', 'karma:unit']); - grunt.registerTask('build', ['concat:tmp', 'concat:modules', 'clean:rm_tmp', 'uglify']); - grunt.registerTask('build-doc', ['build', 'concat:html_doc', 'UGF', 'copy']); - grunt.registerTask('server', ['karma:start']); + grunt.registerTask('serve', [ 'karma:continuous', 'dist:main', 'dist:demo', 'build:gh-pages', 'connect:continuous', 'watch']); + + grunt.registerTask('dist', ['dist:main', 'dist:sub', 'dist:demo']); + grunt.registerTask('dist:main', ['concat:tmp', 'concat:modules', 'clean:rm_tmp', 'uglify:main']); + grunt.registerTask('dist:sub', ['ngmin', 'uglify:sub']); + grunt.registerTask('dist:demo', ['concat:html_doc', 'copy']); + + + // HACK TO ACCESS TO THE COMPONENT-PUBLISHER + function fakeTargetTask(prefix){ + return function(){ + + if (this.args.length !== 1) return grunt.log.fail('Just give the name of the ' + prefix + ' you want like :\ngrunt ' + prefix + ':bower'); + + var done = this.async(); + var spawn = require('child_process').spawn; + spawn('./node_modules/.bin/gulp', [ prefix, '--branch='+this.args[0] ].concat(grunt.option.flags()), { + cwd : './node_modules/angular-ui-publisher', + stdio: 'inherit' + }).on('close', done); + }; + } + + grunt.registerTask('build', fakeTargetTask('build')); + grunt.registerTask('publish', fakeTargetTask('publish')); + // + + // HACK TO LIST ALL THE MODULE NAMES + var moduleNames = grunt.file.expand({ cwd: 'modules' }, ['*','!utils.js']); + function ngMinModulesConfig(memo, moduleName){ + memo[moduleName]= { + expand: true, + cwd: 'modules/' + moduleName, + src: [moduleName + '.js'], + dest: 'dist/sub/' + moduleName + }; + + return memo; + } + // + + + // HACK TO MAKE TRAVIS WORK var testConfig = function(configFile, customOptions) { var options = { configFile: configFile, singleRun: true }; var travisOptions = process.env.TRAVIS && { browsers: ['Firefox', 'PhantomJS'], reporters: ['dots'] }; return grunt.util._.extend(options, customOptions, travisOptions); }; + // + // Project configuration. - initConfig = { + grunt.initConfig({ bower: 'bower_components', dist : '<%= bower %>/angular-ui-docs', pkg: grunt.file.readJSON('package.json'), @@ -44,27 +72,45 @@ module.exports = function (grunt) { ' * @link <%= pkg.homepage %>', ' * @license <%= pkg.license %>', ' */', - ''].join('\n'), - view : { - humaName : "UI Utils", - repoName : "ui-utils", - demoJS : grunt.file.read("demo/demo.js"), - js : [ - 'build/<%= meta.view.repoName %>.min.js' - ] - }, - destName : '<%= dist %>/build/<%= meta.view.repoName %>' + ''].join('\n') }, + watch: { - karma: { - files: ['modules/**/*.js'], - tasks: ['karma:unit:run'] //NOTE the :run flag + + src: { + files: ['modules/**/*.js', '!modules/**/test/*Spec.js', 'demo/**/*.js'], + tasks: ['jshint:src', 'karma:unit:run', 'dist:main', 'dist:demo', 'build:gh-pages'] + }, + test: { + files: ['modules/**/test/*Spec.js'], + tasks: ['jshint:test', 'karma:unit:run'] + }, + demo: { + files: ['modules/**/demo/*'], + tasks: ['jshint:src', 'dist:demo', 'build:gh-pages'] + }, + livereload: { + files: ['out/built/gh-pages/**/*'], + options: { livereload: true } } }, + + connect: { + options: { + base : 'out/built/gh-pages', + open: true, + livereload: true + }, + server: { options: { keepalive: true } }, + continuous: { options: { keepalive: false } } + }, + karma: { unit: testConfig('test/karma.conf.js'), - start: {configFile: 'test/karma.conf.js'} + server: {configFile: 'test/karma.conf.js'}, + continuous: {configFile: 'test/karma.conf.js', background: true } }, + concat: { html_doc: { options: { @@ -74,7 +120,7 @@ module.exports = function (grunt) { ].join('\n '), footer : ''}, src: [ 'modules/**/demo/index.html'], - dest: '<%= dist %>/demos.html' + dest: 'demo/demos.html' }, tmp: { files: { 'tmp/dep.js': [ 'modules/**/*.js', '!modules/utils.js', '!modules/ie-shiv/*.js', '!modules/**/test/*.js']} @@ -82,57 +128,69 @@ module.exports = function (grunt) { modules: { options: {banner: '<%= meta.banner %>'}, files: { - '<%= meta.destName %>.js': ['tmp/dep.js', 'modules/utils.js'], - '<%= meta.destName %>-ieshiv.js' : ['modules/ie-shiv/*.js'] + 'dist/main/ui-utils.js': ['tmp/dep.js', 'modules/utils.js'], + 'dist/main/ui-utils-ieshiv.js' : ['modules/ie-shiv/*.js'] } } }, uglify: { options: {banner: '<%= meta.banner %>'}, - build: { + main: { files: { - '<%= meta.destName %>.min.js': ['<%= meta.destName %>.js'], - '<%= meta.destName %>-ieshiv.min.js': ['<%= meta.destName %>-ieshiv.js'] + 'dist/main/ui-utils.min.js': ['dist/main/ui-utils.js'], + 'dist/main/ui-utils-ieshiv.min.js': ['dist/main/ui-utils-ieshiv.js'] } + }, + sub: { + expand: true, + cwd: 'dist/sub/', + src: ['**/*.js'], + ext: '.min.js', + dest: 'dist/sub/' } }, clean: { rm_tmp: {src: ['tmp']} }, jshint: { - files:['modules/**/*.js', 'gruntFile.js', 'test/**/*Spec.js', 'demo/**/*.js'], - options: { - curly: true, - eqeqeq: true, - immed: true, - latedef: true, - newcap: true, - noarg: true, - sub: true, - boss: true, - eqnull: true, - globals: {} + src: { + files:{ src : ['modules/**/*.js', '!modules/**/test/*Spec.js','demo/**/*.js'] }, + options: { jshintrc: '.jshintrc' } + }, + test: { + files:{ src : [ 'modules/**/test/*Spec.js', 'gruntFile.js'] }, + options: grunt.util._.extend({}, grunt.file.readJSON('.jshintrc'), { + node: true, + globals: { + angular: false, + inject: false, + jQuery: false, + + jasmine: false, + afterEach: false, + beforeEach: false, + ddescribe: false, + describe: false, + expect: false, + iit: false, + it: false, + spyOn: false, + xdescribe: false, + xit: false + } + }) } }, copy: { main: { files: [ - {src: ['demo/demo.js'], dest: '<%= dist %>/core/demo.js', filter: 'isFile'}, - // UI.Include needs a external html source. - {src: ['modules/include/demo/fragments.html'], dest: '<%= dist %>/assets/fragments.html', filter: 'isFile'} - ] - }, - template : { - options : {processContent : function(content){ - return grunt.template.process(content); - }}, - files: [ - {src: ['<%= dist %>/.tmpl/index.tmpl'], dest: '<%= dist %>/index.html'} + {src: ['modules/include/demo/fragments.html'], dest: 'demo/fragments.html', filter: 'isFile'} ] } - } - }; - grunt.initConfig(initConfig); + }, + + ngmin: moduleNames.reduce(ngMinModulesConfig, {}) + }); -}; \ No newline at end of file +}; diff --git a/modules/alias/alias.js b/modules/alias/alias.js index 184a0cf7..6048b1f9 100644 --- a/modules/alias/alias.js +++ b/modules/alias/alias.js @@ -1,3 +1,5 @@ +'use strict'; + angular.module('ui.alias', []).config(['$compileProvider', 'uiAliasConfig', function($compileProvider, uiAliasConfig){ uiAliasConfig = uiAliasConfig || {}; angular.forEach(uiAliasConfig, function(config, alias){ @@ -11,4 +13,4 @@ angular.module('ui.alias', []).config(['$compileProvider', 'uiAliasConfig', func return config; }); }); -}]); \ No newline at end of file +}]); diff --git a/modules/event/event.js b/modules/event/event.js index ba265e26..1a1a2aed 100644 --- a/modules/event/event.js +++ b/modules/event/event.js @@ -1,3 +1,5 @@ +'use strict'; + /** * General-purpose Event binding. Bind any event not natively supported by Angular * Pass an object with keynames for events to ui-event diff --git a/modules/event/test/eventSpec.js b/modules/event/test/eventSpec.js index 96bf8ce4..aded0675 100644 --- a/modules/event/test/eventSpec.js +++ b/modules/event/test/eventSpec.js @@ -1,4 +1,6 @@ describe('uiEvent', function () { + 'use strict'; + var $scope, $rootScope, $compile; beforeEach(module('ui.event')); @@ -76,4 +78,4 @@ describe('uiEvent', function () { }); }); -}); \ No newline at end of file +}); diff --git a/modules/format/format.js b/modules/format/format.js index 005c10ec..7842c6bd 100644 --- a/modules/format/format.js +++ b/modules/format/format.js @@ -1,3 +1,4 @@ +'use strict'; /** * A replacement utility for internationalization very similar to sprintf. diff --git a/modules/format/test/formatSpec.js b/modules/format/test/formatSpec.js index 9ca86c2d..6068d1b9 100644 --- a/modules/format/test/formatSpec.js +++ b/modules/format/test/formatSpec.js @@ -1,4 +1,6 @@ describe('format', function() { + 'use strict'; + var formatFilter; beforeEach(module('ui.format')); @@ -30,4 +32,4 @@ describe('format', function() { it('should do nothing if tokens are undefined', function() { expect(formatFilter('Hello There')).toEqual('Hello There'); }); -}); \ No newline at end of file +}); diff --git a/modules/highlight/highlight.js b/modules/highlight/highlight.js index b799018d..e00d51b8 100644 --- a/modules/highlight/highlight.js +++ b/modules/highlight/highlight.js @@ -1,3 +1,5 @@ +'use strict'; + /** * Wraps the * @param text {string} haystack to search through diff --git a/modules/highlight/test/highlightSpec.js b/modules/highlight/test/highlightSpec.js index fd234f17..205a98e2 100644 --- a/modules/highlight/test/highlightSpec.js +++ b/modules/highlight/test/highlightSpec.js @@ -1,4 +1,6 @@ describe('highlight', function () { + 'use strict'; + var highlightFilter, testPhrase = 'Prefix Highlight Suffix'; beforeEach(module('ui.highlight')); @@ -45,4 +47,4 @@ describe('highlight', function () { it('should highlight nothing if empty filter string passed - issue #114', function () { expect(highlightFilter(testPhrase, '')).toEqual(testPhrase); }); -}); \ No newline at end of file +}); diff --git a/modules/ie-shiv/ie-shiv.js b/modules/ie-shiv/ie-shiv.js index 17ce3eff..a077f37d 100644 --- a/modules/ie-shiv/ie-shiv.js +++ b/modules/ie-shiv/ie-shiv.js @@ -13,9 +13,9 @@ // (function (window, document) { + "use strict"; - var debug = window.ieShivDebug || false, - tags = [ "ngInclude", "ngPluralize", "ngView", "ngSwitch", "uiCurrency", "uiCodemirror", "uiDate", "uiEvent", + var tags = [ "ngInclude", "ngPluralize", "ngView", "ngSwitch", "uiCurrency", "uiCodemirror", "uiDate", "uiEvent", "uiKeypress", "uiKeyup", "uiKeydown", "uiMask", "uiMapInfoWindow", "uiMapMarker", "uiMapPolyline", "uiMapPolygon", "uiMapRectangle", "uiMapCircle", "uiMapGroundOverlay", "uiModal", "uiReset", "uiScrollfix", "uiSelect2", "uiShow", "uiHide", "uiToggle", "uiSortable", "uiTinymce" @@ -29,7 +29,7 @@ var dashed = str.replace(/([A-Z])/g, function ($1) { return " " + $1.toLowerCase(); }); - var tokens = dashed.split(' '); + var tokens = dashed.split(" "); // If a token is just a single name (i.e. no namespace) then we juse define the elements the name given if (tokens.length === 1) { @@ -40,7 +40,7 @@ result.push("data-" + name); } else { var ns = tokens[0]; - var dirname = tokens.slice(1).join('-'); + var dirname = tokens.slice(1).join("-"); // this is finite list and it seemed senseless to create a custom method result.push(ns + ":" + dirname); diff --git a/modules/include/demo/index.html b/modules/include/demo/index.html index 5c17d919..f0e83c76 100644 --- a/modules/include/demo/index.html +++ b/modules/include/demo/index.html @@ -40,7 +40,7 @@

Demo


Fragment content (fragment="'{{uiIncludeFragment}}'"):
- +
diff --git a/modules/include/include.js b/modules/include/include.js index e7cb0048..445fccd0 100644 --- a/modules/include/include.js +++ b/modules/include/include.js @@ -1,3 +1,5 @@ +'use strict'; + // modeled after: angular-1.0.7/src/ng/directive/ngInclude.js angular.module('ui.include',[]) .directive('uiInclude', ['$http', '$templateCache', '$anchorScroll', '$compile', diff --git a/modules/include/test/includeSpec.js b/modules/include/test/includeSpec.js index 3196ba2f..95b0b142 100644 --- a/modules/include/test/includeSpec.js +++ b/modules/include/test/includeSpec.js @@ -1,5 +1,7 @@ // modeled after: angular.js/test/ng/directive/ngIncludeSpec.js describe('uiInclude', function() { + 'use strict'; + var scope, $compile, $templateCache, element; afterEach(function() { @@ -20,14 +22,14 @@ describe('uiInclude', function() { it('should include on external file', function () { putIntoCache('myUrl', '{{name}}'); element = $compile('
')(scope); - scope.$apply("name = 'misko'"); + scope.$apply('name = "misko"'); expect(element.text()).toEqual('misko'); }); it('should work with a fragment selector', function () { putIntoCache('myUrl', 'foo {{name}}bar {{name}}baz {{name}}'); element = $compile('
')(scope); - scope.$apply("name = 'misko'"); + scope.$apply('name = "misko"'); expect(element.text()).toEqual('bar misko'); }); diff --git a/modules/indeterminate/indeterminate.js b/modules/indeterminate/indeterminate.js index f466a3fb..797ed4a2 100644 --- a/modules/indeterminate/indeterminate.js +++ b/modules/indeterminate/indeterminate.js @@ -1,3 +1,5 @@ +'use strict'; + /** * Provides an easy way to toggle a checkboxes indeterminate property * @@ -12,7 +14,7 @@ angular.module('ui.indeterminate',[]).directive('uiIndeterminate', [ } return function ($scope, elm, attrs) { - $scope.$watch(attrs.uiIndeterminate, function(newVal, oldVal) { + $scope.$watch(attrs.uiIndeterminate, function(newVal) { elm[0].indeterminate = !!newVal; }); }; diff --git a/modules/indeterminate/test/indeterminateSpec.js b/modules/indeterminate/test/indeterminateSpec.js index 4e4b3231..88c4ea2c 100644 --- a/modules/indeterminate/test/indeterminateSpec.js +++ b/modules/indeterminate/test/indeterminateSpec.js @@ -1,5 +1,7 @@ describe('uiIndeterminate', function () { - var $scope, $compile; + 'use strict'; + + var $scope, $compile, elm; beforeEach(module('ui.indeterminate')); beforeEach(inject(function (_$rootScope_, _$compile_) { @@ -28,4 +30,4 @@ describe('uiIndeterminate', function () { $scope.$apply(); expect(elm[0].indeterminate).toBeFalsy(); }); -}); \ No newline at end of file +}); diff --git a/modules/inflector/inflector.js b/modules/inflector/inflector.js index 3ea6ceed..1345cd63 100644 --- a/modules/inflector/inflector.js +++ b/modules/inflector/inflector.js @@ -1,3 +1,5 @@ +'use strict'; + /** * Converts variable-esque naming conventions to something presentational, capitalized words separated by space. * @param {String} value The value to be parsed and prettified. @@ -33,7 +35,7 @@ angular.module('ui.inflector',[]).filter('inflector', function () { } }; - return function (text, inflector, separator) { + return function (text, inflector) { if (inflector !== false && angular.isString(text)) { inflector = inflector || 'humanize'; return inflectors[inflector](text); diff --git a/modules/inflector/test/inflectorSpec.js b/modules/inflector/test/inflectorSpec.js index a4ea1e19..6ee890e2 100644 --- a/modules/inflector/test/inflectorSpec.js +++ b/modules/inflector/test/inflectorSpec.js @@ -1,4 +1,6 @@ describe('inflector', function () { + 'use strict'; + var inflectorFilter, testPhrase = 'here isMy_phone_number'; beforeEach(module('ui.inflector')); @@ -33,7 +35,7 @@ describe('inflector', function () { expect(inflectorFilter(testPhrase, 'variable')).toEqual('hereIsMyPhoneNumber'); }); it('should do nothing if already formatted properly', function () { - expect(inflectorFilter("hereIsMyPhoneNumber", 'variable')).toEqual('hereIsMyPhoneNumber'); + expect(inflectorFilter('hereIsMyPhoneNumber', 'variable')).toEqual('hereIsMyPhoneNumber'); }); }); -}); \ No newline at end of file +}); diff --git a/modules/jq/jq.js b/modules/jq/jq.js index 958060bf..6584a2b8 100644 --- a/modules/jq/jq.js +++ b/modules/jq/jq.js @@ -1,3 +1,5 @@ +'use strict'; + /** * General-purpose jQuery wrapper. Simply pass the plugin name as the expression. * @@ -55,7 +57,7 @@ angular.module('ui.jq',[]). // If ui-refresh is used, re-fire the the method upon every change if (attrs.uiRefresh) { - scope.$watch(attrs.uiRefresh, function(newVal) { + scope.$watch(attrs.uiRefresh, function() { callPlugin(); }); } diff --git a/modules/jq/test/jqSpec.js b/modules/jq/test/jqSpec.js index 04795f0e..05bfe01e 100644 --- a/modules/jq/test/jqSpec.js +++ b/modules/jq/test/jqSpec.js @@ -1,4 +1,6 @@ describe('uiJq', function () { + 'use strict'; + var scope, compile, timeout; scope = null; beforeEach(module('ui.jq')); @@ -18,14 +20,14 @@ describe('uiJq', function () { describe('function or plugin isn\'t found', function () { it('should throw an error', function () { expect(function () { - compile("
")(scope); + compile('
')(scope); }).toThrow(); }); }); describe('calling a jQuery element function', function () { it('should just like, sort of work and junk', function () { spyOn(jQuery.fn, 'foo'); - compile("
")(scope); + compile('
')(scope); timeout.flush(); expect(jQuery.fn.foo).toHaveBeenCalled(); }); @@ -36,7 +38,7 @@ describe('uiJq', function () { // console.log(length); }; scope.$apply('items=[1, 2]'); - compile("")(scope); + compile('')(scope); scope.$apply(); timeout.flush(); expect(length).toBe(2); diff --git a/modules/keypress/keypress.js b/modules/keypress/keypress.js index 52378e2f..22cd9207 100644 --- a/modules/keypress/keypress.js +++ b/modules/keypress/keypress.js @@ -1,3 +1,5 @@ +'use strict'; + angular.module('ui.keypress',[]). factory('keypressHelper', ['$parse', function keypress($parse){ var keysByCode = { @@ -111,4 +113,4 @@ angular.module('ui.keypress').directive('uiKeyup', ['keypressHelper', function(k keypressHelper('keyup', scope, elm, attrs); } }; -}]); \ No newline at end of file +}]); diff --git a/modules/keypress/test/keydownSpec.js b/modules/keypress/test/keydownSpec.js index 51a0806a..5b3851a4 100644 --- a/modules/keypress/test/keydownSpec.js +++ b/modules/keypress/test/keydownSpec.js @@ -1,9 +1,10 @@ describe('uiKeydown', function () { + 'use strict'; var $scope, $compile; var createKeyEvent = function (mainKey, alt, ctrl, shift, meta) { - var keyEvent = jQuery.Event("keydown"); + var keyEvent = jQuery.Event('keydown'); keyEvent.keyCode = mainKey; keyEvent.altKey = alt; @@ -16,7 +17,7 @@ describe('uiKeydown', function () { var createElement = function (elementDef) { var elementStr = angular.isString(elementDef) ? elementDef : angular.toJson(elementDef); - return $compile("")($scope); + return $compile('')($scope); }; beforeEach(module('ui.keypress')); @@ -38,7 +39,7 @@ describe('uiKeydown', function () { createElement({'ctrl-shift-13': 'event=true'}).trigger(createKeyEvent(13, false, true, true, false)); expect($scope.event).toBe(true); }); - + it('should support alternative combinations', function () { $scope.event = 0; createElement({'ctrl-shift-14 ctrl-shift-13': 'event=event+1'}).trigger(createKeyEvent(13, false, true, true, false)).trigger(createKeyEvent(14, false, true, true, false)); @@ -72,4 +73,4 @@ describe('uiKeydown', function () { element.trigger(createKeyEvent(13)); expect($scope.event2.keyCode).toBe(13); }); -}); \ No newline at end of file +}); diff --git a/modules/keypress/test/keypressSpec.js b/modules/keypress/test/keypressSpec.js index daea9d91..32244377 100644 --- a/modules/keypress/test/keypressSpec.js +++ b/modules/keypress/test/keypressSpec.js @@ -1,10 +1,10 @@ - describe('uiKeypress', function () { + 'use strict'; var $scope, $compile; var createKeyEvent = function (mainKey, alt, ctrl, shift, meta) { - var keyEvent = jQuery.Event("keypress"); + var keyEvent = jQuery.Event('keypress'); keyEvent.keyCode = mainKey; keyEvent.altKey = alt; @@ -17,7 +17,7 @@ describe('uiKeypress', function () { var createElement = function (elementDef) { var elementStr = angular.isString(elementDef) ? elementDef : angular.toJson(elementDef); - return $compile("")($scope); + return $compile('')($scope); }; beforeEach(module('ui.keypress')); @@ -39,7 +39,7 @@ describe('uiKeypress', function () { createElement({'ctrl-shift-13': 'event=true'}).trigger(createKeyEvent(13, false, true, true, false)); expect($scope.event).toBe(true); }); - + it('should support alternative combinations', function () { $scope.event = 0; createElement({'ctrl-shift-14 ctrl-shift-13': 'event=event+1'}).trigger(createKeyEvent(13, false, true, true, false)).trigger(createKeyEvent(14, false, true, true, false)); @@ -73,4 +73,4 @@ describe('uiKeypress', function () { element.trigger(createKeyEvent(13)); expect($scope.event2.keyCode).toBe(13); }); -}); \ No newline at end of file +}); diff --git a/modules/keypress/test/keyupSpec.js b/modules/keypress/test/keyupSpec.js index 5c104451..56faa174 100644 --- a/modules/keypress/test/keyupSpec.js +++ b/modules/keypress/test/keyupSpec.js @@ -1,9 +1,10 @@ describe('uiKeyup', function () { + 'use strict'; var $scope, $compile; var createKeyEvent = function (mainKey, alt, ctrl, shift, meta) { - var keyEvent = jQuery.Event("keyup"); + var keyEvent = jQuery.Event('keyup'); keyEvent.keyCode = mainKey; keyEvent.altKey = alt; @@ -16,7 +17,7 @@ describe('uiKeyup', function () { var createElement = function (elementDef) { var elementStr = angular.isString(elementDef) ? elementDef : angular.toJson(elementDef); - return $compile("")($scope); + return $compile('')($scope); }; beforeEach(module('ui.keypress')); @@ -38,7 +39,7 @@ describe('uiKeyup', function () { createElement({'ctrl-shift-13': 'event=true'}).trigger(createKeyEvent(13, false, true, true, false)); expect($scope.event).toBe(true); }); - + it('should support alternative combinations', function () { $scope.event = 0; createElement({'ctrl-shift-14 ctrl-shift-13': 'event=event+1'}).trigger(createKeyEvent(13, false, true, true, false)).trigger(createKeyEvent(14, false, true, true, false)); @@ -72,4 +73,4 @@ describe('uiKeyup', function () { element.trigger(createKeyEvent(13)); expect($scope.event2.keyCode).toBe(13); }); -}); \ No newline at end of file +}); diff --git a/modules/mask/mask.js b/modules/mask/mask.js index 4bc0099d..dfafa12c 100644 --- a/modules/mask/mask.js +++ b/modules/mask/mask.js @@ -1,3 +1,5 @@ +'use strict'; + /* Attaches input mask onto input element */ @@ -213,10 +215,10 @@ angular.module('ui.mask', []) function getPlaceholderChar(i) { var placeholder = iAttrs.placeholder; - if (typeof placeholder !== "undefined" && placeholder[i]) { + if (typeof placeholder !== 'undefined' && placeholder[i]) { return placeholder[i]; } else { - return "_"; + return '_'; } } @@ -243,7 +245,7 @@ angular.module('ui.mask', []) minRequiredLength = 0; var isOptional = false, - splitMask = mask.split(""); + splitMask = mask.split(''); angular.forEach(splitMask, function (chr, i){ if (linkOptions.maskDefinitions[chr]) { @@ -258,7 +260,7 @@ angular.module('ui.mask', []) minRequiredLength++; } } - else if (chr === "?") { + else if (chr === '?') { isOptional = true; } else { @@ -297,11 +299,13 @@ angular.module('ui.mask', []) iElement.bind('mousedown mouseup', mouseDownUpHandler); function mouseoutHandler(){ + /*jshint validthis: true */ oldSelectionLength = getSelectionLength(this); iElement.unbind('mouseout', mouseoutHandler); } function eventHandler(e){ + /*jshint validthis: true */ e = e || {}; // Allows more efficient minification var eventWhich = e.which, @@ -412,6 +416,7 @@ angular.module('ui.mask', []) function isValidCaretPosition(pos){ return maskCaretMap.indexOf(pos) > -1; } function getCaretPosition(input){ + if (!input) return 0; if (input.selectionStart !== undefined) { return input.selectionStart; } else if (document.selection) { @@ -425,6 +430,7 @@ angular.module('ui.mask', []) } function setCaretPosition(input, pos){ + if (!input) return 0; if (input.offsetWidth === 0 || input.offsetHeight === 0) { return; // Input's hidden } @@ -443,6 +449,7 @@ angular.module('ui.mask', []) } function getSelectionLength(input){ + if (!input) return 0; if (input.selectionStart !== undefined) { return (input.selectionEnd - input.selectionStart); } @@ -455,7 +462,6 @@ angular.module('ui.mask', []) // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/indexOf if (!Array.prototype.indexOf) { Array.prototype.indexOf = function (searchElement /*, fromIndex */){ - "use strict"; if (this === null) { throw new TypeError(); } diff --git a/modules/mask/test/maskSpec.js b/modules/mask/test/maskSpec.js index c15b498e..1f469070 100644 --- a/modules/mask/test/maskSpec.js +++ b/modules/mask/test/maskSpec.js @@ -1,12 +1,12 @@ -describe('uiMask', function () { +describe("uiMask", function () { + "use strict"; var formHtml = "
"; var inputHtml = ""; var compileElement, scope, config; - beforeEach(module('ui.mask')); + beforeEach(module("ui.mask")); beforeEach(inject(function ($rootScope, $compile, uiMaskConfig) { - c = console.log; scope = $rootScope; config = uiMaskConfig; compileElement = function(html) { @@ -14,145 +14,142 @@ describe('uiMask', function () { }; })); - describe('initialization', function () { + describe("initialization", function () { it("should not not happen if the mask is undefined or invalid", function() { var input = compileElement(inputHtml); scope.$apply("x = 'abc123'"); - expect(input.val()).toBe('abc123'); + expect(input.val()).toBe("abc123"); scope.$apply("mask = '()_abc123'"); - expect(input.val()).toBe('abc123'); + expect(input.val()).toBe("abc123"); }); it("should mask the value only if it's valid", function() { var input = compileElement(inputHtml); scope.$apply("x = 'abc123'"); scope.$apply("mask = '(A) * 9'"); - expect(input.val()).toBe('(a) b 1'); + expect(input.val()).toBe("(a) b 1"); scope.$apply("mask = '(A) * 9 A'"); - expect(input.val()).toBe(''); + expect(input.val()).toBe(""); }); it("should not dirty or invalidate the input", function() { var input = compileElement(inputHtml); scope.$apply("x = 'abc123'"); scope.$apply("mask = '(9) * A'"); - expect(input.hasClass('ng-pristine ng-valid')).toBeTruthy(); + expect(input.hasClass("ng-pristine ng-valid")).toBeTruthy(); scope.$apply("mask = '(9) * A 9'"); - expect(input.hasClass('ng-pristine ng-valid')).toBeTruthy(); + expect(input.hasClass("ng-pristine ng-valid")).toBeTruthy(); }); it("should not change the model value", function() { - var input = compileElement(inputHtml); scope.$apply("x = 'abc123'"); scope.$apply("mask = '(A) * 9'"); - expect(scope.x).toBe('abc123'); + expect(scope.x).toBe("abc123"); scope.$apply("mask = '(A) * 9 A'"); - expect(scope.x).toBe('abc123'); + expect(scope.x).toBe("abc123"); }); it("should set ngModelController.$viewValue to match input value", function() { - var form = compileElement(formHtml); - var input = form.find('input'); + compileElement(formHtml); scope.$apply("x = 'abc123'"); scope.$apply("mask = '(A) * 9'"); - expect(scope.test.input.$viewValue).toBe('(a) b 1'); + expect(scope.test.input.$viewValue).toBe("(a) b 1"); scope.$apply("mask = '(A) * 9 A'"); - expect(scope.test.input.$viewValue).toBe(''); + expect(scope.test.input.$viewValue).toBe(""); }); }); - describe('user input', function () { + describe("user input", function () { it("should mask-as-you-type", function() { var form = compileElement(formHtml); - var input = form.find('input'); + var input = form.find("input"); scope.$apply("x = ''"); scope.$apply("mask = '(A) * 9'"); - input.val('a').triggerHandler('input'); - expect(input.val()).toBe('(a) _ _'); - input.val('ab').triggerHandler('input'); - expect(input.val()).toBe('(a) b _'); - input.val('ab1').triggerHandler('input'); - expect(input.val()).toBe('(a) b 1'); + input.val("a").triggerHandler("input"); + expect(input.val()).toBe("(a) _ _"); + input.val("ab").triggerHandler("input"); + expect(input.val()).toBe("(a) b _"); + input.val("ab1").triggerHandler("input"); + expect(input.val()).toBe("(a) b 1"); }); it("should set ngModelController.$viewValue to match input value", function() { var form = compileElement(formHtml); - var input = form.find('input'); + var input = form.find("input"); scope.$apply("x = ''"); scope.$apply("mask = '(A) * 9'"); - input.val('a').triggerHandler('input'); - input.triggerHandler('change'); // Because IE8 and below are terrible - expect(scope.test.input.$viewValue).toBe('(a) _ _'); + input.val("a").triggerHandler("input"); + input.triggerHandler("change"); // Because IE8 and below are terrible + expect(scope.test.input.$viewValue).toBe("(a) _ _"); }); it("should parse unmasked value to model", function() { var form = compileElement(formHtml); - var input = form.find('input'); + var input = form.find("input"); scope.$apply("x = ''"); scope.$apply("mask = '(A) * 9'"); - input.val('abc123').triggerHandler('input'); - input.triggerHandler('change'); // Because IE8 and below are terrible - expect(scope.x).toBe('ab1'); + input.val("abc123").triggerHandler("input"); + input.triggerHandler("change"); // Because IE8 and below are terrible + expect(scope.x).toBe("ab1"); }); it("should set model to undefined if masked value is invalid", function() { var form = compileElement(formHtml); - var input = form.find('input'); + var input = form.find("input"); scope.$apply("x = ''"); scope.$apply("mask = '(A) * 9'"); - input.val('a').triggerHandler('input'); - input.triggerHandler('change'); // Because IE8 and below are terrible + input.val("a").triggerHandler("input"); + input.triggerHandler("change"); // Because IE8 and below are terrible expect(scope.x).toBeUndefined(); }); it("should not set model to an empty mask", function() { var form = compileElement(formHtml); - var input = form.find('input'); + var input = form.find("input"); scope.$apply("x = ''"); scope.$apply("mask = '(A) * 9'"); - input.triggerHandler('input'); - expect(scope.x).toBe(''); + input.triggerHandler("input"); + expect(scope.x).toBe(""); }); }); - describe('changes from the model', function () { + describe("changes from the model", function () { it("should set the correct ngModelController.$viewValue", function() { - var form = compileElement(formHtml); - var input = form.find('input'); + compileElement(formHtml); scope.$apply("mask = '(A) * 9'"); scope.$apply("x = ''"); expect(scope.test.input.$viewValue).not.toBeDefined(); scope.$apply("x = 'abc'"); expect(scope.test.input.$viewValue).not.toBeDefined(); scope.$apply("x = 'abc123'"); - expect(scope.test.input.$viewValue).toBe('(a) b 1'); + expect(scope.test.input.$viewValue).toBe("(a) b 1"); }); }); - describe('default mask definitions', function () { + describe("default mask definitions", function () { it("should accept optional mask after '?'", function (){ var input = compileElement(inputHtml); scope.$apply("x = ''"); scope.$apply("mask = '**?9'"); - input.val('aa').triggerHandler('input'); - input.triggerHandler('blur'); - expect(input.val()).toBe('aa_'); + input.val("aa").triggerHandler("input"); + input.triggerHandler("blur"); + expect(input.val()).toBe("aa_"); - input.val('99a').triggerHandler('input'); - input.triggerHandler('blur'); - expect(input.val()).toBe('99_'); + input.val("99a").triggerHandler("input"); + input.triggerHandler("blur"); + expect(input.val()).toBe("99_"); - input.val('992').triggerHandler('input'); - input.triggerHandler('blur'); - expect(input.val()).toBe('992'); + input.val("992").triggerHandler("input"); + input.triggerHandler("blur"); + expect(input.val()).toBe("992"); }); }); - describe('placeholders', function () { + describe("placeholders", function () { it("should have default placeholder functionality", function() { var input = compileElement(inputHtml); @@ -174,7 +171,7 @@ describe('uiMask', function () { input.val("12").triggerHandler("input"); - expect(input.val()).toBe('12/DD/YYYY'); + expect(input.val()).toBe("12/DD/YYYY"); }); it("should update mask substitutions via the placeholder attribute", function() { @@ -200,53 +197,53 @@ describe('uiMask', function () { }); - describe('configuration', function () { + describe("configuration", function () { it("should accept the new mask definition set globally", function() { - config.maskDefinitions['@'] = /[fz]/; + config.maskDefinitions["@"] = /[fz]/; var input = compileElement(inputHtml); scope.$apply("x = ''"); scope.$apply("mask = '@193'"); - input.val('f123').triggerHandler('input'); - input.triggerHandler('blur'); - expect(input.val()).toBe('f123'); + input.val("f123").triggerHandler("input"); + input.triggerHandler("blur"); + expect(input.val()).toBe("f123"); }); it("should accept the new mask definition set per element", function() { - delete config.maskDefinitions['@']; + delete config.maskDefinitions["@"]; scope.input = { - options: {maskDefinitions: {'@': /[fz]/}} + options: {maskDefinitions: {"@": /[fz]/}} }; - var input = compileElement(''); + var input = compileElement(""); scope.$apply("x = ''"); scope.$apply("mask = '@999'"); - input.val('f111').triggerHandler('input'); - input.triggerHandler('blur'); - expect(input.val()).toBe('f111'); + input.val("f111").triggerHandler("input"); + input.triggerHandler("blur"); + expect(input.val()).toBe("f111"); }); }); - describe('blurring', function () { + describe("blurring", function () { it("should clear an invalid value from the input", function() { var input = compileElement(inputHtml); scope.$apply("x = ''"); scope.$apply("mask = '(9) * A'"); - input.val('a').triggerHandler('input'); - input.triggerHandler('blur'); - expect(input.val()).toBe(''); + input.val("a").triggerHandler("input"); + input.triggerHandler("blur"); + expect(input.val()).toBe(""); }); it("should clear an invalid value from the ngModelController.$viewValue", function() { var form = compileElement(formHtml); - var input = form.find('input'); + var input = form.find("input"); scope.$apply("x = ''"); scope.$apply("mask = '(A) * 9'"); - input.val('a').triggerHandler('input'); - input.triggerHandler('blur'); - expect(scope.test.input.$viewValue).toBe(''); + input.val("a").triggerHandler("input"); + input.triggerHandler("blur"); + expect(scope.test.input.$viewValue).toBe(""); }); }); diff --git a/modules/reset/reset.js b/modules/reset/reset.js index 6d2c393d..5ea88d85 100755 --- a/modules/reset/reset.js +++ b/modules/reset/reset.js @@ -1,3 +1,5 @@ +'use strict'; + /** * Add a clear button to form inputs to reset their value */ diff --git a/modules/reset/test/resetSpec.js b/modules/reset/test/resetSpec.js index f59b8f8f..3ff9fd5e 100755 --- a/modules/reset/test/resetSpec.js +++ b/modules/reset/test/resetSpec.js @@ -4,7 +4,7 @@ describe('uiReset', function () { var scope, $compile; beforeEach(module('ui.reset')); - beforeEach(inject(function (_$rootScope_, _$compile_, _$window_) { + beforeEach(inject(function (_$rootScope_, _$compile_) { scope = _$rootScope_.$new(); $compile = _$compile_; })); @@ -52,4 +52,4 @@ describe('uiReset', function () { expect(element.val()).toBe('i was reset'); }); }); -}); \ No newline at end of file +}); diff --git a/modules/route/route.js b/modules/route/route.js index 3dbca39f..d0ae049f 100644 --- a/modules/route/route.js +++ b/modules/route/route.js @@ -1,3 +1,5 @@ +'use strict'; + /** * Set a $uiRoute boolean to see if the current route matches */ @@ -69,7 +71,7 @@ angular.module('ui.route', []).directive('uiRoute', ['$location', '$parse', func $scope.$on('$routeChangeSuccess', function(){ watcher(); }); - + //Added for compatibility with ui-router $scope.$on('$stateChangeSuccess', function(){ watcher(); diff --git a/modules/route/test/routeSpec.js b/modules/route/test/routeSpec.js index fa2c2af4..ab062173 100644 --- a/modules/route/test/routeSpec.js +++ b/modules/route/test/routeSpec.js @@ -1,10 +1,9 @@ -/*global describe, beforeEach, module, inject, it, spyOn, expect, $ */ describe('uiRoute', function () { 'use strict'; var scope, $compile, $location; beforeEach(module('ui.route')); - beforeEach(inject(function (_$rootScope_, _$compile_, _$window_, _$location_) { + beforeEach(inject(function (_$rootScope_, _$compile_, _$location_) { scope = _$rootScope_.$new(); $compile = _$compile_; $location = _$location_; @@ -36,7 +35,7 @@ describe('uiRoute', function () { if (routeModel){ elm.attr('ng-model', routeModel);} return $compile(elm[0])(scope); } - + describe('with uiRoute defined', function(){ it('should use the uiRoute property', function(){ compileRoute('
'); diff --git a/modules/scroll/test/ScrollerSpec.js b/modules/scroll/test/ScrollerSpec.js index 6c8f9973..aa327078 100644 --- a/modules/scroll/test/ScrollerSpec.js +++ b/modules/scroll/test/ScrollerSpec.js @@ -4,9 +4,8 @@ describe('uiScroll', function () { angular.module('ui.scroll.test', []) .factory('myEmptyDatasource', [ - '$log', '$timeout', '$rootScope', function(console, $timeout, $rootScope) { - var current, get, loading, revision; - get = function(index, count, success) { + function() { + var get = function(index, count, success) { success([]); }; @@ -17,9 +16,8 @@ describe('uiScroll', function () { ]) .factory('myOnePageDatasource', [ - '$log', '$timeout', '$rootScope', function(console, $timeout, $rootScope) { - var current, get, loading, revision; - get = function(index, count, success) { + function() { + var get = function(index, count, success) { if (index === 1) { success(['one', 'two', 'three']); } else { @@ -34,9 +32,8 @@ describe('uiScroll', function () { ]) .factory('myMultipageDatasource', [ - '$log', '$timeout', '$rootScope', function(console, $timeout, $rootScope) { - var current, get, loading, revision; - get = function(index, count, success) { + function() { + var get = function(index, count, success) { var result = []; for (var i = index; i0 && i<=20) { @@ -52,8 +49,6 @@ describe('uiScroll', function () { } ]); - var sandbox = angular.element('
'); - beforeEach(module('ui.scroll')); beforeEach(module('ui.scroll.test')); @@ -209,7 +204,7 @@ describe('uiScroll', function () { spy = spyOn(myMultipageDatasource, 'get').andCallThrough(); }); runTest(html, - function($window, sandbox) { + function() { expect(spy.calls.length).toBe(3); expect(spy.calls[0].args[0]).toBe(1); @@ -388,4 +383,4 @@ describe('uiScroll', function () { }); -}); \ No newline at end of file +}); diff --git a/modules/scroll/test/jqliteExtrasSpec.js b/modules/scroll/test/jqliteExtrasSpec.js index 0ef21abd..3d42674f 100644 --- a/modules/scroll/test/jqliteExtrasSpec.js +++ b/modules/scroll/test/jqliteExtrasSpec.js @@ -1,3 +1,4 @@ +/* global $: false*/ describe('\njqLite: testing against jQuery\n', function () { 'use strict'; @@ -93,13 +94,6 @@ describe('\njqLite: testing against jQuery\n', function () { '
some text w line height
' ], function(element) { - function validateHeight(element) { - expect(extras.prototype.height.call(element)).toBe(element.height()); - var h = element.height(); - extras.prototype.height.call(element, h*2); - expect(extras.prototype.height.call(element)).toBe(h*2); - } - it('height(value) for ' + element, function() { (function (element) { expect(extras.prototype.height.call(element)).toBe(element.height()); @@ -182,4 +176,4 @@ describe('\njqLite: testing against jQuery\n', function () { }); -}); \ No newline at end of file +}); diff --git a/modules/scroll/ui-scroll-jqlite.js b/modules/scroll/ui-scroll-jqlite.js index 932091e3..29bc5120 100644 --- a/modules/scroll/ui-scroll-jqlite.js +++ b/modules/scroll/ui-scroll-jqlite.js @@ -1,3 +1,4 @@ +'use strict'; angular.module('ui.scroll.jqlite', ['ui.scroll']).service('jqLiteExtras', [ '$log', '$window', function(console, window) { @@ -55,7 +56,7 @@ angular.module('ui.scroll.jqlite', ['ui.scroll']).service('jqLiteExtras', [ convertToPx = function(elem, value) { var core_pnum, left, result, rnumnonpx, rs, rsLeft, style; core_pnum = /[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source; - rnumnonpx = new RegExp("^(" + core_pnum + ")(?!px)[a-z%]+$", "i"); + rnumnonpx = new RegExp('^(' + core_pnum + ')(?!px)[a-z%]+$', 'i'); if (!rnumnonpx.test(value)) { return parseFloat(value); } else { @@ -174,7 +175,8 @@ angular.module('ui.scroll.jqlite', ['ui.scroll']).service('jqLiteExtras', [ if (value === void 0) { return self; } else { - return setOffset; + return value; + } } box = { @@ -187,7 +189,7 @@ angular.module('ui.scroll.jqlite', ['ui.scroll']).service('jqLiteExtras', [ return; } docElem = doc.documentElement; - if (elem.getBoundingClientRect != null) { + if (elem.getBoundingClientRect) { box = elem.getBoundingClientRect(); } win = doc.defaultView || doc.parentWindow; diff --git a/modules/scroll/ui-scroll.js b/modules/scroll/ui-scroll.js index a33f7c66..1c2f625b 100644 --- a/modules/scroll/ui-scroll.js +++ b/modules/scroll/ui-scroll.js @@ -1,5 +1,5 @@ +'use strict'; /* - globals: angular, window List of used element methods available in JQuery but not in JQuery Lite @@ -12,7 +12,7 @@ */ angular.module('ui.scroll', []).directive('ngScrollViewport', [ - '$log', function(console) { + '$log', function() { return { controller: [ '$scope', '$element', function(scope, element) { @@ -33,7 +33,7 @@ angular.module('ui.scroll', []).directive('ngScrollViewport', [ var adapter, adjustBuffer, adjustRowHeight, bof, bottomVisiblePos, buffer, bufferPadding, bufferSize, clipBottom, clipTop, datasource, datasourceName, enqueueFetch, eof, eventListener, fetch, finalize, first, insert, isDatasource, isLoading, itemName, loading, match, next, pending, reload, removeFromBuffer, resizeHandler, scrollHandler, scrollHeight, shouldLoadBottom, shouldLoadTop, tempScope, topVisiblePos, viewport; match = $attr.ngScroll.match(/^\s*(\w+)\s+in\s+(\w+)\s*$/); if (!match) { - throw new Error("Expected ngScroll in form of '_item_ in _datasource_' but got '" + $attr.ngScroll + "'"); + throw new Error('Expected ngScroll in form of "item_ in _datasource_" but got "' + $attr.ngScroll + '"'); } itemName = match[1]; datasourceName = match[2]; @@ -44,7 +44,7 @@ angular.module('ui.scroll', []).directive('ngScrollViewport', [ if (!isDatasource(datasource)) { datasource = $injector.get(datasourceName); if (!isDatasource(datasource)) { - throw new Error("" + datasourceName + " is not a valid datasource"); + throw new Error(datasourceName + ' is not a valid datasource'); } } bufferSize = Math.max(3, +$attr.bufferSize || 10); @@ -52,15 +52,14 @@ angular.module('ui.scroll', []).directive('ngScrollViewport', [ return viewport.height() * Math.max(0.1, +$attr.padding || 0.1); }; scrollHeight = function(elem) { - var _ref; - return (_ref = elem[0].scrollHeight) != null ? _ref : elem[0].document.documentElement.scrollHeight; + return elem[0].scrollHeight || elem[0].document.documentElement.scrollHeight; }; adapter = null; linker(tempScope = $scope.$new(), function(template) { var bottomPadding, createPadding, padding, repeaterType, topPadding, viewport; repeaterType = template[0].localName; if (repeaterType === 'dl') { - throw new Error("ng-scroll directive does not support <" + template[0].localName + "> as a repeating tag: " + template[0].outerHTML); + throw new Error('ng-scroll directive does not support <' + template[0].localName + '> as a repeating tag: ' + template[0].outerHTML); } if (repeaterType !== 'li' && repeaterType !== 'tr') { repeaterType = 'div'; @@ -82,7 +81,7 @@ angular.module('ui.scroll', []).directive('ngScrollViewport', [ }; return result; default: - result = angular.element("<" + repeaterType + ">"); + result = angular.element('<' + repeaterType + '>'); result.paddingHeight = result.height; return result; } @@ -128,7 +127,7 @@ angular.module('ui.scroll', []).directive('ngScrollViewport', [ pending = []; eof = false; bof = false; - loading = datasource.loading || function(value) {}; + loading = datasource.loading || function() {}; isLoading = false; removeFromBuffer = function(start, stop) { var i, _i; @@ -176,7 +175,7 @@ angular.module('ui.scroll', []).directive('ngScrollViewport', [ adapter.bottomPadding(adapter.bottomPadding() + bottomHeight); removeFromBuffer(buffer.length - overage, buffer.length); next -= overage; - return console.log("clipped off bottom " + overage + " bottom padding " + (adapter.bottomPadding())); + return console.log('clipped off bottom ' + overage + ' bottom padding ' + (adapter.bottomPadding())); } }; shouldLoadTop = function() { @@ -201,7 +200,7 @@ angular.module('ui.scroll', []).directive('ngScrollViewport', [ adapter.topPadding(adapter.topPadding() + topHeight); removeFromBuffer(0, overage); first += overage; - return console.log("clipped off top " + overage + " top padding " + (adapter.topPadding())); + return console.log('clipped off top ' + overage + ' top padding ' + (adapter.topPadding())); } }; enqueueFetch = function(direction, scrolling) { @@ -261,7 +260,7 @@ angular.module('ui.scroll', []).directive('ngScrollViewport', [ adjustBuffer = function(scrolling, newItems, finalize) { var doAdjustment; doAdjustment = function() { - console.log("top {actual=" + (adapter.topDataPos()) + " visible from=" + (topVisiblePos()) + " bottom {visible through=" + (bottomVisiblePos()) + " actual=" + (adapter.bottomDataPos()) + "}"); + console.log('top {actual=' + (adapter.topDataPos()) + ' visible from=' + (topVisiblePos()) + ' bottom {visible through=' + (bottomVisiblePos()) + ' actual=' + (adapter.bottomDataPos()) + '}'); if (shouldLoadBottom()) { enqueueFetch(true, scrolling); } else { @@ -310,14 +309,14 @@ angular.module('ui.scroll', []).directive('ngScrollViewport', [ if (result.length === 0) { eof = true; adapter.bottomPadding(0); - console.log("appended: requested " + bufferSize + " records starting from " + next + " recieved: eof"); + console.log('appended: requested ' + bufferSize + ' records starting from ' + next + ' recieved: eof'); } else { clipTop(); for (_i = 0, _len = result.length; _i < _len; _i++) { item = result[_i]; newItems.push(insert(++next, item)); } - console.log("appended: requested " + bufferSize + " received " + result.length + " buffer size " + buffer.length + " first " + first + " next " + next); + console.log('appended: requested ' + bufferSize + ' received ' + result.length + ' buffer size ' + buffer.length + ' first ' + first + ' next ' + next); } return finalize(scrolling, newItems); }); @@ -332,13 +331,13 @@ angular.module('ui.scroll', []).directive('ngScrollViewport', [ if (result.length === 0) { bof = true; adapter.topPadding(0); - console.log("prepended: requested " + bufferSize + " records starting from " + (first - bufferSize) + " recieved: bof"); + console.log('prepended: requested ' + bufferSize + ' records starting from ' + (first - bufferSize) + ' recieved: bof'); } else { clipBottom(); for (i = _i = _ref = result.length - 1; _ref <= 0 ? _i <= 0 : _i >= 0; i = _ref <= 0 ? ++_i : --_i) { newItems.unshift(insert(--first, result[i])); } - console.log("prepended: requested " + bufferSize + " received " + result.length + " buffer size " + buffer.length + " first " + first + " next " + next); + console.log('prepended: requested ' + bufferSize + ' received ' + result.length + ' buffer size ' + buffer.length + ' first ' + first + ' next ' + next); } return finalize(scrolling, newItems); }); @@ -372,7 +371,7 @@ angular.module('ui.scroll', []).directive('ngScrollViewport', [ viewport.unbind('resize', resizeHandler); return viewport.unbind('scroll', scrollHandler); }); - eventListener.$on("update.items", function(event, locator, newItem) { + eventListener.$on('update.items', function(event, locator, newItem) { var wrapper, _fn, _i, _len, _ref; if (angular.isFunction(locator)) { _fn = function(wrapper) { @@ -389,7 +388,7 @@ angular.module('ui.scroll', []).directive('ngScrollViewport', [ } return null; }); - eventListener.$on("delete.items", function(event, locator) { + eventListener.$on('delete.items', function(event, locator) { var i, item, temp, wrapper, _fn, _i, _j, _k, _len, _len1, _len2, _ref; if (angular.isFunction(locator)) { temp = []; @@ -419,7 +418,7 @@ angular.module('ui.scroll', []).directive('ngScrollViewport', [ } return adjustBuffer(false); }); - return eventListener.$on("insert.item", function(event, locator, item) { + return eventListener.$on('insert.item', function(event, locator, item) { var i, inserted, temp, wrapper, _fn, _i, _j, _k, _len, _len1, _len2, _ref; inserted = []; if (angular.isFunction(locator)) { @@ -432,13 +431,13 @@ angular.module('ui.scroll', []).directive('ngScrollViewport', [ var j, newItems, _k, _len2, _results; if (newItems = locator(wrapper.scope)) { insert = function(index, newItem) { - insert(index, item); + insert(index, newItem); return next++; }; - if (isArray(newItems)) { + if (angular.isArray(newItems)) { _results = []; - for (j = _k = 0, _len2 = newitems.length; _k < _len2; j = ++_k) { - item = newitems[j]; + for (j = _k = 0, _len2 = newItems.length; _k < _len2; j = ++_k) { + item = newItems[j]; _results.push(inserted.push(insert(i + j, item))); } return _results; diff --git a/modules/scrollfix/scrollfix.js b/modules/scrollfix/scrollfix.js index 647b2710..77be62bd 100644 --- a/modules/scrollfix/scrollfix.js +++ b/modules/scrollfix/scrollfix.js @@ -1,11 +1,11 @@ -/*global angular, $, document*/ +'use strict'; + /** * Adds a 'ui-scrollfix' class to the element when the page scrolls past it's position. * @param [offset] {int} optional Y-offset to override the detected offset. * Takes 300 (absolute) or -300 or +300 (relative to detected) */ angular.module('ui.scrollfix',[]).directive('uiScrollfix', ['$window', function ($window) { - 'use strict'; return { require: '^?uiScrollfixTarget', link: function (scope, elm, attrs, uiScrollfixTarget) { @@ -29,7 +29,7 @@ angular.module('ui.scrollfix',[]).directive('uiScrollfix', ['$window', function if (angular.isDefined($window.pageYOffset)) { offset = $window.pageYOffset; } else { - var iebody = (document.compatMode && document.compatMode !== "BackCompat") ? document.documentElement : document.body; + var iebody = (document.compatMode && document.compatMode !== 'BackCompat') ? document.documentElement : document.body; offset = iebody.scrollTop; } if (!elm.hasClass('ui-scrollfix') && offset > attrs.uiScrollfix) { @@ -48,7 +48,6 @@ angular.module('ui.scrollfix',[]).directive('uiScrollfix', ['$window', function } }; }]).directive('uiScrollfixTarget', [function () { - 'use strict'; return { controller: ['$element', function($element) { this.$element = $element; diff --git a/modules/showhide/showhide.js b/modules/showhide/showhide.js index 683d868e..18e1e96f 100644 --- a/modules/showhide/showhide.js +++ b/modules/showhide/showhide.js @@ -1,3 +1,5 @@ +'use strict'; + /** * uiShow Directive * @@ -9,7 +11,7 @@ angular.module('ui.showhide',[]) .directive('uiShow', [function () { return function (scope, elm, attrs) { - scope.$watch(attrs.uiShow, function (newVal, oldVal) { + scope.$watch(attrs.uiShow, function (newVal) { if (newVal) { elm.addClass('ui-show'); } else { @@ -29,7 +31,7 @@ angular.module('ui.showhide',[]) */ .directive('uiHide', [function () { return function (scope, elm, attrs) { - scope.$watch(attrs.uiHide, function (newVal, oldVal) { + scope.$watch(attrs.uiHide, function (newVal) { if (newVal) { elm.addClass('ui-hide'); } else { @@ -50,7 +52,7 @@ angular.module('ui.showhide',[]) */ .directive('uiToggle', [function () { return function (scope, elm, attrs) { - scope.$watch(attrs.uiToggle, function (newVal, oldVal) { + scope.$watch(attrs.uiToggle, function (newVal) { if (newVal) { elm.removeClass('ui-hide').addClass('ui-show'); } else { diff --git a/modules/unique/test/uniqueSpec.js b/modules/unique/test/uniqueSpec.js index 241981b0..0550d23c 100644 --- a/modules/unique/test/uniqueSpec.js +++ b/modules/unique/test/uniqueSpec.js @@ -1,4 +1,6 @@ describe('unique', function () { + 'use strict'; + var uniqueFilter; beforeEach(module('ui.unique')); @@ -71,11 +73,11 @@ describe('unique', function () { }); it('should work correctly for arrays of mixed elements and object equality', function () { - expect(uniqueFilter([1, {key: 'value'}, 1, {key: 'value'}, 2, "string", 3])).toEqual([1, {key: 'value'}, 2, "string", 3]); + expect(uniqueFilter([1, {key: 'value'}, 1, {key: 'value'}, 2, 'string', 3])).toEqual([1, {key: 'value'}, 2, 'string', 3]); }); it('should work correctly for arrays of mixed elements and a key specified', function () { - expect(uniqueFilter([1, {key: 'value'}, 1, {key: 'value'}, 2, "string", 3], 'key')).toEqual([1, {key: 'value'}, 2, "string", 3]); + expect(uniqueFilter([1, {key: 'value'}, 1, {key: 'value'}, 2, 'string', 3], 'key')).toEqual([1, {key: 'value'}, 2, 'string', 3]); }); it('should return unmodified object if not array', function () { @@ -90,4 +92,4 @@ describe('unique', function () { expect(uniqueFilter(arrayToFilter, false)).toEqual(arrayToFilter); }); -}); \ No newline at end of file +}); diff --git a/modules/unique/unique.js b/modules/unique/unique.js index e81bacf6..c9fff1e1 100644 --- a/modules/unique/unique.js +++ b/modules/unique/unique.js @@ -1,3 +1,5 @@ +'use strict'; + /** * Filters out all duplicate items from an array by checking the specified key * @param [key] {string} the name of the attribute of each object to compare for uniqueness @@ -14,7 +16,7 @@ angular.module('ui.unique',[]).filter('unique', ['$parse', function ($parse) { } if ((filterOn || angular.isUndefined(filterOn)) && angular.isArray(items)) { - var hashCheck = {}, newItems = [], + var newItems = [], get = angular.isString(filterOn) ? $parse(filterOn) : function (item) { return item; }; var extractValueToCompare = function (item) { @@ -22,7 +24,7 @@ angular.module('ui.unique',[]).filter('unique', ['$parse', function ($parse) { }; angular.forEach(items, function (item) { - var valueToCheck, isDuplicate = false; + var isDuplicate = false; for (var i = 0; i < newItems.length; i++) { if (angular.equals(extractValueToCompare(newItems[i]), extractValueToCompare(item))) { diff --git a/modules/utils.js b/modules/utils.js index 1be809ad..82c900be 100644 --- a/modules/utils.js +++ b/modules/utils.js @@ -1,19 +1,19 @@ angular.module('ui.utils', [ - "ui.event", - "ui.format", - "ui.highlight", - "ui.include", - "ui.indeterminate", - "ui.inflector", - "ui.jq", - "ui.keypress", - "ui.mask", - "ui.reset", - "ui.route", - "ui.scrollfix", - "ui.scroll", - "ui.scroll.jqlite", - "ui.showhide", - "ui.unique", - "ui.validate" + 'ui.event', + 'ui.format', + 'ui.highlight', + 'ui.include', + 'ui.indeterminate', + 'ui.inflector', + 'ui.jq', + 'ui.keypress', + 'ui.mask', + 'ui.reset', + 'ui.route', + 'ui.scrollfix', + 'ui.scroll', + 'ui.scroll.jqlite', + 'ui.showhide', + 'ui.unique', + 'ui.validate' ]); diff --git a/modules/validate/test/validateSpec.js b/modules/validate/test/validateSpec.js index e6ce1985..35275a22 100644 --- a/modules/validate/test/validateSpec.js +++ b/modules/validate/test/validateSpec.js @@ -1,4 +1,6 @@ -describe('uiValidate', function ($compile) { +describe('uiValidate', function () { + 'use strict'; + var scope, compileAndDigest; var trueValidator = function () { diff --git a/modules/validate/validate.js b/modules/validate/validate.js index 966203d7..fb315351 100644 --- a/modules/validate/validate.js +++ b/modules/validate/validate.js @@ -1,3 +1,5 @@ +'use strict'; + /** * General-purpose validator for ngModel. * angular.js comes with several built-in validation mechanism for input fields (ngRequired, ngPattern etc.) but using @@ -20,8 +22,8 @@ angular.module('ui.validate',[]).directive('uiValidate', function () { restrict: 'A', require: 'ngModel', link: function (scope, elm, attrs, ctrl) { - var validateFn, watch, validators = {}, - validateExpr = scope.$eval(attrs.uiValidate); + var validateFn, validators = {}, + validateExpr = scope.$eval(attrs.uiValidate); if (!validateExpr){ return;} diff --git a/package.json b/package.json index b773e5be..867a2e95 100644 --- a/package.json +++ b/package.json @@ -7,14 +7,18 @@ "homepage": "http://angular-ui.github.com", "dependencies": {}, "devDependencies": { + "angular-ui-publisher": "~1.x", "grunt": "~0.4.1", "grunt-contrib-clean": "~0.4.1", "grunt-contrib-concat": "~0.3.0", + "grunt-contrib-connect": "~0.5.0", "grunt-contrib-copy": "~0.4.1", "grunt-contrib-jshint": "~0.5.4", "grunt-contrib-uglify": "~0.2.1", "grunt-contrib-watch": "~0.4.3", - "grunt-karma": "~0.6.2" + "grunt-karma": "~0.6.2", + "load-grunt-tasks": "~0.2.0", + "grunt-ngmin": "0.0.3" }, "scripts": {}, "repository": { diff --git a/publish.js b/publish.js new file mode 100644 index 00000000..fae15f0f --- /dev/null +++ b/publish.js @@ -0,0 +1,44 @@ +/* jshint node:true */ + +'use strict'; + +var fs = require('fs'); + +module.exports = function() { + + var modulesName = []; + if (fs.existsSync(__dirname + '/dist/sub')){ + modulesName = fs.readdirSync(__dirname + '/dist/sub'); + } + + function makingComponentData(memo, name){ + memo[name] = { + name: 'angular-ui-' + name, + main: './' + name + '.js' + }; + + return memo; + } + + return { + // gh-pages stuff + humaName : 'UI.Utils', + repoName : 'ui-utils', + inlineHTML : fs.readFileSync(__dirname + '/demo/demos.html'), + inlineJS : fs.readFileSync(__dirname + '/demo/demo.js'), + // gh-pages css dependencies + // css : [] + // gh-pages js dependencies + js : ['dist/ui-utils.js'], + + + // HACK... + main_dist_dir: 'main', + + + // The sub-components + subcomponents : modulesName.reduce(makingComponentData, {}), + // HACK... + sub_dist_dir: 'sub' + }; +};