IFY Widgets
Javascript Object oriented test, creating widgets in pure JS with inheritance
by fabriziopaino86
CSS
.IFY_Widgets.WindowPanel {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.4);
z-index: 99999999;
}
.IFY_Widgets.WindowPanel .Window {
position: relative;
margin: auto;
top: 10%;
width: 600px;
height: 500px;
background-color: #222;
border: solid 2px #8fc800;
-webkit-border-radius: 2px;
border-radius: 2px;
color: #ddd;
}
.IFY_Widgets.WindowPanel .TitleBar {
position: relative;
padding: 5px;
text-align: center;
}
.IFY_Widgets.WindowPanel .TitleActions {
position: relative;
float: right;
}
.IFY_Widgets.WindowPanel .TitleActions .CloseButton {
padding: 0 5px 5px 5px;
color: #8fc800;
cursor: pointer;
}
.IFY_Widgets.WindowPanel .ContentPanel {
position: absolute;
padding: 0 5px;
padding-top: 5px;
top: 30px;
bottom: 0;
left: 0;
right: 0;
overflow-y: auto;
}
.IFY_Widgets.Button {
padding: 2px 10px;
-webkit-border-radius: 5px;
border-radius: 5px;
background-color: #111;
border: solid 2px #8fc800;
color: #bbb;
margin: 2px;
cursor: pointer;
}
.IFY_Widgets.Button:hover {
border-color: #B6E00D;
background-color: #333;
color: #fff;
}
.IFY_Widgets.TextBox {
padding: 2px 10px;
-webkit-border-radius: 5px;
border-radius: 5px;
background-color: #111;
border: solid 2px #8fc800;
color: #bbb;
margin: 5px 0;
display: table;
}
.IFY_Widgets.TextBox:hover {
border-color: #B6E00D;
background-color: #333;
}
.IFY_Widgets.TextBox span {
padding-right: 4px;
font-weight: bold;
}
.IFY_Widgets.TextBox input[type=text] {
background-color: transparent;
border: none;
border-bottom: solid 1px #8fc800;
color: #fff;
}
JavaScript
_ = IFY_Widgets = (function () {
function Inherit(object, parent) {
object.prototype = new parent();
object.constructor = object;
};
function Crt(name) {
return document.createElement(name);
};
function div() {
return Crt("div");
};
function span() {
return Crt('span');
};
function textBox() {
var inpt = Crt('input');
inpt.type = "text";
return inpt;
};
function Append(parent, child) {
parent.appendChild(child);
};
function AppendAt(parent, child, index) {
parent.insertBefore(child, parent.children[index]);
};
function Remove(parent, child) {
parent.removeChild(child);
};
function Widget() {
var Me = this;
var root = div();
var parent;
var dataUrl;
var methodType;
var ajaxDataHandler;
var showEvenet;
var removeEvent;
var Init = function () {
Me.SetName("");
Me.SetClassName("IFY_Widgets");
methodType = "GET"
};
this.SetParent = function (value) {
if (value.IsHtml() || value.IsWidget()) parent = value;
else throw ("Not a valid parent element");
};
this.AsyncLoad = function () {
$.ajax({
url: dataUrl,
type: methodType,
success: function (data) {
if (ajaxDataHandler != undefined) ajaxDataHandler(Me, data);
}
});
};
this.SetDataUrl = function (url) {
dataUrl = url;
};
this.SetAjaxType = function (methodType) {
Me.methodType = methodType;
};
this.SetAjaxLoadHandler = function (handler) {
ajaxDataHandler = handler;
};
this.GetId = function () {
return root.id;
};
this.SetId = function (value) {
...