//Jquery should already be loaded. //Just because IE incase the console doesn't exist (LTE IE9). var console = console ? console : { log: function () {}, info: function () {}, warn: function () {}, error: function () {} }; var navi_helper = { current_page:0, min_page:0, max_page:8, static_image: '/wp-content/uploads/2016/02/just_map_tidalcurrents_20150208T0100.png', fps: 3, //show two frames every second. (1000 ms/#) my_timer: { 1: null, 2: null }, dynamic_images:{ //You'll need to update if you want dynamic year and month. Currently hardcoded into feb 2015 4:{ num_images:1, location:'/wp-content/uploads/2016/02/just_map_tidalcurrents_', frames: { 1: { show_picture:0, curr_day:7, curr_hr:23, start_day:8, start_hr:0, end_day:22, end_hr:0, pictures: [] } } }, 5:{ //Has two images. num_images:2, location:'/wp-content/uploads/2016/02/tidalcurrents_', frames: { 1: { show_picture:0, curr_day:7, curr_hr:23, start_day:8, start_hr:0, end_day:11, end_hr:0, pictures: [] }, 2: { show_picture:0, curr_day:13, curr_hr:23, start_day:14, start_hr:0, end_day:17, end_hr:0, pictures: [] } } }, 6:{ //Has two images. num_images:2, location:'/wp-content/uploads/2016/02/tidalcurrents_', frames: { 1: { show_picture:0, curr_day:7, curr_hr:23, start_day:8, start_hr:0, end_day:11, end_hr:0, pictures: [] }, 2: { show_picture:0, curr_day:13, curr_hr:23, start_day:14, start_hr:0, end_day:17, end_hr:0, pictures: [] } } }, 7:{ num_images:1, location:'/wp-content/uploads/2016/02/tidalcurrents_', frames: { 1: { show_picture:0, curr_day:7, curr_hr:23, start_day:8, start_hr:0, end_day:22, end_hr:0, pictures: [] } } } }, my_popups:{ 1:[], //None 2:[ { icon:'', position:{ top:'28%', left: '63%', align:''}, content:'CODAR station at Palmer Research Station ', size:'small' },{ icon:'', position:{ top:'65%', left: '64%', align:''}, content:'CODAR station within Wauwermans Islands. ', size:'small' },{ icon:'', position:{ top:'31%', left: '37%', align:''}, content:'CODAR station within Joubin Islands ', size:'small' },{ icon:'info', position:{ top:'3%', left: '68%', align:'right-side'}, content:'The date and time that the data were collected for the figure we are looking at.', size:'' },{ icon:'info', position:{ top:'14%', left: '74%', align:'right-side'}, content:'This is the North arrow to demonstrate which direction is North on the map.', size:'' },{ icon:'info', position:{ top:'22%', left: '67%', align:''}, //content:'Anvers Island, Antarctica (gray area represents the land).', content:'Anvers Island, Antarctica (gray area represents the land).', size:'small' },{ icon:'info', position:{ top:'65%', left: '35%', align:'right-side'}, content:'Each black arrow over the ocean area represents the direction (not speed) the surface water was moving.', size:'' },{ icon:'info', position:{ top:'15%', left: '30%', align:'right-side'}, content:'Open ocean around Palmer Research Station.', size:'small' } ], 3:[ { icon:'', position:{ top:'28%', left: '63%', align:''}, content:'CODAR station at Palmer Research Station ', size:'small' },{ icon:'', position:{ top:'65%', left: '64%', align:''}, content:'CODAR station within Wauwermans Islands. ', size:'small' },{ icon:'', position:{ top:'31%', left: '37%', align:''}, content:'CODAR station within Joubin Islands ', size:'small' },{ icon:'info', position:{ top:'40%', left: '37%', align:'right-side'}, content:'Each black arrow over the ocean area represents the direction (not speed) the surface water was moving.', size:'' },{ icon:'info', position:{ top:'75%', left: '37%', align:'right-side'}, content:'When the arrows are pointing away from a location, this indicates a Divergent Front.', size:'' },{ icon:'info', position:{ top:'80%', left: '54%', align:'right-side'}, content:'When the arrows are following a circular pattern in a location, this indicates an eddy.', size:'' },{ icon:'info', position:{ top:'60%', left: '56%', align:'right-side'}, //????:content:'When the arrows are pointing away from a location, this indicates a Convergent Front.', content:'When the arrows are pointing towards a location, this indicates a Convergent Front.', size:'' } ], 4:[], 5:[], 6:[], 7:[{ icon:'', position:{ top:'22%', left: '62%', align:''}, content:'CODAR station at Palmer Research Station ', size:'small' },{ icon:'', position:{ top:'54%', left: '63%', align:''}, content:'CODAR station within Wauwermans Islands. ', size:'small' },{ icon:'', position:{ top:'25%', left: '37%', align:''}, content:'CODAR station within Joubin Islands ', size:'small' },{ icon:'penguin', position:{top:'40%', left: '64%', align:''}, icon_position:{ 1: {top:'22%', left: '54%', align:''}, 2: {top:'34%', left: '56%', align:''}, 3: {top:'29%', left: '69%', align:''}, 4: {top:'62%', left: '59%', align:''}, 5: {top:'37%', left: '30%', align:''} /*ORIGINAL POSITIONS 1: {top:'22%', left: '58%', align:''}, 2: {top:'26%', left: '59%', align:''}, 3: {top:'29%', left: '64%', align:''}, 4: {top:'31%', left: '70%', align:''} */ }, content:'There are multiple seabird colonies (e.g., Adelie penguin, Gentoo penguin, Chinstrap penguin, Skuas, Petrals) around Palmer Research Station. ', size:'' },{ icon:'whale', position:{top:'-7%', left: '1%', align:''}, icon_position:{ 1: {top:'31%', left: '40%', align:''}, 2: {top:'59%', left: '41%', align:''}, 3: {top:'46%', left: '66%', align:''} /*ORIGINAL POSITIONS 1: {top:'22%', left: '47%', align:''}, 2: {top:'31%', left: '44%', align:''}, 3: {top:'41%', left: '35%', align:''}, 4: {top:'57%', left: '55%', align:''}, 5: {top:'36%', left: '61%', align:''} */ }, content:'There are multiple marine mammal populations (e.g., Humpback Whales, Leopard seals) that live or visit the ocean around Palmer Research Station.', size:'' },{ icon:'plankton', position:{top:'45%', left: '-1%', align:''}, icon_position:{ 1: {top:'35%', left: '64%', align:''}, 2: {top:'25%', left: '41%', align:''}, 3: {top:'45%', left: '45%', align:''}, 4: {top:'41%', left: '32%', align:''}, 5: {top:'52%', left: '51%', align:''}, 6: {top:'63%', left: '31%', align:''} /*ORIGINAL POSITIONS 1: {top:'39%', left: '50%', align:''}, 2: {top:'45%', left: '46%', align:''}, 3: {top:'52%', left: '42%', align:''} */ }, content:'Phytoplankton and zooplankton make up the base of the Antarctica food web. They move with the currents in the ocean around Palmer Research Station. ', size:'' } ], 8:[{ icon:'', position:{ top:'22%', left: '62%', align:''}, content:'CODAR station at Palmer Research Station ', size:'small' },{ icon:'', position:{ top:'54%', left: '63%', align:''}, content:'CODAR station within Wauwermans Islands. ', size:'small' },{ icon:'', position:{ top:'25%', left: '37%', align:''}, content:'CODAR station within Joubin Islands ', size:'small' },{ icon:'penguin', position:{top:'40%', left: '64%', align:''}, icon_position:{ 1: {top:'22%', left: '54%', align:''}, 2: {top:'34%', left: '56%', align:''}, 3: {top:'29%', left: '69%', align:''}, 4: {top:'62%', left: '59%', align:''}, 5: {top:'37%', left: '30%', align:''} /*ORIGINAL POSITIONS 1: {top:'22%', left: '58%', align:''}, 2: {top:'26%', left: '59%', align:''}, 3: {top:'29%', left: '64%', align:''}, 4: {top:'31%', left: '70%', align:''} */ }, content:'There are multiple seabird colonies (e.g., Adelie penguin, Gentoo penguin, Chinstrap penguin, Skuas, Petrals) around Palmer Research Station. ', size:'' },{ icon:'whale', position:{top:'-7%', left: '1%', align:''}, icon_position:{ 1: {top:'31%', left: '40%', align:''}, 2: {top:'59%', left: '41%', align:''}, 3: {top:'46%', left: '66%', align:''} /*ORIGINAL POSITIONS 1: {top:'22%', left: '47%', align:''}, 2: {top:'31%', left: '44%', align:''}, 3: {top:'41%', left: '35%', align:''}, 4: {top:'57%', left: '55%', align:''}, 5: {top:'36%', left: '61%', align:''} */ }, content:'There are multiple marine mammal populations (e.g., Humpback Whales, Leopard seals) that live or visit the ocean around Palmer Research Station.', size:'' },{ icon:'plankton', position:{top:'45%', left: '-1%', align:''}, icon_position:{ 1: {top:'35%', left: '64%', align:''}, 2: {top:'25%', left: '41%', align:''}, 3: {top:'45%', left: '45%', align:''}, 4: {top:'41%', left: '32%', align:''}, 5: {top:'52%', left: '51%', align:''}, 6: {top:'63%', left: '31%', align:''} /*ORIGINAL POSITIONS 1: {top:'39%', left: '50%', align:''}, 2: {top:'45%', left: '46%', align:''}, 3: {top:'52%', left: '42%', align:''} */ }, content:'Phytoplankton and zooplankton make up the base of the Antarctica food web. They move with the currents in the ocean around Palmer Research Station. ', size:'' } ] }, go_to_page: function ( page_num ) { //console.info('[navi_helper]: Go to page `'+ page_num +'`.'); if( page_num == 'next' ) { this.current_page++; }else if( page_num == 'prev' ) { this.current_page--; if( this.current_page < this.min_page) { this.current_page = this.min_page; } }else{ this.current_page = parseInt(page_num); } if( this.current_page < this.min_page) { this.current_page = this.min_page; }else if ( this.max_page < this.current_page ) { this.current_page = this.max_page; } jQuery('#info-instructions-2-3').hide(); jQuery('#info-instructions-6').hide(); jQuery('div.mosaic-content-left').removeClass('wide-screen'); jQuery('div.mosaic-content-right').removeClass('wide-screen'); if( this.current_page == 2 || this.current_page == 3 ) { jQuery('#info-instructions-2-3').show(); }else if( this.current_page == 7 || this.current_page == 8 ) { jQuery('#info-instructions-6').show(); }else if(this.current_page == 7 ) { //jQuery('div.mosaic-content-left').addClass('wide-screen'); //jQuery('div.mosaic-content-right').addClass('wide-screen'); } if( this.current_page == 5 ||this.current_page == 6 ) { jQuery('#tide-information-1').show(); jQuery('#tide-information-2').show(); }else{ jQuery('#tide-information-1').hide(); jQuery('#tide-information-2').hide(); } this.update_info_bubbles(); jQuery('button','#mosaic-button-nav').removeClass('current-page'); jQuery('button[data-page-id="'+ this.current_page +'"]','#mosaic-button-nav').addClass('current-page'); jQuery('.switch-page','#mosaic-page-content').removeClass('view-page'); jQuery('#mosaic-page-' + this.current_page + '-left','#mosaic-page-content').addClass('view-page'); if( this.current_page == 5 ) { jQuery('#play-controls-1').css({display: 'none'} ); jQuery('#play-controls-2').css({display: 'none'} ); }else{ jQuery('#play-controls-1').css({display: ( this.current_page > 3 ? 'block' : 'none' ) } ); jQuery('#play-controls-2').css({display: 'block'} ); } this.update_image_information(); return this.next_button_state() && this.prev_button_state(); }, update_info_bubbles: function () { jQuery('span.marker').remove(); var my_icons = navi_helper.my_popups[ this.current_page ]; for(var index in my_icons ) { var create_icon = my_icons[index]; //Only picture-frame-1 is currently getting icons var target = jQuery('#image-wrapper-1'); //console.log(create_icon); if( create_icon.icon == '' ) { // jQuery('') .css({ top: create_icon.position.top, left: create_icon.position.left }).html(''+ create_icon.content +''). appendTo(target); }else if( create_icon.icon == 'info' ) { jQuery('') .css({ top: create_icon.position.top, left: create_icon.position.left }).html(''+ create_icon.content +''). appendTo(target); }else if( create_icon.icon == 'penguin' ) { jQuery('') .css({ top: create_icon.position.top, left: create_icon.position.left }).html(''+ create_icon.content +''). appendTo(target); for(var i in create_icon.icon_position){ var new_pos = create_icon.icon_position[i]; jQuery('') .css({ top: new_pos.top, left: new_pos.left }).html(''). appendTo(target); } }else if( create_icon.icon == 'whale' ) { jQuery('') .css({ top: create_icon.position.top, left: create_icon.position.left }).html(''+ create_icon.content +''). appendTo(target); for(var i in create_icon.icon_position){ var new_pos = create_icon.icon_position[i]; jQuery('') .css({ top: new_pos.top, left: new_pos.left }).html(''). appendTo(target); } }else if( create_icon.icon == 'plankton' ) { //Are amoebas plankton? Probably. No longer questioning it. jQuery('') .css({ top: create_icon.position.top, left: create_icon.position.left }).html(''+ create_icon.content +''). appendTo(target); for(var i in create_icon.icon_position){ var new_pos = create_icon.icon_position[i]; jQuery('') .css({ top: new_pos.top, left: new_pos.left }).html(''). appendTo(target); } } } jQuery('span.marker').on('click', function() { var $marker = jQuery(this), $caption = jQuery('span.caption', $marker); //console.log($caption); if( $caption.length < 1 ) { if( $marker.hasClass('penguin') ) { jQuery('span.marker.penguin.is-clickable').trigger('click'); }else if( $marker.hasClass('whale') ) { jQuery('span.marker.whale.is-clickable').trigger('click'); }else if( $marker.hasClass('plankton') ) { jQuery('span.marker.plankton.is-clickable').trigger('click'); } }else{ if ($caption.is(':hidden')) { $caption.slideDown(300); } else { $caption.slideUp(300); } } }); //Fix anchor links in the span marker click to avoid event propagation // and other bad behavior jQuery('span.marker a').on('click', function (event) { event.stopPropagation(); return true; }); return true; }, update_image_information: function () { this.pause_images(1); this.pause_images(2); if( this.current_page < 4 || this.current_page > 6) { jQuery('#picture-frame-1').removeClass('dual-image'); jQuery('#picture-frame-2').removeClass('dual-image').hide(); jQuery('#image-changer-1').prop({src: this.static_image}); jQuery('#play-controls-1').hide(); return true; } if( this.current_page == 5 ) { jQuery('#play-controls-1').hide(); }else{ jQuery('#play-controls-1').show(); } jQuery('#picture-frame-1').removeClass('dual-image'); jQuery('#picture-frame-2').removeClass('dual-image').hide(); var my_rules = this.dynamic_images[ this.current_page ]; if( my_rules.num_images == 1 ) { this.dynamic_images[ this.current_page ].frames[1].show_picture = 0; jQuery('#play-slider-1').val(0).prop({max:this.dynamic_images[ this.current_page ].frames[1].pictures.length-1}); var pad = "00"; var str_day = '' + this.dynamic_images[ this.current_page ].frames[1].curr_day; var str_hr = '' + this.dynamic_images[ this.current_page ].frames[1].curr_hr; jQuery('#image-changer-1').prop({ src: this.dynamic_images[ this.current_page ].location + '201502' + pad.substring(0, pad.length - str_day.length) + str_day + 'T' + pad.substring(0, pad.length - str_hr.length) + str_hr + '00.png' });//.removeClass('dual-image'); jQuery('#picture-frame-2').css({display:'none'}) }else{ jQuery('#play-slider-1').val(0).prop({max:this.dynamic_images[ this.current_page ].frames[1].pictures.length-1}); jQuery('#play-slider-2').val(0).prop({max:this.dynamic_images[ this.current_page ].frames[2].pictures.length-1}); this.dynamic_images[ this.current_page ].frames[1].show_picture = 0; this.dynamic_images[ this.current_page ].frames[2].show_picture = 0; jQuery('#picture-frame-1').addClass('dual-image'); jQuery('#picture-frame-2').addClass('dual-image').css({display:'inline-block'}); var pad = "00"; var str_day = '' + this.dynamic_images[ this.current_page ].frames[1].curr_day; var str_hr = '' + this.dynamic_images[ this.current_page ].frames[1].curr_hr; var str_day2 = '' + this.dynamic_images[ this.current_page ].frames[2].curr_day; var str_hr2 = '' + this.dynamic_images[ this.current_page ].frames[2].curr_hr; jQuery('#image-changer-1').prop({ src: this.dynamic_images[ this.current_page ].location + '201502' + pad.substring(0, pad.length - str_day.length) + str_day + 'T' + pad.substring(0, pad.length - str_hr.length) + str_hr + '00.png' }); jQuery('#image-changer-2').prop({ src: this.dynamic_images[ this.current_page ].location + '201502' + pad.substring(0, pad.length - str_day2.length) + str_day2 + 'T' + pad.substring(0, pad.length - str_hr2.length) + str_hr2 + '00.png' }); } if( this.current_page == 4 || this.current_page == 6 ){ if( my_rules.num_images == 1 ) { this.play_images(1); }else{ this.play_images(1); this.play_images(2); } } return true; }, play_images: function (frame_id) { this.pause_images(frame_id); this.my_timer[frame_id] = setInterval( function () { //console.log('Image change.'); navi_helper.forward_image_source(frame_id); }, ( 1000 / this.fps ) ); }, pause_images: function (frame_id) { if( this.my_timer[frame_id] !== null ) { clearInterval( this.my_timer[frame_id] ); this.my_timer[frame_id] = null; } }, step_forward: function (frame_id) { this.pause_images(frame_id); this.forward_image_source(frame_id); }, step_back: function (frame_id) { this.pause_images(frame_id); this.previous_image_source(frame_id); }, go_to_picture: function (frame_id, picture_id){ this.dynamic_images[ this.current_page ].frames[frame_id].show_picture = picture_id; this.show_images(frame_id); }, forward_image_source: function (frame_id) { this.dynamic_images[ this.current_page ].frames[frame_id].show_picture++; if( this.dynamic_images[ this.current_page ].frames[frame_id].show_picture >= this.dynamic_images[ this.current_page ].frames[frame_id].pictures.length ) { this.dynamic_images[ this.current_page ].frames[frame_id].show_picture=0; } //console.log(this.dynamic_images[ this.current_page ]); jQuery('#play-slider-' + frame_id).val( this.dynamic_images[ this.current_page ].frames[frame_id].show_picture ) ; this.show_images(frame_id); return true; }, previous_image_source: function (frame_id) { this.dynamic_images[ this.current_page ].frames[frame_id].show_picture--; if( this.dynamic_images[ this.current_page ].frames[frame_id].show_picture < 0 ) { this.dynamic_images[ this.current_page ].frames[frame_id].show_picture=this.dynamic_images[ this.current_page ].frames[frame_id].pictures.length-1; } jQuery('#play-slider-' + frame_id).val( this.dynamic_images[ this.current_page ].frames[frame_id].show_picture ) ; this.show_images(frame_id); return true; }, show_images: function (frame_id) { var my_rules = this.dynamic_images[ this.current_page ].frames[frame_id]; var pad = "00"; var str_day = '' + this.dynamic_images[ this.current_page ].frames[frame_id].curr_day; var str_hr = '' + this.dynamic_images[ this.current_page ].frames[frame_id].curr_hr; jQuery('#image-changer-' + frame_id).prop({ src: this.dynamic_images[ this.current_page ].frames[frame_id].pictures[ this.dynamic_images[ this.current_page ].frames[frame_id].show_picture ] }); ///wp-content/uploads/2016/02/tidalcurrents_20150208T0100.png /* jQuery('#image-changer-' + frame_id).prop({ src: this.dynamic_images[ this.current_page ].location + '201502' + pad.substring(0, pad.length - str_day.length) + str_day + 'T' + pad.substring(0, pad.length - str_hr.length) + str_hr + '00.png' }); */ return true; }, prev_button_state: function () { jQuery('#mosaic-prev-button').prop({disabled: (this.current_page == this.min_page) }); return true; }, next_button_state: function () { jQuery('#mosaic-next-button').prop({disabled: (this.current_page == this.max_page) }); return true; }, preload_all_images: function() { return true; }, initialize_pictures: function () { var my_dynamic_images = this.dynamic_images; for(var page in my_dynamic_images){ var my_frames = this.dynamic_images[page].frames; for(var my_frame in my_frames){ //We'll need to calculate then push (in order) var total_time = (this.dynamic_images[ page ].frames[my_frame].curr_day * 100) + this.dynamic_images[ page ].frames[my_frame].curr_hr; var end_time = (this.dynamic_images[ page ].frames[my_frame].end_day * 100) + this.dynamic_images[ page ].frames[my_frame].end_hr; while( total_time < end_time ) { this.dynamic_images[ page ].frames[my_frame].curr_hr++; if( this.dynamic_images[ page ].frames[my_frame].curr_hr >= 24 ) { this.dynamic_images[ page ].frames[my_frame].curr_day++; this.dynamic_images[ page ].frames[my_frame].curr_hr=0; } //e.g. day = 8 (or '08') hour = 11 (or '11'), total time = 811 or ('0811') vs end time of 2200 for day 22, hour 00 total_time = (this.dynamic_images[ page ].frames[my_frame].curr_day * 100) + this.dynamic_images[ page ].frames[my_frame].curr_hr; var pad = "00"; var str_day = '' + this.dynamic_images[ page ].frames[my_frame].curr_day; var str_hr = '' + this.dynamic_images[ page ].frames[my_frame].curr_hr; this.dynamic_images[ page ].frames[my_frame].pictures.push( this.dynamic_images[ page ].location + '201502' + pad.substring(0, pad.length - str_day.length) + str_day + 'T' + pad.substring(0, pad.length - str_hr.length) + str_hr + '00.png' ); } console.info('Page: `'+ page +'`, Frame: `'+ my_frame +'` initialized'); } } return true; } }; //There might be a conflict with the shorthand Dollar sign ($), so we'll just use jQuery instead jQuery(function () { console.log('[jQuery loaded]'); jQuery.get('https://polar-ice.org/wp-content/uploads/2020/04/story_3_eng.html.txt', function(data) { console.log('THE DATA: ', data); var myHTML = data.replace(/REPLACE_OPEN_ANGLE_BRACKET/g, '<'); myHTML = myHTML.replace(/REPLACE_CLOSE_ANGLE_BRACKET/g, '>'); jQuery('#story-3-div').html(myHTML); console.log('HTML Loaded. Loading other items.'); jQuery('#mosaic-next-button').prop({disabled:false}); jQuery('button','#mosaic-button-nav').on('click', function () { navi_helper.go_to_page( jQuery(this).data('page-id') ); }); //We're going to remove the #sidebar for now and make #main width 100% jQuery('#sidebar').hide(); jQuery('#main').css({width:'100%'}); navi_helper.initialize_pictures(); jQuery('#step-back-1').on('click', function () { console.info('Step-Back button clicked.'); navi_helper.step_back(1); }); jQuery('#pause-1').on('click', function () { console.info('Pause button clicked.'); navi_helper.pause_images(1); }); jQuery('#play-1').on('click', function () { console.info('Play button clicked.'); navi_helper.play_images(1); }); jQuery('#step-forward-1').on('click', function () { console.info('Step-Forward button clicked.'); navi_helper.step_forward(1); }); jQuery('#step-back-2').on('click', function () { console.info('Step-Back button clicked.'); navi_helper.step_back(2); }); jQuery('#pause-2').on('click', function () { console.info('Pause button clicked.'); navi_helper.pause_images(2); }); jQuery('#play-2').on('click', function () { console.info('Play button clicked.'); navi_helper.play_images(2); }); jQuery('#step-forward-2').on('click', function () { console.info('Step-Forward button clicked.'); navi_helper.step_forward(2); }); }, 'text'); });