Ero sivun ”Widget:CitobsDBcounter” versioiden välillä
Järvi-meriwikistä
(Ak: Uusi sivu: <includeonly> <script src="//www.jarviwiki.fi/citobsjs/citobso311.js"></script> <script type="text/javascript"> function <!--{$id|default:vesificounter|escape:'html'}-->_jQueryTest...) |
|||
(36 välissä olevaa versiota samalta käyttäjältä ei näytetä) | |||
Rivi 1: | Rivi 1: | ||
<includeonly> | <includeonly> | ||
+ | <span id="<!--{$id|default:vesificounter|escape:'html'}-->_container">...</span> | ||
<script src="//www.jarviwiki.fi/citobsjs/citobso311.js"></script> | <script src="//www.jarviwiki.fi/citobsjs/citobso311.js"></script> | ||
<script type="text/javascript"> | <script type="text/javascript"> | ||
+ | |||
function <!--{$id|default:vesificounter|escape:'html'}-->_jQueryTest() { | function <!--{$id|default:vesificounter|escape:'html'}-->_jQueryTest() { | ||
if ( typeof window.jQuery == 'undefined' || typeof queryApi == 'undefined' ) { | if ( typeof window.jQuery == 'undefined' || typeof queryApi == 'undefined' ) { | ||
setTimeout( function(){ <!--{$id|default:vesificounter|escape:'html'}-->_jQueryTest() }, 300); | setTimeout( function(){ <!--{$id|default:vesificounter|escape:'html'}-->_jQueryTest() }, 300); | ||
} else { | } else { | ||
− | <!--{$id|default:vesificounter|escape:'html'}--> | + | <!--{$id|default:vesificounter|escape:'html'}-->_jQueryOK(); |
} | } | ||
}; setTimeout( function(){ <!--{$id|default:vesificounter|escape:'html'}-->_jQueryTest() }, 300); | }; setTimeout( function(){ <!--{$id|default:vesificounter|escape:'html'}-->_jQueryTest() }, 300); | ||
− | function <!--{$id|default:vesificounter|escape:'html'}--> | + | function <!--{$id|default:vesificounter|escape:'html'}-->_jQueryOK() { |
− | + | ||
+ | jQuery.getScript( '//www.jarviwiki.fi/citobsjs/citobso311.js', function() { | ||
+ | <!--{$id|default:vesificounter|escape:'html'}-->_allOk() | ||
+ | }); | ||
} | } | ||
− | function <!--{$id|default:vesificounter|escape:'html'}--> | + | function <!--{$id|default:vesificounter|escape:'html'}-->_allOk() { |
+ | |||
+ | var lang = "<!--{$lang|default:fi|escape:'html'}-->"; | ||
+ | var service_code = "<!--{$service_code|default:x|escape:'html'}-->"; | ||
+ | var keyword = "<!--{$keyword|default:x|escape:'html'}-->"; | ||
+ | var start_date= "<!--{$start_date|default:x|escape:'html'}-->"; | ||
+ | var end_date= "<!--{$end_date|default:x|escape:'html'}-->"; | ||
+ | |||
+ | var citobs = new CitobsOpen311(); | ||
+ | |||
+ | var today = new Date(); | ||
+ | var weekago = new Date(); weekago.setDate( weekago.getDate() - 7 ); | ||
+ | |||
+ | if ( start_date == 'x' ) { start_date = weekago.toISOString().split( 'T' )[0]; } | ||
+ | if ( end_date == 'x' ) { end_date = today.toISOString().split( 'T' )[0]; } | ||
+ | |||
+ | citobs.loadRequests( { 'service_code': service_code, 'keyword': keyword, 'start_date': start_date, 'end_date': end_date }, function() { | ||
+ | var c1 = 0; | ||
+ | var c2 = 0; | ||
+ | |||
+ | var b0 = 0; | ||
+ | var b1 = 0; | ||
+ | var b2 = 0; | ||
+ | var b3 = 0; | ||
+ | |||
+ | for ( var o in citobs.request ) { | ||
+ | c1++; | ||
+ | if ( citobs.request[ o ].attributes[ 'algaebloom_singlevaluelist_201808151546174' ] != '1' ) { | ||
+ | c2++; | ||
+ | } | ||
+ | |||
+ | if ( citobs.request[ o ].attributes[ 'algaebloom_singlevaluelist_201808151546174' ] == '1' ) { | ||
+ | b0++; | ||
+ | } | ||
+ | |||
+ | if ( citobs.request[ o ].attributes[ 'algaebloom_singlevaluelist_201808151546174' ] == '2' ) { | ||
+ | b1++; | ||
+ | } | ||
+ | |||
+ | if ( citobs.request[ o ].attributes[ 'algaebloom_singlevaluelist_201808151546174' ] == '3' ) { | ||
+ | b2++; | ||
+ | } | ||
+ | |||
+ | if ( citobs.request[ o ].attributes[ 'algaebloom_singlevaluelist_201808151546174' ] == '4' ) { | ||
+ | b3++; | ||
+ | } | ||
+ | |||
+ | } | ||
+ | var out; | ||
+ | |||
+ | if ( lang == 'fi' ) { | ||
+ | out = 'Lisäksi Vesi.fi-palvelun kautta on valittuna ajanjaksona lähetetty ' + c1 + ' havaintoa sinilevätilanteesta. Näistä ' + c2 + ' kappaleessa havaittiin sinilevää.'; | ||
+ | } else { | ||
+ | out = 'In addition, ' + c1 + ' observations about the blue-green algae situation have been sent through the Vesi.fi service during the selected period. In ' + c2 + ' of these observations, algae had been detected.'; | ||
+ | } | ||
+ | console.log( '0: ' + b0 ); | ||
+ | console.log( '1: ' + b1 ); | ||
+ | console.log( '2: ' + b2 ); | ||
+ | console.log( '3: ' + b3 ); | ||
+ | |||
+ | jQuery( "#<!--{$id|default:vesificounter|escape:'html'}-->_container" ).html ( out ); | ||
− | + | } ); | |
} | } | ||
+ | </script> | ||
+ | </includeonly> |