Remove addon_hooks template variable
- Update addon documentation
This commit is contained in:
parent
adbc1d3224
commit
be348cf8c8
3 changed files with 43 additions and 44 deletions
|
@ -67,47 +67,61 @@ $b can be called anything you like.
|
||||||
This is information specific to the hook currently being processed, and generally contains information that is being immediately processed or acted on that you can use, display, or alter.
|
This is information specific to the hook currently being processed, and generally contains information that is being immediately processed or acted on that you can use, display, or alter.
|
||||||
Remember to declare it with `&` if you wish to alter it.
|
Remember to declare it with `&` if you wish to alter it.
|
||||||
|
|
||||||
## JavaScript addon hooks
|
## Global stylesheets
|
||||||
|
|
||||||
### PHP part
|
If your addon requires adding a stylesheet on all pages of Friendica, add the following hook:
|
||||||
|
|
||||||
Make sure your JavaScript addon file (addon/*addon_name*/*addon_name*.js) is listed in the document response.
|
|
||||||
|
|
||||||
In your addon install function, add:
|
|
||||||
|
|
||||||
```php
|
```php
|
||||||
Addon::registerHook('template_vars', __FILE__, '<addon_name>_template_vars');
|
function <addon>_install()
|
||||||
```
|
|
||||||
|
|
||||||
In your addon uninstall function, add:
|
|
||||||
|
|
||||||
```php
|
|
||||||
Addon::unregisterHook('template_vars', __FILE__, '<addon_name>_template_vars');
|
|
||||||
```
|
|
||||||
|
|
||||||
Then, add your addon name to the *addon_hooks* template variable array:
|
|
||||||
|
|
||||||
```php
|
|
||||||
function <addon_name>_template_vars($a, &$arr)
|
|
||||||
{
|
{
|
||||||
if (!array_key_exists('addon_hooks', $arr['vars']))
|
Addon::registerHook('head', __FILE__, '<addon>_head');
|
||||||
{
|
...
|
||||||
$arr['vars']['addon_hooks'] = array();
|
|
||||||
}
|
}
|
||||||
$arr['vars']['addon_hooks'][] = "<addon_name>";
|
|
||||||
|
|
||||||
|
function <addon>_head(App $a)
|
||||||
|
{
|
||||||
|
$a->registerStylesheet(__DIR__ . '/relative/path/to/addon/stylesheet.css');
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### JavaScript part
|
## JavaScript
|
||||||
|
|
||||||
Register your addon hooks in file `addon/*addon_name*/*addon_name*.js`.
|
### Global scripts
|
||||||
|
|
||||||
|
If your addon requires adding a script on all pages of Friendica, add the following hook:
|
||||||
|
|
||||||
|
|
||||||
|
```php
|
||||||
|
function <addon>_install()
|
||||||
|
{
|
||||||
|
Addon::registerHook('footer', __FILE__, '<addon>_footer');
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
function <addon>_footer(App $a)
|
||||||
|
{
|
||||||
|
$a->registerFooterScript(__DIR__ . '/relative/path/to/addon/script.js');
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### JavaScript hooks
|
||||||
|
|
||||||
|
The main Friendica script provides hooks via events dispatched on the `document` property.
|
||||||
|
In your Javascript file included as described above, add your event listener like this:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
document.addEventListener(name, callback);
|
document.addEventListener(name, callback);
|
||||||
```
|
```
|
||||||
|
|
||||||
*name* is the name of the hook and corresponds to a known Friendica JavaScript hook.
|
- *name* is the name of the hook and corresponds to a known Friendica JavaScript hook.
|
||||||
*callback* is a JavaScript function to execute.
|
- *callback* is a JavaScript function to execute.
|
||||||
|
|
||||||
|
#### Current JavaScript hooks
|
||||||
|
|
||||||
|
##### postprocess_liveupdate
|
||||||
|
Called at the end of the live update process (XmlHttpRequest) and on a post preview.
|
||||||
|
No additional data is provided.
|
||||||
|
|
||||||
## Modules
|
## Modules
|
||||||
|
|
||||||
|
@ -391,14 +405,9 @@ Hook data:
|
||||||
visitor => array with the contact record of the visitor
|
visitor => array with the contact record of the visitor
|
||||||
url => the query string
|
url => the query string
|
||||||
|
|
||||||
## Current JavaScript hooks
|
|
||||||
|
|
||||||
### postprocess_liveupdate
|
|
||||||
Called at the end of the live update process (XmlHttpRequest)
|
|
||||||
|
|
||||||
## Complete list of hook callbacks
|
## Complete list of hook callbacks
|
||||||
|
|
||||||
Here is a complete list of all hook callbacks with file locations (as of 01-Apr-2018). Please see the source for details of any hooks not documented above.
|
Here is a complete list of all hook callbacks with file locations (as of 24-Sep-2018). Please see the source for details of any hooks not documented above.
|
||||||
|
|
||||||
### index.php
|
### index.php
|
||||||
|
|
||||||
|
|
|
@ -43,11 +43,6 @@
|
||||||
<script type="text/javascript" src="view/asset/imagesloaded/imagesloaded.pkgd.min.js"></script>
|
<script type="text/javascript" src="view/asset/imagesloaded/imagesloaded.pkgd.min.js"></script>
|
||||||
<script type="text/javascript" src="view/js/acl.js" ></script>
|
<script type="text/javascript" src="view/js/acl.js" ></script>
|
||||||
<script type="text/javascript" src="view/asset/base64/base64.min.js" ></script>
|
<script type="text/javascript" src="view/asset/base64/base64.min.js" ></script>
|
||||||
{{if is_array($addon_hooks)}}
|
|
||||||
{{foreach $addon_hooks as $addon_hook}}
|
|
||||||
<script type="text/javascript" src="addon/{{$addon_hook}}/{{$addon_hook}}.js"></script>
|
|
||||||
{{/foreach}}
|
|
||||||
{{/if}}
|
|
||||||
<script type="text/javascript" src="view/js/main.js" ></script>
|
<script type="text/javascript" src="view/js/main.js" ></script>
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
|
|
|
@ -66,11 +66,6 @@
|
||||||
<script type="text/javascript" src="view/asset/imagesloaded/imagesloaded.pkgd.min.js"></script>
|
<script type="text/javascript" src="view/asset/imagesloaded/imagesloaded.pkgd.min.js"></script>
|
||||||
<script type="text/javascript" src="view/js/acl.js"></script>
|
<script type="text/javascript" src="view/js/acl.js"></script>
|
||||||
<script type="text/javascript" src="view/asset/base64/base64.min.js"></script>
|
<script type="text/javascript" src="view/asset/base64/base64.min.js"></script>
|
||||||
{{if is_array($addon_hooks)}}
|
|
||||||
{{foreach $addon_hooks as $addon_hook}}
|
|
||||||
<script type="text/javascript" src="addon/{{$addon_hook}}/{{$addon_hook}}.js"></script>
|
|
||||||
{{/foreach}}
|
|
||||||
{{/if}}
|
|
||||||
<script type="text/javascript" src="view/js/main.js"></script>
|
<script type="text/javascript" src="view/js/main.js"></script>
|
||||||
|
|
||||||
<script type="text/javascript" src="view/theme/frio/frameworks/bootstrap/js/bootstrap.min.js"></script>
|
<script type="text/javascript" src="view/theme/frio/frameworks/bootstrap/js/bootstrap.min.js"></script>
|
||||||
|
|
Loading…
Reference in a new issue