include used options to file name.

This commit is contained in:
Georg Fischer 2013-12-15 20:25:46 +01:00
parent a2917280a9
commit 2e4e510341

View File

@ -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 };
}
);