forked from apache/cloudstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoolTip.js
More file actions
170 lines (136 loc) · 5.36 KB
/
Copy pathtoolTip.js
File metadata and controls
170 lines (136 loc) · 5.36 KB
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
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
(function($, cloudStack) {
$.widget("cloudStack.toolTip", {
_init: function(args) {
var context = this.options.context;
var dataProvider = this.options.dataProvider;
var actions = this.options.actions;
var docID = this.options.docID;
var text = cloudStack.docs[docID].desc;
var $tooltip = $('<div>').addClass('tooltip-box');
var $text = $('<p>').html(text).appendTo($tooltip);
var $container = $('#cloudStack3-container');
$tooltip.appendTo($container);
if (this.options.mode == 'hover') {
$(this.element).hover(hoverHandler, outHandler);
} else if (this.options.mode == 'focus') {
$(this.element).focus(hoverHandler);
$(this.element).blur(outHandler);
} else if (this.options.mode == 'manual') {}
$(this.element).data('$tooltip', $tooltip);
// Add arrow
$tooltip.append($('<div></div>').addClass('arrow'));
$tooltip.hide();
},
show: function() {
var o = this.options;
if (o.mode == 'manual') {
prepare(this.element, o);
}
$(o.toolTip).show();
},
hide: function() {
var o = this.options;
$(o.toolTip).hide();
}
});
$.extend($.cloudStack.toolTip, {
defaults: {
toolTip: '',
onShow: function(sender) {
//Flipping arrow and text
var $tooltip = $('.tooltip-box');
//Switch styles based on how close to viewport border
if ($(window).width() - sender.target.offset().left <= $tooltip.width()) {
$('.tooltiptextleft', $tooltip).removeClass('tooltiptextleft').addClass('tooltiptextright');
$('.tooltiparrowleft', $tooltip).removeClass('tooltiparrowleft').addClass('tooltiparrowright');
} else {
$('.tooltiptextright', $tooltip).removeClass('tooltiptextright').addClass('tooltiptextleft');
$('.tooltiparrowright', $tooltip).removeClass('tooltiparrowright').addClass('tooltiparrowleft');
}
},
onHide: undefined,
mode: 'hover',
// provide a speed for the animation
speed: 1000,
// provide a period for the popup to keep showing
period: 2000,
// default the animation algorithm to the basic slide
animation: 'slide'
},
animations: {
slide: function(e, options) {
},
fade: function(e, options) {
}
}
});
function hoverHandler(event) {
//Fetch Options
var o = $.data(this, 'toolTip').options;
//Element who raised the event
var $this = $(this);
//Helper functon for Positioning and Calling Callback function
prepare($this, o);
//Call Show method of the tooltip Widget,
//Show method should play on any required animations
$.data(this, '$tooltip').show();
};
function outHandler(event) {
//Fetch Options
var o = $.data(this, 'toolTip').options;
//Get tooptip Element
var $tooltip = $(o.toolTip);
//If call back method defined, initiate the call
if ($.data(this, 'toolTip').options.onHide) {
$.data(this, 'toolTip').options.onHide.call(this, {
target: $(this)
});
}
//Call Hide method of the tooltip Widget,
//Hide method should play on any required animations
$.data(this, '$tooltip').hide();
};
function prepare(jObj, options) {
var $tooltip = $(options.tooltip);
var element = options.attachTo ?
jObj.closest(options.attachTo) : jObj;
var offset = element.offset();
var left = offset.left + element.width();
var top = offset.top - 5;
if (options.onShow) {
options.onShow.call(this, {
target: jObj
});
}
if ($(window).width() - offset.left <= $tooltip.width()) {
left = offset.left - $tooltip.width();
} else {
left += 35;
}
$tooltip.css({
position: 'absolute',
top: top + 'px',
left: left + 'px'
});
// Fix overlay
setTimeout(function() {
$('.tooltip-box').zIndex($(':ui-dialog').zIndex() + 10);
});
};
})(jQuery, cloudStack);