// DBX3.0 :: Docking Boxes (dbx) // ***************************************************** // DOM scripting by brothercake -- http://www.brothercake.com/ // GNU Lesser General Public License -- http://www.gnu.org/licenses/lgpl.html //****************************************************** var dbx;function dbxManager(sid, useid, hide, buttontype){dbx = this;if(!/^[-_a-z0-9]+$/i.test(sid)) { throw('Error from dbxManager:\n"' + sid + '" is an invalid session ID'); return; }this.kde = navigator.vendor == 'KDE';this.safari = navigator.vendor == 'Apple Computer, Inc.';this.chrome = navigator.vendor == 'Google Inc.';this.opera = typeof window.opera != 'undefined';this.msie = typeof document.uniqueID != 'undefined';this.supported = (!(typeof document.getElementsByTagName == 'undefined'|| document.getElementsByTagName('*').length == 0|| (this.kde && typeof window.sidebar == 'undefined')|| (this.opera && parseFloat(navigator.userAgent.toLowerCase().split(/opera[\/ ]/)[1].split(' ')[0], 10) < 8)));if(!this.supported) { return; }this.etype = typeof document.addEventListener != 'undefined' ? 'addEventListener' : typeof document.attachEvent != 'undefined' ? 'attachEvent' : 'none';if(this.etype == 'none') { this.supported = false; return; }this.eprefix = (this.etype == 'attachEvent' ? 'on' : '');this.sid = sid;this.cookiename = 'dbx-' + this.sid + '=';this.useid = typeof useid != 'undefined' && useid == 'yes' ? true : false;this.hide = typeof hide != 'undefined' && hide == 'no' ? false : true;this.buttontype = typeof buttontype != 'undefined' && buttontype == 'button' ? 'button' : 'link';this.running = 0;this.gnumbers = {};this.max = 0;this.rootcookie = '';if(document.cookie && document.cookie.indexOf(this.cookiename) != -1){this.rootcookie = document.cookie.split(this.cookiename)[1].split(';')[0];this.rootcookie = this.rootcookie.replace(/\|/g, ',').replace(/:/g, '=');if(this.rootcookie.indexOf('+') == -1){this.rootcookie = this.rootcookie.replace(/(,|$|&)/ig, '+$1').replace(/(\-\+)/g, '-');}}this.savedata = {};this.cookiestate = this.getCookieState();};dbxManager.prototype.setCookieState = function(){var now = new Date();now.setTime(now.getTime() + (365*24*60*60*1000));this.compileStateString();this.cookiestring = this.state.replace(/,/g, '|').replace(/=/g, ':').replace(/\+/g, '');if(typeof this.onstatechange == 'undefined' || this.onstatechange()){document.cookie = this.cookiename+ this.cookiestring+ '; expires=' + now.toGMTString()+ '; path=/';}};dbxManager.prototype.getCookieState = function(){this.cookiestate = null;if(document.cookie){if(document.cookie.indexOf(this.cookiename) != -1){this.cookie = document.cookie.split(this.cookiename)[1].split(';')[0].split('&');for(var i in this.cookie){if(this.unwanted(this.cookie, i)) { continue; }this.cookie[i] = this.cookie[i].replace(/\|/g, ',');this.cookie[i] = this.cookie[i].replace(/:/g, '=');if(this.cookie[i].indexOf('+') == -1){this.cookie[i] = this.cookie[i].replace(/(,|$|&)/ig, '+$1').replace(/(\-\+)/g, '-');}this.cookie[i] = this.cookie[i].split('=');this.cookie[i][1] = this.cookie[i][1].split(',');}this.cookiestate = {};for(i in this.cookie){if(this.unwanted(this.cookie, i)) { continue; }this.cookiestate[this.cookie[i][0]] = this.cookie[i][1];}}}return this.cookiestate;};dbxManager.prototype.compileStateString = function(){var str = '';for(var j in this.savedata){if(this.unwanted(this.savedata, j)) { continue; }str += j + '=' + this.savedata[j] + '&'}this.state = str.replace(/^(.+)&$/, '$1');};dbxManager.prototype.createElement = function(tag){return typeof document.createElementNS != 'undefined' ? document.createElementNS('http://www.w3.org/1999/xhtml', tag) : document.createElement(tag);};dbxManager.prototype.getTarget = function(e, pattern, node){if(typeof node != 'undefined'){var target = node;}else{target = typeof e.target != 'undefined' ? e.target : e.srcElement;}while(!this.hasClass(target, pattern)){target = target.parentNode;if(this.hasClass(target, 'dbx\-group') && !this.hasClass(target, pattern)){return null;}}return target;};dbxManager.prototype.getID = function(element){if(!element || !element.className) { return null; }else if(this.hasClass(element, 'dbx\-suffusion-discards')) { return 'suffusion-discards'; }var cname = element.className.split('dbxid-');if(cname.length == 1) { return null; }return cname[1].replace(/^([a-zA-Z0-9_]+).*$/, '$1');};dbxManager.prototype.getSiblingBox = function(root, sibling){var node = root[sibling];while(node && !this.hasClass(node, 'dbx\-box')){node = node[sibling];}if(!node) { node = root; }return node;};dbxManager.prototype.getPosition = function(obj, center){var position = { 'left' : obj.offsetLeft, 'top' : obj.offsetTop };var tmp = obj.offsetParent;while(tmp){position.left += tmp.offsetLeft;position.top += tmp.offsetTop;tmp = tmp.offsetParent;}if(center){position.left += obj.offsetWidth / 2;position.top += obj.offsetHeight / 2;}return position;};dbxManager.prototype.getViewportWidth = function(){return typeof window.innerWidth != 'undefined'? window.innerWidth: (typeof document.documentElement != 'undefined'&& typeof document.documentElement.clientWidth != 'undefined'&& document.documentElement.clientWidth != 0)? document.documentElement.clientWidth: this.get('body')[0].clientWidth;};dbxManager.prototype.compileAndDispatchOnBeforeStateChange = function(){var actions = {};for(var i=0; i= 0){splitdiffs.positive.push(differences[i]);}else{splitdiffs.negative.push(differences[i]);}}var ary = this.positive ? splitdiffs.positive : splitdiffs.negative;ary.sort(function(a, b){ return Math.abs(a[n]) - Math.abs(b[n]); });for(i=0; i 1){for(i=0; i 0)||(/(S[ew])/.test(direction) && ary[i][2] < 0)){ary.splice(i--, 1);}}}for(i=0; i 0 && Math.abs(ary[i][n]) != Math.abs(ary[0][n])){ary.splice(i--, 1);}}else{if(i > 0 && ary[i][n] != ary[0][n]){ary.splice(i--, 1);}}}n = n == 1 ? 2 : 1;ary.sort(function(a, b){ return Math.abs(a[n]) - Math.abs(b[n]); });if(ary.length == 0){index = '-';}else{index = ary[0][0];}var box = dbx.getTarget(null, 'dbx\-box', anchor);if(index == '-'){return false;}var targetbox = boxes[index];if(this.exchange == 'insert' && this.confirm == false && this.positive == true){targetbox = dbx.get('nextSibling', targetbox);if(!targetbox) { targetbox = boxes[index]; }}if(typeof dbx.onboxdrag == 'undefined' || dbx.onboxdrag()){if(box != targetbox && boxes == this.boxes){var origpoint = {'x' : box.offsetLeft + (box.offsetWidth / 2),'y' : box.offsetTop + (box.offsetHeight / 2)};var boxpoint = {'x' : targetbox.offsetLeft + (targetbox.offsetWidth / 2),'y' : targetbox.offsetTop + (targetbox.offsetHeight / 2)};var testblocks = this.getBlocksDifference(origpoint, boxpoint, box);var testcompass = this.getCompassDirection(origpoint, boxpoint);if(this.functionExists('_testRules') && !this._testRules(testcompass, testblocks, box, null)){if(confirm || this.dialog){this.updateDialog(targetbox, ' dbx-dialog-no', null, null, 'keyboard');if(this.vocab.kno != ''){this.createTooltip(this.vocab.kno,box,true);}}if(manual) { this.refocus(anchor); }return false;}}if(box != targetbox && !dbx.hasClass(targetbox, 'dbx\-(dialog|suffusion-discards)')){targetbox.className += ' dbx-box-target';}if(confirm || this.dialog){var diffs = null, group = null;if(boxes != this.boxes){group = this.dialog.group;var groupcontainer = dbx.getPosition(group.container, false);var callcontainer = dbx.getPosition(this.container, false);var diffs = {'x' : groupcontainer.left - callcontainer.left,'y' : groupcontainer.top - callcontainer.top};}this.updateDialog(targetbox, ' dbx-dialog-yes', diffs, group, 'keyboard');if(this.vocab.kyes != ''){this.createTooltip(this.vocab.kyes,box,true);}if(manual) { this.refocus(anchor); }return false;}if(this.exchange == 'swap'){return this.swapTwoBoxes(parent, targetbox, anchor, manual, this.positive);}else{return this.insertTwoBoxes(parent, targetbox, anchor, manual, direction);}}return false;};dbxGroup.prototype.insertTwoBoxes = function(original, selected, anchor, manual, positive){if(typeof dbx.onbeforestatechange != 'undefined'){var actions = dbx.compileAndDispatchOnBeforeStateChange(['proceed', this, this.container, this.gid, original, selected, 'insert']);if(!actions.proceed) { return false; }}if(this.functionExists('_updateRulePointer')) { this._updateRulePointer(); }var add = false, pointer = 0, theboxes = [], visiboxes = [];for(var i in this.boxes){if(dbx.unwanted(this.boxes, i)) { continue; }theboxes.push(this.boxes[i]);}for(i=0; i 0){for(i=0; i viewsize){this.tooltip.style.left = parseInt(parent.offsetLeft - (position.left + tipsize - viewsize), 10) + 'px';}var tooltip = this.tooltip;window.setTimeout(function(){if(tooltip != null) { tooltip.style.visibility = 'visible'; }}, 400);}};dbxGroup.prototype.removeTooltip = function(){if(this.tooltip){this.tooltip.parentNode.removeChild(this.tooltip);this.tooltip = null;}};dbxGroup.prototype.hover = function(e){if(!this.keydown || (dbx.kde && !this.mouseisdown)){var found = false, target = typeof e.target != 'undefined' ? e.target : e.srcElement;for(var i=0; i this.current.x ? 'right' : 'left'): (e.clientY > this.current.y ? 'down' : 'up');this.current = { 'x' : e.clientX, 'y' : e.clientY };var overall = { 'x' : this.current.x - this.initial.x, 'y' : this.current.y - this.initial.y };if(((overall.x >= 0 && overall.x <= this.threshold) || (overall.x <= 0 && overall.x >= 0 - this.threshold))&&((overall.y >= 0 && overall.y <= this.threshold) || (overall.y <= 0 && overall.y >= 0 - this.threshold))){this.current.x -= overall.x;this.current.y -= overall.y;}if(this.released || overall.x > this.threshold || overall.x < (0 - this.threshold) || overall.y > this.threshold || overall.y < (0 - this.threshold)){dbx.dbxobject = this;dbx.group = this.container;dbx.sourcebox = this.box;dbx.clonebox = this.boxclone;dbx.event = e;if(typeof dbx.onboxdrag == 'undefined' || dbx.onboxdrag()){this.released = true;if(this.restrict != 'vertical' || this.orientation == 'horizontal'){this.boxclone.style.left = parseInt(this.current.x - this.difference.x, 10) + 'px';}if(this.restrict != 'horizontal' || this.orientation == 'vertical'){this.boxclone.style.top = parseInt(this.current.y - this.difference.y, 10) + 'px';}if(this.restrict == 'freeform'){var clonepoint = {'x' : this.boxclone.offsetLeft + (this.boxclone.offsetWidth / 2),'y' : this.boxclone.offsetTop + (this.boxclone.offsetHeight / 2)};var proportion = 0.2;var hypotonuse = Math.round(Math.sqrt(Math.pow(this.boxclone.offsetWidth, 2) + Math.pow(this.boxclone.offsetHeight, 2)));if(clonepoint.x < 0 || clonepoint.x > (this.container.offsetWidth - proportion * hypotonuse)|| clonepoint.y < 0 || clonepoint.y > (this.container.offsetHeight - proportion * hypotonuse)){this.mouseup(e);return true;}}this.moveBoxByMouse(this.current.x, this.current.y, this.confirm);if(typeof e.preventDefault != 'undefined' ) { e.preventDefault(); }}}}return true;};dbxGroup.prototype.mouseup = function(e){this.removeActiveClasses('dbx\-box\-(target|active)');if(this.box){if(this.dialog){if(typeof this.dialog.group != 'undefined' && typeof this.boxes[dbx.getID(this.dialog)] == 'undefined'){var xgroup = this.dialog.group;var xinsert = xgroup.boxes[dbx.getID(this.dialog)];}this.clearDialog();if(typeof xgroup != 'undefined'){dbx.mousemove(e, this, xgroup, xinsert);return;}this.moveBoxByMouse(e.clientX, e.clientY, false);}this.removeCloneBox();this.regenerateBoxOrder();if(typeof document.onselectstart != 'undefined'){document.onselectstart = function() { return true; }}}this.clearDialog();this.dragok = false;};dbxGroup.prototype.click = function(e, anchor){if(anchor.hasfocus === true || anchor.hasfocus === null){if(this.dialog){var box = dbx.getTarget(null, 'dbx\-box', anchor);var dbxid = dbx.getID(this.dialog);{var targetbox = this.boxes[dbxid];}if(this.exchange == 'insert' && this.confirm == true && this.positive == true){targetbox = dbx.get('nextSibling', targetbox);if(!targetbox) { targetbox = this.boxes[dbxid]; }}var confirmed = dbx.hasClass(this.dialog, 'dbx\-dialog\-yes');this.clearDialog();this.removeTooltip();if(typeof targetbox != 'undefined' && targetbox != box && confirmed == true){if(this.exchange == 'swap'){this.swapTwoBoxes(box, targetbox, anchor, true, false);}else{return this.insertTwoBoxes(box, targetbox, anchor, true, false);}}return false;}this.removeTooltip();this.toggleBoxState(anchor, true, true, null);}return false;};dbxGroup.prototype.keypress = function(e, anchor){var parentbox = dbx.getTarget(null, 'dbx\-box', anchor);if(/^(3[7-9])|(40)$/.test(e.keyCode.toString())){if(dbx.opera && e.shiftKey) { return true; }if(!dbx.hasClass(dbx.getTarget(null, 'dbx\-box', anchor), 'dbx\-nograb')){parentbox.className += ' dbx-box-active';this.removeTooltip();var direction = '';switch(e.keyCode){case 37 :direction = 'W';break;case 38 :direction = 'N';break;case 39 :direction = 'E';break;case 40 :direction = 'S';break;}var wait = 75;if(this.currentdir && this.currentdir != direction){direction += this.currentdir.toLowerCase();switch(direction){case 'En' : direction = 'Ne'; break;case 'Es' : direction = 'Se'; break;case 'Wn' : direction = 'Nw'; break;case 'Ws' : direction = 'Sw'; break;}clearTimeout(this.keytimer);wait = 0;}else{this.currentdir = direction;}var self = this;this.keytimer = setTimeout(function(){if(!/^(Ns|Sn|Ew|Ww)$/.test(direction)){if(self.dialog){var dbxid = dbx.getID(self.dialog);{var box = self.boxes[dbxid];}}else{box = dbx.getTarget(null, 'dbx\-box', anchor);}self.moveBoxByKeyboard(e, anchor, box, direction, self.confirm, true);}}, wait);if(typeof e.preventDefault != 'undefined') { e.preventDefault(); }else { return false; }typeof e.stopPropagation != 'undefined' ? e.stopPropagation() : e.cancelBubble = true;this.keydown = false;}}else if(dbx.kde && e.target == anchor && (e.keyCode == 13 || e.keyCode == 32)){this.click(e, anchor);e.preventDefault();}else{this.removeActiveClasses('dbx\-box\-(target|active)');}if(e.keyCode == 13 || e.keyCode == 32){parentbox.className += ' dbx-box-active';}return true;};dbxGroup.prototype.regenerateBoxOrder = function(){this.order = [];var len = this.eles.length;for(var j=0; j boxprops.xy && cloneprops.xy < boxprops.xy)||(!this.positive && cloneprops.xy < boxprops.xy && cloneprops.xy + cloneprops.wh > boxprops.xy)){if(this.boxes[i] == this.box) { return; }var sibling = dbx.getSiblingBox(this.box, 'nextSibling');if(this.box == sibling || this.boxes[i] == sibling) { return; }var index = i;break;}}}if(this.orientation == 'freeform'){differences.sort(function(a, b) { return a[1] - b[1]; });index = differences[0][0];var targetbox = this.boxes[index];var originaltargetbox = targetbox;if(this.exchange == 'insert' && (this.direction == 'down' || this.direction == 'right')){targetbox = dbx.get('nextSibling', targetbox);}if(targetbox == this.box) { return; }boxprops = {'left' : originaltargetbox.offsetLeft,'top' : originaltargetbox.offsetTop};boxprops.right = boxprops.left + targetbox.offsetWidth;boxprops.bottom = boxprops.top + targetbox.offsetHeight;var proportion = confirm || this.dialog ? 0 : 0.1;var hypotonuse = Math.round(Math.sqrt(Math.pow(originaltargetbox.offsetWidth, 2) + Math.pow(originaltargetbox.offsetHeight, 2)));if(!(clonepoint.x > boxprops.left + (hypotonuse * proportion) && clonepoint.x < boxprops.right - (hypotonuse * proportion)&& clonepoint.y > boxprops.top + (hypotonuse * proportion) && clonepoint.y < boxprops.bottom - (hypotonuse * proportion))){return;}if(this.last.box == targetbox && this.last.direction == this.direction){return;}var origpoint = {'x' : this.box.offsetLeft + (this.box.offsetWidth / 2),'y' : this.box.offsetTop + (this.box.offsetHeight / 2)};boxpoint = {'x' : originaltargetbox.offsetLeft + (originaltargetbox.offsetWidth / 2),'y' : originaltargetbox.offsetTop + (originaltargetbox.offsetHeight / 2)};var blocks = this.getBlocksDifference(origpoint, boxpoint, this.box);var compass = this.getCompassDirection(origpoint, boxpoint);if(this.functionExists('_testRules') && !this._testRules(compass, blocks, this.box, null)){if(confirm || this.dialog){this.updateDialog(originaltargetbox, ' dbx-dialog-no', null, null, 'mouse');}return;}if(confirm || this.dialog){if(!dbx.hasClass(targetbox, 'dbx\-(dialog|suffusion-discards)')){originaltargetbox.className += ' dbx-box-target';}this.updateDialog(originaltargetbox, ' dbx-dialog-yes', null, null, 'mouse');return;}if(this.functionExists('_updateRulePointer')) { this._updateRulePointer(); }this.last = {'box' : originaltargetbox,'direction' : this.direction};}else{var targetbox = this.boxes[index];var originaltargetbox = targetbox;}if(typeof index == 'undefined') { return; }if(!dbx.hasClass(originaltargetbox, 'dbx\-(dialog|suffusion-discards)')){originaltargetbox.className += ' dbx-box-target';}if(typeof dbx.onbeforestatechange != 'undefined'){var actions = dbx.compileAndDispatchOnBeforeStateChange(['proceed', this, this.container, this.gid, this.box, originaltargetbox,(this.orientation == 'freeform' ? this.exchange : 'move')]);if(!actions.proceed) { return; }}if(this.orientation == 'freeform' ){if(this.exchange == 'swap'){var visibox = originaltargetbox;}else{var add = false, pointer = 0, theboxes = [], visiboxes = [];for(var i in this.boxes){if(dbx.unwanted(this.boxes, i)) { continue; }theboxes.push(this.boxes[i]);}for(i=0; i 0){for(i=0; i b.x){compass += 'w';}return compass;};dbxGroup.prototype.getBlocksDifference = function(a, b, box){var blocks = [parseInt(Math.abs(a.x - b.x) / box.offsetWidth, 10),parseInt(Math.abs(a.y - b.y) / box.offsetHeight, 10)];blocks.sort(function(a, b) { return a - b; });return blocks;};dbxGroup.prototype.updateDialog = function(box, state, position, group, source){if(this.buffer){clearTimeout(this.buffer);this.buffer = null;}var self = this;this.buffer = setTimeout(function(){var boxpos = { 'x' : box.offsetLeft, 'y' : box.offsetTop };if(position){boxpos.x += position.x;boxpos.y += position.y;}self.clearDialog();self.dialog = self.createClone(box, 29999, boxpos, 'dbx-dialog' + state, false, source);self.dialog = dbx.removeClass(self.dialog, 'dbx\-box\-(target|active|hover|focus)');self.dialog.style.visibility = 'visible';clearTimeout(self.buffer);self.buffer = null;}, 20);};dbxGroup.prototype.clearDialog = function(){if(this.dialog){this.container.removeChild(this.dialog);this.dialog = null;}};dbxGroup.prototype.contains = function(outer, inner){if(inner == outer) { return true; }if(inner == null) { return false; }else { return this.contains(outer, inner.parentNode); }};dbxGroup.prototype.refocus = function(target){try { target.focus(); } catch(err){}var box = dbx.getTarget(null, 'dbx\-box', target);if(!dbx.hasClass(box, 'dbx-box-focus')){box.className += ' dbx-box-focus';}};function dbxAnimator(caller, box, pos, res, kbd, anchor, manual){this.caller = caller;if(this.caller.resolution == 0) { this.caller.resolution = 1; }this.box = box;this.timer = null;var before = {'x' : pos.x,'y' : pos.y};var after = {'x' : this.box.offsetLeft,'y' : this.box.offsetTop};if(!(before.x == after.x && before.y == after.y)){if(dbx.running > this.caller.boxes.length - 1) { return; }var clone = this.caller.createClone(this.box, 29999, arguments[2], 'dbx-aniclone', true, 'animator');clone.style.visibility = 'visible';this.box.style.visibility = 'hidden';var change = {'x' : after.x > before.x ? after.x - before.x : 0 - (before.x - after.x),'y' : after.y > before.y ? after.y - before.y : 0 - (before.y - after.y)};this.animateClone(clone,before,change,res,kbd,anchor,manual);}};dbxAnimator.prototype.animateClone = function(clone, current, change, res, kbd, anchor, manual){var self = this;var count = 0;dbx.running ++;this.timer = window.setInterval(function(){count ++;current.x += change.x / res;current.y += change.y / res;clone.style.left = parseInt(current.x, 10) + 'px';clone.style.top = parseInt(current.y, 10) + 'px';if(count == res){window.clearInterval(self.timer);self.timer = null;dbx.running --;self.caller.container.removeChild(clone);self.box.style.visibility = 'visible';if(self.box.className.indexOf('dbxid') != -1){self.box = dbx.removeClass(self.box, 'dbx\-suffusion-discards');}self.caller.boxes[dbx.getID(self.box)] = self.box;if(kbd && manual){if(anchor && anchor.parentNode.style.visibility != 'hidden'){setTimeout(function() { self.caller.refocus(anchor); }, 0);}else if(self.caller.toggles){var button = self.caller.buttons[dbx.getID(self.box)];if(button && typeof button.isactive != 'undefined'){self.caller.refocus(button);}}else{if(typeof self.box.focus == 'function'){setTimeout(function() { self.caller.refocus(self.box); }, 0);}}}if(typeof dbx.onafteranimate == 'function'){setTimeout(function() { dbx.compileAndDispatchOnAfterAnimate(self.box, self.caller) }, 0);}}if(typeof dbx.onanimate == 'function' && self.caller.resolution > 1){dbx.compileAndDispatchOnAnimate(self.box, clone, self.caller, count, res)}}, 20);};if(typeof window.attachEvent != 'undefined'){window.attachEvent('onunload', function(){var ev = ['mousedown', 'mousemove', 'mouseup', 'mouseout', 'click', 'keydown', 'keyup', 'focus', 'blur', 'selectstart', 'statechange', 'boxdrag', 'boxopen', 'boxclose', 'ruletest', 'afteranimate', 'beforestatechange', 'animate'];var el = ev.length;var dl = document.all.length;for(var i=0; i