mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-82024 format_topics: toggle un/highlight section icon correctly.
This commit is contained in:
parent
cd781ab1b7
commit
160617d2d5
@ -5,6 +5,6 @@ define("format_topics/section",["exports","core/reactive","core_courseformat/cou
|
||||
* @module format_topics/section
|
||||
* @copyright 2022 Ferran Recio <ferran@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_templates=(obj=_templates)&&obj.__esModule?obj:{default:obj};class HighlightSection extends _reactive.BaseComponent{create(){this.name="format_topics_section",this.selectors={SECTION:"[data-for='section']",SETMARKER:'[data-action="sectionHighlight"]',REMOVEMARKER:'[data-action="sectionUnhighlight"]',ACTIONTEXT:".menu-action-text",ICON:".icon"},this.classes={HIDE:"d-none"},this.formatActions={HIGHLIGHT:"sectionHighlight",UNHIGHLIGHT:"sectionUnhighlight"}}getWatchers(){return[{watch:"section.current:updated",handler:this._refreshHighlight}]}async _refreshHighlight(_ref){var _affectedAction$datas,_affectedAction$datas2;let selector,newAction,{element:element}=_ref;element.current?(selector=this.selectors.SETMARKER,newAction=this.formatActions.UNHIGHLIGHT):(selector=this.selectors.REMOVEMARKER,newAction=this.formatActions.HIGHLIGHT);const affectedAction=this.getElement("".concat(this.selectors.SECTION," ").concat(selector),element.id);if(!affectedAction)return;affectedAction.dataset.action=newAction;const actionText=affectedAction.querySelector(this.selectors.ACTIONTEXT);if(null!==(_affectedAction$datas=affectedAction.dataset)&&void 0!==_affectedAction$datas&&_affectedAction$datas.swapname&&actionText){const oldText=null==actionText?void 0:actionText.innerText;actionText.innerText=affectedAction.dataset.swapname,affectedAction.dataset.swapname=oldText}const icon=affectedAction.querySelector(this.selectors.ICON);if(null!==(_affectedAction$datas2=affectedAction.dataset)&&void 0!==_affectedAction$datas2&&_affectedAction$datas2.swapicon&&icon){const newIcon=affectedAction.dataset.swapicon;if(newIcon){const pixHtml=await _templates.default.renderPix(newIcon,"core");_templates.default.replaceNode(icon,pixHtml,"")}}}}_exports.init=()=>{const courseEditor=(0,_courseeditor.getCurrentCourseEditor)();courseEditor.supportComponents&&courseEditor.isEditing&&new HighlightSection({element:document.getElementById("region-main"),reactive:courseEditor})}}));
|
||||
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_templates=(obj=_templates)&&obj.__esModule?obj:{default:obj};class HighlightSection extends _reactive.BaseComponent{create(){this.name="format_topics_section",this.selectors={SECTION:"[data-for='section']",SETMARKER:'[data-action="sectionHighlight"]',REMOVEMARKER:'[data-action="sectionUnhighlight"]',ACTIONTEXT:".menu-action-text",ICON:".icon"},this.classes={HIDE:"d-none"},this.formatActions={HIGHLIGHT:"sectionHighlight",UNHIGHLIGHT:"sectionUnhighlight"}}getWatchers(){return[{watch:"section.current:updated",handler:this._refreshHighlight}]}async _refreshHighlight(_ref){var _affectedAction$datas,_affectedAction$datas2;let selector,newAction,{element:element}=_ref;element.current?(selector=this.selectors.SETMARKER,newAction=this.formatActions.UNHIGHLIGHT):(selector=this.selectors.REMOVEMARKER,newAction=this.formatActions.HIGHLIGHT);const affectedAction=this.getElement("".concat(this.selectors.SECTION," ").concat(selector),element.id);if(!affectedAction)return;affectedAction.dataset.action=newAction;const actionText=affectedAction.querySelector(this.selectors.ACTIONTEXT);if(null!==(_affectedAction$datas=affectedAction.dataset)&&void 0!==_affectedAction$datas&&_affectedAction$datas.swapname&&actionText){const oldText=null==actionText?void 0:actionText.innerText;actionText.innerText=affectedAction.dataset.swapname,affectedAction.dataset.swapname=oldText}const icon=affectedAction.querySelector(this.selectors.ICON);if(null!==(_affectedAction$datas2=affectedAction.dataset)&&void 0!==_affectedAction$datas2&&_affectedAction$datas2.swapicon&&icon){const newIcon=affectedAction.dataset.swapicon;if(newIcon){const pixHtml=await _templates.default.renderPix(newIcon,"core");_templates.default.replaceNode(icon,pixHtml,""),affectedAction.dataset.swapicon=affectedAction.dataset.icon,affectedAction.dataset.icon=newIcon}}}}_exports.init=()=>{const courseEditor=(0,_courseeditor.getCurrentCourseEditor)();courseEditor.supportComponents&&courseEditor.isEditing&&new HighlightSection({element:document.getElementById("region-main"),reactive:courseEditor})}}));
|
||||
|
||||
//# sourceMappingURL=section.min.js.map
|
File diff suppressed because one or more lines are too long
@ -98,6 +98,8 @@ class HighlightSection extends BaseComponent {
|
||||
if (newIcon) {
|
||||
const pixHtml = await Templates.renderPix(newIcon, 'core');
|
||||
Templates.replaceNode(icon, pixHtml, '');
|
||||
affectedAction.dataset.swapicon = affectedAction.dataset.icon;
|
||||
affectedAction.dataset.icon = newIcon;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -117,13 +117,16 @@ class controlmenu extends controlmenu_base {
|
||||
}
|
||||
|
||||
$highlightoff = get_string('highlightoff');
|
||||
$highlightofficon = 'i/marked';
|
||||
|
||||
$highlighton = get_string('highlight');
|
||||
$highlightonicon = 'i/marker';
|
||||
|
||||
if ($course->marker == $section->section) { // Show the "light globe" on/off.
|
||||
$url->param('marker', 0);
|
||||
$result = [
|
||||
'url' => $url,
|
||||
'icon' => 'i/marked',
|
||||
'icon' => $highlightofficon,
|
||||
'name' => $highlightoff,
|
||||
'pixattr' => ['class' => ''],
|
||||
'attr' => [
|
||||
@ -131,15 +134,16 @@ class controlmenu extends controlmenu_base {
|
||||
'data-action' => 'sectionUnhighlight',
|
||||
'data-sectionreturn' => $sectionreturn,
|
||||
'data-id' => $section->id,
|
||||
'data-icon' => $highlightofficon,
|
||||
'data-swapname' => $highlighton,
|
||||
'data-swapicon' => 'i/marker',
|
||||
'data-swapicon' => $highlightonicon,
|
||||
],
|
||||
];
|
||||
} else {
|
||||
$url->param('marker', $section->section);
|
||||
$result = [
|
||||
'url' => $url,
|
||||
'icon' => 'i/marker',
|
||||
'icon' => $highlightonicon,
|
||||
'name' => $highlighton,
|
||||
'pixattr' => ['class' => ''],
|
||||
'attr' => [
|
||||
@ -147,8 +151,9 @@ class controlmenu extends controlmenu_base {
|
||||
'data-action' => 'sectionHighlight',
|
||||
'data-sectionreturn' => $sectionreturn,
|
||||
'data-id' => $section->id,
|
||||
'data-icon' => $highlightonicon,
|
||||
'data-swapname' => $highlightoff,
|
||||
'data-swapicon' => 'i/marked',
|
||||
'data-swapicon' => $highlightofficon,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user