-
Notifications
You must be signed in to change notification settings - Fork 20
/
jquery.fs.picker.min.js
9 lines (8 loc) · 3.21 KB
/
jquery.fs.picker.min.js
1
2
3
4
5
6
7
8
9
/*
* Picker v3.1.2 - 2015-04-04
* A jQuery plugin for replacing default checkboxes and radios. Part of the formstone library.
* http://classic.formstone.it/picker/
*
* Copyright 2015 Ben Plum; MIT Licensed
*/
!function(a,b){"use strict";function c(b){b=a.extend({},l,b);for(var c=a(this),e=0,f=c.length;f>e;e++)d(c.eq(e),b);return c}function d(b,c){if(!b.data("picker")){c=a.extend({},c,b.data("picker-options"));var d=b.closest("label"),g=d.length?d.eq(0):a("label[for="+b.attr("id")+"]"),k=b.attr("type"),l="picker-"+("radio"===k?"radio":"checkbox"),m=b.attr("name"),n='<div class="picker-handle"><div class="picker-flag" /></div>';c.toggle&&(l+=" picker-toggle",n='<span class="picker-toggle-label on">'+c.labels.on+'</span><span class="picker-toggle-label off">'+c.labels.off+"</span>"+n),b.addClass("picker-element"),g.length?g.wrap('<div class="picker '+l+" "+c.customClass+'" />').before(n).addClass("picker-label"):b.before('<div class="picker '+l+" "+c.customClass+'">'+n+"</div>");var o=g.length?g.parents(".picker"):b.prev(".picker"),p=o.find(".picker-handle"),q=o.find(".picker-toggle-label");b.is(":checked")&&o.addClass("checked"),b.is(":disabled")&&o.addClass("disabled");var r=a.extend({},c,{$picker:o,$input:b,$handle:p,$label:g,$labels:q,group:m,isRadio:"radio"===k,isCheckbox:"checkbox"===k});r.$input.on("focus.picker",r,i).on("blur.picker",r,j).on("change.picker",r,f).on("click.picker",r,e).on("deselect.picker",r,h).data("picker",r),r.$picker.on("click.picker",r,e)}}function e(b){b.stopPropagation();var c=b.data;a(b.target).is(c.$input)||(b.preventDefault(),c.$input.trigger("click"))}function f(a){var b=a.data;if(!b.$input.is(":disabled")){var c=b.$input.is(":checked");b.isCheckbox?c?g(a,!0):h(a,!0):(c||k&&!c)&&g(a)}}function g(b,c){var d=b.data;"undefined"!=typeof d.group&&d.isRadio&&a('input[name="'+d.group+'"]').not(d.$input).trigger("deselect"),d.$picker.addClass("checked")}function h(a,b){var c=a.data;c.$picker.removeClass("checked")}function i(a){a.data.$picker.addClass("focus")}function j(a){a.data.$picker.removeClass("focus")}var k=document.all&&document.querySelector&&!document.addEventListener,l={customClass:"",toggle:!1,labels:{on:"ON",off:"OFF"}},m={defaults:function(b){return l=a.extend(l,b||{}),"object"==typeof this?a(this):!0},destroy:function(){return a(this).each(function(b,c){var d=a(c).data("picker");d&&(d.$picker.off(".picker"),d.$handle.remove(),d.$labels.remove(),d.$input.off(".picker").removeClass("picker-element").data("picker",null),d.$label.removeClass("picker-label").unwrap())})},disable:function(){return a(this).each(function(b,c){var d=a(c).data("picker");d&&(d.$input.prop("disabled",!0),d.$picker.addClass("disabled"))})},enable:function(){return a(this).each(function(b,c){var d=a(c).data("picker");d&&(d.$input.prop("disabled",!1),d.$picker.removeClass("disabled"))})},update:function(){return a(this).each(function(b,c){var d=a(c).data("picker");d&&!d.$input.is(":disabled")&&(d.$input.is(":checked")?g({data:d},!0):h({data:d},!0))})}};a.fn.picker=function(a){return m[a]?m[a].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof a&&a?this:c.apply(this,arguments)},a.picker=function(a){"defaults"===a&&m.defaults.apply(this,Array.prototype.slice.call(arguments,1))}}(jQuery);