dj library
A javascriot library which builds it's components on the latest version of the underrated closure library.
Intro
What you need to use it
You just need to get the latest version of the closure library: https://github.com/google/closure-library
Coming features
- Dynamic configuration for each component (incl. base64)
- Static configuration for each component
SYS and EXT
SYS: It provides the component manager of the library.
EXT: All components and utilities already created. E.g. OverlyComponent, DropdownComponent, ...
Component
Creating a component
The very basic structure of a component could like like this:
goog;goog; /** * @constructor * @extends */yoursample{ yoursampleComponent;};goog;
The components "ready" and "init" methods
You have to methods to affect the loading and initialization behaviour of a component.
The components ready method
This method is the first after the component manager has become a component for initialization. This function needs to return a promise, which tells the component manager to continue with the initialization. There is a helper function for this in the parent component to prevent differences between the components. This could look like this:
/** @inheritDoc */yoursampleComponentprototype{ return this;};
The components init method
After the component is ready the manager goes to the next function: "init". It's behaving like the ready method:
/** @inheritDoc */yoursampleComponentprototype{ return this;};
The features of AbstractComponent
The base class comes with some useful features. Like a handleResize or handleScroll implementation. To register these functionalities you can call
this;
or
this;
This will register a listener on the scroll or resize provider. You are able to do your stuff on resize or scroll by overriding these two functions:
/** @inheritDoc */yoursampleComponentprototype{ yoursampleComponentprototype; // Do your stuff on resize}; /** @inheritDoc */yoursampleComponentprototype{ yoursampleComponentprototype; // Do your stuff on scroll};
To obtain the scroll position or the screen size you can call:
var scrollPosition = this;
or
var windowSize = this;
Component manager
Using the component manager
To set up the component manager simply do it like this:
goog; // Your created componentsgoog;goog; // Instantiate the component managervar componentManager = ; // Start adding available componentscomponentManager;componentManager; // After that you are able to init the componentscomponentManager;
Extended usage of the component manager
Update the component manager
componentManager;
Change the attribute name the component manager is using to select the components. The default attribute name is data-cmp.
var yourComponentInstnace = componentManager;
Manually initialize a component instance. Immediately resolved if the component was already initialized.
componentManager;
Set a different root element, only components under this element will be recognized. The default root is the document element.
componentManager;
Change the attribute name the component manager is using to select the components. The default attribute name is data-cmp.
componentManager;
License
The dj library is open-sourced software licensed under the MIT license.