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
8.0 KiB

define(["jquery","core/modal_factory","core/config","core/templates","core/notification","core/ajax"],function(a,b,c,d,e,f){"use strict";var g,h,i={},j=a(window),k={toggleCompletion:".togglecompletion",modal:".modal",modalDialog:".modal-dialog",modalBody:".modal-body",sectionMain:".section.main",pageContent:"#page-content",regionMain:"#region-main",completionState:"#completionstate_",cmModalClose:".embed_cm_modal .close",cmModal:".embed_cm_modal",moodleMediaPlayer:".mediaplugin_videojs",urlModalLoadWarning:"#embed-url-error-msg-",closeBtn:"button.close",ACTIVITY:"li.activity",URLACTIVITYPOPUPLINK:".activity.modtype_url.urlpopup a",newWindowButton:".button_expand",modalHeader:".modal-header",embedModuleButtons:".embed-module-buttons"},l={launchResourceModal:"launch-tiles-resource-modal",launchModuleModal:"launch-tiles-module-modal",launchUrlModal:"launch-tiles-url-modal"},m=function(){return Math.min(j.width(),1e3)},n=function(b){var c=b.find("iframe");c.length>0&&b.find(k.closeBtn).click(function(b){a(b.currentTarget).closest(k.cmModal).find("iframe").each(function(b,c){c=a(c),c.attr("src",c.attr("src"))})});var d=b.find("object");d.length>0&&b.find(k.closeBtn).click(function(b){var c=a(b.currentTarget).closest(k.cmModal);c.find("object").each(function(b,c){c=a(c),c.attr("data","")}),i[c.attr("data-cmid")]=void 0});var e=b.find(k.moodleMediaPlayer);e.length>0&&(b.find(k.closeBtn).click(function(){b.find(k.moodleMediaPlayer).html("")}),i[b.attr("data-cmid")]=void 0)},o=function(f){var h=f.attr("data-cmid");return b.create({type:b.types.DEFAULT,title:f.attr("data-title"),body:g}).done(function(b){i[h]=b,b.setLarge(),b.show();var g=a(b.root);g.attr("id","embed_mod_modal_"+h),g.attr("data-cmid",h),g.addClass("embed_cm_modal");var l={id:h,pluginfileUrl:f.attr("data-url"),objectType:"text/html",width:"100%",height:Math.round(j.height()-60),cmid:h,tileid:f.closest(k.sectionMain).attr("data-section"),isediting:0,sesskey:c.sesskey,modtitle:f.attr("data-title"),config:{wwwroot:c.wwwroot},showDownload:0,showNewWindow:0,completionInUseForCm:0};if("resource_pdf"===f.attr("data-modtype")&&(l.objectType="application/pdf",l.showDownload=1,l.showNewWindow=1),d.render("format_tiles/embed_file_modal_body",l).done(function(a){b.setBody(a),g.find(k.modalBody).animate({"min-height":Math.round(j.height()-60)},"fast"),"resource_html"===f.attr("data-modtype")?(g.find(k.modal).animate({"max-width":"100%"},"fast"),g.find(k.modalDialog).animate({"max-width":"100%"},"fast"),g.find(k.modalBody).animate({"max-width":"100%"},"fast"),n(g)):(g.find(k.modal).animate({"max-width":m()},"fast"),g.find(k.modalDialog).animate({"max-width":m()},"fast"))}).fail(e.exception),0!==f.find(k.toggleCompletion).length){var o=parseInt(a(k.completionState+h).attr("value"));l.completionInUseForCm=1,l.completionstate=1-o,l.completionicon=1===o?"n":"y",l.completionstateInverse=o,l.completionIsManual=f.find(k.toggleCompletion).attr("data-ismanual")}return d.render("format_tiles/embed_module_modal_header_btns",l).done(function(a){g.find(k.modalHeader).append(a),g.find(k.closeBtn).detach().appendTo(g.find(k.embedModuleButtons))}).fail(e.exception),!0}),!1},p=function(f){var h=f.attr("data-cmid");return b.create({type:b.types.DEFAULT,title:f.attr("data-title"),body:g}).done(function(b){i[h]=b,b.setLarge(),b.show();var g=a(b.root);g.attr("id","embed_mod_modal_"+h),g.attr("data-cmid",h),g.addClass("embed_cm_modal");var l=Math.round(.9*j.width()),m=Math.round(.9*j.height()),o={id:h,pluginfileUrl:f.attr("data-url"),objectType:"text/html",width:l-30,height:m-30,cmid:h,tileid:f.closest(k.sectionMain).attr("data-section"),isediting:0,sesskey:c.sesskey,modtitle:f.attr("data-title"),config:{wwwroot:c.wwwroot},showDownload:0,showNewWindow:1,completionInUseForCm:0,secondaryurl:f.closest(k.ACTIVITY).attr("data-url-secondary")};if(d.render("format_tiles/embed_url_modal_body",o).done(function(a){b.setBody(a),g.find(k.modalBody).animate({"min-height":m},"fast"),g.find(k.modal).animate({"max-width":l},"fast"),g.find(k.modalDialog).animate({"max-width":l},"fast"),g.find(k.modalBody).animate({"max-width":l},"fast"),n(g),g.find(k.modalBody).addClass("text-center")}).fail(e.exception),0!==f.find(k.toggleCompletion).length){var p=parseInt(a(k.completionState+h).attr("value"));o.completionInUseForCm=1,o.completionstate=1-p,o.completionicon=1===p?"n":"y",o.completionstateInverse=p,o.completionIsManual=f.find(k.toggleCompletion).attr("data-ismanual")}return d.render("format_tiles/embed_module_modal_header_btns",o).done(function(a){g.find(k.modalHeader).append(a),g.find(k.closeBtn).detach().appendTo(g.find(k.embedModuleButtons))}).fail(e.exception),setTimeout(function(){g.find(k.newWindowButton).click(function(){i[g.attr("data-cmid")]=void 0,g.remove(),a(".modal-backdrop").not("#window-overlay").removeClass("show").addClass("hide")})},1e3),!0}),!1},q=function(b){b.find(k.modal).animate({"max-width":m()},"fast");var c=70,d=a(k.moodleMediaPlayer);d.find("div").each(function(b,c){a(c).css("max-width","")}),d.length>0&&n(b),b.find("iframe").each(function(d,e){var f;f=b.find(k.modalDialog),0===f.length&&(f=b.find(k.modal));var g=Math.min(a(e).width(),j.width());g>f.width()-c&&(f.animate({"max-width":Math.max(g+c,m())},"fast"),b.find(k.modal).animate({"max-width":Math.max(g+c,m())},"fast"));var h=Math.min(a(e).height(),j.height()),i=b.find(k.modalBody);h>i.height()-c&&i.animate({"min-height":Math.min(h+c,j.height())},"fast"),i.css("text-align","center"),n(b)})},r=function(j){var l=j.attr("data-cmid"),m="format_tiles_get_mod_"+j.attr("data-modtype")+"_html";return b.create({type:b.types.DEFAULT,title:j.attr("data-title"),body:g}).done(function(b){i[l]=b,b.setLarge(),b.show();var g=a(b.root);g.attr("data-cmid",l),g.attr("id","embed_mod_modal_"+l),g.addClass("embed_cm_modal"),g.addClass("mod_"+j.attr("data-modtype")),n(g),f.call([{methodname:m,args:{courseid:h,cmid:l}}])[0].done(function(c){var f={cmid:l,modtitle:j.attr("data-title"),content:c.html};if(0!==j.find(k.toggleCompletion).length){var h=parseInt(a(k.completionState+l).attr("value"));f.completionInUseForCm=1,f.completionstate=1-h,f.completionstateInverse=h,f.completionIsManual=j.find(k.toggleCompletion).attr("data-ismanual"),f.completionicon=1===h?"n":"y"}else f.completionInUseForCm=0;return b.setBody(f.content),d.render("format_tiles/embed_module_modal_header_btns",f).done(function(a){g.find(k.modalHeader).append(a),g.find(k.closeBtn).detach().appendTo(g.find(k.embedModuleButtons))}).fail(e.exception),q(g),!0}).fail(function(a){c.developerdebug!==!0?window.location=c.wwwroot+"/mod/"+j.attr("data-modtype")+"/view.php?id="+l:e.exception(a)})}),!1},s=function(b){var c=a(b.currentTarget).closest(k.ACTIVITY);void 0!==c.attr("data-url")&&(b.stopPropagation(),b.preventDefault(),f.call([{methodname:"format_tiles_log_mod_view",args:{courseid:h,cmid:c.attr("data-cmid")}}])[0].done(function(){require(["format_tiles/completion"],function(a){a.markAsAutoCompleteInUI(h,c)});var a=window.open(c.attr("data-url"));try{a.focus()}catch(b){var d='<div><a href="'+c.attr("data-url")+'">'+c.attr("data-url")+"</a></div>";require(["core/str","core/notification"],function(a,b){var c=[{key:"sectionerrortitle",component:"format_tiles"},{key:"blockedpopup",component:"format_tiles"},{key:"cancel"}];a.get_strings(c).done(function(a){b.alert(a[0],a[1]+d,a[2])})})}}).fail(e.exception))};return{init:function(b,c){h=b,a(document).ready(function(){var b=Object.keys(l).map(function(a){return'[data-action="'+l[a]+'"]'}).join(", "),j=a(k.pageContent);0===j.length&&(j=a(k.regionMain)),j.on("click",b,function(b){b.preventDefault();var c=a(b.currentTarget),d=c.closest("li.activity"),g=i[d.attr("data-cmid")];if("object"==typeof g)g.show();else{switch(c.attr("data-action")){case l.launchModuleModal:r(d);break;case l.launchResourceModal:o(d);break;case l.launchUrlModal:p(d);break;default:throw new Error("Unknown modal type "+c.attr("data-action"))}f.call([{methodname:"format_tiles_log_mod_view",args:{courseid:h,cmid:d.attr("data-cmid")}}])[0].fail(e.exception)}}),d.render("format_tiles/loading",{})["catch"](e.exception).done(function(a){g=a}).fail(e.exception),c||j.on("click",k.URLACTIVITYPOPUPLINK,function(a){s(a)})})}}});