summaryrefslogtreecommitdiffstats
path: root/bubble.js
blob: d44780e4ab22cb12a7402691c3c5dd195fb51515 (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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
/*
    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(oElm, strTagName, oClassNames){
   var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
   var arrReturnElements = new Array();
   var arrRegExpClassNames = new Array();
   if(typeof oClassNames == "object"){
      for(var i=0; i<oClassNames.length; i++){
         arrRegExpClassNames.push(new RegExp("(^|\s)" + oClassNames[i].replace(/-/g, "\-") + "(\s|$)"));
      }
   }
   else{
      arrRegExpClassNames.push(new RegExp("(^|\s)" + oClassNames.replace(/-/g, "\-") + "(\s|$)"));
   }
   var oElement;
   var bMatchesAll;
   for(var j=0; j<arrElements.length; j++){
      oElement = arrElements[j];
      bMatchesAll = true;
      for(var k=0; k<arrRegExpClassNames.length; k++){
         if(!arrRegExpClassNames[k].test(oElement.className)){
            bMatchesAll = false;
            break;
         }
      }
      if(bMatchesAll){
         arrReturnElements.push(oElement);
      }
   }
   return (arrReturnElements)
}
/*function WSR_getElementsByClassName(_2,_3,_4){

   var _5=(_3=="*"&&_2.all)?_2.all:_2.getElementsByTagName(_3);
         window.alert(_5[0]);
   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,"img","thumb");
   for(i=0;i<lbActions.length;i++){
      if(window.addEventListener){ // Mozilla, Firefox
         lbActions[i].addEventListener("mouseover",attachBubble,false);
         lbActions[i].addEventListener("mouseout",detachBubble,false);
         lbActions[i].addEventListener("click",detachBubble,false);
      }else if (window.attachEvent) { // IE
         lbActions[i].attachEvent("onmouseover",attachBubble);
         lbActions[i].attachEvent("onmouseout",detachBubble);
         lbActions[i].attachEvent("onclick",detachBubble);
      } else {
         // it seems this browser doesn't support any eventhandling
      }  
   }
}

function attachBubble(_b){
   var _c;
   if(_b["srcElement"]){ // IE
      _c=_b["srcElement"];
   }else{ // Mozilla, Firefox
      _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";

   if(BrowserDetect.browser != 'Explorer') {

      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]-363;
         bubbleImage = bubbleImageUp;
      }
      else {
         var _f=findPos(_c)[1]+17;
         bubbleImage = bubbleImageDown;
      }
   }
   else {
         var _e=findPos(_c)[0]+5;
         var _f=findPos(_c)[1]+129;
         bubbleImage = bubbleImageDown;
   }
   if (BrowserDetect.browser == 'Explorer') {
      _10.style.width="275px";
      _10.style.height="275px";
      _10.style.position="absolute";
      _10.style.top=_f;
      _10.style.zIndex=99999;
      _10.style.left=_e;
      _10.style.textAlign="left";
      _10.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + bubbleImage + "',sizingMethod='image')";
   } else if (BrowserDetect.browser == 'Safari' || BrowserDetect.browser == 'Konqueror' ) {
      _10.setAttribute("style","text-align: center; z-index: 99999; position: absolute; top: "+ _f +"px ; left: "+ _e +"px ; background: url("+ bubbleImage +") no-repeat; width: 275px; height: 275px; padding: 0; margin: 0;");
   } else {
      _10.setAttribute("style","text-align: center; z-index: 99999; position: absolute; top: "+_f+"px ; left: "+ _e +"px ; background: url("+ bubbleImage +") no-repeat; width: 275px; height: 275px; padding: 0; margin: 0;");
   }

   if(cur_height >= get_page_height()) 
      showBubbleDetails(_10, _c.id, 'up');
   else
      showBubbleDetails(_10, _c.id, 'down');

}

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

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(arr,level) {
   var dumped_text = "";
   if(!level) level = 0;
   
   //The padding given at the beginning of the line.
   var level_padding = "";
   for(var j=0;j<level+1;j++) level_padding += "    ";
   
   if(typeof(arr) == 'object') { //Array/Hashes/Objects 
      for(var item in arr) {
         var value = arr[item];
         
         if(typeof(value) == 'object') { //If it is an array,
            dumped_text += level_padding + "'" + item + "' ...\n";
            dumped_text += dump(value,level+1);
         } else {
            dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
         }
      }
   } else { //Stings/Chars/Numbers etc.
      dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
   }
   return dumped_text;

}//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' &&
         typeof window.scrollTop != 'undefined')
         return window.scrollTop;
      else {
         if(typeof document.documentElement.scrollTop != 'undefined')
            return document.documentElement.scrollTop;
         else {
            if (typeof document.body.scrollTop != 'undefined')
               return document.body.scrollTop;
         }
      }
   }

   return 0;

}

BrowserDetect.init();