1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
| // utilitaires divers (DOM constantes, position, event target, etc.)
var utils = function()
{
function getRealTarget(t) { return t && t.nodeType == document.TEXT_NODE ? t.parentNode : t; }
function getTarget_IE(e)
{
var E = e || window.event;
return getRealTarget(t = E && E.srcElement ? E.srcElement : null);
}
function getTarget_W3C(e)
{
return getRealTarget(e && e.target ? e.target : null);
}
function getTarget(e)
{
var E = e || window.event;
if ( E && E.srcElement )
{
utils.getTarget = getTarget_IE;
return utils.getTarget(e);
}
else if ( E && E.target )
{
utils.getTarget = getTarget_W3C;
return utils.getTarget(e);
}
return null;
}
function getX(e)
{
var
E = e || window.event,
x = E.pageX;
if ( !x && 0 !== x )
{
x = E.clientX || 0;
// devrait calculer en prenant en considération
// document[body|documentElement].scrollLeft pour IE,
// mais je m'en fous ici
}
return x;
}
function getY(e)
{
var
E = e || window.event,
y = E.pageY;
if ( !y && 0 !== y )
{
y = E.clientY || 0;
// devrait calculer en prenant en considération
// document[body|documentElement].scrollTop pour IE,
// mais je m'en fous ici
}
return y;
}
/**
* Définition des constantes DOM indispensables (ELEMENT_NODE et TEXT_NODE) que certains clients n'exposent pas (comme IE6)
* @public
*/
(
function()
{
var
i,
D = document,
T = [
'ELEMENT_NODE', 'ATTRIBUTE_NODE', 'TEXT_NODE',
'CDATA_SECTION_NODE', 'ENTITY_REFERENCE_NODE',
'ENTITY_NODE', 'PROCESSING_INSTRUCTION_NODE',
'COMMENT_NODE', 'DOCUMENT_NODE', 'DOCUMENT_TYPE_NODE',
'DOCUMENT_FRAGMENT_NODE', 'DOCUMENT_NOTATION_MODE'
];
for ( i = 0; i < T.length; i++ )
{
if ( typeof D[T[i]] == 'undefined' || D[T[i]] === null ) { D[T[i]] = 1 + i; }
}
}()
);
return {
getX:getX, getY:getY,
getTarget:getTarget
}
}();
var splitter = function()
{
var source_drag, panels = {};
function mousedown(e)
{
var target = utils.getTarget(e);
if ( target && target.id == "SplitBar")
{
document.onmousemove = mousemove;
document.onmouseup = mouseup;
source_drag = target;
return false;
}
return true;
}
function mousemove(e)
{
var
delta,
splitter_width = 7, //devrait être calculé
splitter_height = 7; //devrait être calculé
if ( source_drag )
{
delta = utils.getX(e);
if (delta >= 200 && delta <= 500)
{
source_drag.style.left = delta + "px";
panels.Arborescence.style.width = delta + "px";
panels.Donnees.style.left = (delta + splitter_width) + "px";
}
}
return true;
}
function mouseup(e)
{
// ici on pourrait par exemple envoyer au serveur par XHR
// la position du splitter pour une réutilisation au même endroit
// pour la prochaine session
source_drag = null;
document.onmousemove = null;
document.onmouseup = null;
return true;
}
return {
init:function()
{
function $(e) { return document.getElementById(e); }
panels.Arborescence = $("Arborescence");
panels.Donnees = $("Donnees");
panels.SplitBar = $("SplitBar");
panels.SplitBar.onmousedown = mousedown;
}
};
}();
window.onload = splitter.init; |
Partager