function replace() { $replacement .addClass(config.replacementClass + '-' + currentId) // CSS class name .insertBefore($input) // input'a .bind( 'mouseenter' , function () { toggleVisibility( true ); toggleHoverClass( true ); }) .bind( 'init' , function () { createWrapper(); // createFileName(); // }) .trigger( 'init' ); } * This source code was highlighted with Source Code Highlighter .
function replace() { $replacement .addClass(config.replacementClass + '-' + currentId) // CSS class name .insertBefore($input) // input'a .bind( 'mouseenter' , function () { toggleVisibility( true ); toggleHoverClass( true ); }) .bind( 'init' , function () { createWrapper(); // createFileName(); // }) .trigger( 'init' ); } * This source code was highlighted with Source Code Highlighter .
function replace() { $replacement .addClass(config.replacementClass + '-' + currentId) // CSS class name .insertBefore($input) // input'a .bind( 'mouseenter' , function () { toggleVisibility( true ); toggleHoverClass( true ); }) .bind( 'init' , function () { createWrapper(); // createFileName(); // }) .trigger( 'init' ); } * This source code was highlighted with Source Code Highlighter .
function replace() { $replacement .addClass(config.replacementClass + '-' + currentId) // CSS class name .insertBefore($input) // input'a .bind( 'mouseenter' , function () { toggleVisibility( true ); toggleHoverClass( true ); }) .bind( 'init' , function () { createWrapper(); // createFileName(); // }) .trigger( 'init' ); } * This source code was highlighted with Source Code Highlighter .
function replace() { $replacement .addClass(config.replacementClass + '-' + currentId) // CSS class name .insertBefore($input) // input'a .bind( 'mouseenter' , function () { toggleVisibility( true ); toggleHoverClass( true ); }) .bind( 'init' , function () { createWrapper(); // createFileName(); // }) .trigger( 'init' ); } * This source code was highlighted with Source Code Highlighter .
function replace() { $replacement .addClass(config.replacementClass + '-' + currentId) // CSS class name .insertBefore($input) // input'a .bind( 'mouseenter' , function () { toggleVisibility( true ); toggleHoverClass( true ); }) .bind( 'init' , function () { createWrapper(); // createFileName(); // }) .trigger( 'init' ); } * This source code was highlighted with Source Code Highlighter .
function replace() { $replacement .addClass(config.replacementClass + '-' + currentId) // CSS class name .insertBefore($input) // input'a .bind( 'mouseenter' , function () { toggleVisibility( true ); toggleHoverClass( true ); }) .bind( 'init' , function () { createWrapper(); // createFileName(); // }) .trigger( 'init' ); } * This source code was highlighted with Source Code Highlighter .
function replace() { $replacement .addClass(config.replacementClass + '-' + currentId) // CSS class name .insertBefore($input) // input'a .bind( 'mouseenter' , function () { toggleVisibility( true ); toggleHoverClass( true ); }) .bind( 'init' , function () { createWrapper(); // createFileName(); // }) .trigger( 'init' ); } * This source code was highlighted with Source Code Highlighter .
function replace() { $replacement .addClass(config.replacementClass + '-' + currentId) // CSS class name .insertBefore($input) // input'a .bind( 'mouseenter' , function () { toggleVisibility( true ); toggleHoverClass( true ); }) .bind( 'init' , function () { createWrapper(); // createFileName(); // }) .trigger( 'init' ); } * This source code was highlighted with Source Code Highlighter .
function replace() { $replacement .addClass(config.replacementClass + '-' + currentId) // CSS class name .insertBefore($input) // input'a .bind( 'mouseenter' , function () { toggleVisibility( true ); toggleHoverClass( true ); }) .bind( 'init' , function () { createWrapper(); // createFileName(); // }) .trigger( 'init' ); } * This source code was highlighted with Source Code Highlighter .
function replace() { $replacement .addClass(config.replacementClass + '-' + currentId) // CSS class name .insertBefore($input) // input'a .bind( 'mouseenter' , function () { toggleVisibility( true ); toggleHoverClass( true ); }) .bind( 'init' , function () { createWrapper(); // createFileName(); // }) .trigger( 'init' ); } * This source code was highlighted with Source Code Highlighter .
function replace() { $replacement .addClass(config.replacementClass + '-' + currentId) // CSS class name .insertBefore($input) // input'a .bind( 'mouseenter' , function () { toggleVisibility( true ); toggleHoverClass( true ); }) .bind( 'init' , function () { createWrapper(); // createFileName(); // }) .trigger( 'init' ); } * This source code was highlighted with Source Code Highlighter .
function replace() { $replacement .addClass(config.replacementClass + '-' + currentId) // CSS class name .insertBefore($input) // input'a .bind( 'mouseenter' , function () { toggleVisibility( true ); toggleHoverClass( true ); }) .bind( 'init' , function () { createWrapper(); // createFileName(); // }) .trigger( 'init' ); } * This source code was highlighted with Source Code Highlighter .
function replace() { $replacement .addClass(config.replacementClass + '-' + currentId) // CSS class name .insertBefore($input) // input'a .bind( 'mouseenter' , function () { toggleVisibility( true ); toggleHoverClass( true ); }) .bind( 'init' , function () { createWrapper(); // createFileName(); // }) .trigger( 'init' ); } * This source code was highlighted with Source Code Highlighter .
function replace() { $replacement .addClass(config.replacementClass + '-' + currentId) // CSS class name .insertBefore($input) // input'a .bind( 'mouseenter' , function () { toggleVisibility( true ); toggleHoverClass( true ); }) .bind( 'init' , function () { createWrapper(); // createFileName(); // }) .trigger( 'init' ); } * This source code was highlighted with Source Code Highlighter .
function replace() { $replacement .addClass(config.replacementClass + '-' + currentId) // CSS class name .insertBefore($input) // input'a .bind( 'mouseenter' , function () { toggleVisibility( true ); toggleHoverClass( true ); }) .bind( 'init' , function () { createWrapper(); // createFileName(); // }) .trigger( 'init' ); } * This source code was highlighted with Source Code Highlighter .
* This source code was highlighted with Source Code Highlighter .
- function createWrapper () {
- var cord = getElementCoordinates ($ replacement); // it is necessary that the wrapper be exactly the same size as the placeholder
- var wrap = $ ( '<div />' , {
- css: {
- position: "absolute" ,
- visibility: "hidden" , // the wrapper is hidden by default
- overflow: "hidden" ,
- zIndex: 10,000,000, // position it "above" all other elements on the page
- opacity: 0, // we should not see the standard button for loading
- left: cord.left,
- top: cord.top,
- width: $ replacement.get (0) .offsetWidth,
- height: $ replacement.get (0) .offsetHeight,
- margin: 0,
- padding: 0,
- direction: "ltr"
- }
- })
- .addClass (config.wrapperClass)
- .bind ( 'mouseout' , function () {
- toggleVisibility ( false );
- toggleHoverClass ( false );
- });
- $ input.wrap (wrap) .css (config.inputCss);
- }
* This source code was highlighted with Source Code Highlighter .
- inputCss: {
- fontSize: '600px' , // make the "Browse" button maximum large
- position: "absolute" ,
- right: 0, // align it with the right border of the wrapper
- margin: 0,
- padding: 0
- },
* This source code was highlighted with Source Code Highlighter .
- function createFileName () {
- try {
- if (! jQuery.contains ( document .body, $ filename.get (0))) {
- throw ( "not found" );
- }
- } catch (e) {
- if (! $ filename.length) {
- throw ( "filename is empty" );
- }
- $ replacement.after ($ filename);
- }
- $ filename.addClass (config.filenameClass + '-' + currentId);
- }
* This source code was highlighted with Source Code Highlighter .
- function onClear () {
- var el = $ input.get (0);
- var attrs = {};
- // copy all the attributes of the old input'a except for the value
- for ( var i = 0; i <el.attributes.length; i + = 1) {
- var attrib = el.attributes [i];
- if (attrib.specified === true && attrib.name! == 'value' ) {
- attrs [attrib.name] = attrib.value;
- }
- }
- attrs.value = "" ;
- // create a new input and replace it with the old one
- $ input = $ ( '<input />' , attrs);
- $ ( this ) .replaceWith ($ input);
- // bind events to it
- $ input.css (config.inputCss) .bind ( 'change' , onChange) .bind ( 'clear' , onClear) .trigger ( 'change' );
- toggleActiveClass ( false );
- }
* This source code was highlighted with Source Code Highlighter .
- <script type = "text / javascript" >
- $ ( function () {
- $ ( "# fileupload-1" ) .customInputFile ({
- filename: "# filename-1"
- });
- $ ( "# fileupload-2" ) .customInputFile ();
- $ ( '#clear' ) .bind ( 'click' , function () {
- $ ( "# fileupload-1, # fileupload-2" ) .trigger ( "clear" );
- });
- });
- </ script>
* This source code was highlighted with Source Code Highlighter .
- replacementClass: "customInputFile" ,
- replacementClassHover: "customInputFileHover" ,
- replacementClassActive: "customInputFileActive" ,
Source: https://habr.com/ru/post/98260/
All Articles