diff --git a/amd/build/collapse.min.js b/amd/build/collapse.min.js new file mode 100644 index 0000000..2c01a13 --- /dev/null +++ b/amd/build/collapse.min.js @@ -0,0 +1,2 @@ +define ("theme_wwu2019/collapse",["jquery"],function(a){var b=M.util.image_url("t/collapsed","core"),c=M.util.image_url("t/expanded","core"),d=function(c){a("#section-"+c).find(".content").each(function(a,b){b.hidden=!0});var d=a("#collapseicon"+c);d.attr("src",b);d.click(function(){d.unbind("click");e(c)})},e=function(b){a("#section-"+b).find(".content").each(function(a,b){b.hidden=!1});var e=a("#collapseicon"+b);e.attr("src",c);e.click(function(){e.unbind("click");d(b)})};return{init:function init(b){var c=a("#collapseicon"+b);c.click(function(){c.unbind("click");d(b)})}}}); +//# sourceMappingURL=collapse.min.js.map diff --git a/amd/build/collapse.min.js.map b/amd/build/collapse.min.js.map new file mode 100644 index 0000000..d70fffd --- /dev/null +++ b/amd/build/collapse.min.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/collapse.js"],"names":["define","$","collapsed_url","M","util","image_url","expanded_url","hide","section","find","each","index","element","hidden","arrow","attr","click","unbind","show","init","sectionindex"],"mappings":"AAGAA,OAAM,0BAAC,CAAC,QAAD,CAAD,CAAa,SAAUC,CAAV,CAAa,IAEtBC,CAAAA,CAAa,CAAGC,CAAC,CAACC,IAAF,CAAOC,SAAP,CAAiB,aAAjB,CAAgC,MAAhC,CAFM,CAGtBC,CAAY,CAAGH,CAAC,CAACC,IAAF,CAAOC,SAAP,CAAiB,YAAjB,CAA+B,MAA/B,CAHO,CAKxBE,CAAI,CAAG,SAAUC,CAAV,CAAmB,CAC1BP,CAAC,CAAC,YAAcO,CAAf,CAAD,CAAyBC,IAAzB,CAA8B,UAA9B,EAA0CC,IAA1C,CAA+C,SAAUC,CAAV,CAAiBC,CAAjB,CAA0B,CACrEA,CAAO,CAACC,MAAR,GACH,CAFD,EAGA,GAAIC,CAAAA,CAAK,CAAGb,CAAC,CAAC,gBAAkBO,CAAnB,CAAb,CACAM,CAAK,CAACC,IAAN,CAAW,KAAX,CAAkBb,CAAlB,EACAY,CAAK,CAACE,KAAN,CAAY,UAAY,CAAEF,CAAK,CAACG,MAAN,CAAa,OAAb,EAAuBC,CAAI,CAACV,CAAD,CAAY,CAAjE,CACH,CAZ2B,CAcxBU,CAAI,CAAG,SAAUV,CAAV,CAAmB,CAC1BP,CAAC,CAAC,YAAcO,CAAf,CAAD,CAAyBC,IAAzB,CAA8B,UAA9B,EAA0CC,IAA1C,CAA+C,SAAUC,CAAV,CAAiBC,CAAjB,CAA0B,CACrEA,CAAO,CAACC,MAAR,GACH,CAFD,EAGA,GAAIC,CAAAA,CAAK,CAAGb,CAAC,CAAC,gBAAkBO,CAAnB,CAAb,CACAM,CAAK,CAACC,IAAN,CAAW,KAAX,CAAkBT,CAAlB,EACAQ,CAAK,CAACE,KAAN,CAAY,UAAY,CAAEF,CAAK,CAACG,MAAN,CAAa,OAAb,EAAuBV,CAAI,CAACC,CAAD,CAAY,CAAjE,CACH,CArB2B,CA2B5B,MAAO,CACHW,IAAI,CALG,QAAPA,CAAAA,IAAO,CAAUC,CAAV,CAAwB,CAC/B,GAAIN,CAAAA,CAAK,CAAGb,CAAC,CAAC,gBAAkBmB,CAAnB,CAAb,CACAN,CAAK,CAACE,KAAN,CAAY,UAAY,CAACF,CAAK,CAACG,MAAN,CAAa,OAAb,EAAuBV,CAAI,CAACa,CAAD,CAAgB,CAApE,CACH,CACM,CAGV,CA9BK,CAAN","sourcesContent":["// WWU Addon. Allows collapsing of topics in courses.\n// Robin Tschudi\n\ndefine(['jquery'], function ($) {\n\n const collapsed_url = M.util.image_url(\"t/collapsed\", \"core\");\n const expanded_url = M.util.image_url(\"t/expanded\", \"core\");\n\n var hide = function (section) {\n $(\"#section-\" + section).find(\".content\").each(function (index, element) {\n element.hidden = true;\n });\n let arrow = $(\"#collapseicon\" + section);\n arrow.attr(\"src\", collapsed_url);\n arrow.click(function () { arrow.unbind(\"click\"); show(section); });\n };\n\n var show = function (section) {\n $(\"#section-\" + section).find(\".content\").each(function (index, element) {\n element.hidden = false;\n });\n let arrow = $(\"#collapseicon\" + section);\n arrow.attr(\"src\", expanded_url);\n arrow.click(function () { arrow.unbind(\"click\"); hide(section); });\n };\n\n var init = function (sectionindex) {\n let arrow = $(\"#collapseicon\" + sectionindex);\n arrow.click(function () {arrow.unbind(\"click\"); hide(sectionindex);});\n };\n return {\n init: init,\n };\n});"],"file":"collapse.min.js"} \ No newline at end of file diff --git a/amd/src/collapse.js b/amd/src/collapse.js new file mode 100644 index 0000000..f7ea703 --- /dev/null +++ b/amd/src/collapse.js @@ -0,0 +1,34 @@ +// WWU Addon. Allows collapsing of topics in courses. +// Robin Tschudi + +define(['jquery'], function ($) { + + const collapsed_url = M.util.image_url("t/collapsed", "core"); + const expanded_url = M.util.image_url("t/expanded", "core"); + + var hide = function (section) { + $("#section-" + section).find(".content").each(function (index, element) { + element.hidden = true; + }); + let arrow = $("#collapseicon" + section); + arrow.attr("src", collapsed_url); + arrow.click(function () { arrow.unbind("click"); show(section); }); + }; + + var show = function (section) { + $("#section-" + section).find(".content").each(function (index, element) { + element.hidden = false; + }); + let arrow = $("#collapseicon" + section); + arrow.attr("src", expanded_url); + arrow.click(function () { arrow.unbind("click"); hide(section); }); + }; + + var init = function (sectionindex) { + let arrow = $("#collapseicon" + sectionindex); + arrow.click(function () {arrow.unbind("click"); hide(sectionindex);}); + }; + return { + init: init, + }; +}); \ No newline at end of file diff --git a/classes/output/wwu_format_trait.php b/classes/output/wwu_format_trait.php index e1d7f06..e446b36 100644 --- a/classes/output/wwu_format_trait.php +++ b/classes/output/wwu_format_trait.php @@ -75,6 +75,11 @@ public function wwu_section_header($section, $course, $onsectionpage) { $leftcontent = $this->section_left_content($section, $course, $onsectionpage); $o .= html_writer::tag('div', $leftcontent, array('class' => 'left side')); + global $OUTPUT; + $arrowurl = $OUTPUT->image_url("t/expanded", "core"); + $o .= html_writer::img($arrowurl, "collapse", array("id" => "collapseicon" . $section->section)); + $this->page->requires->js_call_amd('theme_wwu2019/collapse', 'init', array($section->section)); + $sectionname = html_writer::tag('span', $this->section_title($section, $course)); $o .= $this->output->heading($sectionname, 3, 'sectionname');