1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-12-26 02:55:02 +00:00

Bugfx: Correct new JS api.

This commit is contained in:
Starbeamrainbowlabs 2016-11-05 14:08:50 +00:00
parent 9d25376d82
commit 0c625cd3da
4 changed files with 57 additions and 47 deletions

View file

@ -1245,7 +1245,7 @@ class page_renderer
$result .= self::getJS();
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))
{
@ -1303,18 +1303,18 @@ class page_renderer
private static $jsLinks = [];
public function AddJSLink(string $scriptUrl)
{
$jsLinks[] = $scriptUrl;
static::$jsLinks[] = $scriptUrl;
}
public function AddJSSnippet(string $script)
{
$jsSnippets[] = $script;
static::$jsSnippets[] = $script;
}
private static function getJS()
{
$result = "";
$result = "<!-- Javascript -->\n";
foreach(static::$jsSnippets as $snippet)
$result .= "<script defer>$snippet</script>\n";
$result .= "<script defer>\n$snippet\n</script>\n";
foreach(static::$jsLinks as $link)
$result .= "<script src='" . $link . "' defer></script>\n";
return $result;
@ -3941,29 +3941,34 @@ register_module([
<p class='editing-message'>$settings->editing_message</p>
<input name='submit-edit' type='submit' value='Save Page' tabindex='3' />
</form>";
page_renderer::AddJSSnippet("// Adapted from https://jsfiddle.net/2wAzx/13/
document.querySelector(\"[name=content]\").addEventListener(\"keydown\", (event) => {
if(event.keyCode !== 9) return true;
var currentValue = event.target.value, startPos = event.target.selectionStart, endPos = event.target.selectionEnd;
event.target.value = currentValue.substring(0, startPos) + \"\\t\" + currentValue.substring(endPos);
event.target.selectionStart = event.target.selectionEnd = startPos + 1;
event.stopPropagation(); event.preventDefault();
return false;
// 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) => {
if(event.keyCode !== 9) return true;
var currentValue = event.target.value, startPos = event.target.selectionStart, endPos = event.target.selectionEnd;
event.target.value = currentValue.substring(0, startPos) + \"\\t\" + currentValue.substring(endPos);
event.target.selectionStart = event.target.selectionEnd = startPos + 1;
event.stopPropagation(); event.preventDefault();
return false;
});
});");
// ~
/// ~~~ Smart saving ~~~ ///
page_renderer::AddJSSnippet('// Smart saving
function getSmartSaveKey() { return document.querySelector("main h1").innerHTML.replace("Creating ", "").replace("Editing ", "").trim(); }
// Saving
document.querySelector("textarea[name=content]").addEventListener("keyup", function(event) { window.localStorage.setItem(getSmartSaveKey(), event.target.value) });
// Loading
window.addEventListener("load", function(event) {
var editor = document.querySelector("textarea[name=content]");
if(editor.value.length > 0) return; // Don\'t restore if there\'s data in the editor already
editor.value = localStorage.getItem(getSmartSaveKey());
page_renderer::AddJSSnippet('document.addEventListener("load", function(event) {
// Smart saving
function getSmartSaveKey() { return document.querySelector("main h1").innerHTML.replace("Creating ", "").replace("Editing ", "").trim(); }
// Saving
document.querySelector("textarea[name=content]").addEventListener("keyup", function(event) { window.localStorage.setItem(getSmartSaveKey(), event.target.value) });
// Loading
window.addEventListener("load", function(event) {
var editor = document.querySelector("textarea[name=content]");
if(editor.value.length > 0) return; // Don\'t restore if there\'s data in the editor already
editor.value = localStorage.getItem(getSmartSaveKey());
});
});');
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><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>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>Shows a gallery containing all the files that are sub pages of the current page.</td></tr>
</table>");

View file

@ -936,7 +936,7 @@ class page_renderer
$result .= self::getJS();
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))
{
@ -994,18 +994,18 @@ class page_renderer
private static $jsLinks = [];
public function AddJSLink(string $scriptUrl)
{
$jsLinks[] = $scriptUrl;
static::$jsLinks[] = $scriptUrl;
}
public function AddJSSnippet(string $script)
{
$jsSnippets[] = $script;
static::$jsSnippets[] = $script;
}
private static function getJS()
{
$result = "";
$result = "<!-- Javascript -->\n";
foreach(static::$jsSnippets as $snippet)
$result .= "<script defer>$snippet</script>\n";
$result .= "<script defer>\n$snippet\n</script>\n";
foreach(static::$jsLinks as $link)
$result .= "<script src='" . $link . "' defer></script>\n";
return $result;

View file

@ -122,7 +122,7 @@
"author": "Starbeamrainbowlabs",
"description": "Allows you to edit pages by adding the edit and save actions. You should probably include this one.",
"id": "page-edit",
"lastupdate": 1477821977,
"lastupdate": 1478354728,
"optional": false
},
{
@ -212,7 +212,7 @@
"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.",
"id": "parser-parsedown",
"lastupdate": 1476906745,
"lastupdate": 1478204933,
"optional": false
}
]

View file

@ -88,29 +88,34 @@ register_module([
<p class='editing-message'>$settings->editing_message</p>
<input name='submit-edit' type='submit' value='Save Page' tabindex='3' />
</form>";
page_renderer::AddJSSnippet("// Adapted from https://jsfiddle.net/2wAzx/13/
document.querySelector(\"[name=content]\").addEventListener(\"keydown\", (event) => {
if(event.keyCode !== 9) return true;
var currentValue = event.target.value, startPos = event.target.selectionStart, endPos = event.target.selectionEnd;
event.target.value = currentValue.substring(0, startPos) + \"\\t\" + currentValue.substring(endPos);
event.target.selectionStart = event.target.selectionEnd = startPos + 1;
event.stopPropagation(); event.preventDefault();
return false;
// 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) => {
if(event.keyCode !== 9) return true;
var currentValue = event.target.value, startPos = event.target.selectionStart, endPos = event.target.selectionEnd;
event.target.value = currentValue.substring(0, startPos) + \"\\t\" + currentValue.substring(endPos);
event.target.selectionStart = event.target.selectionEnd = startPos + 1;
event.stopPropagation(); event.preventDefault();
return false;
});
});");
// ~
/// ~~~ Smart saving ~~~ ///
page_renderer::AddJSSnippet('// Smart saving
function getSmartSaveKey() { return document.querySelector("main h1").innerHTML.replace("Creating ", "").replace("Editing ", "").trim(); }
// Saving
document.querySelector("textarea[name=content]").addEventListener("keyup", function(event) { window.localStorage.setItem(getSmartSaveKey(), event.target.value) });
// Loading
window.addEventListener("load", function(event) {
var editor = document.querySelector("textarea[name=content]");
if(editor.value.length > 0) return; // Don\'t restore if there\'s data in the editor already
editor.value = localStorage.getItem(getSmartSaveKey());
page_renderer::AddJSSnippet('document.addEventListener("load", function(event) {
// Smart saving
function getSmartSaveKey() { return document.querySelector("main h1").innerHTML.replace("Creating ", "").replace("Editing ", "").trim(); }
// Saving
document.querySelector("textarea[name=content]").addEventListener("keyup", function(event) { window.localStorage.setItem(getSmartSaveKey(), event.target.value) });
// Loading
window.addEventListener("load", function(event) {
var editor = document.querySelector("textarea[name=content]");
if(editor.value.length > 0) return; // Don\'t restore if there\'s data in the editor already
editor.value = localStorage.getItem(getSmartSaveKey());
});
});');
exit(page_renderer::render_main("$title - $settings->sitename", $content));