The $p (page) framework is a way to organize the JavaScript code for your site in way that keeps the code easily maintainable.
The concept behind this framework is that all code should be organized into a single data structure (referred to as “$p”). This avoids conflicts with other JavaScript tools and libraries, and makes sure the code follows predictable conventions.
The framework comes with tools to streamline initializing each module in a consistent manner. To this end, initialisation is split into two phases:
_init()” method) is called after the page structure is finished loading (at the DOMContentLoaded event to be precise). This is the place for basic integrity checks. This method is typically created by the module author.init()” method is created in the implementation. This is the place where user-initialisations can take place.
For all child objects of the $p object, both of these are called automatically. For sub-elements, it is up to the author of these modules to use $p._callInit() to call the initialization functions, or in some cases the implementer to provide the necessary functionality.
More details and examples are provided in the following sub-articles:
Work in progress. More soon.