From ef08168847ee2edb4dd013bae626d74fdd4c169a Mon Sep 17 00:00:00 2001 From: rtschu Date: Fri, 2 Oct 2020 21:54:50 +0200 Subject: [PATCH 1/2] make sections collapsible --- amd/build/collapse.min.js | 2 ++ amd/build/collapse.min.js.map | 1 + amd/src/collapse.js | 31 +++++++++++++++++++++++++++++ classes/output/wwu_format_trait.php | 4 ++++ 4 files changed, 38 insertions(+) create mode 100644 amd/build/collapse.min.js create mode 100644 amd/build/collapse.min.js.map create mode 100644 amd/src/collapse.js diff --git a/amd/build/collapse.min.js b/amd/build/collapse.min.js new file mode 100644 index 0000000..1677d53 --- /dev/null +++ b/amd/build/collapse.min.js @@ -0,0 +1,2 @@ +define ("theme_wwu2019/collapse",["jquery","core/url"],function(a,b){var c=function(c){a("#section-"+c).find(".content").each(function(a,b){b.hidden=!0});var e=a("#collapseicon"+c);e.attr("src",b.fileUrl("/pix/t","collapsed.png"));e.click(function(){d(c)})},d=function(d){a("#section-"+d).find(".content").each(function(a,b){b.hidden=!1});var e=a("#collapseicon"+d);e.attr("src",b.fileUrl("/pix/t","expanded.png"));e.click(function(){c(d)})};return{init:function init(b){var d=a("#collapseicon"+b);d.click(function(){c(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..eb3f435 --- /dev/null +++ b/amd/build/collapse.min.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/collapse.js"],"names":["define","$","url","hide","section","find","each","index","element","hidden","arrow","attr","fileUrl","click","show","init","sectionindex"],"mappings":"AAGAA,OAAM,0BAAC,CAAC,QAAD,CAAW,UAAX,CAAD,CAAyB,SAAUC,CAAV,CAAaC,CAAb,CAAkB,IAEzCC,CAAAA,CAAI,CAAG,SAAUC,CAAV,CAAmB,CAC1BH,CAAC,CAAC,YAAcG,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,CAAGT,CAAC,CAAC,gBAAkBG,CAAnB,CAAb,CACAM,CAAK,CAACC,IAAN,CAAW,KAAX,CAAkBT,CAAG,CAACU,OAAJ,CAAY,QAAZ,CAAsB,eAAtB,CAAlB,EACAF,CAAK,CAACG,KAAN,CAAY,UAAY,CAAEC,CAAI,CAACV,CAAD,CAAY,CAA1C,CACH,CAT4C,CAWzCU,CAAI,CAAG,SAAUV,CAAV,CAAmB,CAC1BH,CAAC,CAAC,YAAcG,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,CAAGT,CAAC,CAAC,gBAAkBG,CAAnB,CAAb,CACAM,CAAK,CAACC,IAAN,CAAW,KAAX,CAAkBT,CAAG,CAACU,OAAJ,CAAY,QAAZ,CAAsB,cAAtB,CAAlB,EACAF,CAAK,CAACG,KAAN,CAAY,UAAY,CAAEV,CAAI,CAACC,CAAD,CAAY,CAA1C,CACH,CAlB4C,CAwB7C,MAAO,CACHW,IAAI,CALG,QAAPA,CAAAA,IAAO,CAAUC,CAAV,CAAwB,CAC/B,GAAIN,CAAAA,CAAK,CAAGT,CAAC,CAAC,gBAAkBe,CAAnB,CAAb,CACAN,CAAK,CAACG,KAAN,CAAY,UAAY,CAACV,CAAI,CAACa,CAAD,CAAiB,CAA9C,CACH,CACM,CAGV,CA3BK,CAAN","sourcesContent":["// WWU Addon. Allows collapsing of topics in courses.\n// Robin Tschudi\n\ndefine(['jquery', 'core/url'], function ($, url) {\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\", url.fileUrl(\"/pix/t\", \"collapsed.png\"));\n arrow.click(function () { 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\", url.fileUrl(\"/pix/t\", \"expanded.png\"));\n arrow.click(function () { hide(section); });\n };\n\n var init = function (sectionindex) {\n let arrow = $(\"#collapseicon\" + sectionindex);\n arrow.click(function () {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..79de618 --- /dev/null +++ b/amd/src/collapse.js @@ -0,0 +1,31 @@ +// WWU Addon. Allows collapsing of topics in courses. +// Robin Tschudi + +define(['jquery', 'core/url'], function ($, url) { + + var hide = function (section) { + $("#section-" + section).find(".content").each(function (index, element) { + element.hidden = true; + }); + let arrow = $("#collapseicon" + section); + arrow.attr("src", url.fileUrl("/pix/t", "collapsed.png")); + arrow.click(function () { show(section); }); + }; + + var show = function (section) { + $("#section-" + section).find(".content").each(function (index, element) { + element.hidden = false; + }); + let arrow = $("#collapseicon" + section); + arrow.attr("src", url.fileUrl("/pix/t", "expanded.png")); + arrow.click(function () { hide(section); }); + }; + + var init = function (sectionindex) { + let arrow = $("#collapseicon" + sectionindex); + arrow.click(function () {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..0ea7b60 100644 --- a/classes/output/wwu_format_trait.php +++ b/classes/output/wwu_format_trait.php @@ -75,6 +75,10 @@ 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 $CFG; + $o .= html_writer::img($CFG->wwwroot . "/pix/t/expanded.png", "collapsed", 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'); From 750926889c7a8775e926ea87d3e50c20a7b23e89 Mon Sep 17 00:00:00 2001 From: rtschu Date: Fri, 9 Oct 2020 16:26:39 +0200 Subject: [PATCH 2/2] changed to native pix requiring --- amd/build/collapse.min.js | 2 +- amd/build/collapse.min.js.map | 2 +- amd/src/collapse.js | 15 +++++++++------ classes/output/wwu_format_trait.php | 5 +++-- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/amd/build/collapse.min.js b/amd/build/collapse.min.js index 1677d53..2c01a13 100644 --- a/amd/build/collapse.min.js +++ b/amd/build/collapse.min.js @@ -1,2 +1,2 @@ -define ("theme_wwu2019/collapse",["jquery","core/url"],function(a,b){var c=function(c){a("#section-"+c).find(".content").each(function(a,b){b.hidden=!0});var e=a("#collapseicon"+c);e.attr("src",b.fileUrl("/pix/t","collapsed.png"));e.click(function(){d(c)})},d=function(d){a("#section-"+d).find(".content").each(function(a,b){b.hidden=!1});var e=a("#collapseicon"+d);e.attr("src",b.fileUrl("/pix/t","expanded.png"));e.click(function(){c(d)})};return{init:function init(b){var d=a("#collapseicon"+b);d.click(function(){c(b)})}}}); +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 index eb3f435..d70fffd 100644 --- a/amd/build/collapse.min.js.map +++ b/amd/build/collapse.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/collapse.js"],"names":["define","$","url","hide","section","find","each","index","element","hidden","arrow","attr","fileUrl","click","show","init","sectionindex"],"mappings":"AAGAA,OAAM,0BAAC,CAAC,QAAD,CAAW,UAAX,CAAD,CAAyB,SAAUC,CAAV,CAAaC,CAAb,CAAkB,IAEzCC,CAAAA,CAAI,CAAG,SAAUC,CAAV,CAAmB,CAC1BH,CAAC,CAAC,YAAcG,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,CAAGT,CAAC,CAAC,gBAAkBG,CAAnB,CAAb,CACAM,CAAK,CAACC,IAAN,CAAW,KAAX,CAAkBT,CAAG,CAACU,OAAJ,CAAY,QAAZ,CAAsB,eAAtB,CAAlB,EACAF,CAAK,CAACG,KAAN,CAAY,UAAY,CAAEC,CAAI,CAACV,CAAD,CAAY,CAA1C,CACH,CAT4C,CAWzCU,CAAI,CAAG,SAAUV,CAAV,CAAmB,CAC1BH,CAAC,CAAC,YAAcG,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,CAAGT,CAAC,CAAC,gBAAkBG,CAAnB,CAAb,CACAM,CAAK,CAACC,IAAN,CAAW,KAAX,CAAkBT,CAAG,CAACU,OAAJ,CAAY,QAAZ,CAAsB,cAAtB,CAAlB,EACAF,CAAK,CAACG,KAAN,CAAY,UAAY,CAAEV,CAAI,CAACC,CAAD,CAAY,CAA1C,CACH,CAlB4C,CAwB7C,MAAO,CACHW,IAAI,CALG,QAAPA,CAAAA,IAAO,CAAUC,CAAV,CAAwB,CAC/B,GAAIN,CAAAA,CAAK,CAAGT,CAAC,CAAC,gBAAkBe,CAAnB,CAAb,CACAN,CAAK,CAACG,KAAN,CAAY,UAAY,CAACV,CAAI,CAACa,CAAD,CAAiB,CAA9C,CACH,CACM,CAGV,CA3BK,CAAN","sourcesContent":["// WWU Addon. Allows collapsing of topics in courses.\n// Robin Tschudi\n\ndefine(['jquery', 'core/url'], function ($, url) {\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\", url.fileUrl(\"/pix/t\", \"collapsed.png\"));\n arrow.click(function () { 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\", url.fileUrl(\"/pix/t\", \"expanded.png\"));\n arrow.click(function () { hide(section); });\n };\n\n var init = function (sectionindex) {\n let arrow = $(\"#collapseicon\" + sectionindex);\n arrow.click(function () {hide(sectionindex); });\n };\n return {\n init: init,\n };\n});"],"file":"collapse.min.js"} \ No newline at end of file +{"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 index 79de618..f7ea703 100644 --- a/amd/src/collapse.js +++ b/amd/src/collapse.js @@ -1,15 +1,18 @@ // WWU Addon. Allows collapsing of topics in courses. // Robin Tschudi -define(['jquery', 'core/url'], function ($, url) { +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", url.fileUrl("/pix/t", "collapsed.png")); - arrow.click(function () { show(section); }); + arrow.attr("src", collapsed_url); + arrow.click(function () { arrow.unbind("click"); show(section); }); }; var show = function (section) { @@ -17,13 +20,13 @@ define(['jquery', 'core/url'], function ($, url) { element.hidden = false; }); let arrow = $("#collapseicon" + section); - arrow.attr("src", url.fileUrl("/pix/t", "expanded.png")); - arrow.click(function () { hide(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 () {hide(sectionindex); }); + arrow.click(function () {arrow.unbind("click"); hide(sectionindex);}); }; return { init: init, diff --git a/classes/output/wwu_format_trait.php b/classes/output/wwu_format_trait.php index 0ea7b60..e446b36 100644 --- a/classes/output/wwu_format_trait.php +++ b/classes/output/wwu_format_trait.php @@ -75,8 +75,9 @@ 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 $CFG; - $o .= html_writer::img($CFG->wwwroot . "/pix/t/expanded.png", "collapsed", array("id" => "collapseicon" . $section->section)); + 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));