This repository has been archived by the owner on May 1, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
custom-form-elements.min.js
2 lines (2 loc) · 3.09 KB
/
custom-form-elements.min.js
1
2
/*! Custom Form Elements v2.0.0 / http://github.com/karbassi/Custom-Form-Elements / Written by Ali Karbassi (karbassi.com) */
!function(e,t,s){var i=function(e){this.init.call(this,e)};i.prototype={init:function(e){this.options=s.extend({},i.options,e||{});var c=t.getElementsByTagName("head")[0],n=t.createElement("style");n.type="text/css";var o=t.createTextNode("input."+this.options.cssClass+" { display: none; } select."+this.options.cssClass+", input."+this.options.cssClass+'[type=file] { position: relative; display: block; opacity: 0; -ms-filter:"progid:DXImageTransform.Microsoft.Alpha"(Opacity=0); filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0); filter:alpha(opacity=0); z-index: 5; } ');n.styleSheet?n.styleSheet.cssText=o.nodeValue:n.appendChild(o),c.appendChild(n),this.repaint()},repaint:function(){s("."+this.options.cssClass+"[type=checkbox], ."+this.options.cssClass+"[type=radio], ."+this.options.cssClass+"[type=file], ."+this.options.cssClass).each(function(){var e=t.getElementById("cfe-"+this.id+".cfe");e&&s(e).remove();var i="cfe";"select-one"===this.type?i+=" cfe-select":(i+=" cfe-"+this.type,"file"!==this.type&&(this.checked?i+=" cfe-state-2":i+=" cfe-state-0")),this.disabled&&(i+=" cfe-disabled"),this.getAttribute("readonly")&&(i+=" cfe-readonly");var c=t.createElement("span");c.id="cfe-"+this.id,c.className=i,c.innerHTML=s(this).find("option:selected").text(),this.parentNode.insertBefore(c,this),s("label[for="+this.id+"]").addClass("cfe")}),this.listeners()},listeners:function(){var e=this;s(".cfe-radio:not(.cfe-disabled, .cfe-readonly), .cfe-checkbox:not(.cfe-disabled, .cfe-readonly)").off(".cfe").on("mousedown.cfe",function(t){e.mousedown(this,t)}).on("mouseup.cfe",function(t){e.mouseup(this,t)}),s("select."+e.options.cssClass+", input."+e.options.cssClass+"[type=file]").off(".cfe").on("change.cfe",e.change),s("label.cfe").off(".cfe").on("click.cfe",function(e){e.preventDefault()}).on("mousedown.cfe",function(s){var i=t.getElementById("cfe-"+this.htmlFor);s.target!==i&&i.className.indexOf("cfe-disabled")<0&&e.mousedown(i,s)}).on("mouseup.cfe",function(s){var i=t.getElementById("cfe-"+this.htmlFor);s.target!==i&&i.className.indexOf("cfe-disabled")<0&&e.mouseup(i,s)})},mousedown:function(e,s){if(s.isTrigger||1===s.which){var i=t.getElementById(e.id.split("cfe-").pop());this.setState(e,i.checked?3:1)}},mouseup:function(e,i){if(i.isTrigger||1===i.which){var c=this,n=t.getElementById(e.id.split("cfe-").pop());"radio"!==n.type||!0!==n.checked?(s("."+this.options.cssClass+'[type=radio][name="'+n.name+'"]').not(":disabled, .cfe-disabled, #"+n.id).each(function(){c.setState(t.getElementById("cfe-"+this.id),0)}),this.setState(e,n.checked?0:2),i.isTrigger||(n.checked=!n.checked),s(n).trigger("change")):this.setState(e,2)}},change:function(e){var s;s="file"===this.type?this.value.replace(/C:\\fakepath\\/,""):this.options[this.selectedIndex].text,t.getElementById("cfe-"+this.id).innerHTML=s},setState:function(e,t){e.className=e.className.replace(/(?:^|\s)cfe-state-\d(?!\S)/,""),e.className+=" cfe-state-"+t}},i.options={cssClass:"cfe-styled"},e.CustomFormElements=i}(window,document,jQuery);