include used options to file name.
This commit is contained in:
parent
a2917280a9
commit
2e4e510341
@ -5,6 +5,9 @@ define(
|
||||
var signals;
|
||||
var export_button;
|
||||
var png_link;
|
||||
var default_file_name;
|
||||
var file_name;
|
||||
var file_suffix = '.png';
|
||||
|
||||
function init( shared )
|
||||
{
|
||||
@ -12,20 +15,31 @@ define(
|
||||
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;
|
||||
|
||||
export_button.addEventListener( 'click', exportButtonClicked, false );
|
||||
png_link.addEventListener( 'click', hidePNGLink, false );
|
||||
|
||||
signals['control-updated'].add( updateFileName );
|
||||
}
|
||||
|
||||
function exportButtonClicked( event )
|
||||
{
|
||||
event.preventDefault();
|
||||
|
||||
signals['image-data-url-requested'].dispatch( upldatePNGLinkAddress );
|
||||
signals['image-data-url-requested'].dispatch( updatePNGLinkAddress );
|
||||
}
|
||||
|
||||
function upldatePNGLinkAddress( data_url )
|
||||
function updateFileName( options )
|
||||
{
|
||||
file_name = default_file_name + '-' + objToString( options ) + '.png';
|
||||
}
|
||||
|
||||
function updatePNGLinkAddress( data_url )
|
||||
{
|
||||
png_link.href = data_url;
|
||||
png_link.setAttribute( 'download', file_name );
|
||||
png_link.classList.add( 'is-active' );
|
||||
}
|
||||
|
||||
@ -34,6 +48,18 @@ define(
|
||||
png_link.classList.remove( 'is-active' );
|
||||
}
|
||||
|
||||
function objToString( obj )
|
||||
{
|
||||
var result = [ ];
|
||||
|
||||
for ( var key in obj )
|
||||
{
|
||||
result.push( key + '' + obj[key] );
|
||||
}
|
||||
|
||||
return result.join( '-' );
|
||||
}
|
||||
|
||||
return { init: init };
|
||||
}
|
||||
);
|
||||
Loading…
x
Reference in New Issue
Block a user