====== Using the Page framework ====== The ''$p'' (page) framework is a way to organize the JavaScript code for your site in way that keeps the code easily maintainable. ===== Organization ===== The concept behind this framework is that all code should be organized into a single data structure (referred to as “''[[framework:page:index|$p]]''”). This avoids conflicts with other JavaScript tools and libraries, and makes sure the code follows predictable conventions. ===== Initialization ===== The framework comes with tools to streamline initializing each module in a consistent manner. To this end, initialisation is split into two phases: - Pre-init (the “''_init()''” method) is called after the page structure is finished loading (at the [[mdn>Web/API/Document/DOMContentLoaded_event|DOMContentLoaded event]] to be precise). This is the place for basic integrity checks. This method is typically created by the module author. - The actual “''init()''” method is created in the implementation. This is the place where user-initialisations can take place. For all child objects of the ''[[framework:page:index|$p]]'' object, both of these are called automatically. For sub-elements, it is up to the author of these modules to use [[framework:page:p-core:callinit|$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: * Code organisation * Initialisation FIXME Work in progress. More soon.