Skip to content

anime-db/js-controller

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

js-controller

Micro framework for JavaScript

Require

jQuery 1.11+

How to

Create control

// ControlFormDate.js
var ControlFormDate = function() {
};

extend(ControlFormDate, ControllerControl);

ControlFormDate.prototype.bind = function(target) {
    target.datepicker({dateFormat: 'yy-mm-dd'});
};

Add new control to controller

// common.js
var cont = new Controller();
cont.addControl('form-date', new ControlFormDate());

$(function(){
    cont.bind();
});

Use in HTML

<!-- ... -->

<script src="js/js-controller/build/controller.min.js"></script>
<script src="js/ControlFormDate.js"></script>
<script src="js/common.js"></script>

<!-- ... -->

<form>
    <input type="date" name="date" data-control="form-date" />
    <button type="submit">Submit</button>
</form>

Rebind

You can bind the added controls for a new content:

var content = $('<input type="date" name="date" data-control="form-date" />');
$('body').append(content);
cont.bind(content);

Locker util

Util for lock page and element on page.

var lock = new Locker();
lock.lock(); // add css class 'locker_wait' to body tag
lock.isLock(); // return true
lock.unlock(); // remove class 'locker_wait'

Lock element

var el = $('.example');
var lock = new Locker();
lock.lock(el); // add class 'locker_wait' to body and add class 'locker_lock' to element
lock.unlock(el); // remove all added classes

Use locker from control

// ControlLock.js
var ControlLock = function() {
};

extend(ControlLock, ControllerControl);

ControlLock.prototype.bind = function(target) {
    var that = this;
    target.keydown(function(){
        that.getController.getLocker().lock(target);
    }).keyup(function(){
        that.getController.getLocker().unlock(target);
    });
};
// common.js
var cont = new Controller(new Locker());
cont.addControl('lock', new ControlLock());

$(function(){
    cont.bind();
});

License

This bundle is under the MIT license. See the complete license in the file: LICENSE

About

[TRANSMITTED] The project is transmitted to a different vendor

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published