From cefa394356e9b96ee1276453978c795543c1d2fb Mon Sep 17 00:00:00 2001 From: Micky Hulse Date: Tue, 12 Mar 2013 13:56:41 -0700 Subject: [PATCH] House cleaning. Closes #19, and closes #18. --- CHANGELOG.md | 6 +++++ build/Gruntfile.js | 38 +++++++++++++++++++++++++++++--- build/package.json | 3 ++- build/src/onmediaquery.js | 19 ++++++++++------ onmediaquery/onmediaquery.js | 21 +++++++++++------- onmediaquery/onmediaquery.min.js | 2 +- 6 files changed, 69 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f15b350..e2499e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## v2.1.0 +#### March 12, 2013 + +* Added `clean` task to build. +* Moved all vars to tops of functions for jshint and readability's sake. +* Minor house cleaning. + #### March 11, 2013 * Updated this file. diff --git a/build/Gruntfile.js b/build/Gruntfile.js index 9fff6d8..60db91a 100644 --- a/build/Gruntfile.js +++ b/build/Gruntfile.js @@ -37,8 +37,10 @@ module.exports = function(grunt) { /*----------------------------------( 01 )----------------------------------*/ /** + * Validate files with JSHint. + * * @see http://www.jshint.com/docs/ - * @see https://github.com/jshint/jshint/blob/r12/jshint.js#L256 + * @see https://github.com/gruntjs/grunt-contrib-jshint */ jshint: { @@ -61,6 +63,32 @@ module.exports = function(grunt) { /*----------------------------------( 02 )----------------------------------*/ /** + * Clean files and folders. + * + * @see https://github.com/gruntjs/grunt-contrib-clean + */ + + clean : { + + options : { + + force : true // Sketchy! + + }, + + dist : [ + + '../<%= pkg.name %>/**/*' + + ] + + }, + + /*----------------------------------( 03 )----------------------------------*/ + + /** + * Minify files with UglifyJS. + * * @see https://github.com/gruntjs/grunt-contrib-uglify */ @@ -84,9 +112,11 @@ module.exports = function(grunt) { }, - /*----------------------------------( 03 )----------------------------------*/ + /*----------------------------------( 04 )----------------------------------*/ /** + * Concatenate files. + * * @see https://github.com/gruntjs/grunt-contrib-concat */ @@ -113,12 +143,14 @@ module.exports = function(grunt) { grunt.loadNpmTasks('grunt-contrib-jshint'); + grunt.loadNpmTasks('grunt-contrib-clean'); + grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-contrib-concat'); //---------------------------------- - grunt.registerTask('default', ['jshint', 'uglify', 'concat']); + grunt.registerTask('default', ['jshint', 'clean', 'uglify', 'concat']); }; diff --git a/build/package.json b/build/package.json index 93e3d13..033257e 100644 --- a/build/package.json +++ b/build/package.json @@ -26,8 +26,9 @@ "dependencies": {}, "devDependencies": { "grunt": "0.4.0", - "grunt-contrib-jshint": "0.2.0", "grunt-contrib-nodeunit": "0.1.2", + "grunt-contrib-jshint": "0.2.0", + "grunt-contrib-clean": "0.4.0", "grunt-contrib-uglify": "0.1.2", "grunt-contrib-concat": "0.1.3" } diff --git a/build/src/onmediaquery.js b/build/src/onmediaquery.js index 2b56ffb..fe48d24 100644 --- a/build/src/onmediaquery.js +++ b/build/src/onmediaquery.js @@ -17,6 +17,9 @@ omq.init = function(query_array) { + // Declare one `var` statement per function: + var i, l; + // rgne.ws/UJ8hYh this._callbacks = []; // Container for all callbacks registered with the plugin. this._context = ''; // Current active query to be read inside callbacks, as `this._last_context` won't be set when they're called! @@ -24,7 +27,7 @@ if (typeof query_array !== 'undefined') { - for (var i = 0, l = query_array.length; i < l; i++) { + for (i = 0, l = query_array.length; i < l; i++) { this.addQuery(query_array[i]); @@ -91,9 +94,11 @@ omq.removeQuery = function(query_object) { + var match; + if (query_object) { // rgne.ws/VpFmUI - var match = -1; + match = -1; while ((match = this._callbacks.indexOf(query_object)) > -1) { @@ -187,10 +192,8 @@ _triggerCallbacks = function(size, key) { if (size && key) { - - var callback_function, - i, - l; + + var callback_function, i, l; for (i = 0, l = this._callbacks.length; i < l; i++) { @@ -285,7 +288,9 @@ _inArray = function(needle, haystack) { - for (var i = 0, l = haystack.length; i < l; i++) { + var i, l; + + for (i = 0, l = haystack.length; i < l; i++) { if (haystack[i] == needle) { diff --git a/onmediaquery/onmediaquery.js b/onmediaquery/onmediaquery.js index 6daf30b..6f2ce4e 100644 --- a/onmediaquery/onmediaquery.js +++ b/onmediaquery/onmediaquery.js @@ -8,7 +8,7 @@ * @copyright Copyright (c) 2013 Josh Barr. * @license Released under the Released under the MIT license.. * @version 2.1.0 - * @date 2013/03/11 + * @date 2013/03/12 */ (function(omq) { // rgne.ws/V4HOQy @@ -30,6 +30,9 @@ omq.init = function(query_array) { + // Declare one `var` statement per function: + var i, l; + // rgne.ws/UJ8hYh this._callbacks = []; // Container for all callbacks registered with the plugin. this._context = ''; // Current active query to be read inside callbacks, as `this._last_context` won't be set when they're called! @@ -37,7 +40,7 @@ if (typeof query_array !== 'undefined') { - for (var i = 0, l = query_array.length; i < l; i++) { + for (i = 0, l = query_array.length; i < l; i++) { this.addQuery(query_array[i]); @@ -104,9 +107,11 @@ omq.removeQuery = function(query_object) { + var match; + if (query_object) { // rgne.ws/VpFmUI - var match = -1; + match = -1; while ((match = this._callbacks.indexOf(query_object)) > -1) { @@ -200,10 +205,8 @@ _triggerCallbacks = function(size, key) { if (size && key) { - - var callback_function, - i, - l; + + var callback_function, i, l; for (i = 0, l = this._callbacks.length; i < l; i++) { @@ -298,7 +301,9 @@ _inArray = function(needle, haystack) { - for (var i = 0, l = haystack.length; i < l; i++) { + var i, l; + + for (i = 0, l = haystack.length; i < l; i++) { if (haystack[i] == needle) { diff --git a/onmediaquery/onmediaquery.min.js b/onmediaquery/onmediaquery.min.js index ce84a90..bdda677 100644 --- a/onmediaquery/onmediaquery.min.js +++ b/onmediaquery/onmediaquery.min.js @@ -1 +1 @@ -/*! onMediaQuery v2.1.0 | Released under the MIT license. | https://github.com/registerguard/js-media-queries */(function(t){"use strict";t.init=function(e){if(this._callbacks=[],this._context="",this._last_context="",e!==void 0)for(var o=0,i=e.length;i>o;o++)this.addQuery(e[o]);c(window,"resize",n,t),n.call(this)},t.addQuery=function(t){return t?(this._callbacks.push(t),"string"==typeof t.context&&(t.context=[t.context]),"boolean"!=typeof t.call_for_each_context&&(t.call_for_each_context=!0),this._last_context&&i(this._last_context,t.context)&&t.match(),this._callbacks[this._callbacks.length-1]):void 0},t.removeQuery=function(t){if(t)for(var n=-1;(n=this._callbacks.indexOf(t))>-1;)this._callbacks.splice(n,1)},t.getContext=function(){return this._context?this._context:o()},t.getLastContext=function(){return this._last_context?this._last_context:this._context};var n=function(){var t=o();t&&(t!==this._last_context&&(this._context=t,e.call(this,this._last_context,"unmatch"),e.call(this,this._context,"match")),this._last_context=this._context)},e=function(t,n){if(t&&n){var e,c,o;for(c=0,o=this._callbacks.length;o>c;c++)this._callbacks[c].call_for_each_context===!1&&("match"===n&&i(this._last_context,this._callbacks[c].context)||"unmatch"===n&&i(this._context,this._callbacks[c].context))||(e=this._callbacks[c][n],i(t,this._callbacks[c].context)&&void 0!==e&&e())}},c=function(t,n,e,c){t&&(t.addEventListener?t.addEventListener(n,function(){e.call(c)},!1):t.attachEvent?t.attachEvent("on"+n,function(){e.call(c)}):t["on"+n]=function(){e.call(c)})},o=function(){var t=l(document.body)||a(document.documentElement);return t.replace(/['",]/g,"")},i=function(t,n){for(var e=0,c=n.length;c>e;e++)if(n[e]==t)return!0;return!1},a=function(t){return t?t.currentStyle?t.currentStyle.fontFamily:window.getComputedStyle?window.getComputedStyle(t,null).getPropertyValue("font-family"):"":void 0},l=function(t){return t?window.getComputedStyle?window.getComputedStyle(t,":after").getPropertyValue("content"):"":void 0};return t})(window.oMQ=window.oMQ||{}); \ No newline at end of file +/*! onMediaQuery v2.1.0 | Released under the MIT license. | https://github.com/registerguard/js-media-queries */(function(t){"use strict";t.init=function(e){var o,i;if(this._callbacks=[],this._context="",this._last_context="",e!==void 0)for(o=0,i=e.length;i>o;o++)this.addQuery(e[o]);c(window,"resize",n,t),n.call(this)},t.addQuery=function(t){return t?(this._callbacks.push(t),"string"==typeof t.context&&(t.context=[t.context]),"boolean"!=typeof t.call_for_each_context&&(t.call_for_each_context=!0),this._last_context&&i(this._last_context,t.context)&&t.match(),this._callbacks[this._callbacks.length-1]):void 0},t.removeQuery=function(t){var n;if(t)for(n=-1;(n=this._callbacks.indexOf(t))>-1;)this._callbacks.splice(n,1)},t.getContext=function(){return this._context?this._context:o()},t.getLastContext=function(){return this._last_context?this._last_context:this._context};var n=function(){var t=o();t&&(t!==this._last_context&&(this._context=t,e.call(this,this._last_context,"unmatch"),e.call(this,this._context,"match")),this._last_context=this._context)},e=function(t,n){if(t&&n){var e,c,o;for(c=0,o=this._callbacks.length;o>c;c++)this._callbacks[c].call_for_each_context===!1&&("match"===n&&i(this._last_context,this._callbacks[c].context)||"unmatch"===n&&i(this._context,this._callbacks[c].context))||(e=this._callbacks[c][n],i(t,this._callbacks[c].context)&&void 0!==e&&e())}},c=function(t,n,e,c){t&&(t.addEventListener?t.addEventListener(n,function(){e.call(c)},!1):t.attachEvent?t.attachEvent("on"+n,function(){e.call(c)}):t["on"+n]=function(){e.call(c)})},o=function(){var t=l(document.body)||a(document.documentElement);return t.replace(/['",]/g,"")},i=function(t,n){var e,c;for(e=0,c=n.length;c>e;e++)if(n[e]==t)return!0;return!1},a=function(t){return t?t.currentStyle?t.currentStyle.fontFamily:window.getComputedStyle?window.getComputedStyle(t,null).getPropertyValue("font-family"):"":void 0},l=function(t){return t?window.getComputedStyle?window.getComputedStyle(t,":after").getPropertyValue("content"):"":void 0};return t})(window.oMQ=window.oMQ||{}); \ No newline at end of file