summaryrefslogtreecommitdiffstats
path: root/bubble.js
blob: 600407bd5af36bc464664d4cb3c539cc6f0376b6 (plain)
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
/*
    WebSnapr - Preview Bubble Javascript
    Written by Juan Xavier Larrea 
    http://www.websnapr.com - xavier@websnapr.com   
    
*/

// Point this variable to the correct location of the bg.png file
var bubbleImageUp = 'resources/bubble_up.png';
var bubbleImageDown = 'resources/bubble_down.png';

if(typeof Array.prototype.push!="function"){
   Array.prototype.push=ArrayPush;

   function ArrayPush(_1){
      this[this.length]=_1;
   }
}

function WSR_getElementsByClassName(_2,_3,_4){

   var _5=(_3=="*"&&_2.all)?_2.all:_2.getElementsByTagName(_3);
   var _6=new Array();
   _4=_4.replace(/\-/g,"\\-");
   var _7=new RegExp("(^|\\s)"+_4+"(\\s|$)");
   var _8;
   for(var i=0;i<_5.length;i++){
      _8=_5[i];
      if(_7.test(_8.className)){
         _6.push(_8);
      }
   }
   return (_6);
}

function bindBubbles(e){
   lbActions=WSR_getElementsByClassName(document,"a","bubble");
   for(i=0;i<lbActions.length;i++){
      if(window.addEventListener){
         lbActions[i].addEventListener("mouseover",attachBubble,false);
         lbActions[i].addEventListener("mouseout",detachBubble,false);
      }else{
         lbActions[i].attachEvent("onmouseover",attachBubble);
         lbActions[i].attachEvent("onmouseout",detachBubble);
      }
   }
}

function attachBubble(_b){
   var _c;
   if(_b["srcElement"]){
      _c=_b["srcElement"];
   }else{
      _c=_b["target"];
   }
   if (_c.href == undefined){
      _c=_c.parentNode;
   }

   var _d=_c.href;
   var _10=document.createElement("div");
   document.getElementsByTagName("body")[0].appendChild(_10);
   _10.className="bubble";

   var _e=findPos(_c)[0]+5;
   var cur_height = findPos(_c)[1]-get_scroll_position() + 283;

   // should the bubble be displayed above or below the object
   if(cur_height >= get_page_height()) {
      var _f=findPos(_c)[1]-283;
      var _mT=16;
      var _mL=12;
      bubbleImage = bubbleImageUp;
   }
   else {
      var _f=findPos(_c)[1]+17;
      var _mT=27;
      var _mL=12;
      bubbleImage = bubbleImageDown;
   }

   if (BrowserDetect.browser == 'Explorer') {
      _10.style.width="240px";
      _10.style.position="absolute";
      _10.style.top=_f;
      _10.style.zIndex=99999;
      _10.style.left=_e;
      _10.style.textAlign="left";
      _10.style.height="190px";
      _10.style.paddingTop="0";
      _10.style.paddingLeft="0";
      _10.style.paddingBottom="0";
      _10.style.paddingRight="0";
      _10.style.marginTop="0";
      _10.style.marginLeft="0";
      _10.style.marginBottom="0";
      _10.style.marginRight="0";
      _10.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + bubbleImage + "',sizingMethod='image')";
   } else {
      _10.setAttribute("style","text-align: center; z-index: 99999; position: absolute; top: "+_f+"px ; left: "+_e+"px ; background: url("+ bubbleImage +") no-repeat; width: 240px; height: 190px; padding: 0; margin: 0;");
   }

   if (BrowserDetect.browser == 'Safari' || BrowserDetect.browser == 'Konqueror' ) {

      var _height = _f;
    
      _10.setAttribute("style","text-align: center; z-index: 99999; position: absolute; top: "+ _height +"px ; left: "+_e+"px ; background: url("+ bubbleImage +") no-repeat; width: 240px; height: 190px; padding: 0; margin: 0;");
    
   }

   var img=document.createElement("img");
   _10.appendChild(img);

   if (BrowserDetect.browser == 'Explorer') {
      img.style.paddingTop="0";
      img.style.paddingLeft="0";
      img.style.paddingBottom="0";
      img.style.paddingRight="0";
      img.style.margin="auto";
      img.style.marginTop=_mT;
      img.style.marginLeft=_mL;
      img.style.marginBottom="0";
      img.style.marginRight="0";
      img.style.borderTop="0";
      img.style.borderLeft="0";
      img.style.borderBottom="0";
      img.style.borderRight="0";
   } else {
      img.setAttribute("style","padding-top: 0; padding-left: 0; padding-right: 0; padding-bottom: 0; margin-top: " + _mT +"px; margin-left: " + _mL +"px; margin-bottom: 0; margin-right: 0; border: 0");
   }
   img.setAttribute("src","phpfspot_img.php?idx=" + _c.id + "&width=200");
   img.setAttribute("width",202);
   img.setAttribute("height",152);
   img.setAttribute("alt","Snapshot");
}

function detachBubble(_12){
   lbActions=WSR_getElementsByClassName(document,"div","bubble");
   for(i=0;i<lbActions.length;i++){
      lbActions[i].parentNode.removeChild(lbActions[i]);
   }
}

/*if(window.addEventListener){
   addEventListener("load",bindBubbles,false);
}else{
   attachEvent("onload",bindBubbles);
}*/

function findPos(obj){
   var _14=curtop=0;
   if(obj.offsetParent){
      _14=obj.offsetLeft;
      curtop=obj.offsetTop;
      while(obj=obj.offsetParent){
         _14+=obj.offsetLeft;
         curtop+=obj.offsetTop;
      }
   }
   return [_14,curtop];
}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};

function var_dump(obj) {
   if(typeof obj == "object") {
      return "Type: "+typeof(obj)+((obj.constructor) ? "\nConstructor: "+obj.constructor : "")+"\nValue: " + obj;
   } else {
      return "Type: "+typeof(obj)+"\nValue: "+obj;
   }
}//end function var_dump

function get_page_height()
{
   var myHeight = 0;
   if( typeof( window.innerHeight ) == 'number' ) {
      //Non-IE
      myHeight = window.innerHeight;
   } else if( document.documentElement && document.documentElement.clientHeight  ) {
      //IE 6+ in 'standards compliant mode'
      myHeight = document.documentElement.clientHeight;
   } else if( document.body &&  document.body.clientHeight ) {
      //IE 4 compatible
      myHeight = document.body.clientHeight;
   }

   return myHeight;
}

function get_scroll_position()
{

  if (typeof window.pageYOffset != 'undefined')
    return window.pageYOffset;
  else
    if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat')
      return window.scrollTop;
    else
      if (typeof document.body != 'undefined')
        return document.body.scrollTop;

}

BrowserDetect.init();