Merge pull request #2190 from splitbrain/betterJSINFO
feat: canonically provide $ACT to javascript
This commit is contained in:
commit
d9e82b09c1
4 changed files with 21 additions and 9 deletions
4
doku.php
4
doku.php
|
@ -90,10 +90,6 @@ if($DATE_AT) {
|
|||
//make infos about the selected page available
|
||||
$INFO = pageinfo();
|
||||
|
||||
//export minimal info to JS, plugins can add more
|
||||
$JSINFO['id'] = $ID;
|
||||
$JSINFO['namespace'] = (string) $INFO['namespace'];
|
||||
|
||||
// handle debugging
|
||||
if($conf['allowdebug'] && $ACT == 'debug') {
|
||||
html_debug();
|
||||
|
|
|
@ -300,6 +300,23 @@ function pageinfo() {
|
|||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize and/or fill global $JSINFO with some basic info to be given to javascript
|
||||
*/
|
||||
function jsinfo() {
|
||||
global $JSINFO, $ID, $INFO, $ACT;
|
||||
|
||||
if (!is_array($JSINFO)) {
|
||||
$JSINFO = [];
|
||||
}
|
||||
//export minimal info to JS, plugins can add more
|
||||
$JSINFO['id'] = $ID;
|
||||
$JSINFO['namespace'] = (string) $INFO['namespace'];
|
||||
$JSINFO['ACT'] = act_clean($ACT);
|
||||
$JSINFO['useHeadingNavigation'] = (int) useHeading('navigation');
|
||||
$JSINFO['useHeadingContent'] = (int) useHeading('content');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return information about the current media item as an associative array.
|
||||
*
|
||||
|
|
|
@ -335,13 +335,12 @@ function tpl_metaheaders($alt = true) {
|
|||
'href'=> DOKU_BASE.'lib/exe/css.php?t='.rawurlencode($conf['template']).'&tseed='.$tseed
|
||||
);
|
||||
|
||||
// make $INFO and other vars available to JavaScripts
|
||||
$json = new JSON();
|
||||
$script = "var NS='".$INFO['namespace']."';";
|
||||
if($conf['useacl'] && $INPUT->server->str('REMOTE_USER')) {
|
||||
$script .= "var SIG='".toolbar_signature()."';";
|
||||
}
|
||||
$script .= 'var JSINFO = '.$json->encode($JSINFO).';';
|
||||
jsinfo();
|
||||
$script .= 'var JSINFO = ' . json_encode($JSINFO).';';
|
||||
$head['script'][] = array('type'=> 'text/javascript', '_data'=> $script);
|
||||
|
||||
// load jquery
|
||||
|
|
|
@ -100,8 +100,8 @@ function js_out(){
|
|||
'secure' => $conf['securecookie'] && is_ssl()
|
||||
)).";";
|
||||
// FIXME: Move those to JSINFO
|
||||
print "var DOKU_UHN = ".((int) useHeading('navigation')).";";
|
||||
print "var DOKU_UHC = ".((int) useHeading('content')).";";
|
||||
print "Object.defineProperty(window, 'DOKU_UHN', { get: function() { console.warn('Using DOKU_UHN is deprecated. Please use JSINFO.useHeadingNavigation instead'); return JSINFO.useHeadingNavigation; } });";
|
||||
print "Object.defineProperty(window, 'DOKU_UHC', { get: function() { console.warn('Using DOKU_UHC is deprecated. Please use JSINFO.useHeadingContent instead'); return JSINFO.useHeadingContent; } });";
|
||||
|
||||
// load JS specific translations
|
||||
$lang['js']['plugins'] = js_pluginstrings();
|
||||
|
|
Loading…
Reference in a new issue