Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

checkboxes.js

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

checkboxes.js - npm Package Compare versions

Comparing version 1.0.7 to 1.2.0

.babelrc

7

bower.json
{
"name": "checkboxes.js",
"version": "1.0.7",
"version": "1.2.0",
"homepage": "http://rmariuzzo.github.io/checkboxes.js/",

@@ -28,6 +28,5 @@ "authors": [

],
"devDependencies": {
"jquery": "~2.1.1",
"jasmine-jquery": "~2.0.3"
"dependencies": {
"jquery": "^2.0.0"
}
}
'use strict';
module.exports = function (grunt) {
module.exports = (grunt) => {

@@ -24,3 +24,3 @@ // Load all Grunt tasks.

],
tasks: ['jshint', 'jasmine']
tasks: ['jshint', 'babel', 'jasmine']
}

@@ -32,8 +32,8 @@ },

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 */'
}

@@ -59,8 +59,8 @@ }

all: {
src: 'src/**/*.js',
src: 'dist/jquery.checkboxes-<%= pkg.version %>.js',
options: {
specs: 'tests/specs/*_spec.js',
vendor: [
'bower_components/jquery/dist/jquery.min.js',
'bower_components/jasmine-jquery/lib/jasmine-jquery.js'
'node_modules/jquery/dist/jquery.min.js',
'node_modules/jasmine-jquery/lib/jasmine-jquery.js'
],

@@ -72,2 +72,14 @@ helpers: [

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

@@ -78,6 +90,6 @@

grunt.registerTask('default', ['jshint', 'watch']);
grunt.registerTask('build', ['clean', 'jshint', 'jasmine', 'uglify']);
grunt.registerTask('test', ['jasmine']);
grunt.registerTask('travis', ['jshint', 'jasmine']);
grunt.registerTask('build', ['clean', 'jshint', 'babel', 'jasmine', 'uglify']);
grunt.registerTask('test', ['babel', 'jasmine']);
grunt.registerTask('travis', ['jshint', 'babel', 'jasmine']);
};
{
"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": "rubens@mariuzzo.com",
"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.2.0",
"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": "rubens@mariuzzo.com",
"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.24.1",
"grunt": "~0.4.1",
"grunt-babel": "^6.0.0",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-jasmine": "^1.1.0",
"grunt-contrib-jshint": "~0.10.0",
"grunt-contrib-uglify": "~0.2.2",
"grunt-contrib-watch": "~0.6.1",
"jasmine-jquery": "^2.1.1",
"load-grunt-tasks": "~0.4.0"
},
"scripts": {
"test": "grunt travis --verbose"
},
"dependencies": {
"jquery": "^2.2.4"
}
}

@@ -1,21 +0,25 @@

# checkboxes.js
![checkboxes.js – A jQuery plugin that gives you nice powers over your checkboxes](banner.png)
> A jQuery plugin that gives you nice powers over your checkboxes. http://rmariuzzo.github.io/checkboxes.js
[![Build Status](https://travis-ci.org/rmariuzzo/checkboxes.js.svg?branch=develop)](https://travis-ci.org/rmariuzzo/checkboxes.js)
[![Built with Grunt](https://cdn.gruntjs.com/builtwith.png)](http://gruntjs.com/)
[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/rmariuzzo/checkboxes.js)
## Installation
#### With bower:
**With NPM:**
bower install checkboxes --save
```shell
npm install checkboxes.js --save
```
#### Without bower:
**With bower:**
```shell
bower install checkboxes --save
```
**Manually:**
1. [Download the latest release](https://github.com/rmariuzzo/checkboxes.js/releases).
2. Then include `jquery.checkboxes-###.min.js` just after jQuery.
### Features
## Features

@@ -39,5 +43,5 @@ * **Check all** checkboxes in context.

> All help are more than welcome!
All help are more than welcome!
#### Pre-requesites
#### Pre-requisites

@@ -52,12 +56,21 @@ - [node.js](http://nodejs.org/).

2. **Clone** your fork and create a feature branch from develop.
git clone git@github.com:<your-username>/checkboxes.js.git
git fetch origin
git checkout develop
git checkout -b feature-<super-power>
```shell
git clone git@github.com:<your-username>/checkboxes.js.git
git fetch origin
git checkout develop
git checkout -b feature-<super-power>
```
3. **Install** development dependencies.
npm install
bower install
```shell
npm install
bower install
```
4. **Code** and be happy!
5. **Test** your code using Jasmine.
6. Submit a **pull request** and grab popcorn.
5. **Test** your code (run `grunt` to watch JS files and execute the test specs).
6. When everything is in good shape prepare the distribution files (run `grunt build`).
7. Submit a **pull request** and grab popcorn.

@@ -74,8 +87,10 @@ Questions? [Hit me](https://github.com/rmariuzzo/).

grunt test
```shell
grunt test
```
### Credits
**checkboxes.js** was created by [Rubens Mariuzzo](http://github.com/rmariuzzo) with all the love in the world.
- **checkboxes.js** was created by [Rubens Mariuzzo](http://github.com/rmariuzzo) with all the love in the world.
**checkboxes.js** would not have been possible without the help of: [jQuery](http://jquery.com/), [Highlight.js](http://softwaremaniacs.org/soft/highlight/en/), [Font Awesome](http://fortawesome.github.io/Font-Awesome/), [Glyphicons](http://glyphicons.com/), [Twitter Bootstrap](http://twitter.github.io/bootstrap/) and [Subtle Patterns](http://subtlepatterns.com/). _I'm very thankful for all!_
- **checkboxes.js** would not have been possible without the help of: [jQuery](http://jquery.com/), [Highlight.js](http://softwaremaniacs.org/soft/highlight/en/), [Font Awesome](http://fortawesome.github.io/Font-Awesome/), [Glyphicons](http://glyphicons.com/), [Twitter Bootstrap](http://twitter.github.io/bootstrap/) and [Subtle Patterns](http://subtlepatterns.com/). _I'm very thankful for all!_
'use strict';
(function ($) {
(($) => {
////////////////////////
/* Checkboxes object. */
////////////////////////
/**
* Create a new checkbox context.
*
* @param {Object} context DOM context.
* The Checkboxes class object.
*/
var Checkboxes = function (context) {
this.$context = context;
};
class Checkboxes {
/**
* Check all checkboxes in context.
*/
Checkboxes.prototype.check = function () {
this.$context.find(':checkbox')
.filter(':not(:disabled)')
.filter(':visible')
.prop('checked', true);
};
/**
* Create a new checkbox context.
*
* @param {Object} context DOM context.
*/
constructor(context) {
this.$context = context;
}
/**
* Uncheck all checkboxes in context.
*/
Checkboxes.prototype.uncheck = function () {
this.$context.find(':checkbox:visible')
.filter(':not(:disabled)')
.prop('checked', false);
};
/**
* Check all checkboxes in context.
*/
check() {
this.$context.find(':checkbox')
.filter(':not(:disabled)')
.filter(':visible')
.prop('checked', true)
.trigger('change');
}
/**
* 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'));
});
};
/**
* Uncheck all checkboxes in context.
*/
uncheck() {
this.$context.find(':checkbox:visible')
.filter(':not(:disabled)')
.prop('checked', false)
.trigger('change');
}
/**
* 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');
/**
* Toggle the state of all checkboxes in context.
*/
toggle() {
this.$context.find(':checkbox:visible')
.filter(':not(:disabled)')
.each((i, element) => {
let $checkbox = $(element);
$checkbox.prop('checked', !$checkbox.is(':checked'));
})
.trigger('change');
}
};
/**
* 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;
/**
* Set the maximum number of checkboxes that can be checked.
*
* @param {Number} max The maximum number of checkbox allowed to be checked.
*/
max(max) {
if (max > 0) {
// Enable max.
let instance = this;
this.$context.on('click.checkboxes.max', ':checkbox', () => {
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');
}
}
this.$context.on('click.checkboxes.range', ':checkbox', function (event) {
var $checkbox = $(event.target);
/**
* Enable or disable range selection.
*
* @param {Boolean} enable Indicate is range selection has to be enabled.
*/
range(enable) {
if (enable) {
let instance = this;
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;
this.$context.on('click.checkboxes.range', ':checkbox', (event) => {
let $checkbox = $(event.target);
$checkboxes.slice(start, end)
.filter(':not(:disabled)')
.prop('checked', $checkbox.prop('checked'));
}
instance.$last = $checkbox;
});
} else {
this.$context.off('click.checkboxes.range');
if (event.shiftKey && instance.$last) {
let $checkboxes = instance.$context.find(':checkbox:visible');
let from = $checkboxes.index(instance.$last);
let to = $checkboxes.index($checkbox);
let start = Math.min(from, to);
let end = Math.max(from, to) + 1;
$checkboxes.slice(start, end)
.filter(':not(:disabled)')
.prop('checked', $checkbox.prop('checked'))
.trigger('change');
}
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;
let old = $.fn.checkboxes;

@@ -117,11 +121,11 @@ /**

// Get extra arguments as method arguments.
var methodArgs = Array.prototype.slice.call(arguments, 1);
let args = Array.prototype.slice.call(arguments, 1);
return this.each(function () {
var $this = $(this);
return this.each((i, element) => {
let $this = $(element);
// Check if we already have an instance.
var instance = $this.data('checkboxes');
let instance = $this.data('checkboxes');
if (!instance) {
$this.data('checkboxes', (instance = new Checkboxes($this, typeof method === 'object' && method)));
$this.data('checkboxes', (instance = new Checkboxes($this)));
}

@@ -131,3 +135,3 @@

if (typeof method === 'string' && instance[method]) {
instance[method].apply(instance, methodArgs);
instance[method].apply(instance, args);
}

@@ -140,6 +144,3 @@ });

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

@@ -154,6 +155,3 @@ /**

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

@@ -165,3 +163,3 @@ /**

*/
var dataApiClickHandler = function (event) {
var dataApiClickHandler = (event) => {
var el = $(event.target);

@@ -183,8 +181,8 @@ var href = el.attr('href');

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

@@ -191,0 +189,0 @@ }

@@ -30,2 +30,4 @@ // Setup Jasmine's fixtures path.

it('should check all visible and enabled checkboxes in context', function () {
var spyEvent = spyOnEvent(ctx.modified, 'change');
// Check all checkboxes in context.

@@ -42,4 +44,6 @@ ctx.modified.checkboxes('check');

});
expect(spyEvent).toHaveBeenTriggered();
});
});

@@ -33,9 +33,9 @@ // Setup Jasmine's fixtures path.

// Click all checkboxes.
ctx.modified.find(':checkbox').each(function (i) {
ctx.modified.find(':checkbox').each(function () {
$(this).click();
});
expect(ctx.modified.find(':checkbox:checked').length, 7);
expect(ctx.modified.find(':checkbox:checked').length).toBe(7);
});
});

@@ -30,2 +30,4 @@ // Setup Jasmine's fixtures path.

it('should toggle all visible and enabled checkboxes in context', function () {
var spyEvent = spyOnEvent(ctx.modified, 'change');
// Toggle all checkboxes in context.

@@ -42,4 +44,6 @@ ctx.modified.checkboxes('toggle');

});
expect(spyEvent).toHaveBeenTriggered();
});
});

@@ -30,2 +30,4 @@ // Setup Jasmine's fixtures path.

it('should uncheck all visible and enabled checkboxes in context', function () {
var spyEvent = spyOnEvent(ctx.modified, 'change');
// Uncheck all checkboxes in context.

@@ -42,4 +44,6 @@ ctx.modified.checkboxes('uncheck');

});
expect(spyEvent).toHaveBeenTriggered();
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc