-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathraphaeljs-infobox.js
46 lines (40 loc) · 1.96 KB
/
raphaeljs-infobox.js
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
// Copyright 2012: Kelley Reynolds, RubyScale
// http://rubyscale.com/blog/2010/11/22/embedding-arbitrary-html-into-raphaeljs/
// Takes a raphaeljs object, some options, and some container attributes
function Infobox(r, options, attrs) {
options = options || {};
attrs = attrs || {};
this.paper = r;
this.x = options.x || 0;
this.y = options.y || 0;
this.width = options.width || this.paper.width;
this.height = options.height || this.paper.height;
this.rounding = options.rounding || 0;
this.show_border = options.with_border || false;
this.container = this.paper.rect(this.x, this.y, this.width, this.height, this.rounding).attr(attrs);
var container_id = this.container.node.parentNode.parentNode.id;
container_id = container_id || this.container.node.parentNode.parentNode.parentNode.id;
this.raph_container = jQuery('#' + container_id);
if (!this.show_border) { this.container.hide(); }
this.div = jQuery('<div style="position: absolute; overflow: auto; width: 0; height: 0;"></div>').insertAfter(this.raph_container);
jQuery(document).bind('ready', this, function(event) { event.data.update(); });
jQuery(window).bind('resize', this, function(event) { event.data.update(); });
}
Infobox.prototype.update = function() {
var offset = this.raph_container.offset();
this.div.css({
'top': (this.y + (this.rounding) + (offset.top)) + 'px',
'left': (this.x + (this.rounding) + (offset.left)) + 'px',
'height': (this.height - (this.rounding*2) + 'px'),
'width': (this.width - (this.rounding*2) + 'px')
});
}
// Note that the fadein/outs for the content div are at double speed. With frequent animations, it gives the best behavior
Infobox.prototype.show = function() {
this.container.animate({opacity: 1}, 400, ">");
this.div.fadeIn(200);
}
Infobox.prototype.hide = function() {
this.container.animate({opacity: 0}, 400, ">");
this.div.fadeOut(200);
}