automizy-js
Version:
Automizy widget collection
124 lines (121 loc) • 4.15 kB
JavaScript
/*
* Module.create
* Module.widget
* Module.skin
* Module.draw
* Module.drawTo
* Module.show
* Module.hide
* Module.remove
* Module.id
* $A.newModule
* $A.getModule
* $A.getAllModule
* $A.removeModule
* $A.removeAllModule
*/
define([], function () {
$A.initBasicFunctions = function (module, moduleName) {
var module = module || false;
if (module === false)
return false;
var moduleName = moduleName || false;
if (moduleName === false)
return false;
var moduleNameLower = moduleName.toLowerCase();
var p = module.prototype;
p.create = function (func) {
if (typeof func === 'function') {
this.d.create = func;
} else {
return this.d.create(this, this.d.$widget);
}
return this;
};
p.widget = function () {
return this.d.$widget;
};
p.skin = function (skin) {
if (typeof skin !== 'undefined') {
this.d.skin = skin;
this.d.$widget.removeClassPrefix('automizy-skin-');
this.d.$widget.addClass('automizy-skin-' + skin);
return this;
}
return this.d.skin;
};
p.draw = p.drawTo = function ($target) {
var t = this;
var $target = $target || $('body');
t.d.$widget.appendTo($target);
t.d.hasObject = true;
t.show(function () {
t.d.create(t, t.d.$widget);
if (typeof t.d.createFunctions !== 'undefined') {
for (var i = 0; i < t.d.createFunctions.length; i++) {
t.d.createFunctions[i]();
}
}
});
return this;
};
if(typeof p.show === 'undefined'){
p.show = function (func) {
if(typeof this.open === 'function')this.open();
this.d.$widget.ashow();
//setTimeout(function(){
if(typeof func === 'function')func();
//}, 50);
return this;
};
}
p.hide = function () {
$A.setWindowScroll(true, this.id());
if(typeof this.close === 'function')this.close();
this.d.$widget.ahide();
return this;
};
p.remove = function () {
this.draw().d.$widget[0].parentElement.removeChild(this.d.$widget[0]);
$A.setWindowScroll(true, this.id());
delete $A.d[moduleNameLower + "s"][this.id()];
return true;
};
p.id = function (id) {
if (typeof id === 'number' || typeof id === 'string') {
if($A.setWindowScroll(true, this.d.id)){
$A.setWindowScroll(false, id);
}
$A.d[moduleNameLower + "s"].renameProperty(this.d.id, id);
this.d.$widget.attr('id', id);
this.d.id = id;
return this;
}
return this.d.id;
};
$A.m[moduleName] = module;
$A["new" + moduleName] = function (obj) {
var t = new module(obj);
$A.d[moduleNameLower + "s"][t.id()] = t;
return t;
};
$A["get" + moduleName] = function (id) {
return $A.d[moduleNameLower + "s"][id];
};
$A["getAll" + moduleName] = function () {
return $A.d[moduleNameLower + "s"];
};
$A["remove" + moduleName] = function (id) {
var elem = $A["get" + moduleName](id) || {};
if (typeof elem.remove !== 'undefined')
return elem.remove();
return true;
};
$A["removeAll" + moduleName] = function () {
for (var i in $A["getAll" + moduleName]()) {
$A["remove" + moduleName](i);
}
return true;
};
};
});