-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.styledFileInput.js
1 lines (1 loc) · 1.54 KB
/
jquery.styledFileInput.js
1
(function(a){a.fn.styledFileInput=function(d){var g={styled_file_id:null,use_jquery_ui:true,classes:[],widget_height:null};d=a.extend(g,d);var f=this;var e=null;var b=null;var c=null;this.initStyledFileInput=function(){if(d.styled_file_id==null){alert('StyledFileInput widget: no "styled_file_id" option was passed.');return}f.addClass("styled_file_input");e=a("<div class='styled_file_input' id='"+d.styled_file_id+"'></div>");b=a("<span class='styled_file_input_filename'></span>");c=a("<button class='styled_file_input_browse_btn' id='"+d.styled_file_id+"BrowseBtn' type='button'>Browse...</button>");e.append(b);if(d.widget_height!=null){f.css({height:d.widget_height+"px"});e.css({height:d.widget_height+"px"});if(a.browser.msie&&parseInt(a.browser.version)<=8){e.css({lineHeight:d.widget_height+"px"});f.css({lineHeight:d.widget_height+"px"})}else{e.css({lineHeight:(parseInt(d.widget_height)-2)+"px"});f.css({lineHeight:(parseInt(d.widget_height)-2)+"px"})}}if(d.classes.length>0){for(var h=0;h<d.classes.length;h++){e.addClass(d.classes[h])}}f.after(e);e.after(c);if(d.use_jquery_ui==true&&a.ui!==undefined){c.button().on("click",this.triggerLinkedInputBoxClick)}else{c.on("click",this.triggerLinkedInputBoxClick)}e.on("click",this.triggerLinkedInputBoxClick);f.on("change",this.setCurrentFileNameText)};this.triggerLinkedInputBoxClick=function(h){f.focus().trigger("click")};this.setCurrentFileNameText=function(h){var i=f.prop("value");e.find("span.styled_file_input_filename").html(i).attr("title",i);f.blur()};this.initStyledFileInput();return this}})(jQuery);