mirror of
https://github.com/sbrl/Pepperminty-Wiki.git
synced 2024-11-25 17:23:00 +00:00
Bugfx: Correct new JS api.
This commit is contained in:
parent
9d25376d82
commit
0c625cd3da
4 changed files with 57 additions and 47 deletions
|
@ -1245,7 +1245,7 @@ class page_renderer
|
||||||
$result .= self::getJS();
|
$result .= self::getJS();
|
||||||
|
|
||||||
if(module_exists("feature-search"))
|
if(module_exists("feature-search"))
|
||||||
$result .= "\t\t<link type='application/opensearchdescription+xml' rel='search' href='?action=opensearch-description' />";
|
$result .= "\t\t<link type='application/opensearchdescription+xml' rel='search' href='?action=opensearch-description' />\n";
|
||||||
|
|
||||||
if(!empty($settings->enable_math_rendering))
|
if(!empty($settings->enable_math_rendering))
|
||||||
{
|
{
|
||||||
|
@ -1303,18 +1303,18 @@ class page_renderer
|
||||||
private static $jsLinks = [];
|
private static $jsLinks = [];
|
||||||
public function AddJSLink(string $scriptUrl)
|
public function AddJSLink(string $scriptUrl)
|
||||||
{
|
{
|
||||||
$jsLinks[] = $scriptUrl;
|
static::$jsLinks[] = $scriptUrl;
|
||||||
}
|
}
|
||||||
public function AddJSSnippet(string $script)
|
public function AddJSSnippet(string $script)
|
||||||
{
|
{
|
||||||
$jsSnippets[] = $script;
|
static::$jsSnippets[] = $script;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function getJS()
|
private static function getJS()
|
||||||
{
|
{
|
||||||
$result = "";
|
$result = "<!-- Javascript -->\n";
|
||||||
foreach(static::$jsSnippets as $snippet)
|
foreach(static::$jsSnippets as $snippet)
|
||||||
$result .= "<script defer>$snippet</script>\n";
|
$result .= "<script defer>\n$snippet\n</script>\n";
|
||||||
foreach(static::$jsLinks as $link)
|
foreach(static::$jsLinks as $link)
|
||||||
$result .= "<script src='" . $link . "' defer></script>\n";
|
$result .= "<script src='" . $link . "' defer></script>\n";
|
||||||
return $result;
|
return $result;
|
||||||
|
@ -3941,7 +3941,9 @@ register_module([
|
||||||
<p class='editing-message'>$settings->editing_message</p>
|
<p class='editing-message'>$settings->editing_message</p>
|
||||||
<input name='submit-edit' type='submit' value='Save Page' tabindex='3' />
|
<input name='submit-edit' type='submit' value='Save Page' tabindex='3' />
|
||||||
</form>";
|
</form>";
|
||||||
page_renderer::AddJSSnippet("// Adapted from https://jsfiddle.net/2wAzx/13/
|
// Allow tab characters in the page editor
|
||||||
|
page_renderer::AddJSSnippet("window.addEventListener('load', function(event) {
|
||||||
|
// Adapted from https://jsfiddle.net/2wAzx/13/
|
||||||
document.querySelector(\"[name=content]\").addEventListener(\"keydown\", (event) => {
|
document.querySelector(\"[name=content]\").addEventListener(\"keydown\", (event) => {
|
||||||
if(event.keyCode !== 9) return true;
|
if(event.keyCode !== 9) return true;
|
||||||
var currentValue = event.target.value, startPos = event.target.selectionStart, endPos = event.target.selectionEnd;
|
var currentValue = event.target.value, startPos = event.target.selectionStart, endPos = event.target.selectionEnd;
|
||||||
|
@ -3949,13 +3951,15 @@ document.querySelector(\"[name=content]\").addEventListener(\"keydown\", (event)
|
||||||
event.target.selectionStart = event.target.selectionEnd = startPos + 1;
|
event.target.selectionStart = event.target.selectionEnd = startPos + 1;
|
||||||
event.stopPropagation(); event.preventDefault();
|
event.stopPropagation(); event.preventDefault();
|
||||||
return false;
|
return false;
|
||||||
|
});
|
||||||
});");
|
});");
|
||||||
|
|
||||||
// ~
|
// ~
|
||||||
|
|
||||||
/// ~~~ Smart saving ~~~ ///
|
/// ~~~ Smart saving ~~~ ///
|
||||||
|
|
||||||
page_renderer::AddJSSnippet('// Smart saving
|
page_renderer::AddJSSnippet('document.addEventListener("load", function(event) {
|
||||||
|
// Smart saving
|
||||||
function getSmartSaveKey() { return document.querySelector("main h1").innerHTML.replace("Creating ", "").replace("Editing ", "").trim(); }
|
function getSmartSaveKey() { return document.querySelector("main h1").innerHTML.replace("Creating ", "").replace("Editing ", "").trim(); }
|
||||||
// Saving
|
// Saving
|
||||||
document.querySelector("textarea[name=content]").addEventListener("keyup", function(event) { window.localStorage.setItem(getSmartSaveKey(), event.target.value) });
|
document.querySelector("textarea[name=content]").addEventListener("keyup", function(event) { window.localStorage.setItem(getSmartSaveKey(), event.target.value) });
|
||||||
|
@ -3964,6 +3968,7 @@ window.addEventListener("load", function(event) {
|
||||||
var editor = document.querySelector("textarea[name=content]");
|
var editor = document.querySelector("textarea[name=content]");
|
||||||
if(editor.value.length > 0) return; // Don\'t restore if there\'s data in the editor already
|
if(editor.value.length > 0) return; // Don\'t restore if there\'s data in the editor already
|
||||||
editor.value = localStorage.getItem(getSmartSaveKey());
|
editor.value = localStorage.getItem(getSmartSaveKey());
|
||||||
|
});
|
||||||
});');
|
});');
|
||||||
|
|
||||||
exit(page_renderer::render_main("$title - $settings->sitename", $content));
|
exit(page_renderer::render_main("$title - $settings->sitename", $content));
|
||||||
|
@ -5174,7 +5179,7 @@ register_module([
|
||||||
<tr><th>Type this</th><th>To get this</th></tr>
|
<tr><th>Type this</th><th>To get this</th></tr>
|
||||||
<tr><td><code>{{{@}}}</code></td><td>Lists all variables and their values in a table.</td></tr>
|
<tr><td><code>{{{@}}}</code></td><td>Lists all variables and their values in a table.</td></tr>
|
||||||
<tr><td><code>{{{#}}}</code></td><td>Shows a 'stack trace', outlining all the parent includes of the current page being parsed.</td></tr>
|
<tr><td><code>{{{#}}}</code></td><td>Shows a 'stack trace', outlining all the parent includes of the current page being parsed.</td></tr>
|
||||||
<tr><td><code>{{{~}}}</code></td><td>Outputs the requested pagee's name.</td></tr>
|
<tr><td><code>{{{~}}}</code></td><td>Outputs the requested page's name.</td></tr>
|
||||||
<tr><td><code>{{{*}}}</code></td><td>Outputs a comma separated list of all the subpages of the current page.</td></tr>
|
<tr><td><code>{{{*}}}</code></td><td>Outputs a comma separated list of all the subpages of the current page.</td></tr>
|
||||||
<tr><td><code>{{{+}}}</code></td><td>Shows a gallery containing all the files that are sub pages of the current page.</td></tr>
|
<tr><td><code>{{{+}}}</code></td><td>Shows a gallery containing all the files that are sub pages of the current page.</td></tr>
|
||||||
</table>");
|
</table>");
|
||||||
|
|
10
core.php
10
core.php
|
@ -936,7 +936,7 @@ class page_renderer
|
||||||
$result .= self::getJS();
|
$result .= self::getJS();
|
||||||
|
|
||||||
if(module_exists("feature-search"))
|
if(module_exists("feature-search"))
|
||||||
$result .= "\t\t<link type='application/opensearchdescription+xml' rel='search' href='?action=opensearch-description' />";
|
$result .= "\t\t<link type='application/opensearchdescription+xml' rel='search' href='?action=opensearch-description' />\n";
|
||||||
|
|
||||||
if(!empty($settings->enable_math_rendering))
|
if(!empty($settings->enable_math_rendering))
|
||||||
{
|
{
|
||||||
|
@ -994,18 +994,18 @@ class page_renderer
|
||||||
private static $jsLinks = [];
|
private static $jsLinks = [];
|
||||||
public function AddJSLink(string $scriptUrl)
|
public function AddJSLink(string $scriptUrl)
|
||||||
{
|
{
|
||||||
$jsLinks[] = $scriptUrl;
|
static::$jsLinks[] = $scriptUrl;
|
||||||
}
|
}
|
||||||
public function AddJSSnippet(string $script)
|
public function AddJSSnippet(string $script)
|
||||||
{
|
{
|
||||||
$jsSnippets[] = $script;
|
static::$jsSnippets[] = $script;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function getJS()
|
private static function getJS()
|
||||||
{
|
{
|
||||||
$result = "";
|
$result = "<!-- Javascript -->\n";
|
||||||
foreach(static::$jsSnippets as $snippet)
|
foreach(static::$jsSnippets as $snippet)
|
||||||
$result .= "<script defer>$snippet</script>\n";
|
$result .= "<script defer>\n$snippet\n</script>\n";
|
||||||
foreach(static::$jsLinks as $link)
|
foreach(static::$jsLinks as $link)
|
||||||
$result .= "<script src='" . $link . "' defer></script>\n";
|
$result .= "<script src='" . $link . "' defer></script>\n";
|
||||||
return $result;
|
return $result;
|
||||||
|
|
|
@ -122,7 +122,7 @@
|
||||||
"author": "Starbeamrainbowlabs",
|
"author": "Starbeamrainbowlabs",
|
||||||
"description": "Allows you to edit pages by adding the edit and save actions. You should probably include this one.",
|
"description": "Allows you to edit pages by adding the edit and save actions. You should probably include this one.",
|
||||||
"id": "page-edit",
|
"id": "page-edit",
|
||||||
"lastupdate": 1477821977,
|
"lastupdate": 1478354728,
|
||||||
"optional": false
|
"optional": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -212,7 +212,7 @@
|
||||||
"author": "Emanuil Rusev & Starbeamrainbowlabs",
|
"author": "Emanuil Rusev & Starbeamrainbowlabs",
|
||||||
"description": "An upgraded (now default!) parser based on Emanuil Rusev's Parsedown Extra PHP library (https:\/\/github.com\/erusev\/parsedown-extra), which is licensed MIT. Please be careful, as this module adds some weight to your installation, and also *requires* write access to the disk on first load.",
|
"description": "An upgraded (now default!) parser based on Emanuil Rusev's Parsedown Extra PHP library (https:\/\/github.com\/erusev\/parsedown-extra), which is licensed MIT. Please be careful, as this module adds some weight to your installation, and also *requires* write access to the disk on first load.",
|
||||||
"id": "parser-parsedown",
|
"id": "parser-parsedown",
|
||||||
"lastupdate": 1476906745,
|
"lastupdate": 1478204933,
|
||||||
"optional": false
|
"optional": false
|
||||||
}
|
}
|
||||||
]
|
]
|
|
@ -88,7 +88,9 @@ register_module([
|
||||||
<p class='editing-message'>$settings->editing_message</p>
|
<p class='editing-message'>$settings->editing_message</p>
|
||||||
<input name='submit-edit' type='submit' value='Save Page' tabindex='3' />
|
<input name='submit-edit' type='submit' value='Save Page' tabindex='3' />
|
||||||
</form>";
|
</form>";
|
||||||
page_renderer::AddJSSnippet("// Adapted from https://jsfiddle.net/2wAzx/13/
|
// Allow tab characters in the page editor
|
||||||
|
page_renderer::AddJSSnippet("window.addEventListener('load', function(event) {
|
||||||
|
// Adapted from https://jsfiddle.net/2wAzx/13/
|
||||||
document.querySelector(\"[name=content]\").addEventListener(\"keydown\", (event) => {
|
document.querySelector(\"[name=content]\").addEventListener(\"keydown\", (event) => {
|
||||||
if(event.keyCode !== 9) return true;
|
if(event.keyCode !== 9) return true;
|
||||||
var currentValue = event.target.value, startPos = event.target.selectionStart, endPos = event.target.selectionEnd;
|
var currentValue = event.target.value, startPos = event.target.selectionStart, endPos = event.target.selectionEnd;
|
||||||
|
@ -96,13 +98,15 @@ document.querySelector(\"[name=content]\").addEventListener(\"keydown\", (event)
|
||||||
event.target.selectionStart = event.target.selectionEnd = startPos + 1;
|
event.target.selectionStart = event.target.selectionEnd = startPos + 1;
|
||||||
event.stopPropagation(); event.preventDefault();
|
event.stopPropagation(); event.preventDefault();
|
||||||
return false;
|
return false;
|
||||||
|
});
|
||||||
});");
|
});");
|
||||||
|
|
||||||
// ~
|
// ~
|
||||||
|
|
||||||
/// ~~~ Smart saving ~~~ ///
|
/// ~~~ Smart saving ~~~ ///
|
||||||
|
|
||||||
page_renderer::AddJSSnippet('// Smart saving
|
page_renderer::AddJSSnippet('document.addEventListener("load", function(event) {
|
||||||
|
// Smart saving
|
||||||
function getSmartSaveKey() { return document.querySelector("main h1").innerHTML.replace("Creating ", "").replace("Editing ", "").trim(); }
|
function getSmartSaveKey() { return document.querySelector("main h1").innerHTML.replace("Creating ", "").replace("Editing ", "").trim(); }
|
||||||
// Saving
|
// Saving
|
||||||
document.querySelector("textarea[name=content]").addEventListener("keyup", function(event) { window.localStorage.setItem(getSmartSaveKey(), event.target.value) });
|
document.querySelector("textarea[name=content]").addEventListener("keyup", function(event) { window.localStorage.setItem(getSmartSaveKey(), event.target.value) });
|
||||||
|
@ -111,6 +115,7 @@ window.addEventListener("load", function(event) {
|
||||||
var editor = document.querySelector("textarea[name=content]");
|
var editor = document.querySelector("textarea[name=content]");
|
||||||
if(editor.value.length > 0) return; // Don\'t restore if there\'s data in the editor already
|
if(editor.value.length > 0) return; // Don\'t restore if there\'s data in the editor already
|
||||||
editor.value = localStorage.getItem(getSmartSaveKey());
|
editor.value = localStorage.getItem(getSmartSaveKey());
|
||||||
|
});
|
||||||
});');
|
});');
|
||||||
|
|
||||||
exit(page_renderer::render_main("$title - $settings->sitename", $content));
|
exit(page_renderer::render_main("$title - $settings->sitename", $content));
|
||||||
|
|
Loading…
Reference in a new issue