source: DASISH/t5.6/client/trunk/chrome/markingcollection/content/markingcollection/imagetooltip.js @ 2711

Last change on this file since 2711 was 2711, checked in by olof, 11 years ago

moved to trunk

File size: 4.8 KB
Line 
1var bitsImageTooltip = {
2        tooltipRow : -1,
3        tooltipTimer : null,
4
5        get TOOLTIP() { return window.top.document.getElementById("MarkingCollectionImageTooltip"); },
6        get CANVAS()  { return window.top.document.getElementById("MarkingCollectionImageTooltipCanvas"); },
7        get SIDEBAR() { return window.top.document.getElementById("sidebar"); },
8
9        get Database(){ return window.top.bitsObjectMng.Database; },
10
11        init : function(){},
12
13        done : function(){},
14
15        onMousedown : function(aEvent){
16                bitsImageTooltip.hidePopup();
17        },
18
19        onMouseout : function(aEvent){
20                bitsImageTooltip.hidePopup();
21        },
22
23        hidePopup : function(){
24                if(bitsImageTooltip.tooltipTimer) clearTimeout(bitsImageTooltip.tooltipTimer);
25                bitsImageTooltip.tooltipTimer = null;
26                bitsImageTooltip.TOOLTIP.hidePopup();
27                bitsImageTooltip.tooltipRow = -1;
28        },
29
30        onMousemove : function(aEvent,aParam){
31                bitsImageTooltip.hidePopup();
32                if(aParam.tree && (aParam.row == undefined || bitsImageTooltip.tooltipRow == aParam.row.value) )return;
33                bitsImageTooltip.tooltipTimer = setTimeout(
34                        function(){
35                                bitsImageTooltip._onMousemove(aParam);
36                        },500)
37        },
38
39        _onMousemove : function(aParam){
40                try {
41                        if(aParam.tree){
42                                var curIdx = aParam.row.value;
43                                bitsImageTooltip.tooltipRow = curIdx;
44                                if(aParam.tree.view.isContainer(curIdx)){
45                                        bitsImageTooltip.TOOLTIP.hidePopup();
46                                        return;
47                                }
48                        }
49                        if(!aParam.obj){
50                                bitsImageTooltip.TOOLTIP.hidePopup();
51                                return;
52                        }
53                        if(aParam.obj.oid_type.match(/^image\/(.+)$/)){
54                                var itemX = {};
55                                var itemY = {};
56                                var width = {};
57                                var height = {};
58                                var screenX = 0;
59                                var screenY = 0;
60                                if(aParam.tree){
61                                        aParam.tree.treeBoxObject.getCoordsForCellItem(aParam.row.value,aParam.col.value,aParam.childElt.value,itemX,itemY,width,height);
62                                        screenX = aParam.tree.treeBoxObject.screenX;
63                                        screenY = aParam.tree.treeBoxObject.screenY;
64                                }else if(aParam.menuitem){
65                                        itemX.value = aParam.menuitem.boxObject.x;
66                                        itemY.value = aParam.menuitem.boxObject.y;
67                                        width.value = aParam.menuitem.boxObject.width;
68                                        height.value = aParam.menuitem.boxObject.height;
69                                        screenX = aParam.menuitem.boxObject.screenX;
70                                        screenY = aParam.menuitem.boxObject.screenY;
71                                }
72                                var blob = bitsImageTooltip.Database.getObjectBLOB(aParam.obj.oid,aParam.obj.dbtype);
73                                if(blob && blob.length>0 && blob[0].length>0){
74                                        var images = String.fromCharCode.apply(String, blob[0]);
75                                        var image_b64 = btoa(images); // base64 encoding
76                                        image_b64 = 'data:' + aParam.obj.oid_type + ';base64,' + image_b64;
77                                        var img = new Image();
78                                        img.src = image_b64;
79                                        img.onload = function(){
80                                                if(bitsImageTooltip.updatePreview(img)){
81                                                        var x=0;
82                                                        var y=0;
83                                                        if(aParam.tree){
84                                                                x = screenX + itemX.value - parseInt((top.outerWidth-top.innerWidth)/2);
85                                                                y = screenY + itemY.value;
86                                                                if(aParam.tree && aParam.tree.id == "bitsItemTree"){
87                                                                        x += width.value;
88                                                                        y += height.value+4;
89                                                                }
90                                                        }else if(aParam.menuitem){
91                                                                x = screenX + parseInt(width.value/3);
92                                                                y = screenY;
93                                                        }
94                                                        if(bitsImageTooltip.tooltipTimer) clearTimeout(bitsImageTooltip.tooltipTimer);
95                                                        bitsImageTooltip.showPreview(x,y,aParam);
96                                                }else{
97                                                        bitsImageTooltip.hidePopup();
98                                                }
99                                                img = undefined;
100                                        }
101                                }else{
102                                        bitsImageTooltip.TOOLTIP.hidePopup();
103                                }
104                        }else{
105                                bitsImageTooltip.TOOLTIP.hidePopup();
106                        }
107                }catch(ex){
108                        window.top.bitsObjectMng._dump('bitsImageTooltip.onMousemove():' + ex);
109                        bitsImageTooltip.TOOLTIP.hidePopup();
110                }
111        },
112
113        updatePreview: function(aImage){
114                var canvas = bitsImageTooltip.CANVAS;
115                var tooltip = bitsImageTooltip.TOOLTIP;
116                var canvasW = aImage.width;
117                var canvasH = aImage.height;
118                canvas.style.width = canvasW+"px";
119                canvas.style.height = canvasH+"px";
120                canvas.width = canvasW;
121                canvas.height = canvasH;
122
123                var width = canvasW;
124                var height = canvasH;
125                var tWIDTH = 480;
126                if(canvasW > tWIDTH){
127                        width = tWIDTH-14;
128                        height = parseInt((canvasH*width)/canvasW);
129                        canvas.style.width = width+"px";
130                        canvas.style.height = height+"px";
131                        canvas.width = width;
132                        canvas.height = height;
133                }
134                try{
135                        if(!canvas.getContext) return false;
136                        var ctx = canvas.getContext("2d");
137                        ctx.clearRect(0, 0, canvasW, canvasH);
138                        ctx.save();
139                        ctx.scale(width/canvasW, height/canvasH);
140                        ctx.drawImage(aImage,0,0);
141                        ctx.restore();
142                }
143                catch(ex){
144                        window.top.bitsObjectMng._dump('bitsImageTooltip.updatePreview():' + ex);
145                        return false;
146                }
147                return true;
148  },
149
150        showPreview: function(x, y, aParam){
151                if(this.tooltipTimer) clearTimeout(this.tooltipTimer);
152                this.tooltipTimer = null;
153                if(this.TOOLTIP.openPopupAtScreen){
154                        this.TOOLTIP.openPopupAtScreen(x, y, false);
155                }else{
156                        if(aParam.tree){
157                                this.TOOLTIP.showPopup(this.SIDEBAR, x, y, "tooltip");
158                        }else if(aParam.menuitem){
159                        }
160                }
161  },
162
163};
Note: See TracBrowser for help on using the repository browser.