Ero sivun ”Widget:JwObsCharts” versioiden välillä
Järvi-meriwikistä
Rivi 114: | Rivi 114: | ||
//https://www.jarviwiki.fi/wiki/Toiminnot:Lomakemuokkaus/ObsICE/V%C3%A4lij%C3%A4rvi_(74.021.1.051)/Luikonsaari | //https://www.jarviwiki.fi/wiki/Toiminnot:Lomakemuokkaus/ObsICE/V%C3%A4lij%C3%A4rvi_(74.021.1.051)/Luikonsaari | ||
+ | |||
+ | memo.editEl.on( 'click', function() { | ||
+ | |||
+ | window.location.href = memo.editUrl; | ||
+ | |||
+ | }); | ||
+ | |||
+ | memo.fullscreenEl.on( 'click', function() { | ||
+ | |||
+ | var elem = memo.widgetEl[0]; | ||
+ | |||
+ | if (!!document.fullscreenElement) { | ||
+ | |||
+ | //memo.options.chartArea = { top: memo.margins.top, left: memo.margins.left, width: (memo.widgetEl.width() - memo.margins.left - memo.margins.right), height: (memo.widgetEl.height() - memo.margins.top - memo.margins.bottom), backgroundColor: { fill: '#daf0fa', stroke: '#fff', strokeWidth: 6 }}; | ||
+ | |||
+ | if (document.exitFullscreen) { | ||
+ | document.exitFullscreen(); | ||
+ | } else if (document.mozCancelFullScreen) { /* Firefox */ | ||
+ | document.mozCancelFullScreen(); | ||
+ | } else if (document.webkitExitFullscreen) { /* Chrome, Safari and Opera */ | ||
+ | document.webkitExitFullscreen(); | ||
+ | } else if (document.msExitFullscreen) { /* IE/Edge */ | ||
+ | document.msExitFullscreen(); | ||
+ | } | ||
+ | |||
+ | memo.fullscreenEl.find( 'button' ).html( '<i class="fas fa-expand"></i>' ); | ||
+ | |||
+ | } else { | ||
+ | |||
+ | if (elem.requestFullscreen) { | ||
+ | elem.requestFullscreen(); | ||
+ | } else if (elem.mozRequestFullScreen) { /* Firefox */ | ||
+ | elem.mozRequestFullScreen(); | ||
+ | } else if (elem.webkitRequestFullscreen) { /* Chrome, Safari and Opera */ | ||
+ | elem.webkitRequestFullscreen(); | ||
+ | } else if (elem.msRequestFullscreen) { /* IE/Edge */ | ||
+ | elem.msRequestFullscreen(); | ||
+ | } | ||
+ | |||
+ | memo.fullscreenEl.find( 'button' ).html( '<i class="fas fa-compress"></i>' ); | ||
+ | |||
+ | } | ||
+ | |||
+ | //doResize(); | ||
+ | }); | ||
+ | |||
+ | memo.downloadEl.on( 'click', function() { | ||
+ | |||
+ | var header = ''; | ||
+ | header += '\uFEFF'; // BOM | ||
+ | var csv = ''; | ||
+ | //csv += '\r\nsep=,\r\n'; | ||
+ | |||
+ | var headerCols = []; | ||
+ | var csvCols = []; | ||
+ | |||
+ | if ( i18n[memo.obscode].type == 'num' ) { | ||
+ | |||
+ | //headerCols.push( i18n[ 'Date' ][ memo.lang ] ); | ||
+ | //headerCols.push( i18n[ 'Date' ][ memo.lang ] ); | ||
+ | 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].obsdatetime.getFullYear() + '-' + ( memo.obses[o].obsdatetime.getMonth() + 1 ) + '-' + memo.obses[o].obsdatetime.getDate() ); | ||
+ | |||
+ | if ( memo.obses[o].obsdatetime.getUTCHours() == 0 && memo.obses[o].obsdatetime.getUTCMinutes() == 0 && memo.obses[o].obsdatetime.getUTCSeconds() == 0 ) { | ||
+ | csvCols.push( '' ); | ||
+ | } else { | ||
+ | csvCols.push( ( "0" + memo.obses[o].obsdatetime.getUTCHours() ).slice(-2) + ':' + ( "0" + memo.obses[o].obsdatetime.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' ) { | ||
+ | |||
+ | if ( i18n[memo.obscode].season == 'winter' ) { | ||
+ | header += i18n[ 'season' ][ i18n[memo.obscode].season ][ memo.lang ]; | ||
+ | } else { | ||
+ | header += i18n[ 'year' ][ memo.lang ]; | ||
+ | } | ||
+ | |||
+ | header += ';' + i18n[ 'Observation' ][ memo.lang ]; | ||
+ | header += ';' + i18n[ 'Value' ][ memo.lang ]; | ||
+ | header += ';' + i18n[ 'ValueUnit' ][ memo.lang ]; | ||
+ | header += ';' + i18n[ 'Additionalinfo' ][ memo.lang ]; | ||
+ | header += ';' + i18n[ 'Image' ][ memo.lang ]; | ||
+ | header += ';' + i18n[ 'ObserverStatus' ][ memo.lang ]; | ||
+ | |||
+ | for ( var s in memo.seriesA ) { | ||
+ | |||
+ | for ( var o in memo.seriesA[ s ].obses ) { | ||
+ | |||
+ | obs = memo.seriesA[ s ].obses[ o ]; | ||
+ | |||
+ | csv += '\r\n'; | ||
+ | |||
+ | csv += obs.season + '-' + (obs.season+1); | ||
+ | |||
+ | csv += ';' + i18n[ memo.seriesA[ s ].id ].title[ memo.lang ]; | ||
+ | |||
+ | csv += ';' + obs.value; | ||
+ | csv += ';' + obs.valueUnit; | ||
+ | |||
+ | csv += ';' + obs.addInfo; | ||
+ | csv += ';'; | ||
+ | csv += ';' + obs.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].obsdatetime.toLocaleDateString(); //.toISOString(); | ||
+ | |||
+ | if ( memo.obses[o].obsdatetime.getUTCHours() == 0 && memo.obses[o].obsdatetime.getUTCMinutes() == 0 && memo.obses[o].obsdatetime.getUTCSeconds() == 0 ) { | ||
+ | csv += ';'; | ||
+ | } else { | ||
+ | csv += ';' + ( "0" + memo.obses[o].obsdatetime.getUTCHours() ).slice(-2) + ':' + ( "0" + memo.obses[o].obsdatetime.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; | ||
+ | //console.log( csv ); | ||
+ | var exportedFilename = memo.csvfile; | ||
+ | |||
+ | 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); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | }); | ||
}); | }); | ||
Rivi 1 031: | Rivi 1 214: | ||
}); | }); | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
jQuery( window ).resize(function() { | jQuery( window ).resize(function() { |