diff --git a/amd/build/synhi.min.js b/amd/build/synhi.min.js index b6ead1f..5cb978c 100644 --- a/amd/build/synhi.min.js +++ b/amd/build/synhi.min.js @@ -1,4 +1,4 @@ -define("filter_synhi/synhi",["exports","core/log"],(function(_exports,_log){var obj; +define("filter_synhi/synhi",["exports","jquery","core/log"],(function(_exports,_jquery,_log){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}} /** * SynHi filter. * @@ -6,6 +6,6 @@ define("filter_synhi/synhi",["exports","core/log"],(function(_exports,_log){var * @copyright © 2020-onwards G J Barnard. * @author G J Barnard - {@link http://moodle.org/user/profile.php?id=442195} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later. - */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_log=(obj=_log)&&obj.__esModule?obj:{default:obj};var done=!1;_exports.init=data=>{if(_log.default.debug("SynHi ES6 init"),!done){var body=document.getElementsByTagName("body")[0];body.innerHTML+='';\n if (data.theinit) {\n body.innerHTML += '';\n }\n var head = document.getElementsByTagName('head')[0];\n head.innerHTML += '';\n\n done = true;\n }\n};\n"],"names":["done","data","debug","body","document","getElementsByTagName","innerHTML","thejs","theinit","thecss"],"mappings":";;;;;;;;wIA0BIA,MAAO,gBAOUC,uBACbC,MAAM,mBACLF,KAAM,KACHG,KAAOC,SAASC,qBAAqB,QAAQ,GACjDF,KAAKG,WAAa,uDAAyDL,KAAKM,MAAQ,eACpFN,KAAKO,UACLL,KAAKG,WAAa,kDAAoDL,KAAKO,QAAU,cAE9EJ,SAASC,qBAAqB,QAAQ,GAC5CC,WAAa,gDAAkDL,KAAKQ,OAAS,KAElFT,MAAO"} \ No newline at end of file +{"version":3,"file":"synhi.min.js","sources":["../src/synhi.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * SynHi filter.\n *\n * @module filter_synhi/synhi\n * @copyright © 2020-onwards G J Barnard.\n * @author G J Barnard - {@link http://moodle.org/user/profile.php?id=442195}\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.\n */\n\nimport $ from 'jquery';\nimport log from 'core/log';\n\nvar done = false;\n\n/**\n * Init.\n *\n * @param {array} data The urls to use.\n */\nexport const init = (data) => {\n log.debug('SynHi ES6 init');\n if (!done) {\n var $body = $('body');\n $body.append('');\n if (data.theinit) {\n $body.append('');\n }\n $('head').append('');\n\n done = true;\n }\n};\n"],"names":["done","data","debug","$body","append","thejs","theinit","thecss"],"mappings":";;;;;;;;gKA2BIA,MAAO,gBAOUC,uBACbC,MAAM,mBACLF,KAAM,KACHG,OAAQ,mBAAE,QACdA,MAAMC,OAAO,uDAAyDH,KAAKI,MAAQ,gBAC/EJ,KAAKK,SACLH,MAAMC,OAAO,kDAAoDH,KAAKK,QAAU,kCAElF,QAAQF,OAAO,gDAAkDH,KAAKM,OAAS,MAEjFP,MAAO"} \ No newline at end of file diff --git a/amd/src/synhi_cannot_make_work.js b/amd/src/synhi_cannot_make_work.js new file mode 100644 index 0000000..ee061ac --- /dev/null +++ b/amd/src/synhi_cannot_make_work.js @@ -0,0 +1,73 @@ +// This file is part of Moodle - http://moodle.org/ +// +// Moodle is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Moodle is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see . + +/** + * SynHi filter. + * + * @module filter_synhi/synhi + * @copyright © 2020-onwards G J Barnard. + * @author G J Barnard - {@link http://moodle.org/user/profile.php?id=442195} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later. + */ + +//import $ from 'jquery'; +import log from 'core/log'; + +var done = false; + +/** + * Init. + * + * @param {array} data The urls to use. + */ +export const init = (data) => { + log.debug('SynHi ES6 init'); + if (!done) { + const body = document.getElementsByTagName('body').item(0); + let thejs = document.createElement("script"); + thejs.src = data.thejs; + thejs.type = 'text/javascript'; + thejs.charset = 'utf-8'; + thejs.defer = false; + body.appendChild(thejs); + //$body.append(''); + if (data.theinit) { + let theinit = document.createElement("script"); + theinit.text = data.theinit; + theinit.type = 'text/javascript'; + theinit.charset = 'utf-8'; + theinit.defer = true; + if (document.readyState !== 'loading') { + log.debug("SynHi ES6 init DOM content already loaded"); + body.appendChild(theinit); + } else { + log.debug("SynHi ES6 init JS DOM content not loaded"); + document.addEventListener('DOMContentLoaded', function () { + log.debug("SynHi ES6 init JS DOM content loaded"); + body.appendChild(theinit); // E.g. Enlighter not found, so code runs before JS file is known about. + }); + } + //$body.append(''); + } + let thecss = document.createElement("link"); + thecss.href = data.thecss; + thecss.type = 'text/css'; + thecss.rel = 'stylesheet'; + document.getElementsByTagName('head').item(0).appendChild(thecss); + //$('head').append(''); + + done = true; + } +};