1/* 2 Bootstrap - File Input 3 ====================== 4 5 This is meant to convert all file input tags into a set of elements that displays consistently in all browsers. 6 7 Converts all 8 <input type="file"> 9 into Bootstrap buttons 10 <a class="btn">Browse</a> 11 12*/ 13(function($) { 14 15$.fn.bootstrapFileInput = function() { 16 17 this.each(function(i,elem){ 18 19 var $elem = $(elem); 20 21 // Maybe some fields don't need to be standardized. 22 if (typeof $elem.attr('data-bfi-disabled') != 'undefined') { 23 return; 24 } 25 26 // Set the word to be displayed on the button 27 var buttonWord = 'Browse'; 28 29 if (typeof $elem.attr('title') != 'undefined') { 30 buttonWord = $elem.attr('title'); 31 } 32 33 var className = ''; 34 35 if (!!$elem.attr('class')) { 36 className = ' ' + $elem.attr('class'); 37 } 38 39 // Now we're going to wrap that input field with a Bootstrap button. 40 // The input will actually still be there, it will just be float above and transparent (done with the CSS). 41 $elem.wrap('<a class="file-input-wrapper btn btn-default ' + className + '"></a>').parent().prepend($('<span></span>').html(buttonWord)); 42 }) 43 44 // After we have found all of the file inputs let's apply a listener for tracking the mouse movement. 45 // This is important because the in order to give the illusion that this is a button in FF we actually need to move the button from the file input under the cursor. Ugh. 46 .promise().done( function(){ 47 48 // As the cursor moves over our new Bootstrap button we need to adjust the position of the invisible file input Browse button to be under the cursor. 49 // This gives us the pointer cursor that FF denies us 50 $('.file-input-wrapper').mousemove(function(cursor) { 51 52 var input, wrapper, 53 wrapperX, wrapperY, 54 inputWidth, inputHeight, 55 cursorX, cursorY; 56 57 // This wrapper element (the button surround this file input) 58 wrapper = $(this); 59 // The invisible file input element 60 input = wrapper.find("input"); 61 // The left-most position of the wrapper 62 wrapperX = wrapper.offset().left; 63 // The top-most position of the wrapper 64 wrapperY = wrapper.offset().top; 65 // The with of the browsers input field 66 inputWidth= input.width(); 67 // The height of the browsers input field 68 inputHeight= input.height(); 69 //The position of the cursor in the wrapper 70 cursorX = cursor.pageX; 71 cursorY = cursor.pageY; 72 73 //The positions we are to move the invisible file input 74 // The 20 at the end is an arbitrary number of pixels that we can shift the input such that cursor is not pointing at the end of the Browse button but somewhere nearer the middle 75 moveInputX = cursorX - wrapperX - inputWidth + 30; 76 // Slides the invisible input Browse button to be positioned middle under the cursor 77 moveInputY = cursorY- wrapperY - (inputHeight/2) + 10; 78 79 // Apply the positioning styles to actually move the invisible file input 80 /* 81 input.css({ 82 left:moveInputX, 83 top:moveInputY 84 });*/ 85 }); 86 87 $('body').on('change', '.file-input-wrapper input[type=file]', function(){ 88 89 var fileName; 90 fileName = $(this).val(); 91 92 // Remove any previous file names 93 $(this).parent().next('.file-input-name').remove(); 94 if (!!$(this).prop('files') && $(this).prop('files').length > 1) { 95 fileName = $(this)[0].files.length+' files'; 96 } 97 else { 98 fileName = fileName.substring(fileName.lastIndexOf('\\') + 1, fileName.length); 99 } 100 101 // Don't try to show the name if there is none 102 if (!fileName) { 103 return; 104 } 105 106 var selectedFileNamePlacement = $(this).data('filename-placement'); 107 if (selectedFileNamePlacement === 'inside') { 108 // Print the fileName inside 109 $(this).siblings('span').html(fileName); 110 $(this).attr('title', fileName); 111 } else { 112 // Print the fileName aside (right after the the button) 113 $(this).parent().after('<span class="file-input-name">'+fileName+'</span>'); 114 } 115 }); 116 117 }); 118 119}; 120 121// Add the styles before the first stylesheet 122// This ensures they can be easily overridden with developer styles 123var cssHtml = '<style>'+ 124 '.file-input-wrapper { overflow: hidden; position: relative; cursor: pointer; z-index: 1; }'+ 125 '.file-input-wrapper input[type=file], .file-input-wrapper input[type=file]:focus, .file-input-wrapper input[type=file]:hover { position: absolute; top: 0; left: 0; cursor: pointer; opacity: 0; filter: alpha(opacity=0); z-index: 99; outline: 0; }'+ 126 '.file-input-name { margin-left: 8px; }'+ 127 '</style>'; 128$('link[rel=stylesheet]').eq(0).before(cssHtml); 129 130})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.