[rhmessaging-commits] rhmessaging commits: r4391 - in mgmt/trunk/cumin: resources and 1 other directory.

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Mon Oct 18 10:03:39 EDT 2010


Author: eallen
Date: 2010-10-18 10:03:39 -0400 (Mon, 18 Oct 2010)
New Revision: 4391

Added:
   mgmt/trunk/cumin/resources/slotvis.js
Modified:
   mgmt/trunk/cumin/python/cumin/grid/slot.strings
Log:
BZ 643914: Moved png slot vis javascript to separate .js file

Modified: mgmt/trunk/cumin/python/cumin/grid/slot.strings
===================================================================
--- mgmt/trunk/cumin/python/cumin/grid/slot.strings	2010-10-15 16:48:35 UTC (rev 4390)
+++ mgmt/trunk/cumin/python/cumin/grid/slot.strings	2010-10-18 14:03:39 UTC (rev 4391)
@@ -40,833 +40,8 @@
 </table>
 
 [SlotMap.javascript]
-var vis;
+addJavascript('resource?name=slotvis.js', 'head');
 
-(function() {
-    vis = new Visualization();
-
-    var slot_clip_left;
-    var slot_clip_top;
-    var slot_zoom;
-    var slot_last_index;
-    var slot_info_timer;
-    var slot_hover_timer;
-    var slot_png_timer;
-    var slot_zoom_initialized;
-    var slot_center_index;
-
-    function Visualization() {
-        slot_clip_left = 0;
-        slot_clip_top = 0;
-        slot_zoom = 1;
-        slot_last_index = -1;
-        slot_info_timer = null;
-        slot_hover_timer = null;
-        slot_png_timer = null;
-        slot_zoom_initialized = false;
-        slot_center_index = -1;
-
-        this.notify = function(fullpage, size) {
-            slot_clip_size = size;            
-            this.img_loaded(document.images[slot_current_id]);
-        }
-        this.pan_left = function () {
-            if (slot_clip_left == 0) return;
-            var now = new Date();
-            animate_pan(slot_clip_left, Math.min(Math.floor(slot_clip_size / 1.1), -slot_clip_left), (now-0), "slot_clip_left");
-        }
-
-        this.pan_right = function () {
-            var to_pan = Math.floor(slot_clip_size / 1.1);
-            if (slot_clip_left - slot_clip_size - to_pan < -slot_map_info.width) {
-                to_pan = slot_map_info.width - slot_clip_size + slot_clip_left;
-            }
-            var now = new Date();
-            animate_pan(slot_clip_left, -to_pan, (now-0), "slot_clip_left");
-        }
-
-        this.pan_up = function () {
-            if (slot_clip_top == 0) return;
-            var now = new Date();
-            animate_pan(slot_clip_top, Math.min(Math.floor(slot_clip_size / 1.1), -slot_clip_top), (now-0), "slot_clip_top");
-        }
-
-        this.pan_down = function () {
-            if (slot_map_info.height < slot_clip_size) return;
-
-            var to_pan = Math.floor(slot_clip_size / 1.1);
-            if (slot_clip_top - slot_clip_size - to_pan < -slot_map_info.height) {
-                to_pan = slot_map_info.height - slot_clip_size + slot_clip_top;
-            }
-            var now = new Date();
-            animate_pan(slot_clip_top, -to_pan, (now-0), "slot_clip_top");
-        }
-
-
-        // in case server stops and then restarts, reget the images
-        this.img_error = function (oImg) {
-            stop_auto_updates();
-            var oZooming = document.getElementById("slot_zooming");
-            if (oZooming) {
-                oZooming.style.display = "none";
-            }
-            oImg.style.visibility = "hidden"; // hide broken image indicator
-            slot_map_info.size = 0;
-            slot_map_info.width = 1;
-            slot_map_info.height = 1;
-            slot_map_info.rows = 1;
-            slot_map_info.cols = 1;
-            slot_map_info.count = 0;
-            slot_png_timer = setInterval(update_png, 10000);
-        }
-
-        this.img_loaded = function (oImg) {
-            stop_auto_updates();
-            var oZooming = document.getElementById("slot_zooming");
-            if (oZooming) {
-                oZooming.style.display = "none";
-            }
-
-            if (oImg) {
-                oImg.style.visibility = "visible";
-                slot_cookie_info();
-                oImg.width = slot_map_info.width;
-                oImg.height = slot_map_info.height;
-                set_pan("slot_panup", "width", slot_map_info.size * slot_map_info.cols, this.pan_up);
-                set_pan("slot_pandown", "width", slot_map_info.size * slot_map_info.cols, this.pan_down);
-                set_pan("slot_panleft", "height", slot_map_info.size * slot_map_info.rows, this.pan_left);
-                set_pan("slot_panright", "height", slot_map_info.size * slot_map_info.rows, this.pan_right);
-
-                var oMap = document.getElementById(slot_current_id);
-                if (oMap) {
-                    oMap.style.width = Math.min(oImg.width, slot_clip_size) + "px";
-                    oMap.style.height = Math.min(oImg.height, slot_clip_size) + "px";
-                    if ((slot_map_info.size * slot_map_info.rows < slot_clip_size) &&
-                        (slot_map_info.size * slot_map_info.cols < slot_clip_size))
-                            oMap.style.borderColor = "transparent";
-                    else
-                            oMap.style.borderColor = "#CCCCCC";
-
-                }
-                var oGlass = document.getElementById("slot_glass");
-                if (oGlass) {
-                    oGlass.style.width = Math.min(oImg.width, slot_clip_size) + "px";
-                    oGlass.style.height = Math.min(oImg.height, slot_clip_size) + "px";
-                }
-                if (!slot_zoom_initialized)
-                    initialize_zoom();
-
-                animate_zoom_to(slot_zoom);
-                var oControls = document.getElementById("slot_controls");
-                if (oControls) {
-                    var oMap = document.getElementById(slot_current_id);
-                    oControls.style.left = (oMap.offsetLeft + oMap.offsetWidth - oControls.offsetWidth) + "px";
-                    //oControls.style.left = (420 - oControls.offsetWidth) + "px";
-                }
-                refire_info();
-            }
-            center_on_index();
-            draw_clipped();
-            slot_png_timer = setInterval(update_png, 6000);
-        }
-
-        this.upGlass = function (e) {
-            if (!e) var e = window.event;
-            var oGlass = document.getElementById("slot_glass");
-            if (oGlass) {
-                if (oGlass.dragging) {
-                    oGlass.dragging = false;
-                }
-            }
-        }
-
-        this.moveGlass = function (e) {
-            if (slot_map_info.size == 0) return;
-            if (!e) var e = window.event;
-            var oGlass = document.getElementById("slot_glass");
-            if (oGlass) {
-                if (oGlass.dragging) {
-                    var posxy = get_event_pos(e);
-                    if ((posxy.x - oGlass.down_pos.x > 0) || (posxy.y - oGlass.down_pos.y > 0))
-                        oGlass.down_pos = {x: posxy.x - slot_clip_left, y: posxy.y - slot_clip_top};
-
-                    slot_clip_left = Math.min(posxy.x - oGlass.down_pos.x, 0);
-                    slot_clip_top = Math.min(posxy.y - oGlass.down_pos.y, 0);
-                    oGlass.drug = true;
-
-                    draw_clipped();
-                    if (e.preventDefault)
-                        e.preventDefault();
-                    return false;
-                }
-            }
-
-            var rpos = get_relative_event_pos(e);
-            if (rpos) {
-                get_slot_info(rpos.x, rpos.y);
-            }
-        }
-
-        this.downGlass = function (e) {
-            if (!e) var e = window.event;
-
-            var oGlass = document.getElementById("slot_glass");
-            if (oGlass) {
-                oGlass.dragging = true;
-                var posxy = get_event_pos(e);
-                oGlass.down_pos = {x: posxy.x - slot_clip_left, y: posxy.y - slot_clip_top};
-                clear_hover();
-                hide_info();
-            }
-            return false;
-        }
-
-        this.outGlass = function outGlass(e) {
-            if (!e) var e = window.event;
-            clear_hover();
-            hide_info();
-        }
-
-        this.zoom_in_slots = function (posxy) {
-            if (slot_zoom >= get_max_zoom()) return;
-            var click_info = vis.get_index(posxy.x, posxy.y);
-            slot_center_index = click_info.index;
-            do_zoom(slot_zoom + 1);
-        }
-
-        this.fire_slot_info = function (index) {
-            slot_last_index = index;
-            slot_info_timer = null;
-            do_info_request(index);
-        }
-
-        this.get_index = function (x, y) {
-            var width = slot_map_info.size;
-            var pngrow = Math.floor((y - slot_clip_top) / width);
-            var pngcol = Math.floor((x - slot_clip_left) / width);
-
-            if ((pngcol < slot_map_info.cols) && (pngrow < slot_map_info.rows)) {
-                var index = pngrow * slot_map_info.cols + pngcol;
-
-                if (index < slot_map_info.count)
-                    return {"index": index, "row": pngrow, "col": pngcol};
-            }
-
-            return null;
-        }
-
-    }
-
-    function slot_zoom_to(e) {
-        if (!e) var e = window.event;
-        var targ = get_event_target(e);
-        var level = parseInt(targ.level, 10);
-
-        get_center_index();
-        do_zoom(level);
-
-        if (e.stopPropagation)
-            e.stopPropagation()
-        else if (e.cancelBubble)
-            e.cancelBubble = true;
-    }
-
-    function do_zoom(level) {
-        var old_zoom = slot_zoom;
-        slot_zoom = level;
-
-        stop_auto_updates();
-        var oZooming = document.getElementById("slot_zooming");
-        if (oZooming) {
-            oZooming.style.display = "block";
-            //var oMap = document.getElementById(slot_current_id);
-            //if (oMap) {
-            //    oZooming.style.width = oMap.offsetWidth + "px";
-            //}
-        }
-        var oImg = document.images[slot_current_id];
-        if (oImg) {
-            var src = oImg.src;
-            var branch = wooly.session.branch(src);
-            branch.zl = level;
-            branch.zx = slot_clip_left;
-            branch.zy = slot_clip_top;
-            src = branch.marshal();
-            
-            src = cumin.refreshTime(src);
-            oImg.src = src;
-        }
-
-        animate_zoom_to(level);
-        return false;
-    }
-
-    function animate_zoom_to(level) {
-        var oPos = document.getElementById("zoom_pos");
-        if (oPos) {
-            var original_x = oPos.offsetLeft;
-            var now = new Date();
-            var x_amount = ((level - 1) * 13) - original_x;
-            animate_zoom_pos(original_x, (now-0), x_amount)
-        }
-    }
-
-    function animate_zoom_pos(original_x, original_time, x_amount) {
-        var oPos = document.getElementById("zoom_pos");
-
-        if (oPos) {
-            var now = new Date();
-            var delta = (now - original_time) / 400.0;
-            var partial = 1;
-
-            if (delta < 1)
-                partial = Math.sin(Math.PI/2 * delta);
-
-            oPos.style.left = Math.floor(original_x + x_amount * partial) + "px";
-
-            if (delta < 1) {
-                setTimeout(function() {
-                        animate_zoom_pos(original_x, original_time, x_amount)
-                }, 10);
-            }
-        }
-    }
-
-    function stop_auto_updates() {
-        if (slot_png_timer) {
-            clearInterval(slot_png_timer);
-            slot_png_timer = null;
-        }
-    }
-
-    function update_png() {
-        stop_auto_updates();
-        cumin.updateChart(slot_current_id, null);
-    }
-
-    function set_pan(id, which, value, fn) {
-        var obj = document.getElementById(id);
-        if (obj) {
-            if (value <= slot_clip_size) {
-                eval("obj.style." + which + " = '" + Math.min(value, slot_clip_size) + "px'");
-                obj.style.visibility = "hidden";
-                obj.onclick = null;
-            } else {
-                eval("obj.style." + which + " = '" + Math.min(value, slot_clip_size) + "px'");
-                obj.style.visibility = "visible";
-                obj.onclick = fn;
-            }
-        }
-    }
-
-    function slot_cookie_info() {
-        var slot_info = get_cookie("slot_info");
-        if (slot_info) {
-            var vals = slot_info.split("|");
-            if (vals.length == 6) {
-                slot_map_info.size = parseInt(vals[0], 10);
-                slot_map_info.width = parseInt(vals[1], 10);
-                slot_map_info.height = parseInt(vals[2], 10);
-                slot_map_info.count = parseInt(vals[3], 10);
-                slot_map_info.rows = parseInt(vals[4], 10);
-                slot_map_info.cols = parseInt(vals[5], 10);
-            }
-        }
-    }
-
-    function center_on_index() {
-        if (slot_center_index == -1) return;
-
-        var row = slot_center_index % slot_map_info.cols;
-        var col = Math.floor(slot_center_index / slot_map_info.cols);
-        var x = col * slot_map_info.size + slot_map_info.size / 2;
-        var y = row * slot_map_info.size + slot_map_info.size / 2;
-
-        var cl = (Math.min(slot_clip_size, slot_map_info.width) / 2) - x;
-        var ct = (Math.min(slot_clip_size, slot_map_info.height) / 2) - y;
-
-        if (slot_map_info.width + cl < slot_clip_size)
-            cl = slot_clip_size - slot_map_info.width;
-
-        if (slot_map_info.height + ct < slot_clip_size)
-            ct = slot_clip_size - slot_map_info.height;
-
-        if (cl > 0) cl = 0;
-        if (ct > 0) ct = 0;
-
-        slot_clip_left = Math.floor(cl);
-        slot_clip_top = Math.floor(ct);
-        slot_center_index = -1;
-    }
-
-    function get_center_index() {
-        var rx = Math.min(slot_clip_size, slot_map_info.width) / 2;
-        var ry = Math.min(slot_clip_size, slot_map_info.height) / 2;
-
-        var click_info = vis.get_index(rx, ry);
-        if (click_info)
-            slot_center_index = click_info.index;
-    }
-
-    function get_max_zoom() {
-        // allow to zoom until each slot is at least 28px wide
-        if ((slot_map_info.size == 0) || (slot_zoom == 0))
-            return 1;
-        return Math.ceil(28 / (slot_map_info.size / slot_zoom));
-    }
-
-    function initialize_zoom() {
-        var max_zoom = get_max_zoom();
-        var oZoom = document.getElementById("zoom_levels");
-        if ((oZoom) && (max_zoom > 1)) {
-            var oDiv, oText, oNode;
-            for (var i=0; i<max_zoom; i++) {
-                var oDiv = document.createElement("div");
-                if (i == 0) {
-                    oDiv.className = "zoom_first";
-                    oDiv.onclick = slot_zoom_to;
-                    oDiv.level = i+1;
-                    set_text(oDiv, (i+1)+ "", "zoom_node");
-                } else if (i == max_zoom - 1) {
-                    oDiv.className = "zoom_last";
-                    oDiv.onclick = slot_zoom_to;
-                    oDiv.level = i+1;
-                    set_text(oDiv, i+1, "zoom_node_last");
-                } else {
-                    oDiv.className = "zoom_middle_left";
-                    oDiv.onclick = slot_zoom_to;
-                    oDiv.level = i+1;
-                    oZoom.appendChild(oDiv);
-                    oDiv = document.createElement("div");
-                    oDiv.className = "zoom_middle_right";
-                    oDiv.onclick = slot_zoom_to;
-                    oDiv.level = i+1;
-                    set_text(oDiv, (i+1)+ "", "zoom_node");
-                }
-                oZoom.appendChild(oDiv);
-            }
-        } else {
-            var oControls = document.getElementById("slot_controls");
-            if (oControls) {
-                oControls.style.display = "none";
-            }
-        }
-        $("slot_visualization").style.display = "block";
-        cumin.makeFullPageable($("slot_visualization"));
-        slot_zoom_initialized = true;
-
-        function set_text(odiv, text, className) {
-            var oText = document.createElement("div");
-            var oNode = document.createTextNode(text+"");
-            oText.className = className;
-            oText.appendChild(oNode);
-            odiv.appendChild(oText);
-            oText.onclick = slot_zoom_to;
-            oText.level = text;
-        }
-    }
-
-    function draw_clipped() {
-
-        var clip_bottom;
-        var clip_right;
-        if (slot_map_info.width < slot_clip_size) {
-            clip_bottom = slot_map_info.height;
-            clip_right = slot_map_info.width;
-            slot_clip_left = 0;
-            slot_clip_top = 0;
-        } else {
-            var iZoom = slot_zoom;
-            var clip_width = slot_clip_size;
-            var clip_height = slot_clip_size;
-            clip_bottom = clip_height - slot_clip_top;
-            clip_right = clip_width - slot_clip_left;
-
-            if (clip_right > slot_map_info.width) {
-                slot_clip_left += (clip_right - slot_map_info.width);
-                clip_right = slot_map_info.width;
-            }
-            if (clip_bottom > slot_map_info.height) {
-                slot_clip_top = Math.min(clip_height - slot_map_info.height, 0);
-                clip_bottom = slot_map_info.height;
-            }
-        }
-
-        var oPng = document.getElementById("slot_png");
-        if (oPng) {
-            oPng.style.left = slot_clip_left + "px";
-            oPng.style.top = slot_clip_top + "px";
-            oPng.style.clip = "rect(" + (-slot_clip_top) + "px " + clip_right + "px " + clip_bottom + "px " + (-slot_clip_left) + "px)";
-        }
-    }
-
-
-    function animate_pan(original_edge, move, timer, which) {
-        var now = new Date();
-        var delta = (now - timer) / 400.0;
-        var expression = "=Math.floor(original_edge + move";
-        if (delta < 1) {
-            expression += " * Math.sin(Math.PI/2 * delta)";
-        }
-        expression += ")";
-        eval(which + expression);
-        draw_clipped();
-        if (delta < 1)
-            setTimeout( function () {animate_pan(original_edge, move, timer, which) }, 10);
-
-    }
-
-    function clear_hover() {
-        if (slot_info_timer) {
-            clearTimeout(slot_info_timer);
-            slot_info_timer = null;
-            slot_last_index = -1;
-        }
-        oHover = document.getElementById("slot_hover");
-        if (oHover) {
-            oHover.style.visibility = "hidden";
-        }
-    }
-
-    function hide_info() {
-        oInfo = $(slot_info_id);
-        if (oInfo) {
-            oInfo.style.visibility = "hidden";
-        }
-        slot_last_index = -1;
-    }
-
-    function get_slot_info(rx, ry) {
-        var click_info = vis.get_index(rx, ry);
-        if (click_info) {
-            if (click_info.index != slot_last_index) {
-                if (slot_info_timer) {
-                    clearTimeout(slot_info_timer);
-                    slot_info_timer = null;
-                }
-                if (slot_hover_timer) {
-                    clearTimeout(slot_hover_timer);
-                    slot_hover_timer = null;
-                }
-                slot_info_timer = setTimeout( function() { vis.fire_slot_info(click_info.index) }, 500);
-                animate_hover(0, click_info.row, click_info.col);
-                oInfo = $(slot_info_id);
-                if (oInfo) {
-                    oInfo.style.display = "none";
-                }
-            }
-        }
-    }
-
-    function animate_hover(leg, row, col) {
-        var oHover = document.getElementById("slot_hover");
-        if (oHover) {
-            if (slot_hover_timer) {
-                clearTimeout(slot_hover_timer);
-                slot_hover_timer = null;
-            }
-            var width = slot_map_info.size;
-            if (width == 0) return;
-            var rx = col * width + slot_clip_left;
-            var ry = row * width + slot_clip_top;
-            oHover.style.width = (width-1) + "px";
-            oHover.style.height = (width-1) + "px";
-
-            switch (leg) {
-            case 0:
-                    oHover.style.left = rx + "px";
-                    oHover.style.top = ry + "px";
-                    oHover.style.width = width + "px";
-                    oHover.style.height = width + "px";
-                    oHover.style.borderColor = "red pink pink pink";
-                    oHover.style.visibility = "visible";
-                    if ((rx < 0) || (ry < 0) || (rx + width > slot_clip_size) || (ry + width > slot_clip_size)) {
-                        var cx = (rx < 0) ? rx : 0;
-                        var cy = (ry < 0) ? ry : 0;
-                        var cw = (rx + width > slot_clip_size) ? slot_clip_size - rx  : width + 1;
-                        var ch = (ry + width > slot_clip_size) ? slot_clip_size - ry  : width + 1;
-                        oHover.style.clip = "rect(" + (-cy) + "px " + (cw) + "px " + (ch) + "px " + (-cx) + "px)";
-                    } else {
-                        oHover.style.clip = "rect(0px " + (width+1) + "px " + (width+1) + "px 0px)";
-                    }
-                    slot_hover_timer = setTimeout( function() {animate_hover(1)}, 500/3);
-                    break;
-            case 1: oHover.style.borderColor = "red red pink pink";
-                    slot_hover_timer = setTimeout( function() {animate_hover(2)}, 500/3);
-                    break;
-            case 2: oHover.style.borderColor = "red red red pink";
-                    slot_hover_timer = setTimeout( function() {animate_hover(3)}, 500/3);
-                    break;
-            case 3: oHover.style.borderColor = "red red red red";
-                    break;
-            }
-        }
-    }
-
-    function refire_info() {
-        if (slot_last_index > -1) {
-            do_info_request(slot_last_index)
-        }
-    }
-
-    function do_info_request(index) {
-        var branch = wooly.session.branch(slot_info_url);
-        branch.session[slot_info_index] = index;
-        var newreq = branch.marshal();
-        wooly.setIntervalUpdate(newreq, got_slot_info, 0, {index: index});
-    }
-
-    function got_slot_info(xhtml, args) {
-        if (slot_last_index == -1) return;
-        var oInfo = $(slot_info_id);
-        var slot_clicked = null;
-        if (oInfo) {
-            oInfo.style.display = "none";
-            if (oInfo.slot_clicked) {
-                slot_clicked = oInfo.slot_clicked;
-                oInfo.slot_clicked = null;
-            }
-        }
-        wooly.updatePage(xhtml);
-        var oInfo = $(slot_info_id);
-        if (oInfo) {
-            oInfo.click_index = args.index;
-            oInfo.slot_clicked = null;
-            if (slot_clicked) {
-                clicks.doClick(slot_clicked.x, slot_clicked.y);
-                return;
-            }
-
-            document.body.appendChild(oInfo); // so position is absolute to entire page
-
-            //oInfo.style.left = "-1000px";
-            //oInfo.style.visibility = "hidden";
-            oInfo.style.display = "block";
-
-            var oMap = document.getElementById(slot_current_id);
-            if (oMap) {
-                var abs_pos = findPos(oMap);
-
-                // top of clicked slot is here
-                var y = Math.floor(args.index / slot_map_info.cols) * slot_map_info.size + slot_clip_top;
-
-                // candidate pos for popup
-                // just under the clicked slot
-                var topUnder = (abs_pos.y + y) + Math.floor(slot_map_info.size * 1.5);
-                var top = topUnder;
-                
-                // if off the bottom of the map
-                if (topUnder + oInfo.offsetHeight > abs_pos.y + oMap.offsetHeight) {
-                    // position popup above clicked slot
-                    top = (abs_pos.y + y) - oInfo.offsetHeight - Math.floor(slot_map_info.size * .5);
-                }
-
-                // if off the top of the page
-                if (top < 0) {
-                    // revert to under the item
-                    top = topUnder;
-                }
-
-                oInfo.style.top = top + "px";
-                oInfo.style.left = abs_pos.x + "px";
-            }
-            oInfo.style.visibility = "visible";
-        }
-    }
-
-}())
-
-var clicks;
-
-(function() {
-    clicks = new Clicks();
-
-    function Clicks() {
-         this.doubleclick_when = 0;
-         this.click_when = 0;
-         this.click_handle = null;
-
-        this.doMouseDown = function(e) {
-            if (!e) var e = window.event;
-            var which = e.type;
-            switch (which) {
-             case "click":
-               // If we've just had a doubleclick then ignore it
-               if (hadDoubleClick()) return false;
-               // Otherwise set timer to act.  It may be preempted by a doubleclick.
-               d = new Date();
-               clicks.click_when = d.getTime();
-                var rpos = get_relative_event_pos(e);
-                if (rpos) {
-                    clicks.click_handle = setTimeout( function() {clicks.doClick(rpos.x, rpos.y)}, 250);
-                    break;
-                }
-             case "dblclick":
-               doDoubleClick(e);
-               break;
-             default:
-           }
-        }
-
-        this.doClick = function(x, y) {
-            // preempt if DC occurred after original click.
-            if (this.click_when - this.doubleclick_when <= 0) {
-                return false;
-            }
-            var oGlass = document.getElementById("slot_glass");
-            if (oGlass) {
-                if (oGlass.drug) {
-                    oGlass.drug = false;
-                    return false;
-                }
-            }
-            var click_info = vis.get_index(x, y);
-            var oInfo = $(slot_info_id);
-            if (oInfo && click_info) {
-                if ((typeof oInfo.click_index != "undefined") &&
-                    (oInfo.click_index == click_info.index)) {
-                    // we already fetched the info for this slot
-                    var oInfoCellId = document.getElementById("slotInfo_id");
-                    if (oInfoCellId) {
-                        var slotid = oInfoCellId.innerHTML;
-                        if (slotid != "") {
-                            go_to_slot(slotid);
-                            return false;
-                        }
-                    }
-                } else {
-                    // fetch the slot info so we can get the slot id
-                    oInfo.slot_clicked = {fetching: true, x: x, y: y};
-                    vis.fire_slot_info(click_info.index);
-                }
-            }
-        }
-    }
-
-    function hadDoubleClick() {
-       var d = new Date();
-       var now = d.getTime();
-       if ((now - this.doubleclick_when) < 100) {
-         return true;
-       }
-       return false;
-    }
-
-    function doDoubleClick(e) {
-       var now = new Date();
-       clicks.doubleclick_when = now.getTime();
-       if (clicks.click_handle != null) {
-         clearTimeout(clicks.click_handle);          // Clear pending Click
-         clicks.click_handle = null;
-       }
-       if (!e) var e = window.event;
-       var posxy = get_relative_event_pos(e);
-       vis.zoom_in_slots(posxy);
-    }
-}())
-
-function go_to_slot(id) {
-    if (show_slot_url != "") {
-        var branch = wooly.session.branch(show_slot_url);
-        branch[branch.frame + ".id"] = id;
-        window.location.href = branch.marshal();
-    }
-}
-function vis_clicked(slot) {
-    go_to_slot(slot);
-}
-/* generic get value from cookie */
-function get_cookie(name) {
-    return get_value(document.cookie, name, ";");
-}
-
-/* generic get value from string */
-function get_value(s, name, sep) {
-    var name_plus = name + "=";
-    var crumbs = s.split(sep);
-    // splitting to avoid false match on substring:
-    // ex: bigfoo=duh;foo=blah;
-    for(var i=0; i < crumbs.length; i++) {
-        var c = crumbs[i];
-        while (c.charAt(0) == ' ') {
-            c = c.substring(1, c.length);
-        }
-
-        if (c.indexOf(name_plus) == 0) {
-            return c.substring(name_plus.length,c.length);
-        }
-    }
-    return null;
-}
-
-/* generic replace a value in a name=value; string */
-function replace_value(s, name, value, sep) {
-    var name_index = s.indexOf(name+"=");
-    if (name_index > -1) {
-        var sep_index = s.indexOf(sep, name_index);
-        if (sep_index == -1) { // end of string
-            sep_index = s.length;
-        }
-        var s1 = s.substring(0, name_index + name.length + 1);
-        var s2 = value + "";
-        var s3 = s.substring(sep_index);
-        return s1 + s2 + s3;
-    }
-    return s;
-}
-
-/* get the absolute position of something */
-function findPos(obj) {
-    var curleft = curtop = 0;
-    if (obj.offsetParent) {
-        do {
-                curleft += obj.offsetLeft;
-                curtop += obj.offsetTop;
-            } while (obj = obj.offsetParent);
-        return {x: curleft, y: curtop};
-    }
-}
-
-/* get the absolute event position */
-function get_event_pos(e) {
-    if (e.pageX || e.pageY)     {
-        posx = e.pageX;
-        posy = e.pageY;
-    }
-    else if (e.clientX || e.clientY)    {
-        posx = e.clientX + document.body.scrollLeft
-            + document.documentElement.scrollLeft;
-        posy = e.clientY + document.body.scrollTop
-            + document.documentElement.scrollTop;
-    }
-    return {"x": posx, "y": posy};
-}
-
-/* find out what element the event was the event target */
-function get_event_target(e) {
-    var targ = null;
-    if (e.target)
-        targ = e.target;
-    else if (e.srcElement)
-        targ = e.srcElement;
-    if (targ.nodeType == 3) // avoid Safari textNode bug
-        targ = targ.parentNode;
-    return targ;
-}
-
-/* get the event position relatave to the event target */
-function get_relative_event_pos(e) {
-    var targ = get_event_target(e);
-    if (targ) {
-        var pxy = findPos(targ);
-        var posxy = get_event_pos(e);
-
-        var rx = posxy.x - pxy.x  - 2;
-        var ry = posxy.y - pxy.y - 2;
-        return {x: rx, y: ry};
-    }
-}
-
 [SlotMap.css]
 div#slot_hover {
     visibility: hidden;

