Events: Allow for easier application extension with hook points.
How does it work?
Every time someone wants to extend the application, instead of modifying original `publishing.js` file, he or she can subscribe to given events, e.g.
Scenario: Table Of Contents extension
```
// resources/public/js/toc.js
events.subscribe('content:rendered', function () {
// Prepend table of contents in edit mode on updates
});
events.subscribe('document:loaded', function () {
// Prepend table of contents on initial load in edit view and preview
});
```
Now, having structured way to hook into app allows to keep the main codebase maintainable and pretty stable and extremely extensible at the same time.
This commit is contained in:
@@ -12,5 +12,11 @@
|
||||
%CONTENT%
|
||||
</article>
|
||||
%FOOTER%
|
||||
|
||||
<script src="/js/events.js"></script>
|
||||
<script>
|
||||
events.publish('document:loaded');
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user