Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for disabled state #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
120 changes: 77 additions & 43 deletions js/jquery.ezmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,59 +19,93 @@
* checkboxCls - custom Checkbox Class
* checkedCls - checkbox Checked State's Class
* radioCls - custom radiobutton Class
* selectedCls - radiobutton's Selected State's Class
* selectedCls - Selected State's Class
* disabledCls - Disabled State's Class
* focusCls - Focus State's Class
* hideCls - Hidden State's Class
*
* </usage>
*
* View Documention/Demo here:
* http://www.itsalif.info/content/ezmark-jquery-checkbox-radiobutton-plugin
*
* @author Abdullah Rubiyath
* @version 1.0
* @contributor Mohammad Ariful Haque
* @version 1.1
* @date June 27, 2010
*/

(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') {
$.fn.ezMark = function(options) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks well formatted but DONT EVER USE TABS.
Also probably it's not good to format someones code because now its hard to find out who is author with git blame.

options = options || {};
var defaultOpt = {
checkboxCls: options.checkboxCls || 'ez-checkbox',
radioCls: options.radioCls || 'ez-radio',
checkedCls: options.checkedCls || 'ez-checked',
selectedCls: options.selectedCls || 'ez-selected',
disabledCls: options.disabledCls || 'ez-disabled',
focusCls: options.focusCls || 'ez-disabled',
hideCls: options.hideCls || 'ez-hide'
};
return this.each(function() {
var $this = $(this);
var customClasses = $(this).attr('class') || '';
var wrapTag = $this.attr('type') == 'checkbox' ? '<div class="' + defaultOpt.checkboxCls + ' ' + customClasses + '">' : '<div class="' + defaultOpt.radioCls + ' ' + customClasses + '">';
// 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(':disabled')) {
$(this).parent().addClass(defaultOpt.disabledCls);
} else {
$(this).parent().removeClass(defaultOpt.disabledCls);
}
}).focus(function() {
$(this).parent().addClass(defaultOpt.focusCls);
}).blur(function() {
$(this).parent().removeClass(defaultOpt.focusCls);
});

if ($this.is(':checked')) {
$this.parent().addClass(defaultOpt.checkedCls);
}
if ($this.is('[disabled]')) {
$this.parent().addClass(defaultOpt.disabledCls);
}
}
else if ($this.attr('type') == 'radio') {

$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);
}
}
});
}
$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(':disabled')) {
$(this).parent().addClass(defaultOpt.disabledCls);
} else {
$(this).parent().removeClass(defaultOpt.disabledCls);
}
});
}).focus(function() {
$(this).parent().addClass(defaultOpt.focusCls);
}).blur(function() {
$(this).parent().removeClass(defaultOpt.focusCls);
});

if ($this.is(':checked')) {
$this.parent().addClass(defaultOpt.selectedCls);
}
if ($this.is('[disabled]')) {
$this.parent().addClass(defaultOpt.disabledCls);
}
}
});
};
})(jQuery);
9 changes: 5 additions & 4 deletions js/jquery.ezmark.min.js

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