Skip to content

Commit

Permalink
Babel setup done.
Browse files Browse the repository at this point in the history
  • Loading branch information
rmariuzzo committed Jul 27, 2016
1 parent 6bda5dc commit 7928fa5
Show file tree
Hide file tree
Showing 7 changed files with 251 additions and 47 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
presets: ['es2015']
}
1 change: 1 addition & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"eqnull" : true,
"node" : true,
"browser" : true,
"esnext": true,
"globals" : {
"it" : true,
"xit" : true,
Expand Down
33 changes: 24 additions & 9 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

module.exports = function (grunt) {
module.exports = (grunt) => {

// Load all Grunt tasks.
require('load-grunt-tasks')(grunt);
Expand All @@ -10,7 +10,10 @@ module.exports = function (grunt) {

pkg: grunt.file.readJSON('package.json'),

clean: ['dist'],
clean: {
all: ['dist'],
build: ['dist/jquery.checkboxes-<%= pkg.version %>.js']
},

watch: {
scripts: {
Expand All @@ -21,19 +24,19 @@ module.exports = function (grunt) {
'tests/helpers.js',
'!.grunt'
],
tasks: ['jshint', 'jasmine']
tasks: ['jshint', 'babel', 'jasmine']
}
},

uglify: {
all: {
files: {
'dist/jquery.checkboxes-<%= pkg.version %>.min.js': ['src/jquery.checkboxes.js']
'dist/jquery.checkboxes-<%= pkg.version %>.min.js': ['dist/jquery.checkboxes-<%= pkg.version %>.js']
},
options: {
banner: '/*! checkboxes.js v<%= pkg.version %> | ' +
'(c) 2013, <%= grunt.template.today("yyyy") %> Rubens Mariuzzo | ' +
'http://github.com/rmariuzzo/checkboxes.js/LICENSE */',
'(c) 2013 - <%= grunt.template.today("yyyy") %> Rubens Mariuzzo | ' +
'http://github.com/rmariuzzo/checkboxes.js/LICENSE */'
}
}
},
Expand All @@ -54,7 +57,7 @@ module.exports = function (grunt) {

jasmine: {
all: {
src: 'src/**/*.js',
src: 'dist/jquery.checkboxes-<%= pkg.version %>.js',
options: {
specs: 'tests/specs/*_spec.js',
vendor: [
Expand All @@ -66,13 +69,25 @@ module.exports = function (grunt) {
]
}
}
},

babel: {
options: {
sourceMap: false,
presets: ['es2015']
},
dist: {
files: {
'dist/jquery.checkboxes-<%= pkg.version %>.js': 'src/jquery.checkboxes.js'
}
}
}

});

grunt.registerTask('default', ['jshint', 'watch']);
grunt.registerTask('build', ['clean', 'jshint', 'jasmine', 'uglify']);
grunt.registerTask('test', ['jasmine']);
grunt.registerTask('build', ['clean:all', 'jshint', 'babel', 'jasmine', 'uglify', 'clean:build']);
grunt.registerTask('test', ['babel', 'jasmine']);
grunt.registerTask('travis', ['jshint', 'jasmine']);

};
183 changes: 183 additions & 0 deletions dist/jquery.checkboxes-1.0.7.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
'use strict';

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };

(function ($) {

////////////////////////
/* Checkboxes object. */
////////////////////////

/**
* Create a new checkbox context.
*
* @param {Object} context DOM context.
*/
var Checkboxes = function Checkboxes(context) {
this.$context = context;
};

/**
* Check all checkboxes in context.
*/
Checkboxes.prototype.check = function () {
this.$context.find(':checkbox').filter(':not(:disabled)').filter(':visible').prop('checked', true);
};

/**
* Uncheck all checkboxes in context.
*/
Checkboxes.prototype.uncheck = function () {
this.$context.find(':checkbox:visible').filter(':not(:disabled)').prop('checked', false);
};

/**
* Toggle the state of all checkboxes in context.
*/
Checkboxes.prototype.toggle = function () {
this.$context.find(':checkbox:visible').filter(':not(:disabled)').each(function () {
var $checkbox = $(this);
$checkbox.prop('checked', !$checkbox.is(':checked'));
});
};

/**
* Set the maximum number of checkboxes that can be checked.
*
* @param {Number} max The maximum number of checkbox allowed to be checked.
*/
Checkboxes.prototype.max = function (max) {
if (max > 0) {
// Enable max.
var instance = this;
this.$context.on('click.checkboxes.max', ':checkbox', function () {
if (instance.$context.find(':checked').length === max) {
instance.$context.find(':checkbox:not(:checked)').prop('disabled', true);
} else {
instance.$context.find(':checkbox:not(:checked)').prop('disabled', false);
}
});
} else {
// Disable max.
this.$context.off('click.checkboxes.max');
}
};

/**
* Enable or disable range selection.
*
* @param {Boolean} enable Indicate is range selection has to be enabled.
*/
Checkboxes.prototype.range = function (enable) {
if (enable) {
var instance = this;

this.$context.on('click.checkboxes.range', ':checkbox', function (event) {
var $checkbox = $(event.target);

if (event.shiftKey && instance.$last) {
var $checkboxes = instance.$context.find(':checkbox:visible');
var from = $checkboxes.index(instance.$last);
var to = $checkboxes.index($checkbox);
var start = Math.min(from, to);
var end = Math.max(from, to) + 1;

$checkboxes.slice(start, end).filter(':not(:disabled)').prop('checked', $checkbox.prop('checked'));
}
instance.$last = $checkbox;
});
} else {
this.$context.off('click.checkboxes.range');
}
};

///////////////////////////////
/* Checkboxes jQuery plugin. */
///////////////////////////////

// Keep old Checkboxes jQuery plugin, if any, to no override it.
var old = $.fn.checkboxes;

/**
* Checkboxes jQuery plugin.
*
* @param {String} method Method to invoke.
*
* @return {Object} jQuery object.
*/
$.fn.checkboxes = function (method) {
// Get extra arguments as method arguments.
var methodArgs = Array.prototype.slice.call(arguments, 1);

return this.each(function () {
var $this = $(this);

// Check if we already have an instance.
var instance = $this.data('checkboxes');
if (!instance) {
$this.data('checkboxes', instance = new Checkboxes($this, (typeof method === 'undefined' ? 'undefined' : _typeof(method)) === 'object' && method));
}

// Check if we need to invoke a public method.
if (typeof method === 'string' && instance[method]) {
instance[method].apply(instance, methodArgs);
}
});
};

// Store a constructor reference.
$.fn.checkboxes.Constructor = Checkboxes;

////////////////////////////////////
/* Checkboxes jQuery no conflict. */
////////////////////////////////////

/**
* No conflictive Checkboxes jQuery plugin.
*/
$.fn.checkboxes.noConflict = function () {
$.fn.checkboxes = old;
return this;
};

//////////////////////////
/* Checkboxes data-api. */
//////////////////////////

/**
* Handle data-api click.
*
* @param {Object} event Click event.
*/
var dataApiClickHandler = function dataApiClickHandler(event) {
var el = $(event.target);
var href = el.attr('href');
var $context = $(el.data('context') || href && href.replace(/.*(?=#[^\s]+$)/, ''));
var action = el.data('action');

if ($context && action) {
if (!el.is(':checkbox')) {
event.preventDefault();
}
$context.checkboxes(action);
}
};

/**
* Handle data-api DOM ready.
*/
var dataApiDomReadyHandler = function dataApiDomReadyHandler() {
$('[data-toggle^=checkboxes]').each(function () {
var el = $(this),
actions = el.data();
delete actions.toggle;
for (var action in actions) {
el.checkboxes(action, actions[action]);
}
});
};

// Register data-api listeners.
$(document).on('click.checkboxes.data-api', '[data-toggle^=checkboxes]', dataApiClickHandler);
$(document).on('ready.checkboxes.data-api', dataApiDomReadyHandler);
})(window.jQuery);
2 changes: 1 addition & 1 deletion dist/jquery.checkboxes-1.0.7.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 38 additions & 36 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
{
"name": "checkboxes.js",
"version": "1.0.7",
"description": "A jQuery plugin that gives you nice powers over your checkboxes.",
"keywords": [
"checkbox",
"checkboxes",
"range",
"jquery",
"plugin"
],
"homepage": "https://github.com/rmariuzzo/checkboxes.js",
"bugs": "https://github.com/rmariuzzo/checkboxes.js/issues",
"license": "MIT",
"author": {
"name": "Rubens Mariuzzo",
"email": "[email protected]",
"url": "https://github.com/rmariuzzo"
},
"contributors": [],
"main": "dist/jquery.checkboxes-1.0.6.min.js",
"repository": {
"type": "git",
"url": "https://github.com/rmariuzzo/checkboxes.js.git"
},
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-jasmine": "~0.6.5",
"grunt-contrib-jshint": "~0.10.0",
"grunt-contrib-uglify": "~0.2.2",
"grunt-contrib-watch": "~0.6.1",
"load-grunt-tasks": "~0.4.0"
},
"scripts": {
"test": "grunt travis --verbose"
}
"name": "checkboxes.js",
"version": "1.0.7",
"description": "A jQuery plugin that gives you nice powers over your checkboxes.",
"keywords": [
"checkbox",
"checkboxes",
"range",
"jquery",
"plugin"
],
"homepage": "https://github.com/rmariuzzo/checkboxes.js",
"bugs": "https://github.com/rmariuzzo/checkboxes.js/issues",
"license": "MIT",
"author": {
"name": "Rubens Mariuzzo",
"email": "[email protected]",
"url": "https://github.com/rmariuzzo"
},
"contributors": [],
"main": "dist/jquery.checkboxes-1.0.6.min.js",
"repository": {
"type": "git",
"url": "https://github.com/rmariuzzo/checkboxes.js.git"
},
"devDependencies": {
"babel-preset-es2015": "^6.9.0",
"grunt": "~0.4.1",
"grunt-babel": "^6.0.0",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-jasmine": "~0.6.5",
"grunt-contrib-jshint": "~0.10.0",
"grunt-contrib-uglify": "~0.2.2",
"grunt-contrib-watch": "~0.6.1",
"load-grunt-tasks": "~0.4.0"
},
"scripts": {
"test": "grunt travis --verbose"
}
}
2 changes: 1 addition & 1 deletion src/jquery.checkboxes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

(function ($) {
(($) => {

////////////////////////
/* Checkboxes object. */
Expand Down

0 comments on commit 7928fa5

Please sign in to comment.