You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1 lines
11 KiB

define(["jquery","core/templates","core/ajax","format_tiles/browser_storage","core/notification","core/str","format_tiles/tile_fitter"],function(a,b,c,d,e,f,g){"use strict";var h,i,j,k,l,m=a("body"),n=a("body, html"),o=[],p=!1,q=!1,r=60,s=!1,t=0,u=!1,v=0,w={PAGE:"#page",TILE:".tile",TILEID:"#tile-",MOVEABLE_SECTION:".moveablesection",FILTER_BUTTON:".filterbutton",TILE_LOADING_ICON:".tile-loading-icon",TILE_LOADING_ICON_ID:"#loading-icon-",TILE_COLLAPSED:".tile-collapsed",TILE_CLICKABLE:".tile-clickable",TILES:"ul.tiles",ACTIVITY:".activity",SPACER:".spacer",SECTION_MOVEABLE:".moveablesection",SECTION_ID:"#section-",SECTION_TITLE:".sectiontitle",SECTION_MAIN:".section.main",SECTION_BUTTONS:"#sectionbuttons",CLOSE_SEC_BTN:".closesectionbtn",HIDE_SEC0_BTN:"#buttonhidesec0",SECTION_ZERO:"#section-0",MOODLE_VIDEO:".mediaplugin.mediaplugin_videojs",LAUNCH_STANDARD:'[data-action="launch-tiles-standard"]',TOOLTIP:"[data-toggle=tooltip]",HEADER_BAR:["header.navbar","nav.fixed-top.navbar","#essentialnavbar.navbar","#navwrap","nav.navbar-fixed-top"]},x={SELECTED:"selected",HEADER_OVERLAY:"header-overlay",OPEN:"open",CLOSED:"closed",LAUNCH_CM_MODAL:"launch-tiles-cm-modal",STATE_VISIBLE:"state-visible"},y={CLICK:"click",KEYDOWN:"keydown",SCROLL:"scroll"},z={DISPLAY:"display",Z_INDEX:"z-index",HEIGHT:"height",BG_COLOUR:"background-color"},A={ESCAPE:27,TAB:9,RETURN:13},B=function(a){return void 0!==k&&(a===!0?k.fadeIn(300):k.fadeOut(300),!0)},C=function(b){var c=a(w.SECTION_ID+b);c.find("iframe").each(function(b,c){c=a(c),c.attr("src",c.attr("src"))});var d=c.find(w.MOODLE_VIDEO);d.length>0&&c.html("")},D=function(b){a(w.MOVEABLE_SECTION).each(function(b,c){c=a(c),c.is(":visible")&&(C(c.attr("data-section")),c.slideUp().removeClass(x.STATE_VISIBLE))}),a(w.TILE).removeClass(x.SELECTED).css(z.Z_INDEX,"").css(z.BG_COLOUR,""),a(".section "+x.SELECTED).removeClass(x.SELECTED).css(z.Z_INDEX,""),j.fadeOut(300),B(!1),void 0!==b&&0!==b&&a(w.TILEID+b).focus(),a(w.TILE_LOADING_ICON).fadeOut(300,function(){a(w.TILE_LOADING_ICON).html("")}),q=!1,v=0},E=function(b,c){if(c){if(b.html(c),a(w.TILE_LOADING_ICON).fadeOut(300,function(){a(w.TILE_LOADING_ICON).html("")}),b.attr("id")!==w.SECTION_ZERO){var e=b.find(w.ACTIVITY).not(w.SPACER);b.on(y.KEYDOWN,function(c){c.keyCode===A.ESCAPE&&(d.setLastVisitedSection(0),D(0),a(w.TILEID+b.attr("data-section")).focus())}),e.on(y.KEYDOWN,function(b){if(b.keyCode===A.RETURN){var c=a(b.currentTarget).find("a");c.hasClass(x.LAUNCH_CM_MODAL)?c.click():void 0!==c.attr("href")&&(window.location=c.attr("href"))}}),h||(e.last().on(y.KEYDOWN,function(c){c.keyCode!==A.TAB||c.shiftKey||a(c.relatedTarget).closest(w.SECTION_MAIN).attr("id")===b.attr("id")||setTimeout(function(){b.find(w.SECTION_TITLE).focus(),n.animate({scrollTop:b.offset().top-r},"slow"),b.find("#sectionbuttons").css("top","")},200)}),b.find(w.SECTION_TITLE).on(y.KEYDOWN,function(c){c.keyCode===A.TAB&&c.shiftKey&&a(c.relatedTarget).closest(w.SECTION_MAIN).attr("id")!==b.attr("id")&&setTimeout(function(){e.last().focus()},200)}))}return h||setTimeout(function(){try{b.find(".togglecompletion, .completioncheckbox, .tag-info").tooltip()}catch(a){require(["core/log"],function(b){b.debug(a)})}},500),0!==b.find(w.MOODLE_VIDEO).length&&require(["media_videojs/loader"],function(a){a.setUp()}),!0}return!1},F=function(b,c){var d=function(){var d=a("#tileText-"+c).offset().top-r;d===a(window).scrollTop&&(d+=1),b.find(w.SECTION_TITLE).focus();var e="scroll mousedown wheel DOMMouseScroll mousewheel keyup touchmove";m.on(e,function(){m.stop()}),n.animate({scrollTop:d},"slow",function(){n.off(e,function(){n.stop()})}),q=!0,v=c,b.find(w.ACTIVITY).first().focus()},e=function(){var c=b.find(w.SECTION_BUTTONS);a(window).on(y.SCROLL,function(){!p&&q&&(p=!0,c.fadeOut(300),setTimeout(function(){var d=a(window).scrollTop(),e=d-b.offset().top+50;e>0&&e<b.outerHeight()-100?(e=d-b.offset().top+50,c.css("top",e),"none"===j.css(z.DISPLAY)&&j.fadeIn(300)):e<0&&c.css("top",0),d>b.offset().top+b.outerHeight()-50?("block"===j.css(z.DISPLAY)&&(j.fadeOut(300),B(!1)),c.css("top",0)):b.offset().top>d+a(window).outerHeight()?("block"===j.css(z.DISPLAY)&&(j.fadeOut(300),B(!1)),c.css("top",0)):"none"===j.css(z.DISPLAY)&&j.fadeIn(300),c.fadeIn(300,function(){p=!1})},500))}),p||q||!j.is(":visible")||j.fadeOut(300)};b.addClass(x.STATE_VISIBLE),b.slideDown(350,function(){d(),e()}),v=c},G=function(b,c){var d=new a.Deferred,e=a(".moveablesection:visible"),f=0;e.length>0&&(f=e.attr("data-section"),D());var h=function(a){g.runReOrg(a).done(function(a){0!==f&&F(e,f),d.resolve(a)}).fail(function(a){0!==f&&F(e,f),d.reject(a)})};return c?setTimeout(function(){g.resizeTilesDivWidth(l).done(function(){h(!1)},b)}):h(b),d.promise()},H=function(a,b,c){throw b?(e.confirm(o.sectionerrortitle,o.sectionerrorstring,o.refresh,o.cancel,function(){window.location.reload()},null),c.html("")):(E(c,"<p>"+o.noconnectionerror+"</p>"),setTimeout(function(){F(c,a)},500)),require(["core/log"],function(a){a.debug(b)}),new Error("Not successful retrieving tile content by AJAX for section "+a)},I=function(a,b){return c.call([{methodname:"format_tiles_get_single_section_page_html",args:{courseid:a,sectionid:b,setjsusedsession:!0}}])[0]},J=function(a,b,c,d){var e=d<0?0:255,f=d<0?d*-1:d,g=Math.round((e-a)*f)+a,h=Math.round((e-b)*f)+b,i=Math.round((e-c)*f)+c;return"rgb("+g+","+h+","+i+")"},K=function(b){j.fadeIn(300),t=parseInt(j.css(z.Z_INDEX));var c=a(w.TILEID+b);if(c.css(z.Z_INDEX,t+1),B(!0),a(w.SECTION_ID+b).css(z.Z_INDEX,t+1),c.css(z.BG_COLOUR)&&"rgba"===c.css(z.BG_COLOUR).substr(0,4)){var d=c.css(z.BG_COLOUR).replace("rgba(","").replace(")","").replace(" ","").split(",");c.css(z.BG_COLOUR,J(parseInt(d[0]),parseInt(d[1]),parseInt(d[2]),.95))}},L=function(b){var c=a(b.currentTarget);if("window-overlay"===c.attr("id")||c.attr("id")===x.HEADER_OVERLAY){c.hide();var d=a(document.elementFromPoint(b.clientX,b.clientY));if(c.show(),"window-overlay"===c.attr("id"))if(d.hasClass("filterbutton")||d.hasClass("list-group-item"))d.click();else{var e=d.closest(w.TILE);e&&e.click()}else D(0),d.click()}},M=function(){var b=a(w.HIDE_SEC0_BTN),c=a(w.SECTION_ZERO);d.storageEnabledLocal()?d.getSecZeroCollapseStatus()===!0?(c.slideUp(0),b.addClass(x.CLOSED).removeClass(x.OPEN)):(c.slideDown(300),b.addClass(x.OPEN).removeClass(x.CLOSED)):(b.addClass(x.OPEN).removeClass(x.CLOSED),c.slideDown(300))},N=function(b,f,g,h){K(g),a(w.TILE).removeClass(x.SELECTED),f.addClass(x.SELECTED),v=g,a(w.MOVEABLE_SECTION).each(function(b,c){c=a(c),c.is(":visible")&&(C(c.attr("data-section")),c.slideUp(200).removeClass(x.STATE_VISIBLE))}),c.call([{methodname:"format_tiles_log_tile_click",args:{courseid:b,sectionid:g}}])[0].fail(e.exception);var j=a(w.SECTION_ID+g);if(j.find(w.ACTIVITY).length>0)F(j,g),(d.getStoredContentAge(b,g)>h||!d.getStoredContentAge(b,g))&&I(b,g).done(function(c){d.storageEnabledSession()&&d.storeCourseContent(b,g,a(c.html).html())});else if(j.html(i),d.storageEnabledLocal()){var k=d.getStoredContentAge(b,g);if(k&&(E(j,d.getCourseContent(b,g)),F(j,g)),!k||k>h){var l=a(w.TILE_LOADING_ICON_ID+g);void 0!==l?l.html(i).fadeIn(200):(l=a("<div>").html(i),j.html(l)),I(b,g).done(function(c){var e=a(c.html).html();E(j,e),F(j,g),d.storageEnabledSession()&&d.storeCourseContent(b,g,e)}).fail(function(a){H(g,a,j),D(g)})}}else I(b,g).done(function(b){E(j,a(b.html).html()),F(j,g)}).fail(function(a){H(g,a,j),D(g)});d.setLastVisitedSection(g)};return{init:function(e,n,p,q,B,C,F,H,J,K,O,P){l=e,h=q,s="1"===K,H=1===H,J="1"===J,d.init(l,p,!1,B,F,J,O),a(document).ready(function(){var e=a("#page-content");0===e.length&&(e=a("#region-main")),0!==B?v=B:s&&d.storageEnabledLocal&&(v=d.getLastVisitedSection()),0!==v?g.init(l,v,P,!1):(a(w.TILEID+"1").focus(),g.init(l,null,P,!1));var p=a(window).outerWidth();if(n){j=a("<div></div>").addClass("modal-backdrop fade in").hide().attr("id","window-overlay").appendTo(m),j.click(function(a){D(0),L(a)}),e.on(y.CLICK,w.TILE_CLICKABLE,function(b){if(n){b.preventDefault(),a(window).off(y.SCROLL),a(w.TILE_LOADING_ICON).fadeOut(300,function(){a(w.TILE_LOADING_ICON).html()});var c=a(b.currentTarget).closest(w.TILE),e=parseInt(c.attr("data-section"));c.hasClass(x.SELECTED)?(D(e),d.setLastVisitedSection(0)):N(l,c,e,C);var f=a(w.SECTION_ID+(e+1));!h&&f.length&&e>0&&setTimeout(function(){var b=d.getStoredContentAge(l,e+1);b&&E(f,d.getCourseContent(l,e+1)),(!b||b>C)&&I(l,e+1).done(function(b){E(f,a(b.html).html()),d.storageEnabledSession()&&d.storeCourseContent(l,e+1,a(b.html).html())})},2e3)}}),a(window).on("resize",function(){u||p===a(window).outerWidth()||(u=!0,setTimeout(function(){var b=!0,c=a(".moveablesection:visible");if(0!==c.length){var d=c.find(".mediaplugin iframe");0!==d.length&&d.each(function(d,e){e=a(e),e.outerWidth()>c.outerWidth()&&(b=!1)})}b&&(p=a(window).outerWidth(),G(!0,P)),u=!1},600))});var q=parseInt(j.css(z.Z_INDEX)),F=a(w.HEADER_BAR.find(function(b){return a(b).length>0}));void 0!==F&&0!==F.length&&(F.css(z.Z_INDEX,q+2),"navwrap"!==F.attr("id")&&void 0!==F.height()&&(r=Math.max(F.height(),50),k=a("<div></div>").addClass(x.HEADER_OVERLAY).attr("id",x.HEADER_OVERLAY).css(z.DISPLAY,"none"),k.insertAfter(w.PAGE).css(z.Z_INDEX,q+3).css(z.HEIGHT,r).click(function(a){D(0),L(a)}))),e.on(y.CLICK,w.CLOSE_SEC_BTN,function(b){D(a(b.currentTarget).attr("data-section"))}),e.on(y.CLICK,w.LAUNCH_STANDARD,function(b){var c=a(b.currentTarget);void 0!==c.attr("href")?window.location=c.attr("href"):void 0!==c.find("a").attr("href")&&(window.location=c.find("a").attr("href"))}),M()}e.on(y.CLICK,w.HIDE_SEC0_BTN,function(b){var c=a(w.SECTION_ZERO);"none"===c.css(z.DISPLAY)?(c.slideDown(250),a(b.currentTarget).addClass(x.OPEN).removeClass(x.CLOSED),d.setSecZeroCollapseStatus("collapsed")):(c.slideUp(250),a(b.currentTarget).addClass(x.CLOSED).removeClass(x.OPEN),d.setSecZeroCollapseStatus("expanded"))}),H&&(require(["format_tiles/filter_buttons"],function(a){a.init(l,d.storageEnabledLocal)}),n&&e.on(y.CLICK,w.FILTER_BUTTON,function(){D(0),G(!0,!1)})),a(".tiles_coursenav").removeClass("hidden"),b.render("format_tiles/loading",{}).done(function(a){i=a});var J=[{key:"sectionerrortitle",component:"format_tiles"},{key:"sectionerrorstring",component:"format_tiles"},{key:"refresh"},{key:"cancel"},{key:"noconnectionerror",component:"format_tiles"},{key:"show"},{key:"hide"},{key:"other",component:"format_tiles"},{key:"blockedpopuptitle",component:"format_tiles"}];if(f.get_strings(J).done(function(a){a.forEach(function(a,b){o[J[b].key]=a})}),h)e.on(y.CLICK,w.ACTIVITY+".video a",function(b){var d=a(b.currentTarget),e=d.closest(w.ACTIVITY).attr("data-url-secondary");if(void 0!==e){b.preventDefault(),b.stopPropagation();var f=d.closest(w.ACTIVITY);c.call([{methodname:"format_tiles_log_mod_view",args:{courseid:l,cmid:f.attr("data-cmid")}}])[0].done(function(){require(["format_tiles/completion"],function(a){a.markAsAutoCompleteInUI(l,f)})}),window.location=e}});else{a(w.TILE).on(y.KEYDOWN,function(b){b.keyCode===A.RETURN&&a(b.currentTarget).click()}),a("ul.tiles .tile").first().focus();var K=a(w.TOOLTIP);if(0!==K.length)try{K.tooltip()}catch(O){require(["core/log"],function(a){a.debug(O)})}}a(document).on("filter-content-updated",function(b,c){if(c.length>0){var d=a(c[0]);d.hasClass("moodle-dialogue")&&d.css("z-index")<t&&d.css("z-index",t+1)}})})}}});