Skip to content
Snippets Groups Projects
Commit 9bdb12f5 authored by Chris Sangwin's avatar Chris Sangwin
Browse files

Code tidy.

parent 3a58b1cd
No related branches found
No related tags found
No related merge requests found
......@@ -13,12 +13,10 @@
//
// You should have received a copy of the GNU General Public License
// along with Stack. If not, see <http://www.gnu.org/licenses/>.
defined('MOODLE_INTERNAL') || die();
/**
* This is a dirty hack trying to remove the need to configure webservers
* to set the correct CORS headers for the few scripts in this directory
* that need them.
*/
// This is a dirty hack trying to remove the need to configure webservers
// to set the correct CORS headers for the few scripts in this directory that need them.
$scriptname = urldecode($_GET['name']);
......
......@@ -20,7 +20,6 @@ require_once(__DIR__ . '/../block.factory.php');
require_once(__DIR__ . '/../../../../vle_specific.php');
/**
* Simple block for dealing with CORS content urls.
*/
......@@ -28,7 +27,6 @@ class stack_cas_castext2_cors extends stack_cas_castext2_block {
public function compile($format, $options): ? MP_Node {
$r = new MP_String(stack_cors_link($this->params['src']));
return $r;
}
......@@ -36,7 +34,6 @@ class stack_cas_castext2_cors extends stack_cas_castext2_block {
return true;
}
public function validate_extract_attributes(): array {
return [];
}
......
......@@ -35,7 +35,6 @@ class stack_cas_castext2_iframe extends stack_cas_castext2_block {
// we use running numbering.
private static $countframes = 1;
public function compile($format, $options): ?MP_Node {
$r = new MP_List([
new MP_String('iframe'),
......@@ -51,8 +50,7 @@ class stack_cas_castext2_iframe extends stack_cas_castext2_block {
}
$opt2['in iframe'] = true;
// Note that [[style]], [[body]], [[script]] blocks will be
// separated during post-processing.
// Note that [[style]], [[body]], [[script]] blocks will be separated during post-processing.
foreach ($this->children as $child) {
$c = $child->compile(castext2_parser_utils::RAWFORMAT, $opt2);
if ($c !== null) {
......@@ -102,7 +100,6 @@ class stack_cas_castext2_iframe extends stack_cas_castext2_block {
}
}
$width = '500px';
$height = '400px';
$aspectratio = false;
......@@ -132,10 +129,8 @@ class stack_cas_castext2_iframe extends stack_cas_castext2_block {
$attributes = ['style' => $astyle, 'id' => $divid];
if ($content === '') {
// For now we ensure that the created document will always
// have some content.
// For now we ensure that the created document will always have some content.
$content = '&nbsp;';
}
......@@ -176,12 +171,10 @@ class stack_cas_castext2_iframe extends stack_cas_castext2_block {
self::$countframes = self::$countframes + 1;
// Output the placeholder for this frame.
return html_writer::tag('div', '', $attributes);
}
public function validate(&$errors=[], $options=[]): bool {
// Basically, check that the dimensions have units we know.
// Also that the references make sense.
......
......@@ -56,8 +56,7 @@ class stack_cas_castext2_jsxgraph extends stack_cas_castext2_block {
$inputs[$inputname] = $value;
}
}
// These are some of the othe parameters we do not need to
// push forward.
// These are some of the othe parameters we do not need to push forward.
if (isset($xpars['version'])) {
unset($xpars['version']);
}
......@@ -138,7 +137,8 @@ class stack_cas_castext2_jsxgraph extends stack_cas_castext2_block {
// Add the div to the doc.
// Note that we have two divs, the exterior one defines the size
// and the interior one contains the graph.
$r->items[] = new MP_String('<div style="' . $astyle . '"><div class="jxgbox" id="jxgbox" style="width:100%;height:100%;"></div></div><script type="module">');
$r->items[] = new MP_String('<div style="' . $astyle .
'"><div class="jxgbox" id="jxgbox" style="width:100%;height:100%;"></div></div><script type="module">');
// For binding we need to import the binding libraries.
$r->items[] = new MP_String("\nimport {stack_js} from '" . stack_cors_link('stackjsiframe.min.js') . "';\n");
......@@ -159,7 +159,6 @@ class stack_cas_castext2_jsxgraph extends stack_cas_castext2_block {
$r->items[] = new MP_String($linkcode);
}
// Plug in the div id = board id thing.
$r->items[] = new MP_String('var divid = "jxgbox";var BOARDID = divid;');
......@@ -194,7 +193,6 @@ class stack_cas_castext2_jsxgraph extends stack_cas_castext2_block {
return false;
}
public function postprocess(array $params, castext2_processor $processor): string {
return 'This is never happening! The logic goes to [[iframe]].';
}
......@@ -288,7 +286,8 @@ class stack_cas_castext2_jsxgraph extends stack_cas_castext2_block {
$err[] = stack_string('stackBlock_jsxgraph_input_missing',
['var' => $varname]);
}
} else if ($key !== 'width' && $key !== 'height' && $key !== 'aspect-ratio' && $key !== 'version' && $key !== 'overridejs' && $key !== 'overridecss') {
} else if ($key !== 'width' && $key !== 'height' && $key !== 'aspect-ratio' &&
$key !== 'version' && $key !== 'overridejs' && $key !== 'overridecss') {
$err[] = "Unknown parameter '$key' for jsxgraph-block.";
$valid = false;
if ($valids === null) {
......
......@@ -30,14 +30,15 @@ class stack_cas_castext2_reveal extends stack_cas_castext2_block {
private static $countreveals = 1;
public function compile($format, $options): ?MP_Node {
// This block compiles into multiple things.
// 1. There is the default hidden div containing the contents.
// 2. There is the [[iframe]] that binds to the input and
// triggers visibility toggling.
// Basically we change the value of $format for this subtree.
// Note that the jsxgraph block does this automatically.
/*
* This block compiles into multiple things.
* 1. There is the default hidden div containing the contents.
* 2. There is the [[iframe]] that binds to the input and
* triggers visibility toggling.
*
* Basically we change the value of $format for this subtree.
* Note that the jsxgraph block does this automatically.
*/
$body = new MP_List([new MP_String('%root')]);
// Name and hide the contents.
......@@ -57,18 +58,20 @@ class stack_cas_castext2_reveal extends stack_cas_castext2_block {
// Once we get the access immediately bind a listener to it.
$code .= 'const input = document.getElementById(id);';
$code .= 'input.addEventListener("change",(e)=>{';
$code .= 'stack_js.toggle_visibility("stack-reveal-' . self::$countreveals . '",input.value===' . json_encode($this->params['value']) . ');});';
$code .= 'stack_js.toggle_visibility("stack-reveal-' . self::$countreveals . '",input.value===' .
json_encode($this->params['value']) . ');});';
// Finally check whether the value was already matching, or
// if it changed during the previous steps.
$code .= 'stack_js.toggle_visibility("stack-reveal-' . self::$countreveals . '",input.value===' . json_encode($this->params['value']) . ');';
$code .= 'stack_js.toggle_visibility("stack-reveal-' . self::$countreveals . '",input.value===' .
json_encode($this->params['value']) . ');';
$code .= '});';
// Now add a hidden [[iframe]] with suitable scripts.
$body->items[] = new MP_List([
new MP_String('iframe'),
new MP_String(json_encode(['hidden' => true, 'title' => 'Logic container for a revealing portion ' . self::$countreveals . '.'])),
new MP_String(json_encode(['hidden' => true, 'title' => 'Logic container for a revealing portion ' .
self::$countreveals . '.'])),
new MP_List([
new MP_String('script'),
new MP_String(json_encode(['type' => 'module'])),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment