Ero sivun ”Widget:XJwCharts” versioiden välillä
Järvi-meriwikistä
Rivi 50: | Rivi 50: | ||
// add fullscreen button | // add fullscreen button | ||
//memo.widgetEl.append( '<div class="obschartbutton fullscreen-button" style="Xdisplay: none; position: absolute; z-index: 120; float: right; top: 40px; right: 1.5px; background-color: rgba( 255, 255, 255, .9 ); border-radius: 50%; border: 1px solid rgba( 230, 230, 230, 0.75 ); width: 24px; height: 24px; padding: 0;"><button title="fullscreen" style="width: 24px; height: 24px; padding: 0; margin: 0; background: none; border: none; background-image: url( //www.jarviwiki.fi/widgets/img/fullscreen_16px.png ); background-size: 50%; background-position: center; background-repeat: no-repeat; "></button></div>' ); | //memo.widgetEl.append( '<div class="obschartbutton fullscreen-button" style="Xdisplay: none; position: absolute; z-index: 120; float: right; top: 40px; right: 1.5px; background-color: rgba( 255, 255, 255, .9 ); border-radius: 50%; border: 1px solid rgba( 230, 230, 230, 0.75 ); width: 24px; height: 24px; padding: 0;"><button title="fullscreen" style="width: 24px; height: 24px; padding: 0; margin: 0; background: none; border: none; background-image: url( //www.jarviwiki.fi/widgets/img/fullscreen_16px.png ); background-size: 50%; background-position: center; background-repeat: no-repeat; "></button></div>' ); | ||
− | memo.widgetEl.append( '<div class="obschartbutton fullscreen-button" style="Xdisplay: none; position: absolute; z-index: 120; float: right; top: 40px; right: 1.5px; background-color: rgba( 255, 255, 255, .9 ); border-radius: 50%; border: 1px solid rgba( 230, 230, 230, 0.75 ); width: 24px; height: 24px; padding: 0;"><button title="fullscreen" style="width: 24px; height: 24px; padding: 0; margin: 0; background: none; border: none; "><i class="fas fa-expand"></i></button></div>' ); | + | memo.widgetEl.append( '<div class="obschartbutton fullscreen-button" style="Xdisplay: none; position: absolute; z-index: 120; float: right; top: 40px; right: 1.5px; background-color: rgba( 255, 255, 255, .9 ); border-radius: 50%; border: 1px solid rgba( 230, 230, 230, 0.75 ); width: 24px; height: 24px; padding: 0;"><button title="fullscreen" style="width: 24px; height: 24px; padding: 0; margin: 0; background: none; border: none; "><i class="fas fa-expand"></i></button></div>' ); |
− | |||
memo.fullscreenEl = jQuery( this ).find( '.fullscreen-button' ); | memo.fullscreenEl = jQuery( this ).find( '.fullscreen-button' ); | ||
+ | |||
+ | // add download data button | ||
+ | memo.widgetEl.append( '<div class="obschartbutton download-button" style="display: none; position: absolute; z-index: 120; float: right; top: 70px; right: 1.5px; background-color: rgba( 255, 255, 255, .9 ); border-radius: 50%; border: 1px solid rgba( 230, 230, 230, 0.75 ); width: 24px; height: 24px; padding: 0;"><button title="' + i18n['download'][memo.lang] + '" style="width: 24px; height: 24px; padding: 0; margin: 0; background: none; border: none; background-image: url( //www.jarviwiki.fi/widgets/img/download_16px.png ); background-size: 50%; background-position: center; background-repeat: no-repeat; "></button></div>' ); | ||
+ | memo.downloadEl = jQuery( this ).find( '.download-button' ); | ||
memo.jw = new jwApi(); | memo.jw = new jwApi(); | ||
Rivi 142: | Rivi 145: | ||
memo.widgetEl.find( '.jwloading' ).remove(); | memo.widgetEl.find( '.jwloading' ).remove(); | ||
− | memo.fullscreenEl.fadeIn( "slow" ); | + | |
+ | memo.fullscreenEl.fadeIn( "slow" ); | ||
+ | memo.downloadEl.fadeIn( "slow" ); | ||
}); | }); | ||
Rivi 181: | Rivi 186: | ||
doResize(); | doResize(); | ||
+ | }); | ||
+ | |||
+ | memo.downloadEl.on( 'click', function() { | ||
+ | |||
+ | //console.log(memo); | ||
+ | |||
+ | var header = ''; | ||
+ | header += '\uFEFF'; // BOM | ||
+ | var csv = ''; | ||
+ | //csv += '\r\nsep=,\r\n'; | ||
+ | |||
+ | var headerCols = []; | ||
+ | var csvCols = []; | ||
+ | |||
+ | if ( i18n[memo.obscode].type == 'num' ) { | ||
+ | |||
+ | headerCols.push( 'Päivämäärä' ); | ||
+ | headerCols.push( 'Kellonaika' ); | ||
+ | headerCols.push( '"' + i18n[memo.obscode].axisTitleV[memo.lang] + '"' ); | ||
+ | headerCols.push( 'Lisätiedot' ); | ||
+ | headerCols.push( 'Valokuva' ); | ||
+ | headerCols.push( 'Havainnoijan status' ); | ||
+ | |||
+ | header += headerCols.join( i18n['sep'][memo.lang] ); | ||
+ | |||
+ | for ( var o in memo.obses ) { | ||
+ | |||
+ | csvCols = []; | ||
+ | |||
+ | csvCols.push( memo.obses[o].datetime.getFullYear() + '-' + ( memo.obses[o].datetime.getMonth() + 1 ) + '-' + memo.obses[o].datetime.getDate() ); | ||
+ | |||
+ | if ( memo.obses[o].datetime.getUTCHours() == 0 && memo.obses[o].datetime.getUTCMinutes() == 0 && memo.obses[o].datetime.getUTCSeconds() == 0 ) { | ||
+ | csvCols.push( '' ); | ||
+ | } else { | ||
+ | csvCols.push( ( "0" + memo.obses[o].datetime.getUTCHours() ).slice(-2) + ':' + ( "0" + memo.obses[o].datetime.getUTCMinutes() ).slice(-2) ); | ||
+ | } | ||
+ | |||
+ | csvCols.push( '"' + memo.obses[o].value.toString().replace( '.', i18n['dec'][memo.lang] ) + '"' ); | ||
+ | csvCols.push( memo.obses[o].addInfo ); | ||
+ | csvCols.push( '' ); | ||
+ | csvCols.push( memo.obses[o].maintainer ); | ||
+ | |||
+ | csv += '\r\n' + csvCols.join( i18n['sep'][memo.lang] ); | ||
+ | |||
+ | } | ||
+ | |||
+ | |||
+ | } else if ( i18n[memo.obscode].type == 'date' ) { | ||
+ | |||
+ | header += 'Vuosi'; | ||
+ | header += ';' + i18n[memo.obscode].title[memo.lang]; | ||
+ | header += ';' + 'Lisätiedot'; | ||
+ | header += ';' + 'Valokuva'; | ||
+ | header += ';' + 'Havainnoijan status'; | ||
+ | |||
+ | for ( var o in memo.obses ) { | ||
+ | |||
+ | csv += '\r\n'; | ||
+ | |||
+ | csv += memo.obses[o].datetime.getFullYear(); | ||
+ | |||
+ | csv += ';' + memo.obses[o].datetime.getDate() + '.' + (memo.obses[o].datetime.getMonth()+1); | ||
+ | |||
+ | csv += ';' + memo.obses[o].addInfo; | ||
+ | csv += ';'; | ||
+ | csv += ';' + memo.obses[o].maintainer; | ||
+ | |||
+ | } | ||
+ | |||
+ | } else if ( i18n[memo.obscode].type == 'cat' ) { | ||
+ | |||
+ | header += 'Päivämäärä'; | ||
+ | header += ';' + 'Kellonaika'; | ||
+ | header += ';' + i18n[memo.obscode].title[memo.lang]; | ||
+ | header += ';' + i18n[memo.obscode].title[memo.lang]; | ||
+ | header += ';' + utf8StringToUtf16String( 'Lisätiedot' ); | ||
+ | header += ';' + 'Valokuva'; | ||
+ | header += ';' + 'Havainnoijan status'; | ||
+ | |||
+ | for ( var o in memo.obses ) { | ||
+ | |||
+ | csv += '\r\n'; | ||
+ | |||
+ | csv += memo.obses[o].datetime.toLocaleDateString(); //.toISOString(); | ||
+ | |||
+ | if ( memo.obses[o].datetime.getUTCHours() == 0 && memo.obses[o].datetime.getUTCMinutes() == 0 && memo.obses[o].datetime.getUTCSeconds() == 0 ) { | ||
+ | csv += ';'; | ||
+ | } else { | ||
+ | csv += ';' + ( "0" + memo.obses[o].datetime.getUTCHours() ).slice(-2) + ':' + ( "0" + memo.obses[o].datetime.getUTCMinutes() ).slice(-2); | ||
+ | } | ||
+ | |||
+ | csv += ';' + memo.obses[o].value; | ||
+ | csv += ';' + i18n[memo.obscode].catNames[memo.obses[o].value][memo.lang]; | ||
+ | |||
+ | csv += ';' + memo.obses[o].addInfo; | ||
+ | csv += ';'; | ||
+ | csv += ';' + memo.obses[o].maintainer; | ||
+ | |||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | csv = header + csv; | ||
+ | |||
+ | var exportedFilename = 'test.csv'; | ||
+ | |||
+ | var blob = new Blob( [csv], { type: 'text/csv;charset=utf-16LE;' }); | ||
+ | |||
+ | if (navigator.msSaveBlob) { // IE 10+ | ||
+ | navigator.msSaveBlob(blob, exportedFilename); | ||
+ | } else { | ||
+ | var link = document.createElement("a"); | ||
+ | if (link.download !== undefined) { // feature detection | ||
+ | // Browsers that support HTML5 download attribute | ||
+ | var url = URL.createObjectURL(blob); | ||
+ | link.setAttribute("href", url); | ||
+ | link.setAttribute("download", exportedFilename); | ||
+ | link.style.visibility = 'hidden'; | ||
+ | document.body.appendChild(link); | ||
+ | link.click(); | ||
+ | document.body.removeChild(link); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | }); | ||
+ | |||
+ | |||
+ | jQuery( window ).resize(function() { | ||
+ | |||
+ | doResize(); | ||
+ | |||
}); | }); | ||