-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.inputreplace.min.js
1 lines (1 loc) · 1.54 KB
/
jquery.inputreplace.min.js
1
!function(e,$){"use strict";$.fn.replaceInput=function(n){function t(e){var n=[],t,c;for(t=0,c=e.length;t<c;t++)n.push("[type="+e[t]+"]");return n}function c(e){var n=e,t=n.prev("input"),c=t.prop("id"),r=$('label[for="'+c+'"]');r.length&&(t.on("click",function(e){o(n,t),e.stopPropagation(),e.preventDefault()}),r.on("click",function(e){o(n,t),e.stopPropagation(),e.preventDefault()})),n.on({click:function(e){o(n,t),e.stopPropagation(),e.preventDefault()},keydown:function(e){32!=e.which&&13!=e.which||o(n,t)}})}function o(e,n){var t=e.hasClass("checked"),c=n.prop("type"),o=n.prop("name");t?"checkbox"===c&&(n.removeAttr("checked"),n.trigger("change"),e.removeClass("checked")):("radio"===c&&$("[name="+o+"]").each(function(){$(this).removeAttr("checked").next(".radio").removeClass("checked")}),n.prop("checked",!0),n.trigger("change"),e.addClass("checked"))}var r=$.extend({},$.fn.replaceInput.defaults,n),a,i=["checkbox","radio"];return a=r.replaceAll?$(this).find(t(i).toString()):$(this).find(r.selector),a.each(function(){var n=$(this),o,a,p,s,l;if(o=n.prop("type"),l=n.data("icon-class"),-1===$.inArray(o,i)&&e.console)return console.info('[replaceInput] id: "'+n.prop("id")+'"; unsupported input type: "'+o+'"; should be one of '+t(i).toString());p=r.hasIcon?l?" "+l:" icon-"+o:"",a='<span class="'+o+p+'" tabindex="0"></span>',n.hide().after(a),s=n.next("."+o),n.is(":checked")&&s.addClass("checked"),c(s)}),r.complete.call(this),this},$.fn.replaceInput.defaults={replaceAll:!0,selector:".js-input-replace",hasIcon:!0,complete:function(){}}}(window,window.jQuery);