forked from dregad/dokuwiki-plugin-addnewpage
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* @input@ placeholder can be used to reference the given input (useful to create a new namespace) makes dregad#70 obsolete * new ? syntax to overwrite config options from the syntax (defaults still come from the config setting) * support for strftime placeholders in the namespace config. Allows to create a daily page for example * New option autopage which hides the input field. Together with the new date placeholder this allows to create a daily page on a single button click
- Loading branch information
1 parent
fec857f
commit b8304a8
Showing
5 changed files
with
145 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,33 @@ | ||
jQuery(document).ready(function() { | ||
jQuery(document).ready(function () { | ||
var $form = jQuery(".addnewpage form"); | ||
if (!$form.length) return; | ||
|
||
// Start with disabled submit button | ||
jQuery(".addnewpage :submit").prop("disabled", true); | ||
// Then enable it when a title is entered | ||
jQuery(".addnewpage input[name='title']").keyup(function(){ | ||
var $submit = jQuery(this).parent("form").find(":submit"); | ||
if (jQuery(this).val().length > 0) { | ||
$submit.removeAttr("disabled"); | ||
} else { | ||
// For when the user deletes the text | ||
$submit.attr("disabled", "disabled"); | ||
} | ||
}).keyup(); | ||
var $ns = $form.find("[name='np_cat']"); | ||
var $title = $form.find("input[name='title']"); | ||
var $id = $form.find("input[name='id']"); | ||
var $submit = $form.find(':submit'); | ||
|
||
// Change the form's page-ID field on submit | ||
jQuery(".addnewpage form").submit(function(e) { | ||
// disable submit unless something is in input or input is disabled | ||
if ($title.attr('type') === 'text') { | ||
$submit.attr('disabled', 'disabled'); | ||
$title.keyup(function () { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
micgro42
|
||
if ($title.val().length > 0) { | ||
$submit.removeAttr('disabled'); | ||
} else { | ||
$submit.attr('disabled', 'disabled'); | ||
} | ||
}); | ||
} | ||
|
||
// Change the form's page-ID field on submit | ||
$form.submit(function () { | ||
// Build the new page ID and save in hidden form field | ||
var ns = jQuery(this).find("[name='np_cat']"); | ||
var title = jQuery(this).find("input[name='title']"); | ||
var id = ns.val()+":"+title.val(); | ||
jQuery(this).find("input[name='id']").val(id); | ||
var id = $ns.val().replace('@INPUT@', $title.val()); | ||
$id.val(id); | ||
|
||
// Clean up the form vars, just to make the resultant URL a bit nicer | ||
ns.prop("disabled", true); | ||
title.prop("disabled", true); | ||
$ns.prop("disabled", true); | ||
$title.prop("disabled", true); | ||
|
||
return true; | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -12,6 +12,9 @@ | |||
*/ | ||||
class syntax_plugin_addnewpage extends DokuWiki_Syntax_Plugin { | ||||
|
||||
/** @var array the parsed options */ | ||||
protected $options; | ||||
|
||||
/** | ||||
* Syntax Type | ||||
*/ | ||||
|
@@ -50,25 +53,44 @@ public function connectTo($mode) { | |||
* {{NEWPAGE#newtpl1|Title1,newtpl2|Title1}} | ||||
* {{NEWPAGE>your:namespace#newtpl1|Title1,newtpl2|Title1}} | ||||
* | ||||
* @param string $match The text matched by the patterns | ||||
* @param int $state The lexer state for the match | ||||
* @param int $pos The character position of the matched text | ||||
* @param string $match The text matched by the patterns | ||||
* @param int $state The lexer state for the match | ||||
* @param int $pos The character position of the matched text | ||||
* @param Doku_Handler $handler The Doku_Handler object | ||||
* @return array Return an array with all data you want to use in render | ||||
* @codingStandardsIgnoreStart | ||||
*/ | ||||
public function handle($match, $state, $pos, Doku_Handler $handler) { | ||||
/* @codingStandardsIgnoreEnd */ | ||||
$options = substr($match, 9, -2); // strip markup | ||||
$options = explode('#', $options, 2); | ||||
|
||||
$namespace = trim(ltrim($options[0], '>')); | ||||
$templates = explode(',', $options[1]); | ||||
$templates = array_map('trim', $templates); | ||||
return array( | ||||
'namespace' => $namespace, | ||||
'newpagetemplates' => $templates | ||||
$match = substr($match, 9, -2); // strip markup | ||||
|
||||
$data = array( | ||||
'namespace' => '', | ||||
'newpagetemplates' => array(), | ||||
'options' => array( | ||||
'exclude' => $this->getConf('addpage_exclude'), | ||||
'showroot' => $this->getConf('addpage_showroot'), | ||||
'hide' => $this->getConf('addpage_hide'), | ||||
'hideacl' => $this->getConf('addpage_hideACL'), | ||||
'autopage' => $this->getConf('addpage_autopage'), | ||||
) | ||||
); | ||||
|
||||
if(preg_match('/>(.*?)(#|\?|$)/', $match, $m)) { | ||||
$data['namespace'] = trim($m[1]); | ||||
} | ||||
|
||||
if(preg_match('/#(.*?)(\?|$)/', $match, $m)) { | ||||
$data['newpagetemplates'] = array_map('trim', explode(',', $m[1])); | ||||
} | ||||
|
||||
if(preg_match('/\?(.*?)(#|$)/', $match, $m)) { | ||||
$this->_parseOptions($m[1], $data['options']); | ||||
// make options available in class | ||||
$this->options = $data['options']; | ||||
This comment has been minimized.
Sorry, something went wrong.
micgro42
|
$this->options = $data['options']; |
Consider using
$title.on('input', function () {});
since this event catches also cut and paste actions. Browser-support is pretty complete: https://caniuse.com/#feat=input-event