Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions css/ezmark.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
* CSS File for ezMark jQuery Plugin
*
**/
.ez-hide { opacity: 0; filter:alpha(opacity=0); }
.ez-checkbox {
.ezmark-hide { opacity: 0; filter:alpha(opacity=0); }
.ezmark-checkbox {
background: transparent url('../images/checkbox-red.png') 0 1px no-repeat;
display:inline-block;
}

.ez-radio {
.ezmark-radio {
background: transparent url('../images/radio-black.png') 0 1px no-repeat;
display:inline-block;
}

.ez-checked { background-position: 0 -18px; }
.ez-selected { background-position: 0 -19px; }
.ezmark-checked { background-position: 0 -18px; }
.ezmark-selected { background-position: 0 -19px; }

.ez-checkbox-green {
.ezmark-checkbox-green {
background: transparent url('../images/checkbox-green.png') 0 1px no-repeat;
display:inline-block;
*display: inline;
}
.ez-checked-green { background-position: 0 -18px; }
.ez-checkbox, .ez-radio { zoom: 1; *display:inline; _height:30px; }
.ezmark-checked-green { background-position: 0 -18px; }
.ezmark-checkbox, .ezmark-radio { zoom: 1; *display:inline; _height:30px; }
195 changes: 122 additions & 73 deletions js/jquery.ezmark.js
Original file line number Diff line number Diff line change
@@ -1,77 +1,126 @@
/**
* ezMark - A Simple Checkbox and Radio button Styling plugin.
* This plugin allows you to use a custom Image for Checkbox or Radio button. Its very simple, small and easy to use.
*
* Copyright (c) Abdullah Rubiyath <http://www.itsalif.info/>.
* Released under MIT License
*
* Files with this plugin:
* - jquery.ezmark.js
* - ezmark.css
*
* <usage>
* At first, include both the css and js file at the top
*
* Then, simply use:
* $('selector').ezMark([options]);
*
* [options] accepts following JSON properties:
* checkboxCls - custom Checkbox Class
* checkedCls - checkbox Checked State's Class
* radioCls - custom radiobutton Class
* selectedCls - radiobutton's Selected State's Class
*
* </usage>
*
* View Documention/Demo here:
* http://www.itsalif.info/content/ezmark-jquery-checkbox-radiobutton-plugin
*
* @author Abdullah Rubiyath
* @version 1.0
* @date June 27, 2010
*/
* ezMark - A Simple Checkbox and Radio button Styling plugin.
* This plugin allows you to use a custom Image for Checkbox or Radio button. Its very simple, small and easy to use.
*
* Copyright (c) Abdullah Rubiyath <http://www.itsalif.info/>.
* Released under MIT License
*
* Files with this plugin:
* - jquery.ezmark.js
* - ezmark.css
*
* <usage>
* At first, include both the css and js file at the top
*
* Then, simply use:
* $('selector').ezMark([options]);
*
* [options] accepts following JSON properties:
* checkboxClass - class applied to wrapping container (div) of a checkbox input
* checkedClass - class applied to wrapping container when the input is checked
* radioClass - class applied to the wrapping container (div) of a radio input
* hideClass - class applied to the input
* hoverClass - class applied while hovering over the label or div
* labelClass - class applied to associated label for custom input
* disabledClass - class applied to wrapping container (div) and associated label when input is disabled
* </usage>
*
* View Documention/Demo here:
* http://www.itsalif.info/content/ezmark-jquery-checkbox-radiobutton-plugin
*
* @author Abdullah Rubiyath, Gregory Waxman
* @version 2.0
* @date January 25, 2011
*/

(function($) {
$.fn.ezMark = function(options) {
options = options || {};
var defaultOpt = {
checkboxCls : options.checkboxCls || 'ez-checkbox' , radioCls : options.radioCls || 'ez-radio' ,
checkedCls : options.checkedCls || 'ez-checked' , selectedCls : options.selectedCls || 'ez-selected' ,
hideCls : 'ez-hide'
};
return this.each(function() {
var $this = $(this);
var wrapTag = $this.attr('type') == 'checkbox' ? '<div class="'+defaultOpt.checkboxCls+'">' : '<div class="'+defaultOpt.radioCls+'">';
// for checkbox
if( $this.attr('type') == 'checkbox') {
$this.addClass(defaultOpt.hideCls).wrap(wrapTag).change(function() {
if( $(this).is(':checked') ) {
$(this).parent().addClass(defaultOpt.checkedCls);
}
else { $(this).parent().removeClass(defaultOpt.checkedCls); }
});

if( $this.is(':checked') ) {
$this.parent().addClass(defaultOpt.checkedCls);
}
}
else if( $this.attr('type') == 'radio') {
(function ($) {
var NAMESPACE = 'ezmark';
var DELEGATE_CLASS = NAMESPACE + '-del';
var defaultOptions = {
checkboxClass: NAMESPACE + '-checkbox',
radioClass: NAMESPACE + '-radio',
checkedClass: NAMESPACE + '-checked',
hideClass: NAMESPACE + '-hide',
hoverClass: NAMESPACE + '-hover',
labelClass: NAMESPACE + '-label',
labelCheckboxClass: NAMESPACE + '-label-checkbox',
labelRadioClass: NAMESPACE + '-label-radio',
disabledClass: NAMESPACE + '-disabled'
};

$this.addClass(defaultOpt.hideCls).wrap(wrapTag).change(function() {
// radio button may contain groups! - so check for group
$('input[name="'+$(this).attr('name')+'"]').each(function() {
if( $(this).is(':checked') ) {
$(this).parent().addClass(defaultOpt.selectedCls);
} else {
$(this).parent().removeClass(defaultOpt.selectedCls);
}
});
});

if( $this.is(':checked') ) {
$this.parent().addClass(defaultOpt.selectedCls);
}
}
$.fn.ezMark = function (options) {
var defaults = $.extend({}, defaultOptions, options);

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

if ((type === 'radio' || type === 'checkbox') && !$.data(this.parentNode, NAMESPACE)) {
var $this = $(this);
var classNames;
var isDisabled = !!this.disabled;

if (type === 'checkbox') {
classNames = {
input: defaults.checkboxClass,
label: defaults.labelCheckboxClass
};
}
else {
classNames = {
input: defaults.radioClass,
label: defaults.labelRadioClass
};
}

classNames.disabled = defaults.disabledClass;

$this.addClass(defaults.hideClass + ' ' + DELEGATE_CLASS)
.wrap('<div class="' +
classNames.input + ' ' +
DELEGATE_CLASS + (isDisabled ? ' ' + classNames.disabled : '') + '">');
var $parent = $this.parent();

if (this.checked) {
$parent.addClass(defaults.checkedClass);
}

$('label[for=' + this.id + ']').addClass(defaults.labelClass + ' ' + DELEGATE_CLASS + ' ' + classNames.label + (isDisabled ? ' ' + classNames.disabled : ''));
$.data(
$parent[0],
NAMESPACE,
{
classNames: {
checkedClass: defaults.checkedClass,
hoverClass: defaults.hoverClass
}
}
);
}
});
};

$(function () {
$(document.body).delegate('input.' + DELEGATE_CLASS, 'click', function ($e) {
var $this = $(this);
var type = this.type;
var $parent = $this.parent();
var parent = $parent[0];
var className = $.data(parent, NAMESPACE).classNames.checkedClass;

if (type === 'checkbox') {
$parent[(this.checked ? 'add' : 'remove') + 'Class'](className);
}
else if (type === 'radio') {
$('input[name="' + this.name + '"]').parent().removeClass(className);
if (this.checked) {
$parent.addClass(className);
}
}
}).delegate('div.' + DELEGATE_CLASS, 'hover', function () {
$(this).toggleClass($.data(this, NAMESPACE).classNames.hoverClass);
}).delegate('label.' + DELEGATE_CLASS, 'hover', function () {
var $divWrapper = $('#' + this.htmlFor).parent();
$divWrapper.toggleClass($.data($divWrapper[0], NAMESPACE).classNames.hoverClass);
});
});
}
})(jQuery);
}(jQuery));