store name of uploaded file
This commit is contained in:
parent
d4108d5bc2
commit
06ea78b0d8
@ -7,21 +7,24 @@ define(
|
||||
var png_link;
|
||||
var default_file_name;
|
||||
var file_name;
|
||||
var download_file_name;
|
||||
var file_suffix = '.png';
|
||||
var file_suffix_regex = /(\.)(jpg|jpeg|png|gif|bmp)/ig;
|
||||
|
||||
function init( shared )
|
||||
{
|
||||
signals = shared.signals;
|
||||
export_button = document.getElementById( 'export-button' );
|
||||
png_link = document.getElementById( 'png-button' );
|
||||
|
||||
default_file_name = png_link.getAttribute( 'download' ).split( file_suffix )[0];
|
||||
file_name = default_file_name + file_suffix;
|
||||
default_file_name = png_link.getAttribute( 'download' ).replace( file_suffix_regex, '' );
|
||||
file_name = default_file_name;
|
||||
download_file_name = default_file_name;
|
||||
|
||||
export_button.addEventListener( 'click', exportButtonClicked, false );
|
||||
png_link.addEventListener( 'click', hidePNGLink, false );
|
||||
|
||||
signals['control-updated'].add( updateFileName );
|
||||
signals['load-file'].add( updateFileName );
|
||||
signals['control-updated'].add( updateDownloadFileName );
|
||||
}
|
||||
|
||||
function exportButtonClicked( event )
|
||||
@ -31,15 +34,26 @@ define(
|
||||
signals['image-data-url-requested'].dispatch( updatePNGLinkAddress );
|
||||
}
|
||||
|
||||
function updateFileName( options )
|
||||
function updateFileName( file )
|
||||
{
|
||||
file_name = default_file_name + '-' + objToString( options ) + '.png';
|
||||
if (
|
||||
file &&
|
||||
typeof file.name === 'string'
|
||||
)
|
||||
{
|
||||
file_name = file.name.replace( file_suffix_regex, '' );
|
||||
}
|
||||
}
|
||||
|
||||
function updateDownloadFileName( options )
|
||||
{
|
||||
download_file_name = file_name + '-' + objToString( options ) + file_suffix;
|
||||
}
|
||||
|
||||
function updatePNGLinkAddress( data_url )
|
||||
{
|
||||
png_link.href = data_url;
|
||||
png_link.setAttribute( 'download', file_name );
|
||||
png_link.setAttribute( 'download', download_file_name );
|
||||
png_link.classList.add( 'is-active' );
|
||||
}
|
||||
|
||||
@ -54,7 +68,7 @@ define(
|
||||
|
||||
for ( var key in obj )
|
||||
{
|
||||
result.push( key + '' + obj[key] );
|
||||
result.push( key[0] + '' + obj[key] );
|
||||
}
|
||||
|
||||
return result.join( '-' );
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user