npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dj-library

v1.0.110

Published

An extension library for the underrated google closure library

Downloads

24

Readme

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.provide('your.sample.Component');
goog.require('dj.sys.components.AbstractComponent');

/**
 * @constructor
 * @extends {dj.sys.components.AbstractComponent}
 */
your.sample.Component = function()
{
  your.sample.Component.base(this, 'constructor');
};
goog.inherits(your.sample.Component, dj.sys.components.AbstractComponent);

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 */
your.sample.Component.prototype.ready = function()
{
  return this.baseReady(your.sample.Component, function(resolve, reject){
    // All ready stuff. After the initialization has finished.
    // Call the resolve function to tell the waiting components it's ready.
    resolve();
  });
};

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 */
your.sample.Component.prototype.init = function()
{
  return this.baseInit(your.sample.Component, function(resolve, reject){
    // All initialization stuff. After the initialization has finished.
    // Call the resolve function to tell the waiting components it's ready.
    resolve();
  });
};

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.listenScroll();

or

this.listenResize();

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 */
your.sample.Component.prototype.handleResize = function()
{
  your.sample.Component.prototype.base(this, 'handleResize');

  // Do your stuff on resize
};

/** @inheritDoc */
your.sample.Component.prototype.handleScroll = function()
{
  your.sample.Component.prototype.base(this, 'handleScroll');

  // Do your stuff on scroll
};

To obtain the scroll position or the screen size you can call:

var scrollPosition = this.getSrollPosition();

or

var windowSize = this.getWindowSize();

Component manager

Using the component manager

To set up the component manager simply do it like this:

goog.require('dj.sys.ComponentManager');

// Your created components
goog.require('your.sample.Component');
goog.require('your.sample.Component2');

// Instantiate the component manager
var componentManager = new dj.sys.ComponentManager();

// Start adding available components
componentManager.add('sample', your.sample.Component);
componentManager.add('sample2', your.sample.Component2);

// After that you are able to init the components
componentManager.init().then(function(){
    // Component initialization finished
}, null, this);

Extended usage of the component manager

Update the component manager

componentManager.update().then(function(){
    // Component initialization finished
}, null, this);

Change the attribute name the component manager is using to select the components. The default attribute name is data-cmp.

var yourComponentInstnace = componentManager.getComponent('a-component-id');

Manually initialize a component instance. Immediately resolved if the component was already initialized.

componentManager.initComponent(yourComponentInstance).then(function(){
    // Component initialized
}, null, this);

Set a different root element, only components under this element will be recognized. The default root is the document element.

componentManager.setRootElement(goog.dom.getElement('element-id'));

Change the attribute name the component manager is using to select the components. The default attribute name is data-cmp.

componentManager.setAttributeName('data-attr-name');

License

The dj library is open-sourced software licensed under the MIT license.