pageToolManager.js
13.5 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
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
/**
* Created by lsj on 2015/4/1.
*/
var pageToolmanager = (function(){
function getShowView(item){
var temp = "<div class='des_container'>"
+"<h3 class='des_title'>"+item.title+"</h3>"
+"<div class='des_describe'>"+item.describe+"</div>"
+"</div>"
return jQuery(temp);
}
return {
initSliderTour:function(itemtoshow){
//滑出导航
var itemcurrent ,tempintem;
for(var i=0; i<itemtoshow.length; i++){
itemcurrent = $("#"+itemtoshow[i].itemid);
if(itemcurrent.length > 0){
tempintem = getShowView(itemtoshow[i]);
itemcurrent.append(tempintem);
itemcurrent.css("overflow","hidden");
itemcurrent.hover(function(){
jQuery(this).addClass("boxshaow");
jQuery(this).find(".des_container").animate({'right':'0'},1000);
},function(){
jQuery(this).removeClass("boxshaow");
jQuery(this).find(".des_container").animate({'right':'-274px'},1000);
});
}
}
//提示导航
},initToolTipTour:function(tipItemToShow){
//提示导航
var itemcurrent ,tempintem;
if(typeof $.fn.tooltip !== 'function'){
this.addToolTip();
}
for(var i=0; i<tipItemToShow.length; i++){
itemcurrent = $("#"+tipItemToShow[i].itemid);
if(itemcurrent.length > 0){
itemcurrent.append(" <div class='tooltip_description' style='display:none' title='"+tipItemToShow[i].title+"'>"+tipItemToShow[i].describe+"</div>");
itemcurrent.addClass("tooltip"+tipItemToShow[i].position);
itemcurrent.tooltip();
}
itemcurrent.hover(function(){
jQuery(this).addClass("boxshaow");
},function(){
jQuery(this).removeClass("boxshaow");
});
}
//分步导航
},initStepsTour:function(steps){
if(document.cookie.indexOf("weavertour=") >= 0)
return;
var WeaverTour = new window.WeaverTour(steps);
WeaverTour.startTour();
var date=new Date();
date.setDate(date.getDate()+365);
document.cookie='weavertour=1;expires='+date;
},addToolTip:function(){
$.fn.tooltip = function(settings) {
var config,
tooltip_map = {},
id_index = 1;
// Configuration setup
config = {
'dialog_content_selector' : 'div.tooltip_description',
'animation_distance' : 50,
'opacity' : 0.85,
'arrow_left_offset' : 70,
'arrow_right_offset' : 20,
'arrow_top_offset' : 50,
'arrow_height' : 20,
'arrow_width' : 20,
'animation_duration_ms' : 300,
'event_in':'mouseenter',
'event_out':'mouseleave',
'hover_in_delay' : 0,
'hover_out_delay' : 0
};
if (settings) {
$.extend(config, settings);
}
function _generateDomId() {
var time = (new Date()).getTime();
id_index += 1;
return id_index + "_" + time;
}
/**
* Creates the dialog box element
* and appends it to the body
**/
function _create(content_elm, target_elm) {
var header = ($(content_elm).attr("title")) ? "<h1>" + $(content_elm).attr("title") + "</h1>" : '',
dom_id = $(target_elm).attr('id'),
dialog_elm;
if ( !dom_id ) {
dom_id = _generateDomId();
$(target_elm).attr('id', dom_id);
}
else if ( tooltip_map[dom_id] ) { // there's a tooltip already assigned to this target element.
return tooltip_map[dom_id];
}
dialog_elm = $(["<div class='jquery-gdakram-tooltip'>",
"<div class='up_arrow arrow'></div>",
"<div class='left_arrow arrow'></div>",
"<div class='right_arrow arrow'></div>",
"<div class='content'>" + header + $(content_elm).html() + "</div>",
"<div style='clear:both'></div>",
"<div class='down_arrow arrow'></div>",
"</div>"
].join(""));
dialog_elm.appendTo("body");
$(dialog_elm).bind('mouseenter', function(){
$(this).attr('data-mouseenter', 1);
})
.bind('mouseleave', function(){
$(this).attr('data-mouseenter', 0);
});
tooltip_map[dom_id] = dialog_elm;
return dialog_elm;
}
/**
* Positions the dialog box based on the target
* element's location
**/
function _show(target_elm) {
var dialog_content = $(target_elm).find(config.dialog_content_selector),
dialog_box = _create(dialog_content, target_elm),
is_top_right = $(target_elm).hasClass("tooltiptopright"),
is_bottom_right = $(target_elm).hasClass("tooltipbottomright"),
is_left = $(target_elm).hasClass("tooltipleft"),
is_top = $(target_elm).hasClass("tooltiptop"),
is_bottom = $(target_elm).hasClass("tooltipbottom"),
has_position = is_top_right || is_bottom_right || is_top || is_bottom,
position,
target_elm_position = $(target_elm).offset();
// coming from the left
if (is_left) {
position = {
start : {
left : target_elm_position.left - config.animation_distance - $(dialog_box).outerWidth(),
top : target_elm_position.top - ($(target_elm).outerHeight() / 2) + config.arrow_right_offset
},
end : {
left : target_elm_position.left - $(dialog_box).outerWidth() + $(dialog_box).find('.right_arrow').outerWidth(),
top : target_elm_position.top - ($(target_elm).outerHeight() / 2) + config.arrow_right_offset
},
arrow_class : "div.right_arrow"
};
}
// coming from the top right
else if (is_top_right || (!has_position && (target_elm_position.top < $(dialog_box).outerHeight() && target_elm_position.top >= config.arrow_top_offset))) {
position = {
start : {
left : target_elm_position.left + $(target_elm).outerWidth() + config.animation_distance,
top : target_elm_position.top + ($(target_elm).outerHeight() / 2) - config.arrow_top_offset
},
end : {
left : target_elm_position.left + $(target_elm).outerWidth(),
top : target_elm_position.top + ($(target_elm).outerHeight() / 2) - config.arrow_top_offset
},
arrow_class : "div.left_arrow"
};
}
// coming from the bottom right
else if (is_bottom_right || (!has_position && (target_elm_position.left < config.arrow_left_offset + $(target_elm).outerWidth() && target_elm_position.top > $(dialog_box).outerHeight()))) {
position = {
start : {
left : target_elm_position.left + $(target_elm).outerWidth() + config.animation_distance,
top : target_elm_position.top + ($(target_elm).outerHeight() / 2) + config.arrow_top_offset - $(dialog_box).outerHeight() + config.arrow_height
},
end : {
left : target_elm_position.left + $(target_elm).outerWidth(),
top : target_elm_position.top + ($(target_elm).outerHeight() / 2) + config.arrow_top_offset - $(dialog_box).outerHeight() + config.arrow_height
},
arrow_class : "div.left_arrow"
};
$(dialog_box).find("div.left_arrow").css({ top: $(dialog_box).outerHeight() - (config.arrow_top_offset * 2) + "px" });
}
// coming from the top
else if (is_top || (!has_position &&(target_elm_position.top + config.animation_distance > $(dialog_box).outerHeight() && target_elm_position.left >= config.arrow_left_offset))) {
position = {
start : {
left : target_elm_position.left + ($(target_elm).outerWidth() / 2) - config.arrow_left_offset,
top : target_elm_position.top - config.animation_distance - $(dialog_box).outerHeight()
},
end : {
left : target_elm_position.left + ($(target_elm).outerWidth() / 2) - config.arrow_left_offset,
top : target_elm_position.top - $(dialog_box).outerHeight() + config.arrow_height
},
arrow_class : "div.down_arrow"
};
}
// coming from the bottom
else if (is_bottom || (!has_position &&(target_elm_position.top + config.animation_distance < $(dialog_box).outerHeight()))) {
position = {
start : {
left : target_elm_position.left + ($(target_elm).outerWidth() / 2) - config.arrow_left_offset,
top : target_elm_position.top + $(target_elm).outerHeight() + config.animation_distance
},
end : {
left : target_elm_position.left + ($(target_elm).outerWidth() / 2) - config.arrow_left_offset,
top : target_elm_position.top + $(target_elm).outerHeight()
},
arrow_class : "div.up_arrow"
};
}
// position and show the box
$(dialog_box).css({
top : position.start.top + "px",
left : position.start.left + "px",
opacity : config.opacity
});
$(dialog_box).find("div.arrow").hide();
$(dialog_box).find(position.arrow_class).show();
// begin animation
$(dialog_box).animate({
top : position.end.top,
left: position.end.left,
opacity : "toggle"
}, config.animation_duration_ms);
} // -- end _show function
/**
* Stop the animation (if any) and remove from dialog box from the DOM
*/
function _hide(target_elm) {
var dom_id = $(target_elm).attr('id'),
dialog_elm = tooltip_map[dom_id];
if ( dialog_elm ) {
// user's still over the tooltip, will hide, once out of the tooltip.
if ( parseInt(dialog_elm.attr('data-mouseenter'), 10) ) {
setTimeout(function(){
_hide(target_elm);
}, 500);
}
else {
dialog_elm.unbind();
dialog_elm.stop().remove();
delete tooltip_map[dom_id];
}
}
}
/**
* Apply interaction to all the matching elements
**/
this.each(function() {
var hoverTimer,
ele = this;
$(this).bind(config.event_in, function(){
clearTimeout(hoverTimer);
hoverTimer = setTimeout(function() { _show(ele); }, config.hover_in_delay );
})
.bind(config.event_out, function(){
clearTimeout(hoverTimer);
hoverTimer = setTimeout(function() {
_hide(ele);
}, config.hover_out_delay );
});
});
return this;
};
}
}
})();