-
Notifications
You must be signed in to change notification settings - Fork 7
/
hx-min.js
1 lines (1 loc) · 15.5 KB
/
hx-min.js
1
var HXGlobalJS=function(){"use strict";void 0===window.hxLocalOptions&&(window.hxLocalOptions={}),void 0===window.HXPUPTimer&&(window.HXPUPTimer=[]),void 0===window.HXChimeTimer&&(window.HXChimeTimer=[]);var e,t,i,s,n,l,o,a={makeTOC:!1,collapsedNav:!1,openPageDiscussion:!1,markExternalLinks:!1,useBackpack:!0,highlightColor:"#ff0",highlightBackground:"rgba(0,0,0,0)",highlightState:!0,highlightCode:!0,slickOptions:{arrows:!0,dots:!0,focusOnChange:!0,infinite:!0,slidesToShow:3,slidesToScroll:3},slickNavOptions:{asNavFor:".hx-bigslider",variableWidth:!0,focusOnSelect:!0,slidesToShow:3,slidesToScroll:1},slickBigOptions:{asNavFor:".hx-navslider",arrows:!1,dots:!0,fade:!0,focusOnChange:!0,adaptiveHeight:!0,slidesToShow:1,slidesToScroll:1},textSliderOptions:{slidesFile:"TextSliderCards.csv",startingSlide:"",slideScope:[],overviewIsOpen:!1,showBottomNav:!0,maxIconsTall:2,causeEffect:["Causes","Effects"]},PUPOptions:{width:800,effect:"fade",effectlength:200,myPosition:"center",atPosition:"center",ofTarget:window},VidLinkOptions:{hideLinkAfter:5,effect:"slide",hide:{direction:"down"},show:{direction:"down"},speed:500,location:"bl"},HXEditorOptions:[["style",["style"]],["font",["bold","italic","underline","clear"]],["color",["color"]],["para",["ul","ol","paragraph"]],["table",["table"]],["insert",["link"]],["view",["fullscreen","codeview","help"]],],ChimeOptions:{}},r=N(window.location.href,"complete");let c=$("script").filter((e,t)=>{if(t.src&&t.src.includes("hx_17.js"))return t}),h=c[0].attributes.src.value.replace("hx_17.js","");if(1===c.length&&(r=h),U({"script asset url":r}),N(window.location.href,"site").indexOf("studio")>-1){console.log("Running HXJS in studio is probably not great. Quitting.");return}let d,p;var g=(e=window.location.href,d=N(e,"partial"),p={},d=d.split(":")[2],p.institution=d.split("+")[0],p.id=d.split("+")[1],p.run=d.split("+")[2],p),u=g.institution+"."+g.id+"_"+g.run;U({"HX.js":"enabled"}),U({course_log_id:u}),Logger.listen("problem_check",null,(e,t)=>C(e,t)),Logger.listen("problem_show",null,(e,t)=>C(e,t)),Logger.listen("problem_reset",null,(e,t)=>C(e,t)),$.getMultiScripts=function(e,t){console.log(e);var i=$.map(e,function(e){console.log(e),console.log(t);let i=t;return"hxGlobalOptions.js"===e&&(i=N(window.location.href)),console.log(i),U({loading_script:i+e}),$.getScript((i||"")+e)});return i.push($.Deferred(function(e){$(e.resolve)})),$.when.apply($,i)};var f=[],x={};f.push("hxGlobalOptions.js");var m=$("code");m.length&&(U({code_block:"found"}),f.push("prism.js"));var k=$(".hx-slider"),v=$(".hx-navslider"),b=$(".hx-bigslider");(k.length||v.length&&b.length)&&(U({image_slider:"found"}),f.push("slick.js"));var y=$(".hx-dynamic-sliderbox");y.length&&(U({dynamic_slider:"found"}),f.push("papaparse.js"),f.push("hx-text-slider.js"));var O=$(".hx-editor:visible");O.length>0&&(U({editor:"found"}),f.push("summernote-lite.min.js"),f.push("HXEditor.js"));var w=!0;window.hxLocalOptions.dontload_video_stuff,!0===window.hxLocalOptions.dontload_video_stuff&&(w=!1,console.log("skipping loading video js"));var T=$(".video");function _(e){if(window.hxOptions=e,console.log("Window hxOptions set"),0===$("#hxbackpackframe").length&&e.useBackpack){let t=N(window.location.href,"site")+"block-v1:"+g.institution+"+"+g.id+"+"+g.run+"+type@problem+block@backpack",c=$("<iframe></iframe>");c.attr("src",t),c.attr("id","hxbackpackframe"),c.attr("aria-hidden","true"),c.attr("tabindex","-1"),c.css("display","none"),$("body").append(c)}if(O.length){$("head").append($('<link rel="stylesheet" href="'+r+'summernote-lite.min.css" type="text/css" />'));let h=$('<div class="hx-loading-indicator"> Editor loading...</div>'),d=$('<span class="fa fa-spinner fa-pulse"></span>');h.prepend(d),O.append(h),hxBackpackLoaded&&void 0===s?s=new HXEditor(e.useBackpack,e.HXEditorOptions):(console.log("Backpack: "+hxBackpackLoaded),console.log("HXED: "+typeof s=="undefined"?"undefined":"ok"))}T.length>0&&w&&($("head").append($('<link rel="stylesheet" href="'+r+'VideoLinks.css" type="text/css" />')),n=new HXVideoLinks(e.VidLinkOptions),$(".jumptime").on("click tap",function(e){e.preventDefault();let t=1;void 0!==$(this).attr("data-for-vidnum")&&(t=$(this).attr("data-for-vidnum"));let i=D($(this).attr("href"));V(t,i)}),0!==window.HXPUPTimer.length&&(l=new HXPopUpProblems(a.PUPOptions,window.HXPUPTimer)),0!==window.HXChimeTimer.length&&(o=new HXVideoChime(a.ChimeOptions,window.HXChimeTimer))),m.length&&e.highlightCode&&$("head").append($('<link rel="stylesheet" href="'+r+'prism.css" type="text/css" />'));let p=Array.from(document.getElementsByClassName("hx-survey-url"));if(p.length){U({hx_surveys:"found"});let u=Array.from(document.getElementsByClassName("hx-survey-url")),f=u.map(function(e){return"a"===e.tagName.toLowerCase()?e.href:"iframe"===e.tagName.toLowerCase()?e.src:e.innerText}),x=f.map(e=>e+"&university="+g.institution+"&course_id="+g.id+"&course_run="+g.run);u.forEach(function(e,t){"a"===e.tagName.toLowerCase()?e.href=x[t]:"iframe"===e.tagName.toLowerCase()?e.src=x[t]:e.innerText=x[t]})}$("a.hx-vidtime").on("click tap",function(){let e=D($(this).attr("data-time")),t=$(this).attr("href"),i=t.slice(t.indexOf("#video")).replace("#video",""),s=t.slice(t.indexOf("/jump_to_id/")+13,t.indexOf("#video"));0===t.indexOf("#")?(U({"link starts video at time":e}),n.jumpToTime(i,e)):(localStorage.HXVideoLinkGo="true",localStorage.HXVideoLinkUnit=s,localStorage.HXVideoLinkNumber=i,localStorage.HXVideoLinkTime=e,U({"storing video info for jump":{unit:s,"video number":i,time:e}}))}),e.collapsedNav&&($(".sequence-nav").hide(),$(".sequence > .path").hide(),$("h3.unit-title").hide());let _=$("#hx-tint");_.length&&$(_).on("click tap",function(){$("p").animate({color:"blue"})}),e.openPageDiscussion&&$(".discussion-show.btn").click(),e.markExternalLinks&&(U("marking external links"),$(".vert .xblock a, .static_tab_wrapper .xblock a").each(function(e,t){var i=$(t).attr("href");P(i)&&$(t).append(' <span class="fa fa-external-link"><span class="sr">External link</span></span>')}));let C,H;j("hx-togglebutton","hx-toggletarget","hx-toggleremember"),$("[class^=hx-highlighter]").on("click tap",function(){let t=B(this.className,"hx-highlighter");e.highlightState?$(".hx-highlight"+t).css({"background-color":e.highlightColor,transition:"background 0.2s"}):$(".hx-highlight"+t).css({"background-color":e.highlightBackground,transition:"background 0.2s"}),e.highlightState=!e.highlightState,U({"Highlight button":"pressed","Highlight number":t})}),e.makeTOC&&($(".edx-notes-wrapper-content").length?$(".edx-notes-wrapper-content:first-of-type").prepend('<div id="auto_toc" class="hx-autotoc"></div>'):$($("#seq_content .vert .xblock")[0]).prepend('<div id="auto_toc" class="hx-autotoc"></div>'),C="<h3>Table of Contents</h3><ul>",H=$("h3, h4").filter(function(){return $(this).is(":visible")}),H.each(function(e){$(this).attr("id","TOCLink"+e);let t=$(this).text(),i;$(this).is("h3")&&(i=3,$(H[e-1]).is("h3")||0===e?C+='<li class="autotoc'+i+'"><a href="#TOCLink'+e+'">'+t+"</a></li>":$(H[e-1]).is("h4")&&(C+='</ul></li><li class="autotoc'+i+'"><a href="#TOCLink'+e+'">'+t+"</a></li>")),$(this).is("h4")&&(i=4,$(H[e-1]).is("h3")?(e>0&&C.slice(0,C.length-5),C+='<ul><li class="autotoc'+i+'"><a href="#TOCLink'+e+'">'+t+"</a></li>"):$(H[e-1]).is("h4")&&(C+='<li class="autotoc'+i+'"><a href="#TOCLink'+e+'">'+t+"</a></li>"))}),C+="</ul>",$("#auto_toc").append(C));$(".hx-popup-opener").length&&($("map").each(function(e){let t=[];$(this).find("area").each(function(e){t.push('<li class="'+this.className.split(/\s+/)[0]+' hx-popup-opener" title="'+this.title+'"><a href="javascript:;">'+this.title+"</a></li>")});let i="<ul>"+t.join("")+"</ul>";i="<h4>Clickable Areas:</h4>"+i;let s=$(this).data("make-accessible-list");"false"===s||!1===s||$(this).after(i)}),$(".hx-popup-opener").on("click tap",function(e){let t=this.className.split(/\s+/)[0];$("div."+t).dialog({dialogClass:"hx-popup-dialog",title:$(this).attr("title"),position:{my:"center",at:"center",of:$(e.target)},show:{effect:"fade",duration:200},hide:{effect:"fade",duration:100},buttons:{Close:function(){$(this).dialog("close")}}},function(e){$("div."+e).css({display:""}),alert(e)}),U({"Pop-up Dialog":"opened",Dialog:t})}));let L=$('span[class^="hx-footnote"]');if(L.length&&function e(t){let i,s,n,l,o;for(let a=0;a<t.length;a++)s=B((i=t[a]).className,"hx-footnote"),n=$("div.hx-footnote-target"+s),$(i).addClass("hx-footnote-style"),$(i).wrap("<sup></sup>"),l=$('h3:contains("Footnote")'),o=$(l[l.length-1]).parent(),$(n).detach().appendTo(o),$(i).wrap('<a href="#hxfoot'+s+'" name="hxfootback'+s+'"></a>').wrap(),n.prepend('<a name="hxfoot'+s+'"></a>'),n.append('<p><a href="#hxfootback'+s+'">(back)</a></p>')}(L),y.length&&($("head").append($('<link rel="stylesheet" href="'+r+'hx-text-slider.css" type="text/css" />')),console.log(e.textSliderOptions),i=new HXTextSlider(e.textSliderOptions),U({"dynamic slider":"created"})),k.length){$("head").append($('<link rel="stylesheet" href="'+r+'slick.css" type="text/css" />')),$("head").append($('<link rel="stylesheet" href="'+r+'slick-theme.css" type="text/css" />'));let S=0,X=setInterval(function(){void 0!==$.fn.slick&&(clearInterval(X),k.slick(e.slickOptions),U({slider:"created"})),++S>30&&(clearInterval(X),U("Slick not ready after 30 tries. Giving up."))},100)}v.length&&b.length&&($("head").append($('<link rel="stylesheet" href="'+r+'slick.css" type="text/css" />')),$("head").append($('<link rel="stylesheet" href="'+r+'slick-theme.css" type="text/css" />')),v.slick(e.slickNavOptions),b.slick(e.slickBigOptions),U({"paired slider":"created"}))}function C(e,t){console.log(e,t);let i;"problem_check"===e?i=t.split("_")[1]:"problem_show"===e&&(i=t.problem.split("@")[2]);let s=$('[id^="'+i+'"]').parent()[0];setTimeout(function(){X("hx-togglebutton","hx-toggletarget"),m.length&&x.highlightCode&&Prism.highlightAllUnder(s)},500)}function H(e,t){e="toggle_"+e,console.log("set vis of "+e+" to "+t);try{let i=JSON.parse(localStorage.HXToggleMemory);i[e]=t,localStorage.HXToggleMemory=JSON.stringify(i)}catch(s){console.log("error"),console.log(s),localStorage.HXToggleMemory=JSON.stringify({[e]:t})}}function L(e,t,i,s){console.log("hiding"),$.ui?$("."+t+s).hide("slide",{direction:"up"},"fast"):$("."+t+s).hide(),$("."+e+s).attr("aria-expanded","false"),$("."+t+s).attr("aria-hidden","true"),$(".hx-toggleset ."+e+s).siblings().attr("disabled",!1),i&&H(s,!1)}function S(e,t,i,s){console.log("showing"),$.ui?$("."+t+s).show("slide",{direction:"up"},"fast"):$("."+t+s).show(),$("."+e+s).attr("aria-expanded","true"),$("."+t+s).attr("aria-hidden","false"),$(".hx-toggleset ."+e+s).siblings().attr("disabled",!0),i&&H(s,!0)}function X(e,t){console.log("setting visibility from memory");let i=[];$("[class*="+t+"]").each(function(){let s=B(this.className,t);if(console.log("toggle "+s+"..."),-1===i.indexOf(s)){i.push(s);let n=function e(t){t="toggle_"+t;let i=!1;try{i=JSON.parse(localStorage.HXToggleMemory)[t]}catch(s){}return i}(s);null!=n&&(n?(console.log("...should be shown. Showing it."),S(e,t,!1,s)):(console.log("...should be hidden. Hiding it."),L(e,t,!1,s)))}else console.log("...is already handled.")})}function j(e,t,i){let s=[];$("[class*="+e+"]").each(function(){let i=B(this.className,e);-1===s.indexOf(i)&&(console.log("prepping toggle "+i),s.push(i),$("."+t+i+":visible").length>0?($("."+e+i).attr("aria-expanded","true"),$("."+t+i).attr("aria-hidden","false")):($("."+e+i).attr("aria-expanded","false"),$("."+t+i).attr("aria-hidden","true")))}),X(e,t),$(".hx-clearmemory").on("click tap",function(){let t=B(this.className,e);null!==t?H(t,void 0):localStorage.HXToggleMemory=""}),$("[class*="+e+"]").on("click tap",function(){var s,n,l;let o=B(this.className,e),a=$(this).hasClass(i),r="";"true"===$(this).attr("aria-expanded")?(r="invisible",L(e,t,a,o,$(document))):(r="visible",S(e,t,a,o,$(document)),1===$("."+t+o).length&&(s=$("."+t+o)[0],n=s.getBoundingClientRect(),l=Math.max(document.documentElement.clientHeight,window.innerHeight),n.bottom<0||n.top-l>=0)&&$("."+t+o)[0].scrollIntoView()),U({"Toggle button":"pressed","Toggled to":r,"Toggle number":o})})}function P(e){return!!(void 0!==e&&isNaN(D(e)))&&!(e.includes("edx.org")||e.includes("edxapp")||e.includes("edx-cdn.org")||e.includes("edx-video.net")||e.includes("/courses/")||e.includes("/assets/courseware/")||e.includes("jump_to_id")||e.includes("cloudfront.net")||e.includes("mailto")||e.includes("javascript:void")||e.includes("javascript:;"))&&"#"!=e.slice(0,1)}function N(e,t){e.includes("%2B")&&(e=e.replace("%2B","+")),e.includes("%3A")&&(e=e.replace("%3A",":"));let i=e.match(/https:\/\/.+\//)[0];if("site"==t)return i;let s=e.replace("courses/course","asset");s.search("xblock/block-v1")>-1&&(s=(s=s.replace("xblock/block","asset")).replace("+type@","/"));let n=s.indexOf("+"),l=s.indexOf("/",n);return(s=s.slice(0,l),s+="+type@asset+block/","partial"==t)?s.replace(i,""):s}function B(e,t){let i=e.split(/\s+/);for(let s=0;s<i.length;s++)if(0===i[s].indexOf(t))return i[s].slice(t.length);return null}function E(e,t,i){let s={};return e||t?s=e?t?$.extend(!0,{},i,t,e):$.extend(!0,{},i,e):$.extend(!0,{},i,t):i}function D(e){let t=(e=e.toString()).split(":"),i=0;return 3==t.length?i=3600*parseInt(t[0])+60*parseInt(t[1])+Number(t[2]):2==t.length?i=60*parseInt(t[0])+Number(t[1]):1==t.length&&(i=Number(t[0])),i}function V(e,t){let i=$(".video")[e-1],s=$(i).data("video-player-state");void 0!==s.videoPlayer?(console.log("jumping video "+e+" to time "+t),i.scrollIntoView(),s.videoPlayer.player.seekTo(t)):console.log("video "+e+" not ready")}function U(e){console.log(JSON.stringify(e)),Logger.log(u+".hxjs",e)}w&&T.length>0&&(U({video:"found"}),f.push("HXVideoLinks.js"),window.HXPUPTimer.length>0&&f.push("HXPopUpProblems.js"),window.HXChimeTimer.length>0&&f.push("HXVideoChime.js")),$.getMultiScripts(f,r).done(function(){U({"Loaded scripts":f}),x=hxGlobalOptions?E(window.hxLocalOptions,hxGlobalOptions,a):E(window.hxLocalOptions,{},a),_(x)}).fail(function(e,t,i){console.log(e),console.log(t),console.log(i),U({scripts:f,script_load_error:t}),x=E(window.hxLocalOptions,{},a),_(x)}),(t=jQuery).fn.hxKonami=function(e,i){return void 0===i&&(i="38,38,40,40,37,39,37,39,66,65"),this.each(function(){let s=[];t(this).keydown(function(t){for(s.push(t.keyCode);s.length>i.split(",").length;)s.shift();s.toString().indexOf(i)>=0&&(s=[],e(t))})})},$(window).hxKonami(function(){alert("+30 Lives"),U({"easter egg":"Konami Code"})}),$(window).off("message.hx").on("message.hx",function(e){var t=e.originalEvent.data;if(e.originalEvent.origin===location.origin&&"string"==typeof t&&"backpack_ready"===t){console.log("Backpack ready.");let i=$("#hxbackpackframe")[0].contentWindow;window.hxSetData=i.hxSetData,window.hxClearData=i.hxSetData,window.hxGetData=i.hxGetData,window.hxGetAllData=i.hxGetAllData,window.hxBackpackLoaded=i.hxBackpackLoaded,x.useBackpack&&O.length>0&&void 0===s&&(s=new HXEditor(x.useBackpack,x.HXEditorOptions))}}),window.getAssetURL=N,window.hmsToTime=D,window.timeToHMS=function e(t){var i,s,n,l="";return i=Math.floor((t=Math.floor(t))/3600),(s=Math.floor(t/60%60))<10&&(s="0"+s),(n=Math.floor(t%60))<10&&(n="0"+n),l="0:"+n,s>0&&(l=s+":"+n),i>0&&(l=i+":"+s+":"+n),l},window.logThatThing=U,window.prepAccessibleToggles=j,window.isExternalLink=P,window.popDataMap=function e(){console.log("Open full-sized map image.");let t=$("#mapframe"),i=t.contents().find("#LargeMapView");t.toggleClass("hx-svg-view"),t.hasClass("hx-svg-view")?i.text("View Regular"):i.text("View Large")},window.jumpToTime=V,window.hxBackpackLoaded=$("#hxbackpackframe").length>0};$(document).ready(function(){if(void 0!==window.hxjs_is_already_running){console.log("hx-js is already loaded, skipping this copy.");return}window.hxjs_is_already_running=!0,HXGlobalJS()});