forked from giteshgoyal/webhelp-element-polymer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelp-behavior.html
73 lines (57 loc) · 2.38 KB
/
help-behavior.html
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
<script>
var help_data = '[]';
var x;
var y;
var MyBehaviors = MyBehaviors || {};
MyBehaviors.HelpBehavior = {
_showHelp:function( element,title, msg,version) {
/**************************************** Fetch Coordinates Of Target Element ***********************************************/
var box = element.getBoundingClientRect();
var body = document.body;
var docEl = document.documentElement;
var scrollTop = window.pageYOffset || docEl.scrollTop || body.scrollTop;
var scrollLeft = window.pageXOffset || docEl.scrollLeft || body.scrollLeft;
var clientTop = docEl.clientTop || body.clientTop || 0;
var clientLeft = docEl.clientLeft || body.clientLeft || 0;
var top = box.top + scrollTop - clientTop;
var left = box.left + scrollLeft - clientLeft;
var bottom=top+(box.bottom-box.top);
var right=left+(box.right-box.left);
var rect_width= box.right-box.left;
var rect_height=box.bottom-box.top;
var w = window,
d = document,
e = d.documentElement,
g = d.getElementsByTagName('body')[0],
width = w.innerWidth || e.clientWidth || g.clientWidth,
height = w.innerHeight|| e.clientHeight|| g.clientHeight;
//*********************************End OF Fetch Coordinates Of Target Element ********************************************/
// ********************* Determining the position on element where to display help **********************
if(left > width*5/6)
x= left;
else
x= right;
if(top > height*2/3)
y= top;
else
y= bottom;
// ********************* End Of Determining the position on element where to display help **********************/
//*************************************************** Push Data In Array ***********************************/
if(x!=0 && y!=0){
this.fire('iron-signal', {name: 'tour', data: {
"id": element.id,
"title": title,
"message": msg,
"x" : x,
"y" : y,
"el_top":top,
"el_left":left,
"el_width":rect_width,
"el_height":rect_height,
"version":version||1
}});
}
//*************************************************End Of Push Data In Array ***********************************/
}
};
</script>