cyrilleinvalides/choupas/www/admin/editor/scripts/onglets.js

134 lines
3.0 KiB
JavaScript
Executable File

function ongletManager(elem) {
this.main = elem;
this.ontop = null;
var micmac = this;
var a = this.main.childNodes;
for(var i = 0; i < a.length; i++) {
if (!a[i].tagName) this.main.removeChild(a[i]);
}
this.newContainer = function (name, content) {
var newong = document.getElementById('onglet_model').cloneNode(true);
var micmac = this;
newong.getElementsByClassName('onglet_title')[0].innerHTML = name;
newong.getElementsByClassName('onglet_title')[0].onclick = function (event) {
event.preventDefault();
micmac.makeOnTop(event.target.parentNode);
}
newong.setTitle = function (title) {
micmac.setTitle(this, title);
}
newong.setDetails = function (tooltip) {
micmac.setToolTip(this, tooltip);
}
newong.setUrl = function (url) {
micmac.setUrl(this, url);
}
newong.makeOnTop = function () {
micmac.makeOnTop(this);
}
newong.close = function (e) {
micmac.close(this);
}
newong.style.display = 'block';
newong.id = '';
if (content) newong.getElementsByClassName('onglet_content')[0].appendChild(content);
if (content) newong.content = content;
this.main.appendChild(newong);
return newong;
};
this.makeOnTop = function (target) {
var a = this.ontop;
if(a) {
if (a.onBeforeMakeOnBottom) a.onBeforeMakeOnBottom();
a.removeClassName('active_onglet');
a.removeClassName('active');
a.addClassName('onglet');
a.addClassName('unactive');
if (a.onMakeOnBottom) a.onMakeOnBottom();
}
if (!target) return false;
target.addClassName('active_onglet');
target.addClassName('active');
target.removeClassName('onglet');
target.removeClassName('unactive');
this.ontop = target;
target.getElementsByClassName('onglet_title')[0].blur();
if (target.onmakeontop) target.onmakeontop();
return false;
};
this.close = function (a) {
var cl = a || this.ontop;
var arr = this.ontop;
if (!cl) return false;
//if (e && e.ctrlKey)
//if (!a) return this.closeAll();
var target = false;
if(arr && arr != a) {
target = arr;
} else if (cl.nextSibling) {
target = cl.nextSibling;
} else if ( cl.previousSibling && cl.previousSibling.id != 'onglet_model' ) {
target = cl.previousSibling;
}
if (cl.onbeforeclose) {
var eventRes = cl.onbeforeclose();
if (!eventRes) {return false;}
}
this.main.removeChild(cl);
if (cl.onClose) cl.onClose();
this.ontop = null;
delete cl;
if (target) this.makeOnTop(target);
return true;
}
this.closeAll = function () {
var cont = true;
while(this.ontop && cont) {
cont = this.close(this.ontop);
}
return cont;
}
this.setTitle = function (target, title) {
target.getElementsByClassName('onglet_title')[0].textContent = title;
}
this.setToolTip = function (target, tooltip) {
target.getElementsByClassName('onglet_title')[0].title = tooltip;
}
this.setUrl = function (target, url) {
target.getElementsByClassName('onglet_title')[0].href = url;
}
}