devel:javascript
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
devel:javascript [2014-01-03 19:14] – [Use unobtrusive JavaScript] 188.23.147.57 | devel:javascript [2024-04-10 15:21] (current) – [Inline scripts] andi | ||
---|---|---|---|
Line 5: | Line 5: | ||
This page gives you an overview how JavaScript is loaded from DokuWiki core, [[: | This page gives you an overview how JavaScript is loaded from DokuWiki core, [[: | ||
- | ===== JavaScript | + | ===== JavaScript |
- | All JavaScript is collected and delivered | + | All JavaScript |
- | [[config: | + | |
DokuWiki will load JavaScript from the following places: | DokuWiki will load JavaScript from the following places: | ||
Line 18: | Line 17: | ||
* conf/ | * conf/ | ||
- | As you can see you can provide JavaScript with your [[: | + | As you can see you can provide JavaScript with your [[: |
+ | |||
+ | ==== Deferred Loading ==== | ||
+ | |||
+ | All JavaScript is loaded with the [[https:// | ||
+ | |||
+ | If you load JavaScript through other means than the recommended methods below and that JavaScript has dependencies on any DokuWiki provided code, you need to ensure it is deferred as well. This also means that you cannot use '' | ||
+ | |||
+ | From the 2020 Hogfather version onwards, all javascript must be load in a deferred way. To update your existing templates javascript to work in this version, you can add the '' | ||
+ | |||
+ | Temporary, the feature flag [[config: | ||
==== Include Syntax ==== | ==== Include Syntax ==== | ||
Line 26: | Line 35: | ||
:!: Included files are not checked for updates by the cache logic. You need to touch the master file for updating the cache. | :!: Included files are not checked for updates by the cache logic. You need to touch the master file for updating the cache. | ||
- | :!: Includes are *not* supported inside included files to avoid any circular references. | + | :!: Includes are **not** supported inside included files to avoid any circular references. |
:!: Includepath may only consist of letter, | :!: Includepath may only consist of letter, | ||
Line 99: | Line 108: | ||
==== Inline scripts ==== | ==== Inline scripts ==== | ||
- | As said before you should avoid mixing JavaScript and XHTML. However if you need to use inline JavaScript, you should | + | As said before you should avoid mixing JavaScript and HTML. However if you need to use inline JavaScript, you should |
- | < | + | < |
- | <script | + | tpl_inlineScript(' |
- | ... | + | alert(" |
- | / | + | '); |
</ | </ | ||
+ | |||
+ | Using this method will create the appropriate script tag including a nonce attribute if needed. | ||
If you need to add inline JavaScript to the < | If you need to add inline JavaScript to the < | ||
Line 147: | Line 158: | ||
DokuWiki passes the global [[devel: | DokuWiki passes the global [[devel: | ||
* '' | * '' | ||
- | * '' | + | * '' |
+ | And after 2018-04-05: | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
Other keys can easily be added from within PHP code. The usual way is using an [[action plugin]] like this: | Other keys can easily be added from within PHP code. The usual way is using an [[action plugin]] like this: | ||
<code php> | <code php> | ||
- | function register(Doku_Event_Handler | + | public |
- | $controller-> | + | $controller-> |
} | } | ||
- | function | + | public |
- | global $JSINFO; | + | global $JSINFO, $INPUT; |
- | $JSINFO[' | + | $JSINFO[' |
} | } | ||
</ | </ | ||
+ | |||
+ | If you want to make sure that your plugin' | ||
The contents of the '' | The contents of the '' | ||
+ | |||
+ | If you need JSINFO in the [[: | ||
+ | |||
+ | Also see: Javascript in [[https:// |
devel/javascript.1388772883.txt.gz · Last modified: 2014-01-03 19:14 by 188.23.147.57