Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* jQuery Checkbox v2.0

  • Loading branch information...
commit 9dbd6502b42a44fa93950341f2835eaa78f4b409 1 parent 2f328a8
@tomekwojcik authored
Showing with 69 additions and 58 deletions.
  1. +0 −58 jquery-checkbox-1.0.js
  2. +69 −0 jquery-checkbox-2.0.js
View
58 jquery-checkbox-1.0.js
@@ -1,58 +0,0 @@
-/**
- * jQuery custom checkboxes
- *
- * Copyright (c) 2010 Tomasz Wójcik (bthlabs.pl)
- * Licensed under the MIT License:
- * http://www.opensource.org/licenses/mit-license.php
- *
- * @version 1.0
- * @category visual
- * @package jquery
- * @subpakage ui.checkbox
- * @author Tomasz Wójcik <tomek@bthlabs.pl>
-**/
-jQuery.fn.checkbox = function(options) {
- var defaults = {
- className: 'jquery-checkbox',
- checkedClass: 'jquery-checkbox-on'
- };
-
- var settings = jQuery.extend(defaults, options || {});
-
- return this.each(function() {
- var _this = jQuery(this);
-
- var _replacement = jQuery(
- '<div class="' + settings.className + '-wrapper">' +
- '<a class="' + settings.className + '" href="#" name="' + _this.attr('id') + '"></a>' +
- '</div>'
- );
-
- if (_this.attr('checked') == true || _this.attr('checked') == "checked") {
- jQuery('a', _replacement).addClass(settings.checkedClass);
- } // eof if()
-
- jQuery('a', _replacement).click(function() {
- var _input = jQuery('input#' + jQuery(this).attr('name'), _replacement.parent());
- if (_input.attr('checked') == true || _input.attr('checked') == "checked") {
- _input.removeAttr('checked');
- } else {
- _input.attr('checked', true);
- } // eof if()
- _input.change();
-
- return false;
- });
- jQuery(_this).change(function() {
- var _input = jQuery(this);
- if (_input.attr('checked') == true || _input.attr('checked') == "checked") {
- jQuery('a[name=' + _input.attr('id') + ']', _replacement.parent()).addClass(settings.checkedClass);
- } else {
- jQuery('a[name=' + _input.attr('id') + ']', _replacement.parent()).removeClass(settings.checkedClass);
- } // eof if()
- });
-
- _this.css({ 'position': 'absolute', 'top': '-200px', 'left': '-200px'}).before(_replacement);
- _replacement.parent().css('overflow', 'hidden');
- });
-};
View
69 jquery-checkbox-2.0.js
@@ -0,0 +1,69 @@
+/**
+ * jQuery custom checkboxes
+ *
+ * Copyright (c) 2010-2012 Tomasz Wójcik (bthlabs.pl)
+ * Licensed under the MIT License:
+ * http://www.opensource.org/licenses/mit-license.php
+ *
+ * @version 2.0
+ * @category visual
+ * @package jquery
+ * @subpakage ui.checkbox
+ * @author Tomasz Wójcik <labs@tomekwojcik.pl>
+ */
+(function() {
+ jQuery.fn.checkbox = function(options) {
+ options = options || {};
+
+ var defaults = {
+ 'className': 'jquery-checkbox',
+ 'checkedClass': 'jquery-checkbox-on'
+ };
+
+ var settings = jQuery.extend(defaults, options);
+
+ return this.each(function() {
+ var self = jQuery(this);
+
+ var replacement = jQuery(
+ '<div class="' + settings.className + '-wrapper">' +
+ '<a class="' + settings.className + '" href="#" name="' + self.attr('id') + '"></a>' +
+ '</div>'
+ );
+ var element = jQuery('a', replacement);
+
+ if (self.attr('checked') === 'checked') {
+ element.addClass(settings.checkedClass);
+ }
+
+ element.on('click', function(event) {
+ event.preventDefault();
+ event.stopPropagation();
+
+ var input = jQuery('input#' + jQuery(this).attr('name'), replacement.parent());
+ if (input.attr('checked') === 'checked') {
+ input.removeAttr('checked');
+ } else {
+ input.attr('checked', 'checked');
+ }
+ input.trigger('change');
+
+ return false;
+ });
+
+ self.on('change', function(event) {
+ var input = jQuery(this);
+ if (input.attr('checked') === 'checked') {
+ jQuery('a[name=' + input.attr('id') + ']', replacement.parent()).addClass(settings.checkedClass);
+ } else {
+ jQuery('a[name=' + input.attr('id') + ']', replacement.parent()).removeClass(settings.checkedClass);
+ }
+
+ return true;
+ });
+
+ self.css({ 'position': 'absolute', 'top': '-200px', 'left': '-200px'}).before(replacement);
+ replacement.parent().css('overflow', 'hidden');
+ });
+ }
+})();
Please sign in to comment.
Something went wrong with that request. Please try again.