Added: mgmt/trunk/cumin/resources/slotvis.js
===================================================================
--- mgmt/trunk/cumin/resources/slotvis.js	                        (rev 0)
+++ mgmt/trunk/cumin/resources/slotvis.js	2010-10-18 14:03:39 UTC (rev 4391)
@@ -0,0 +1,827 @@
+var vis;
+
+(function() {
+    vis = new Visualization();
+
+    var slot_clip_left;
+    var slot_clip_top;
+    var slot_zoom;
+    var slot_last_index;
+    var slot_info_timer;
+    var slot_hover_timer;
+    var slot_png_timer;
+    var slot_zoom_initialized;
+    var slot_center_index;
+
+    function Visualization() {
+        slot_clip_left = 0;
+        slot_clip_top = 0;
+        slot_zoom = 1;
+        slot_last_index = -1;
+        slot_info_timer = null;
+        slot_hover_timer = null;
+        slot_png_timer = null;
+        slot_zoom_initialized = false;
+        slot_center_index = -1;
+
+        this.notify = function(fullpage, size) {
+            slot_clip_size = size;            
+            this.img_loaded(document.images[slot_current_id]);
+        }
+        this.pan_left = function () {
+            if (slot_clip_left == 0) return;
+            var now = new Date();
+            animate_pan(slot_clip_left, Math.min(Math.floor(slot_clip_size / 1.1), -slot_clip_left), (now-0), "slot_clip_left");
+        }
+
+        this.pan_right = function () {
+            var to_pan = Math.floor(slot_clip_size / 1.1);
+            if (slot_clip_left - slot_clip_size - to_pan < -slot_map_info.width) {
+                to_pan = slot_map_info.width - slot_clip_size + slot_clip_left;
+            }
+            var now = new Date();
+            animate_pan(slot_clip_left, -to_pan, (now-0), "slot_clip_left");
+        }
+
+        this.pan_up = function () {
+            if (slot_clip_top == 0) return;
+            var now = new Date();
+            animate_pan(slot_clip_top, Math.min(Math.floor(slot_clip_size / 1.1), -slot_clip_top), (now-0), "slot_clip_top");
+        }
+
+        this.pan_down = function () {
+            if (slot_map_info.height < slot_clip_size) return;
+
+            var to_pan = Math.floor(slot_clip_size / 1.1);
+            if (slot_clip_top - slot_clip_size - to_pan < -slot_map_info.height) {
+                to_pan = slot_map_info.height - slot_clip_size + slot_clip_top;
+            }
+            var now = new Date();
+            animate_pan(slot_clip_top, -to_pan, (now-0), "slot_clip_top");
+        }
+
+
+        // in case server stops and then restarts, reget the images
+        this.img_error = function (oImg) {
+            stop_auto_updates();
+            var oZooming = document.getElementById("slot_zooming");
+            if (oZooming) {
+                oZooming.style.display = "none";
+            }
+            oImg.style.visibility = "hidden"; // hide broken image indicator
+            slot_map_info.size = 0;
+            slot_map_info.width = 1;
+            slot_map_info.height = 1;
+            slot_map_info.rows = 1;
+            slot_map_info.cols = 1;
+            slot_map_info.count = 0;
+            slot_png_timer = setInterval(update_png, 10000);
+        }
+
+        this.img_loaded = function (oImg) {
+            stop_auto_updates();
+            var oZooming = document.getElementById("slot_zooming");
+            if (oZooming) {
+                oZooming.style.display = "none";
+            }
+
+            if (oImg) {
+                oImg.style.visibility = "visible";
+                slot_cookie_info();
+                oImg.width = slot_map_info.width;
+                oImg.height = slot_map_info.height;
+                set_pan("slot_panup", "width", slot_map_info.size * slot_map_info.cols, this.pan_up);
+                set_pan("slot_pandown", "width", slot_map_info.size * slot_map_info.cols, this.pan_down);
+                set_pan("slot_panleft", "height", slot_map_info.size * slot_map_info.rows, this.pan_left);
+                set_pan("slot_panright", "height", slot_map_info.size * slot_map_info.rows, this.pan_right);
+
+                var oMap = document.getElementById(slot_current_id);
+                if (oMap) {
+                    oMap.style.width = Math.min(oImg.width, slot_clip_size) + "px";
+                    oMap.style.height = Math.min(oImg.height, slot_clip_size) + "px";
+                    if ((slot_map_info.size * slot_map_info.rows < slot_clip_size) &&
+                        (slot_map_info.size * slot_map_info.cols < slot_clip_size))
+                            oMap.style.borderColor = "transparent";
+                    else
+                            oMap.style.borderColor = "#CCCCCC";
+
+                }
+                var oGlass = document.getElementById("slot_glass");
+                if (oGlass) {
+                    oGlass.style.width = Math.min(oImg.width, slot_clip_size) + "px";
+                    oGlass.style.height = Math.min(oImg.height, slot_clip_size) + "px";
+                }
+                if (!slot_zoom_initialized)
+                    initialize_zoom();
+
+                animate_zoom_to(slot_zoom);
+                var oControls = document.getElementById("slot_controls");
+                if (oControls) {
+                    var oMap = document.getElementById(slot_current_id);
+                    oControls.style.left = (oMap.offsetLeft + oMap.offsetWidth - oControls.offsetWidth) + "px";
+                    //oControls.style.left = (420 - oControls.offsetWidth) + "px";
+                }
+                refire_info();
+            }
+            center_on_index();
+            draw_clipped();
+            slot_png_timer = setInterval(update_png, 6000);
+        }
+
+        this.upGlass = function (e) {
+            if (!e) var e = window.event;
+            var oGlass = document.getElementById("slot_glass");
+            if (oGlass) {
+                if (oGlass.dragging) {
+                    oGlass.dragging = false;
+                }
+            }
+        }
+
+        this.moveGlass = function (e) {
+            if (slot_map_info.size == 0) return;
+            if (!e) var e = window.event;
+            var oGlass = document.getElementById("slot_glass");
+            if (oGlass) {
+                if (oGlass.dragging) {
+                    var posxy = get_event_pos(e);
+                    if ((posxy.x - oGlass.down_pos.x > 0) || (posxy.y - oGlass.down_pos.y > 0))
+                        oGlass.down_pos = {x: posxy.x - slot_clip_left, y: posxy.y - slot_clip_top};
+
+                    slot_clip_left = Math.min(posxy.x - oGlass.down_pos.x, 0);
+                    slot_clip_top = Math.min(posxy.y - oGlass.down_pos.y, 0);
+                    oGlass.drug = true;
+
+                    draw_clipped();
+                    if (e.preventDefault)
+                        e.preventDefault();
+                    return false;
+                }
+            }
+
+            var rpos = get_relative_event_pos(e);
+            if (rpos) {
+                get_slot_info(rpos.x, rpos.y);
+            }
+        }
+
+        this.downGlass = function (e) {
+            if (!e) var e = window.event;
+
+            var oGlass = document.getElementById("slot_glass");
+            if (oGlass) {
+                oGlass.dragging = true;
+                var posxy = get_event_pos(e);
+                oGlass.down_pos = {x: posxy.x - slot_clip_left, y: posxy.y - slot_clip_top};
+                clear_hover();
+                hide_info();
+            }
+            return false;
+        }
+
+        this.outGlass = function outGlass(e) {
+            if (!e) var e = window.event;
+            clear_hover();
+            hide_info();
+        }
+
+        this.zoom_in_slots = function (posxy) {
+            if (slot_zoom >= get_max_zoom()) return;
+            var click_info = vis.get_index(posxy.x, posxy.y);
+            slot_center_index = click_info.index;
+            do_zoom(slot_zoom + 1);
+        }
+
+        this.fire_slot_info = function (index) {
+            slot_last_index = index;
+            slot_info_timer = null;
+            do_info_request(index);
+        }
+
+        this.get_index = function (x, y) {
+            var width = slot_map_info.size;
+            var pngrow = Math.floor((y - slot_clip_top) / width);
+            var pngcol = Math.floor((x - slot_clip_left) / width);
+
+            if ((pngcol < slot_map_info.cols) && (pngrow < slot_map_info.rows)) {
+                var index = pngrow * slot_map_info.cols + pngcol;
+
+                if (index < slot_map_info.count)
+                    return {"index": index, "row": pngrow, "col": pngcol};
+            }
+
+            return null;
+        }
+
+    }
+
+    function slot_zoom_to(e) {
+        if (!e) var e = window.event;
+        var targ = get_event_target(e);
+        var level = parseInt(targ.level, 10);
+
+        get_center_index();
+        do_zoom(level);
+
+        if (e.stopPropagation)
+            e.stopPropagation()
+        else if (e.cancelBubble)
+            e.cancelBubble = true;
+    }
+
+    function do_zoom(level) {
+        var old_zoom = slot_zoom;
+        slot_zoom = level;
+
+        stop_auto_updates();
+        var oZooming = document.getElementById("slot_zooming");
+        if (oZooming) {
+            oZooming.style.display = "block";
+            //var oMap = document.getElementById(slot_current_id);
+            //if (oMap) {
+            //    oZooming.style.width = oMap.offsetWidth + "px";
+            //}
+        }
+        var oImg = document.images[slot_current_id];
+        if (oImg) {
+            var src = oImg.src;
+            var branch = wooly.session.branch(src);
+            branch.zl = level;
+            branch.zx = slot_clip_left;
+            branch.zy = slot_clip_top;
+            src = branch.marshal();
+            
+            src = cumin.refreshTime(src);
+            oImg.src = src;
+        }
+
+        animate_zoom_to(level);
+        return false;
+    }
+
+    function animate_zoom_to(level) {
+        var oPos = document.getElementById("zoom_pos");
+        if (oPos) {
+            var original_x = oPos.offsetLeft;
+            var now = new Date();
+            var x_amount = ((level - 1) * 13) - original_x;
+            animate_zoom_pos(original_x, (now-0), x_amount)
+        }
+    }
+
+    function animate_zoom_pos(original_x, original_time, x_amount) {
+        var oPos = document.getElementById("zoom_pos");
+
+        if (oPos) {
+            var now = new Date();
+            var delta = (now - original_time) / 400.0;
+            var partial = 1;
+
+            if (delta < 1)
+                partial = Math.sin(Math.PI/2 * delta);
+
+            oPos.style.left = Math.floor(original_x + x_amount * partial) + "px";
+
+            if (delta < 1) {
+                setTimeout(function() {
+                        animate_zoom_pos(original_x, original_time, x_amount)
+                }, 10);
+            }
+        }
+    }
+
+    function stop_auto_updates() {
+        if (slot_png_timer) {
+            clearInterval(slot_png_timer);
+            slot_png_timer = null;
+        }
+    }
+
+    function update_png() {
+        stop_auto_updates();
+        cumin.updateChart(slot_current_id, null);
+    }
+
+    function set_pan(id, which, value, fn) {
+        var obj = document.getElementById(id);
+        if (obj) {
+            if (value <= slot_clip_size) {
+                eval("obj.style." + which + " = '" + Math.min(value, slot_clip_size) + "px'");
+                obj.style.visibility = "hidden";
+                obj.onclick = null;
+            } else {
+                eval("obj.style." + which + " = '" + Math.min(value, slot_clip_size) + "px'");
+                obj.style.visibility = "visible";
+                obj.onclick = fn;
+            }
+        }
+    }
+
+    function slot_cookie_info() {
+        var slot_info = get_cookie("slot_info");
+        if (slot_info) {
+            var vals = slot_info.split("|");
+            if (vals.length == 6) {
+                slot_map_info.size = parseInt(vals[0], 10);
+                slot_map_info.width = parseInt(vals[1], 10);
+                slot_map_info.height = parseInt(vals[2], 10);
+                slot_map_info.count = parseInt(vals[3], 10);
+                slot_map_info.rows = parseInt(vals[4], 10);
+                slot_map_info.cols = parseInt(vals[5], 10);
+            }
+        }
+    }
+
+    function center_on_index() {
+        if (slot_center_index == -1) return;
+
+        var row = slot_center_index % slot_map_info.cols;
+        var col = Math.floor(slot_center_index / slot_map_info.cols);
+        var x = col * slot_map_info.size + slot_map_info.size / 2;
+        var y = row * slot_map_info.size + slot_map_info.size / 2;
+
+        var cl = (Math.min(slot_clip_size, slot_map_info.width) / 2) - x;
+        var ct = (Math.min(slot_clip_size, slot_map_info.height) / 2) - y;
+
+        if (slot_map_info.width + cl < slot_clip_size)
+            cl = slot_clip_size - slot_map_info.width;
+
+        if (slot_map_info.height + ct < slot_clip_size)
+            ct = slot_clip_size - slot_map_info.height;
+
+        if (cl > 0) cl = 0;
+        if (ct > 0) ct = 0;
+
+        slot_clip_left = Math.floor(cl);
+        slot_clip_top = Math.floor(ct);
+        slot_center_index = -1;
+    }
+
+    function get_center_index() {
+        var rx = Math.min(slot_clip_size, slot_map_info.width) / 2;
+        var ry = Math.min(slot_clip_size, slot_map_info.height) / 2;
+
+        var click_info = vis.get_index(rx, ry);
+        if (click_info)
+            slot_center_index = click_info.index;
+    }
+
+    function get_max_zoom() {
+        // allow to zoom until each slot is at least 28px wide
+        if ((slot_map_info.size == 0) || (slot_zoom == 0))
+            return 1;
+        return Math.ceil(28 / (slot_map_info.size / slot_zoom));
+    }
+
+    function initialize_zoom() {
+        var max_zoom = get_max_zoom();
+        var oZoom = document.getElementById("zoom_levels");
+        if ((oZoom) && (max_zoom > 1)) {
+            var oDiv, oText, oNode;
+            for (var i=0; i<max_zoom; i++) {
+                var oDiv = document.createElement("div");
+                if (i == 0) {
+                    oDiv.className = "zoom_first";
+                    oDiv.onclick = slot_zoom_to;
+                    oDiv.level = i+1;
+                    set_text(oDiv, (i+1)+ "", "zoom_node");
+                } else if (i == max_zoom - 1) {
+                    oDiv.className = "zoom_last";
+                    oDiv.onclick = slot_zoom_to;
+                    oDiv.level = i+1;
+                    set_text(oDiv, i+1, "zoom_node_last");
+                } else {
+                    oDiv.className = "zoom_middle_left";
+                    oDiv.onclick = slot_zoom_to;
+                    oDiv.level = i+1;
+                    oZoom.appendChild(oDiv);
+                    oDiv = document.createElement("div");
+                    oDiv.className = "zoom_middle_right";
+                    oDiv.onclick = slot_zoom_to;
+                    oDiv.level = i+1;
+                    set_text(oDiv, (i+1)+ "", "zoom_node");
+                }
+                oZoom.appendChild(oDiv);
+            }
+        } else {
+            var oControls = document.getElementById("slot_controls");
+            if (oControls) {
+                oControls.style.display = "none";
+            }
+        }
+        $("slot_visualization").style.display = "block";
+        cumin.makeFullPageable($("slot_visualization"));
+        slot_zoom_initialized = true;
+
+        function set_text(odiv, text, className) {
+            var oText = document.createElement("div");
+            var oNode = document.createTextNode(text+"");
+            oText.className = className;
+            oText.appendChild(oNode);
+            odiv.appendChild(oText);
+            oText.onclick = slot_zoom_to;
+            oText.level = text;
+        }
+    }
+
+    function draw_clipped() {
+
+        var clip_bottom;
+        var clip_right;
+        if (slot_map_info.width < slot_clip_size) {
+            clip_bottom = slot_map_info.height;
+            clip_right = slot_map_info.width;
+            slot_clip_left = 0;
+            slot_clip_top = 0;
+        } else {
+            var iZoom = slot_zoom;
+            var clip_width = slot_clip_size;
+            var clip_height = slot_clip_size;
+            clip_bottom = clip_height - slot_clip_top;
+            clip_right = clip_width - slot_clip_left;
+
+            if (clip_right > slot_map_info.width) {
+                slot_clip_left += (clip_right - slot_map_info.width);
+                clip_right = slot_map_info.width;
+            }
+            if (clip_bottom > slot_map_info.height) {
+                slot_clip_top = Math.min(clip_height - slot_map_info.height, 0);
+                clip_bottom = slot_map_info.height;
+            }
+        }
+
+        var oPng = document.getElementById("slot_png");
+        if (oPng) {
+            oPng.style.left = slot_clip_left + "px";
+            oPng.style.top = slot_clip_top + "px";
+            oPng.style.clip = "rect(" + (-slot_clip_top) + "px " + clip_right + "px " + clip_bottom + "px " + (-slot_clip_left) + "px)";
+        }
+    }
+
+
+    function animate_pan(original_edge, move, timer, which) {
+        var now = new Date();
+        var delta = (now - timer) / 400.0;
+        var expression = "=Math.floor(original_edge + move";
+        if (delta < 1) {
+            expression += " * Math.sin(Math.PI/2 * delta)";
+        }
+        expression += ")";
+        eval(which + expression);
+        draw_clipped();
+        if (delta < 1)
+            setTimeout( function () {animate_pan(original_edge, move, timer, which) }, 10);
+
+    }
+
+    function clear_hover() {
+        if (slot_info_timer) {
+            clearTimeout(slot_info_timer);
+            slot_info_timer = null;
+            slot_last_index = -1;
+        }
+        oHover = document.getElementById("slot_hover");
+        if (oHover) {
+            oHover.style.visibility = "hidden";
+        }
+    }
+
+    function hide_info() {
+        oInfo = $(slot_info_id);
+        if (oInfo) {
+            oInfo.style.visibility = "hidden";
+        }
+        slot_last_index = -1;
+    }
+
+    function get_slot_info(rx, ry) {
+        var click_info = vis.get_index(rx, ry);
+        if (click_info) {
+            if (click_info.index != slot_last_index) {
+                if (slot_info_timer) {
+                    clearTimeout(slot_info_timer);
+                    slot_info_timer = null;
+                }
+                if (slot_hover_timer) {
+                    clearTimeout(slot_hover_timer);
+                    slot_hover_timer = null;
+                }
+                slot_info_timer = setTimeout( function() { vis.fire_slot_info(click_info.index) }, 500);
+                animate_hover(0, click_info.row, click_info.col);
+                oInfo = $(slot_info_id);
+                if (oInfo) {
+                    oInfo.style.display = "none";
+                }
+            }
+        }
+    }
+
+    function animate_hover(leg, row, col) {
+        var oHover = document.getElementById("slot_hover");
+        if (oHover) {
+            if (slot_hover_timer) {
+                clearTimeout(slot_hover_timer);
+                slot_hover_timer = null;
+            }
+            var width = slot_map_info.size;
+            if (width == 0) return;
+            var rx = col * width + slot_clip_left;
+            var ry = row * width + slot_clip_top;
+            oHover.style.width = (width-1) + "px";
+            oHover.style.height = (width-1) + "px";
+
+            switch (leg) {
+            case 0:
+                    oHover.style.left = rx + "px";
+                    oHover.style.top = ry + "px";
+                    oHover.style.width = width + "px";
+                    oHover.style.height = width + "px";
+                    oHover.style.borderColor = "red pink pink pink";
+                    oHover.style.visibility = "visible";
+                    if ((rx < 0) || (ry < 0) || (rx + width > slot_clip_size) || (ry + width > slot_clip_size)) {
+                        var cx = (rx < 0) ? rx : 0;
+                        var cy = (ry < 0) ? ry : 0;
+                        var cw = (rx + width > slot_clip_size) ? slot_clip_size - rx  : width + 1;
+                        var ch = (ry + width > slot_clip_size) ? slot_clip_size - ry  : width + 1;
+                        oHover.style.clip = "rect(" + (-cy) + "px " + (cw) + "px " + (ch) + "px " + (-cx) + "px)";
+                    } else {
+                        oHover.style.clip = "rect(0px " + (width+1) + "px " + (width+1) + "px 0px)";
+                    }
+                    slot_hover_timer = setTimeout( function() {animate_hover(1)}, 500/3);
+                    break;
+            case 1: oHover.style.borderColor = "red red pink pink";
+                    slot_hover_timer = setTimeout( function() {animate_hover(2)}, 500/3);
+                    break;
+            case 2: oHover.style.borderColor = "red red red pink";
+                    slot_hover_timer = setTimeout( function() {animate_hover(3)}, 500/3);
+                    break;
+            case 3: oHover.style.borderColor = "red red red red";
+                    break;
+            }
+        }
+    }
+
+    function refire_info() {
+        if (slot_last_index > -1) {
+            do_info_request(slot_last_index)
+        }
+    }
+
+    function do_info_request(index) {
+        var branch = wooly.session.branch(slot_info_url);
+        branch.session[slot_info_index] = index;
+        var newreq = branch.marshal();
+        wooly.setIntervalUpdate(newreq, got_slot_info, 0, {index: index});
+    }
+
+    function got_slot_info(xhtml, args) {
+        if (slot_last_index == -1) return;
+        var oInfo = $(slot_info_id);
+        var slot_clicked = null;
+        if (oInfo) {
+            oInfo.style.display = "none";
+            if (oInfo.slot_clicked) {
+                slot_clicked = oInfo.slot_clicked;
+                oInfo.slot_clicked = null;
+            }
+        }
+        wooly.updatePage(xhtml);
+        var oInfo = $(slot_info_id);
+        if (oInfo) {
+            oInfo.click_index = args.index;
+            oInfo.slot_clicked = null;
+            if (slot_clicked) {
+                clicks.doClick(slot_clicked.x, slot_clicked.y);
+                return;
+            }
+
+            document.body.appendChild(oInfo); // so position is absolute to entire page
+
+            //oInfo.style.left = "-1000px";
+            //oInfo.style.visibility = "hidden";
+            oInfo.style.display = "block";
+
+            var oMap = document.getElementById(slot_current_id);
+            if (oMap) {
+                var abs_pos = findPos(oMap);
+
+                // top of clicked slot is here
+                var y = Math.floor(args.index / slot_map_info.cols) * slot_map_info.size + slot_clip_top;
+
+                // candidate pos for popup
+                // just under the clicked slot
+                var topUnder = (abs_pos.y + y) + Math.floor(slot_map_info.size * 1.5);
+                var top = topUnder;
+                
+                // if off the bottom of the map
+                if (topUnder + oInfo.offsetHeight > abs_pos.y + oMap.offsetHeight) {
+                    // position popup above clicked slot
+                    top = (abs_pos.y + y) - oInfo.offsetHeight - Math.floor(slot_map_info.size * .5);
+                }
+
+                // if off the top of the page
+                if (top < 0) {
+                    // revert to under the item
+                    top = topUnder;
+                }
+
+                oInfo.style.top = top + "px";
+                oInfo.style.left = abs_pos.x + "px";
+            }
+            oInfo.style.visibility = "visible";
+        }
+    }
+
+}())
+
+var clicks;
+
+(function() {
+    clicks = new Clicks();
+
+    function Clicks() {
+         this.doubleclick_when = 0;
+         this.click_when = 0;
+         this.click_handle = null;
+
+        this.doMouseDown = function(e) {
+            if (!e) var e = window.event;
+            var which = e.type;
+            switch (which) {
+             case "click":
+               // If we've just had a doubleclick then ignore it
+               if (hadDoubleClick()) return false;
+               // Otherwise set timer to act.  It may be preempted by a doubleclick.
+               d = new Date();
+               clicks.click_when = d.getTime();
+                var rpos = get_relative_event_pos(e);
+                if (rpos) {
+                    clicks.click_handle = setTimeout( function() {clicks.doClick(rpos.x, rpos.y)}, 250);
+                    break;
+                }
+             case "dblclick":
+               doDoubleClick(e);
+               break;
+             default:
+           }
+        }
+
+        this.doClick = function(x, y) {
+            // preempt if DC occurred after original click.
+            if (this.click_when - this.doubleclick_when <= 0) {
+                return false;
+            }
+            var oGlass = document.getElementById("slot_glass");
+            if (oGlass) {
+                if (oGlass.drug) {
+                    oGlass.drug = false;
+                    return false;
+                }
+            }
+            var click_info = vis.get_index(x, y);
+            var oInfo = $(slot_info_id);
+            if (oInfo && click_info) {
+                if ((typeof oInfo.click_index != "undefined") &&
+                    (oInfo.click_index == click_info.index)) {
+                    // we already fetched the info for this slot
+                    var oInfoCellId = document.getElementById("slotInfo_id");
+                    if (oInfoCellId) {
+                        var slotid = oInfoCellId.innerHTML;
+                        if (slotid != "") {
+                            go_to_slot(slotid);
+                            return false;
+                        }
+                    }
+                } else {
+                    // fetch the slot info so we can get the slot id
+                    oInfo.slot_clicked = {fetching: true, x: x, y: y};
+                    vis.fire_slot_info(click_info.index);
+                }
+            }
+        }
+    }
+
+    function hadDoubleClick() {
+       var d = new Date();
+       var now = d.getTime();
+       if ((now - this.doubleclick_when) < 100) {
+         return true;
+       }
+       return false;
+    }
+
+    function doDoubleClick(e) {
+       var now = new Date();
+       clicks.doubleclick_when = now.getTime();
+       if (clicks.click_handle != null) {
+         clearTimeout(clicks.click_handle);          // Clear pending Click
+         clicks.click_handle = null;
+       }
+       if (!e) var e = window.event;
+       var posxy = get_relative_event_pos(e);
+       vis.zoom_in_slots(posxy);
+    }
+}())
+
+function go_to_slot(id) {
+    if (show_slot_url != "") {
+        var branch = wooly.session.branch(show_slot_url);
+        branch[branch.frame + ".id"] = id;
+        window.location.href = branch.marshal();
+    }
+}
+function vis_clicked(slot) {
+    go_to_slot(slot);
+}
+/* generic get value from cookie */
+function get_cookie(name) {
+    return get_value(document.cookie, name, ";");
+}
+
+/* generic get value from string */
+function get_value(s, name, sep) {
+    var name_plus = name + "=";
+    var crumbs = s.split(sep);
+    // splitting to avoid false match on substring:
+    // ex: bigfoo=duh;foo=blah;
+    for(var i=0; i < crumbs.length; i++) {
+        var c = crumbs[i];
+        while (c.charAt(0) == ' ') {
+            c = c.substring(1, c.length);
+        }
+
+        if (c.indexOf(name_plus) == 0) {
+            return c.substring(name_plus.length,c.length);
+        }
+    }
+    return null;
+}
+
+/* generic replace a value in a name=value; string */
+function replace_value(s, name, value, sep) {
+    var name_index = s.indexOf(name+"=");
+    if (name_index > -1) {
+        var sep_index = s.indexOf(sep, name_index);
+        if (sep_index == -1) { // end of string
+            sep_index = s.length;
+        }
+        var s1 = s.substring(0, name_index + name.length + 1);
+        var s2 = value + "";
+        var s3 = s.substring(sep_index);
+        return s1 + s2 + s3;
+    }
+    return s;
+}
+
+/* get the absolute position of something */
+function findPos(obj) {
+    var curleft = curtop = 0;
+    if (obj.offsetParent) {
+        do {
+                curleft += obj.offsetLeft;
+                curtop += obj.offsetTop;
+            } while (obj = obj.offsetParent);
+        return {x: curleft, y: curtop};
+    }
+}
+
+/* get the absolute event position */
+function get_event_pos(e) {
+    if (e.pageX || e.pageY)     {
+        posx = e.pageX;
+        posy = e.pageY;
+    }
+    else if (e.clientX || e.clientY)    {
+        posx = e.clientX + document.body.scrollLeft
+            + document.documentElement.scrollLeft;
+        posy = e.clientY + document.body.scrollTop
+            + document.documentElement.scrollTop;
+    }
+    return {"x": posx, "y": posy};
+}
+
+/* find out what element the event was the event target */
+function get_event_target(e) {
+    var targ = null;
+    if (e.target)
+        targ = e.target;
+    else if (e.srcElement)
+        targ = e.srcElement;
+    if (targ.nodeType == 3) // avoid Safari textNode bug
+        targ = targ.parentNode;
+    return targ;
+}
+
+/* get the event position relatave to the event target */
+function get_relative_event_pos(e) {
+    var targ = get_event_target(e);
+    if (targ) {
+        var pxy = findPos(targ);
+        var posxy = get_event_pos(e);
+
+        var rx = posxy.x - pxy.x  - 2;
+        var ry = posxy.y - pxy.y - 2;
+        return {x: rx, y: ry};
+    }
+}
+



More information about the rhmessaging-commits mailing list