/** * Grid Format - A topics based format that uses a grid of user selectable images to popup a light box of the section. * * @package format_grid * @version See the value of '$plugin->version' in version.php. * @copyright © 2012 onwards G J Barnard in respect to modifications of standard topics format. * @author G J Barnard - {@link http://about.me/gjbarnard} and * {@link http://moodle.org/user/profile.php?id=442195} * @author Based on code originally written by Paul Krix and Julian Ridden. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ M.format_grid=M.format_grid||{ourYUI:null,editing_on:null,section_redirect:null,selected_section:null,num_sections:null,selected_section_no:-1,shadebox_shown_array:null,shadebox_content:null};M.format_grid.init=function(Y,the_editing_on,the_section_redirect,the_num_sections,the_initial_section,the_shadebox_shown_array){"use strict";this.ourYUI=Y;this.editing_on=the_editing_on;this.section_redirect=the_section_redirect;this.selected_section=null;this.num_sections=parseInt(the_num_sections);this.shadebox_shown_array=the_shadebox_shown_array;Y.use('json-parse',function(Y){M.format_grid.shadebox_shown_array=Y.JSON.parse(M.format_grid.shadebox_shown_array)});if(this.num_sections>0){if(the_initial_section>-1){M.format_grid.tab(the_initial_section)}else if(!the_editing_on){this.set_selected_section(this.num_sections,!0,!0)}}else{this.selected_section_no=-1} if(the_editing_on){Y.all(".grid_section").removeClass('hide_section')}else{var navdrawer=M.format_grid.ourYUI.one('[data-region="drawer"] nav:first-child');if(navdrawer){Y.delegate('click',this.navdrawerclick,'[data-region="drawer"] nav:first-child','a',this)} if(this.section_redirect===null){Y.delegate('click',this.icon_click,Y.config.doc,'ul.gridicons a.gridicon_link',this);var shadeboxtoggleone=Y.one("#gridshadebox_overlay");if(shadeboxtoggleone){shadeboxtoggleone.on('click',this.icon_toggle,this)} var shadeboxtoggletwo=Y.one("#gridshadebox_close");if(shadeboxtoggletwo){shadeboxtoggletwo.on('click',this.icon_toggle,this);document.getElementById("gridshadebox_close").style.display=""} var shadeboxprevious=Y.one("#gridshadebox_previous");if(shadeboxprevious){shadeboxprevious.on('click',this.previous_section,this);document.getElementById("gridshadebox_previous").style.display=""} var shadeboxnext=Y.one("#gridshadebox_next");if(shadeboxnext){shadeboxnext.on('click',this.next_section,this);document.getElementById("gridshadebox_next").style.display=""} M.format_grid.shadebox_overlay=document.getElementById('gridshadebox_overlay');if(M.format_grid.shadebox_overlay){M.format_grid.shadebox.initialize_shadebox();M.format_grid.shadebox.update_shadebox();window.onresize=function(){M.format_grid.shadebox.update_shadebox()}}}} this.shadebox_content=Y.one("#gridshadebox_content");if(this.shadebox_content){this.shadebox_content.removeClass('hide_content')} if((this.section_redirect===null)&&(window.location.hash)&&(!the_editing_on)){var idx=parseInt(window.location.hash.substring(window.location.hash.indexOf("-")+1));var min=1;if(M.format_grid.shadebox_shown_array[0]==2){min=0} if((idx>=min)&&(idx<=this.num_sections)&&(M.format_grid.shadebox_shown_array[idx]==2)){M.format_grid.tab(idx);M.format_grid.grid_toggle()}}else if((this.num_sections>0)&&(the_initial_section>-1)){M.format_grid.grid_toggle()}};M.format_grid.icon_click=function(e){"use strict";e.preventDefault();var icon_index=parseInt(e.currentTarget.get('id').replace("gridsection-",""));var previousno=this.selected_section_no;this.selected_section_no=icon_index;this.update_selected_background(previousno);this.icon_toggle(e)};M.format_grid.navdrawerclick=function(e){"use strict";var href=e.currentTarget.get('href');var sectionref=href.indexOf("#section-");if(sectionref===0){return!0} var idx=parseInt(href.substring(sectionref+9));var min=1;if(this.shadebox_shown_array[0]==2){min=0} if((idx>=min)&&(idx<=this.num_sections)&&(this.shadebox_shown_array[idx]==2)){this.tab(idx);this.icon_toggle(e)}};M.format_grid.tab=function(index){"use strict";this.ourYUI.log('M.format_grid.tab: '+index);var previous_no=this.selected_section_no;this.selected_section_no=index;this.update_selected_background(previous_no);if(M.format_grid.shadebox.shadebox_open===!0){this.change_shown()}};M.format_grid.icon_toggle=function(e){"use strict";e.preventDefault();this.grid_toggle()};M.format_grid.grid_toggle=function(){if(this.selected_section_no!=-1){if((this.editing_on===!0)&&(this.update_capability===!0)){window.scroll(0,document.getElementById("section-"+this.selected_section_no).offsetTop)}else if(this.section_redirect!==null){location.assign(this.section_redirect+"§ion="+this.selected_section_no)}else if(M.format_grid.shadebox.shadebox_open===!0){this.shadebox.toggle_shadebox()}else{this.change_shown();this.shadebox.toggle_shadebox()}}};M.format_grid.previous_section=function(){"use strict";this.change_selected_section(!1)};M.format_grid.next_section=function(){this.change_selected_section(!0)};M.format_grid.change_selected_section=function(increase_section){"use strict";if(this.selected_section_no!=-1){this.set_selected_section(this.selected_section_no,increase_section,!1);if(M.format_grid.shadebox.shadebox_open===!0){this.change_shown()}}};M.format_grid.change_shown=function(){"use strict";if(this.selected_section!==null){this.selected_section.addClass('hide_section')} this.selected_section=this.ourYUI.one("#section-"+this.selected_section_no);var firstactivity=document.getElementById("section-"+this.selected_section_no).getElementsByTagName('a')[0];if(firstactivity){firstactivity.focus()} this.selected_section.removeClass('hide_section')};M.format_grid.set_selected_section=function(starting_point,increase_section,initialise){"use strict";if((this.selected_section_no!=-1)||(initialise===!0)){var previous_no=this.selected_section_no;this.selected_section_no=this.find_next_shown_section(starting_point,increase_section);this.update_selected_background(previous_no)}};M.format_grid.update_selected_background=function(previous_no){"use strict";if(this.selected_section_no!=-1){var selected_section=this.ourYUI.one("#gridsection-"+this.selected_section_no);selected_section.get('parentNode').addClass('currentselected')} if((previous_no!=-1)&&(previous_no!=this.selected_section_no)){var previous_section=this.ourYUI.one("#gridsection-"+previous_no);previous_section.get('parentNode').removeClass('currentselected')}};M.format_grid.find_next_shown_section=function(starting_point,increase_section){"use strict";var found=!1;var current=starting_point;var next=starting_point;while(found===!1){if(increase_section===!0){current++;if(current>this.num_sections){current=0}}else{current--;if(current<0){current=this.num_sections}} if(current==starting_point){found=!0}else if(this.shadebox_shown_array[current]==2){next=current;found=!0}} return next};M.format_grid.shadebox=M.format_grid.shadebox||{shadebox_open:null,shadebox_overlay:null,grid_shadebox:null};M.format_grid.shadebox.initialize_shadebox=function(){"use strict";this.shadebox_open=!1;this.shadebox_overlay=document.getElementById('gridshadebox_overlay');this.shadebox_overlay.style.display="";this.grid_shadebox=document.getElementById('gridshadebox');document.body.appendChild(this.grid_shadebox);this.hide_shadebox();var gridshadebox_content=M.format_grid.ourYUI.one('#gridshadebox_content');if(gridshadebox_content.hasClass('absolute')){var top=50;var pageelement=M.format_grid.ourYUI.one('#page-content');if(!pageelement){pageelement=M.format_grid.ourYUI.one('#region-main')} if(pageelement){var pageelementDOM=pageelement.getDOMNode();top=pageelementDOM.offsetTop+pageelementDOM.clientTop;if(top===0){top=pageelementDOM.offsetParent.offsetTop+pageelementDOM.offsetParent.clientTop} top=top+15} var navdrawer=M.format_grid.ourYUI.one('#nav-drawer');if(navdrawer){var navdrawerDOM=navdrawer.getDOMNode();var navdrawerStyle=window.getComputedStyle(navdrawerDOM);var zindex=parseInt(navdrawerStyle.getPropertyValue("z-index"));if(zindex){zindex=zindex+1;this.shadebox_overlay.style.zIndex=''+zindex;zindex=zindex+1;gridshadebox_content.setStyle('zIndex',''+zindex)}} gridshadebox_content.setStyle('top',''+top+'px')}};M.format_grid.shadebox.toggle_shadebox=function(){"use strict";if(this.shadebox_open){this.hide_shadebox();this.shadebox_open=!1}else{window.scrollTo(0,0);this.show_shadebox();this.shadebox_open=!0}};M.format_grid.shadebox.show_shadebox=function(){"use strict";this.update_shadebox();this.grid_shadebox.style.display=""};M.format_grid.shadebox.hide_shadebox=function(){"use strict";this.grid_shadebox.style.display="none"};M.format_grid.shadebox.update_shadebox=function(){"use strict";var pagesize=this.get_page_height();this.shadebox_overlay.style.height=pagesize+"px"};M.format_grid.shadebox.get_page_height=function(){"use strict";var yScroll;if(window.innerHeight&&window.scrollMaxY){yScroll=window.innerHeight+window.scrollMaxY}else if(document.body.scrollHeight>document.body.offsetHeight){yScroll=document.body.scrollHeight}else{yScroll=document.body.offsetHeight} var windowHeight;if(self.innerHeight){windowHeight=self.innerHeight}else if(document.documentElement&&document.documentElement.clientHeight){windowHeight=document.documentElement.clientHeight}else if(document.body){windowHeight=document.body.clientHeight} var pageHeight;if(yScroll