Skip to content

Commit

Permalink
Make editor buttons work
Browse files Browse the repository at this point in the history
  • Loading branch information
dasistwas committed Apr 17, 2024
1 parent 4b6df3c commit 724f43d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 19 deletions.
4 changes: 2 additions & 2 deletions amd/build/editor.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion amd/build/editor.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 41 additions & 15 deletions amd/src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,47 +22,73 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

import {getTinyMCE} from 'editor_tiny/loader';

var M = {
var newsletter = {
mod_newsletter: {}
};

var tinymce = null;

M.mod_newsletter.collapse_subscribe_form = function() {
newsletter.mod_newsletter.collapse_subscribe_form = function() {
var fieldset = document.querySelector('form #id_subscribe');
if (fieldset) {
fieldset.classList.add('collapsed');
}
};

export const loadCss = async function(stylesheets, selected) {
tinymce = await getTinyMCE();
var select = document.querySelector('#id_stylesheetid');

/**
* Wait for tinyMCE to be loaded.
* @returns {Promise}
*/
function waitUntilTinyMCELoaded() {
return new Promise((resolve) => {
/**
* Check if tinyMCE object is available
*/
function checkIfLoaded() {
if (window.tinyMCE) {
// If tinyMCE is available, resolve the promise
resolve(window.tinyMCE);
} else {
// If not, wait and check again
setTimeout(checkIfLoaded, 100); // Check every 100 milliseconds
}
}

// Start checking if loaded
checkIfLoaded();
});
}
waitUntilTinyMCELoaded()
.then((tinyMCE) => {
console.log('tinyMCE is loaded:', tinyMCE);
change_stylesheet({target: select});
tinyMCE.init({
content_css: stylesheets[selected]
});
// Proceed with further operations using tinyMCE
});


/**
* Changes the stylesheet based on the selected option.
* @param {Object} e Event object containing information about the target element.
*/
function change_stylesheet(e) {
var select = e.target;
var selectedIndex = select.value;
tinymce.remove();
tinymce.init({
let selectedTarget = e.target;
let selectedIndex = selectedTarget.value;
tinyMCE.remove();
tinyMCE.init({
selector: 'textarea',
content_css: stylesheets[selectedIndex]
});
}

// Execute change_stylesheet function initially
change_stylesheet({target: select});

if (select) {
select.addEventListener('change', change_stylesheet);
} else {
setTimeout(function() {
M.mod_newsletter.init_editor(stylesheets, selected);
newsletter.mod_newsletter.init_editor(stylesheets, selected);
}, 100);
}
};
2 changes: 1 addition & 1 deletion classes/newsletter.php
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ private function view_edit_issue_page(array $params) {
'filename',
false
);
$options = array();
$options = [];
$options[NEWSLETTER_DEFAULT_STYLESHEET] = "{$CFG->wwwroot}/mod/newsletter/reset.css";
foreach ($files as $file) {
$url = "{$CFG->wwwroot}/pluginfile.php/{$file->get_contextid()}/mod_newsletter/" . NEWSLETTER_FILE_AREA_STYLESHEET;
Expand Down

0 comments on commit 724f43d

Please sign in to comment.