GithubHelp home page GithubHelp logo

kaiser's Introduction

#Kaiser ####A conventional way to write JS

###Install with bower

bower install kaiser

###Create your first module

#####JS

Kaiser.Module.create('myModule', function(scope) {
    
    scope.init = function() {
        // initialize non event-driven, module-specific functionality here
    };
    
    // the events in this object will be bound to the specified element
    // and call the function returned in the scope
    
    scope.events = {
        'click .my-button': 'clickHandler'
    };
    
    scope.clickHandler = function() {
        myLocalFunction();
    };
    
    function myLocalFunction() {
        console.log('button was clicked');
    }
    
    // scope must be returned
    return scope;
    
});

#####HTML When the Kaiser.start() function is called, it will look for module properties in the DOM and initialize the appropriate modules while setting the scope of the corresponding function to the element containing the module attribute. This attribute should be on the root element of where your functionality should be scoped.

<div module="myModule"></div>

All modules can be accessed through the Kaiser.Module.find() function. This function will return all modules or the module name can be passed in to get a specific module. Kaiser.Module.find('myModule'); would return the module created above.

###Directives You can create your own custom directives which will automatically trigger their corresponding logic. Directives can either be attributes or data-attributes.

#####JS

Kaiser.Directive.create('click', function(scope, $element, data) {
    scope.listenTo('click', $element, data);
    return scope;
});

Three parameters are passed into the directive function:

  • scope -- scope of the module containing the directive
  • $element -- the jQuery element containing the directive attribute
  • data -- the value of the directive property

#####HTML

<div module="myModule">
    <button click="clickHandler">Click Me</button>
</div>

This directive would call the function specified on click. Check out test/test.js for more examples.

###Middleware Middleware allows you to create reusable functions that can be imported into Modules, Directives, or other Middleware. These functions are stored privately with simple getter and setter functions create() and find() so that you do not have to directly expose them publicly.

Kaiser.Middleware.create('offline', function($el) {
    var $clone = $el.clone(true);

    $clone.online = function() {
        $el.replaceWith($clone);
        $el = $clone;
    };

    return $clone;
});

To import functions from Middleware or any other namespace, use the import functions and store the return in a variable. var myVar = Kaiser.from(<namespace>).import(<module>);

Kaiser.Module.create('test', function(scope) {
    var offline = Kaiser.from('Middleware').import('offline');
    scope.init = function() {
        console.log('The "offline" function is available via "scope.offline"', scope.offline);
    };
});
This is very much still in development, so any feedback or bug reports is much appreciated.

kaiser's People

Contributors

wescravens avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.