Skip to content

Instantly share code, notes, and snippets.

@bensochar
Last active August 29, 2015 13:56
Show Gist options
  • Save bensochar/9220093 to your computer and use it in GitHub Desktop.
Save bensochar/9220093 to your computer and use it in GitHub Desktop.

Revisions

  1. bensochar revised this gist Feb 26, 2014. 1 changed file with 71 additions and 1 deletion.
    72 changes: 71 additions & 1 deletion jQuery Checkbox Change for oldies
    Original file line number Diff line number Diff line change
    @@ -1 +1,71 @@
    rfrf
    jQuery(document).ready(function($) {
    $('label :checkbox').checkedChange();
    $('label :checkbox').wrapCheckboxInputs();
    $('label :radio').radioChange();
    });

    (function($) {
    $.fn.wrapRadioInputs = function() {
    return this.each(function() {
    var _label = $(this).closest("label.radio");
    var _nme = this.name;
    var _id = this.id;
    $(this).wrap('<div class="box" data-id="' + _id + '"></div>').wrap('<div class="check" data-id="' + _id + '"></div>');
    });
    }
    $.fn.radioChange = function(_class) {
    _class = _class || "checked";
    return this.each(function() {
    var _label = $(this).closest("label.radio");
    var _nme = this.name;
    if (!navigator.userAgent.match(/MSIE/)) {
    $(this).change(function() {
    $('label[for="' + _nme + '"]').removeClass(_class);
    $(this).is(":checked") ? _label.addClass(_class) : _label.removeClass(_class);
    })
    } else {
    $(_label).click(function() {
    $('label[for="' + _nme + '"]').removeClass(_class);
    $(':radio', this).is(":checked") ? _label.addClass(_class) : _label.removeClass(_class);
    })
    }
    $(this).focus(function() {
    $(_label).addClass("focus");
    });
    $(this).blur(function() {
    $(_label).removeClass("focus");
    });
    });
    };

    $.fn.wrapCheckboxInputs = function() {
    return this.each(function() {
    var _label = $(this).closest("label.checkbox");
    var _nme = this.name;
    var _id = this.id;
    $(this).wrap('<div class="box" data-id="' + _id + '"></div>').wrap('<div class="check" data-id="' + _id + '"></div>');
    });
    }
    $.fn.checkedChange = function(_class) {
    _class = _class || "checked";
    return this.each(function() {
    var _label = $(this).closest("label.checkbox");
    var _nme = this.name;
    if (!navigator.userAgent.match(/MSIE/)) {
    $(this).change(function() {
    $(this).is(":checked") ? _label.addClass(_class) : _label.removeClass(_class);
    });
    } else {
    $(this).click(function() {
    $(this).is(":checked") ? _label.addClass(_class) : _label.removeClass(_class);
    });
    }
    $(this).focus(function() {
    $(_label).addClass("focus");
    });
    $(this).blur(function() {
    $(_label).removeClass("focus");
    });
    });
    };
    })(jQuery);
  2. bensochar revised this gist Feb 26, 2014. 1 changed file with 1 addition and 71 deletions.
    72 changes: 1 addition & 71 deletions jQuery Checkbox Change for oldies
    Original file line number Diff line number Diff line change
    @@ -1,71 +1 @@
    jQuery(document).ready(function($) {
    $('label :checkbox').checkedChange();
    $('label :checkbox').wrapCheckboxInputs();
    });


    (function($) {
    $.fn.wrapRadioInputs = function() {
    return this.each(function () {
    var _label = $(this).closest("label.radio");
    var _nme = this.name;
    var _id = this.id;
    $(this).wrap('<div class="box" data-id="'+_id+'"></div>').wrap('<div class="check" data-id="'+_id+'"></div>');
    });
    }
    $.fn.radioChange = function (_class) {
    _class = _class || "checked";
    return this.each(function () {
    var _label = $(this).closest("label.radio");
    var _nme = this.name;
    if(!navigator.userAgent.match(/MSIE/) ) {
    $(this).change(function() {
    $('input[name="' + _nme + '"]').closest("label.radio").removeClass(_class);
    $(this).is(":checked") ? _label.addClass(_class) : _label.removeClass(_class);
    })
    } else {
    $(_chk).click(function() {
    $('input[name="' + _nme + '"]').closest("label.radio").removeClass(_class);
    $(':radio', this).is(":checked") ? _label.addClass(_class) : _label.removeClass(_class);
    })
    }
    $(this).focus(function() {
    $(_label).addClass("focus");
    });
    $(this).blur(function() {
    $(_label).removeClass("focus");
    });
    });
    };

    $.fn.wrapCheckboxInputs = function() {
    return this.each(function () {
    var _label = $(this).closest("label.checkbox");
    var _nme = this.name;
    var _id = this.id;
    $(this).wrap('<div class="box" data-id="'+_id+'"></div>').wrap('<div class="check" data-id="'+_id+'"></div>');
    });
    }
    $.fn.checkedChange = function (_class) {
    _class = _class || "checked";
    return this.each(function () {
    var _label = $(this).closest("label.checkbox");
    var _nme = this.name;
    if(!navigator.userAgent.match(/MSIE/) ) {
    $(this).change(function() {
    $(this).is(":checked") ? _label.addClass(_class) : _label.removeClass(_class);
    });
    } else {
    $(this).click(function() {
    $(this).is(":checked") ? _label.addClass(_class) : _label.removeClass(_class);
    });
    }
    $(this).focus(function() {
    $(_label).addClass("focus");
    });
    $(this).blur(function() {
    $(_label).removeClass("focus");
    });
    });
    };
    })(jQuery);
    rfrf
  3. bensochar revised this gist Feb 26, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions jQuery Checkbox Change for oldies
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,7 @@ jQuery(document).ready(function($) {
    $('label :checkbox').wrapCheckboxInputs();
    });


    (function($) {
    $.fn.wrapRadioInputs = function() {
    return this.each(function () {
  4. bensochar revised this gist Feb 26, 2014. 1 changed file with 30 additions and 30 deletions.
    60 changes: 30 additions & 30 deletions jQuery Checkbox Change for oldies
    Original file line number Diff line number Diff line change
    @@ -5,59 +5,59 @@ jQuery(document).ready(function($) {

    (function($) {
    $.fn.wrapRadioInputs = function() {
    return this.each(function() {
    return this.each(function () {
    var _label = $(this).closest("label.radio");
    var _nme = this.name;
    var _id = this.id;
    $(this).wrap('<div class="box" data-id="' + _id + '"></div>').wrap('<div class="check" data-id="' + _id + '"></div>');
    $(this).wrap('<div class="box" data-id="'+_id+'"></div>').wrap('<div class="check" data-id="'+_id+'"></div>');
    });
    }
    $.fn.radioChange = function(_class) {
    _class = _class || "checked";
    return this.each(function() {
    var _label = $(this).closest("label.radio");
    var _nme = this.name;
    if (!navigator.userAgent.match(/MSIE/)) {
    $(this).change(function() {
    $('label[for="' + _nme + '"]').removeClass(_class);
    $(this).is(":checked") ? _label.addClass(_class) : _label.removeClass(_class);
    })
    } else {
    $(_label).click(function() {
    $('label[for="' + _nme + '"]').removeClass(_class);
    $(':radio', this).is(":checked") ? _label.addClass(_class) : _label.removeClass(_class);
    })
    }
    $(this).focus(function() {
    $(_label).addClass("focus");
    });
    $(this).blur(function() {
    $(_label).removeClass("focus");
    });
    $.fn.radioChange = function (_class) {
    _class = _class || "checked";
    return this.each(function () {
    var _label = $(this).closest("label.radio");
    var _nme = this.name;
    if(!navigator.userAgent.match(/MSIE/) ) {
    $(this).change(function() {
    $('input[name="' + _nme + '"]').closest("label.radio").removeClass(_class);
    $(this).is(":checked") ? _label.addClass(_class) : _label.removeClass(_class);
    })
    } else {
    $(_chk).click(function() {
    $('input[name="' + _nme + '"]').closest("label.radio").removeClass(_class);
    $(':radio', this).is(":checked") ? _label.addClass(_class) : _label.removeClass(_class);
    })
    }
    $(this).focus(function() {
    $(_label).addClass("focus");
    });
    $(this).blur(function() {
    $(_label).removeClass("focus");
    });
    });
    };

    $.fn.wrapCheckboxInputs = function() {
    return this.each(function() {
    return this.each(function () {
    var _label = $(this).closest("label.checkbox");
    var _nme = this.name;
    var _id = this.id;
    $(this).wrap('<div class="box" data-id="' + _id + '"></div>').wrap('<div class="check" data-id="' + _id + '"></div>');
    $(this).wrap('<div class="box" data-id="'+_id+'"></div>').wrap('<div class="check" data-id="'+_id+'"></div>');
    });
    }
    $.fn.checkedChange = function(_class) {
    $.fn.checkedChange = function (_class) {
    _class = _class || "checked";
    return this.each(function() {
    return this.each(function () {
    var _label = $(this).closest("label.checkbox");
    var _nme = this.name;
    if (!navigator.userAgent.match(/MSIE/)) {
    if(!navigator.userAgent.match(/MSIE/) ) {
    $(this).change(function() {
    $(this).is(":checked") ? _label.addClass(_class) : _label.removeClass(_class);
    });
    } else {
    $(this).click(function() {
    $(this).is(":checked") ? _label.addClass(_class) : _label.removeClass(_class);
    });
    });
    }
    $(this).focus(function() {
    $(_label).addClass("focus");
  5. bensochar revised this gist Feb 26, 2014. 1 changed file with 30 additions and 30 deletions.
    60 changes: 30 additions & 30 deletions jQuery Checkbox Change for oldies
    Original file line number Diff line number Diff line change
    @@ -5,59 +5,59 @@ jQuery(document).ready(function($) {

    (function($) {
    $.fn.wrapRadioInputs = function() {
    return this.each(function () {
    return this.each(function() {
    var _label = $(this).closest("label.radio");
    var _nme = this.name;
    var _id = this.id;
    $(this).wrap('<div class="box" data-id="'+_id+'"></div>').wrap('<div class="check" data-id="'+_id+'"></div>');
    $(this).wrap('<div class="box" data-id="' + _id + '"></div>').wrap('<div class="check" data-id="' + _id + '"></div>');
    });
    }
    $.fn.radioChange = function (_class) {
    _class = _class || "checked";
    return this.each(function () {
    var _label = $(this).closest("label.radio");
    var _nme = this.name;
    if(!navigator.userAgent.match(/MSIE/) ) {
    $(this).change(function() {
    $('input[name="' + _nme + '"]').closest("label.radio").removeClass(_class);
    $(this).is(":checked") ? _label.addClass(_class) : _label.removeClass(_class);
    })
    } else {
    $(_chk).click(function() {
    $('input[name="' + _nme + '"]').closest("label.radio").removeClass(_class);
    $(':radio', this).is(":checked") ? _label.addClass(_class) : _label.removeClass(_class);
    })
    }
    $(this).focus(function() {
    $(_label).addClass("focus");
    });
    $(this).blur(function() {
    $(_label).removeClass("focus");
    $.fn.radioChange = function(_class) {
    _class = _class || "checked";
    return this.each(function() {
    var _label = $(this).closest("label.radio");
    var _nme = this.name;
    if (!navigator.userAgent.match(/MSIE/)) {
    $(this).change(function() {
    $('label[for="' + _nme + '"]').removeClass(_class);
    $(this).is(":checked") ? _label.addClass(_class) : _label.removeClass(_class);
    })
    } else {
    $(_label).click(function() {
    $('label[for="' + _nme + '"]').removeClass(_class);
    $(':radio', this).is(":checked") ? _label.addClass(_class) : _label.removeClass(_class);
    })
    }
    $(this).focus(function() {
    $(_label).addClass("focus");
    });
    $(this).blur(function() {
    $(_label).removeClass("focus");
    });
    });
    });
    };

    $.fn.wrapCheckboxInputs = function() {
    return this.each(function () {
    return this.each(function() {
    var _label = $(this).closest("label.checkbox");
    var _nme = this.name;
    var _id = this.id;
    $(this).wrap('<div class="box" data-id="'+_id+'"></div>').wrap('<div class="check" data-id="'+_id+'"></div>');
    $(this).wrap('<div class="box" data-id="' + _id + '"></div>').wrap('<div class="check" data-id="' + _id + '"></div>');
    });
    }
    $.fn.checkedChange = function (_class) {
    $.fn.checkedChange = function(_class) {
    _class = _class || "checked";
    return this.each(function () {
    return this.each(function() {
    var _label = $(this).closest("label.checkbox");
    var _nme = this.name;
    if(!navigator.userAgent.match(/MSIE/) ) {
    if (!navigator.userAgent.match(/MSIE/)) {
    $(this).change(function() {
    $(this).is(":checked") ? _label.addClass(_class) : _label.removeClass(_class);
    });
    } else {
    $(this).click(function() {
    $(this).is(":checked") ? _label.addClass(_class) : _label.removeClass(_class);
    });
    });
    }
    $(this).focus(function() {
    $(_label).addClass("focus");
  6. bensochar revised this gist Feb 26, 2014. 1 changed file with 32 additions and 2 deletions.
    34 changes: 32 additions & 2 deletions jQuery Checkbox Change for oldies
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,41 @@

    jQuery(document).ready(function($) {
    $('label :checkbox').checkedChange();
    $('label :checkbox').wrapCheckboxInputs();
    });

    (function($) {
    $.fn.wrapRadioInputs = function() {
    return this.each(function () {
    var _label = $(this).closest("label.radio");
    var _nme = this.name;
    var _id = this.id;
    $(this).wrap('<div class="box" data-id="'+_id+'"></div>').wrap('<div class="check" data-id="'+_id+'"></div>');
    });
    }
    $.fn.radioChange = function (_class) {
    _class = _class || "checked";
    return this.each(function () {
    var _label = $(this).closest("label.radio");
    var _nme = this.name;
    if(!navigator.userAgent.match(/MSIE/) ) {
    $(this).change(function() {
    $('input[name="' + _nme + '"]').closest("label.radio").removeClass(_class);
    $(this).is(":checked") ? _label.addClass(_class) : _label.removeClass(_class);
    })
    } else {
    $(_chk).click(function() {
    $('input[name="' + _nme + '"]').closest("label.radio").removeClass(_class);
    $(':radio', this).is(":checked") ? _label.addClass(_class) : _label.removeClass(_class);
    })
    }
    $(this).focus(function() {
    $(_label).addClass("focus");
    });
    $(this).blur(function() {
    $(_label).removeClass("focus");
    });
    });
    };

    $.fn.wrapCheckboxInputs = function() {
    return this.each(function () {
    @@ -36,5 +67,4 @@ jQuery(document).ready(function($) {
    });
    });
    };

    })(jQuery);
  7. bensochar revised this gist Feb 26, 2014. 1 changed file with 13 additions and 12 deletions.
    25 changes: 13 additions & 12 deletions jQuery Checkbox Change for oldies
    Original file line number Diff line number Diff line change
    @@ -1,32 +1,33 @@


    jQuery(document).ready(function($) {
    $('label :checkbox').checkedChange();
    $('.lt-ie9 label :checkbox').checkedChangeClick();
    $('label :checkbox').wrapCheckboxInputs();
    });

    (function($) {

    $.fn.checkedChangeClick = function (_class) {
    _class = _class || "checked";
    $.fn.wrapCheckboxInputs = function() {
    return this.each(function () {
    var _label = $(this).closest("label.checkbox");
    var _nme = this.name;
    $(_label).click(function() {

    $(':checkbox', this).is(":checked") ? _label.addClass(_class) : _label.removeClass(_class);
    });
    var _id = this.id;
    $(this).wrap('<div class="box" data-id="'+_id+'"></div>').wrap('<div class="check" data-id="'+_id+'"></div>');
    });
    };
    }
    $.fn.checkedChange = function (_class) {
    _class = _class || "checked";
    return this.each(function () {
    var _label = $(this).closest("label.checkbox");
    var _nme = this.name;
    $(this).change(function() {
    $(this).is(":checked") ? _label.addClass(_class) : _label.removeClass(_class);
    });
    if(!navigator.userAgent.match(/MSIE/) ) {
    $(this).change(function() {
    $(this).is(":checked") ? _label.addClass(_class) : _label.removeClass(_class);
    });
    } else {
    $(this).click(function() {
    $(this).is(":checked") ? _label.addClass(_class) : _label.removeClass(_class);
    });
    }
    $(this).focus(function() {
    $(_label).addClass("focus");
    });
  8. bensochar revised this gist Feb 25, 2014. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions jQuery Checkbox Change for oldies
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,9 @@



    jQuery(document).ready(function($) {
    $('label :checkbox').checkedChange();
    $('.lt-ie9 label :checkbox').checkedChangeClick();
    $('label :checkbox').wrapCheckboxInputs();
    });

    (function($) {
    @@ -14,7 +14,8 @@ jQuery(document).ready(function($) {
    var _label = $(this).closest("label.checkbox");
    var _nme = this.name;
    $(_label).click(function() {
    _label.hasClass(_class) ? _label.removeClass(_class) : _label.addClass(_class);

    $(':checkbox', this).is(":checked") ? _label.addClass(_class) : _label.removeClass(_class);
    });
    });
    };
  9. bensochar revised this gist Feb 25, 2014. 1 changed file with 13 additions and 1 deletion.
    14 changes: 13 additions & 1 deletion jQuery Checkbox Change for oldies
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,13 @@



    jQuery(document).ready(function($) {
    $('label :checkbox').checkedChange();
    $('.lt-ie9 label :checkbox').checkedChangeClick();
    });

    (function($) {

    $.fn.checkedChangeClick = function (_class) {
    _class = _class || "checked";
    return this.each(function () {
    @@ -23,4 +33,6 @@
    $(_label).removeClass("focus");
    });
    });
    };
    };

    })(jQuery);
  10. bensochar created this gist Feb 25, 2014.
    26 changes: 26 additions & 0 deletions jQuery Checkbox Change for oldies
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    $.fn.checkedChangeClick = function (_class) {
    _class = _class || "checked";
    return this.each(function () {
    var _label = $(this).closest("label.checkbox");
    var _nme = this.name;
    $(_label).click(function() {
    _label.hasClass(_class) ? _label.removeClass(_class) : _label.addClass(_class);
    });
    });
    };
    $.fn.checkedChange = function (_class) {
    _class = _class || "checked";
    return this.each(function () {
    var _label = $(this).closest("label.checkbox");
    var _nme = this.name;
    $(this).change(function() {
    $(this).is(":checked") ? _label.addClass(_class) : _label.removeClass(_class);
    });
    $(this).focus(function() {
    $(_label).addClass("focus");
    });
    $(this).blur(function() {
    $(_label).removeClass("focus");
    });
    });
    };