Micro framework for JavaScript
jQuery 1.11+
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>
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);
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();
});
This bundle is under the MIT license. See the complete license in the file: LICENSE