-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtour.js
210 lines (201 loc) · 6.74 KB
/
tour.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
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
var initWysTour = function(){
$("#wys-cms-tour").click(function(){
startWysTour(true);
closeWysToolbar();
});
}
var startWysTour = function(from_beginning){
stepNO = parseInt(localStorage.getItem('tour_current_step'));
allowWysToolbarHide = false;
if(stepNO >= 1){
animatingWysToolbar = false;
openWysToolbar();
}
setTimeout(function(){
bootstrapTour.init();
if(from_beginning){
bootstrapTour.restart();
} else {
bootstrapTour.start();
}
},500);
}
var commonStepActions = function(t){
stepNO = t.getCurrentStep()
elem = $(".popover.tour-tour-"+stepNO)
elem.css("left",parseInt(elem.css("left"))-20)
}
var bootstrapTour = null;
var setupWysTour = function(){
// create a placeholder element for the first step
d = $("<div id='open-toolbar-step' />")
d.css("position","fixed").css("top",10).css("right",10)
d.css("width",20).css("height",20)
$("body").append(d)
// tour properties
bootstrapTour = new Tour({
backdrop: true,
orphan: true,
template: "<div class='popover tour'>"
+"<div class='arrow'></div>"
+"<h3 class='popover-title'></h3>"
+"<div class='popover-content'></div>"
+"<div class='popover-navigation'>"
+" <button class='btn btn-default' data-role='prev'>« "+i18next.t("tour.previous")+"</button>"
+" <span data-role='separator'> </span>"
+" <button class='btn btn-default' data-role='next'>"+i18next.t("tour.next")+" »</button>"
+" <button class='btn btn-default' data-role='end'>"+i18next.t("tour.close")+"</button>"
+"</div>"
+"</div>",
onShow: function(t){
// disable scrolling temporarily
$("html").css("overflow","hidden");
// disable toolbar links temporarily
$("#wys-editor-toolbar a").bindFirst('click.disabled',function(e){
e.stopImmediatePropagation();
e.preventDefault();
// flash the next button
nextButton = $(".popover.tour button[data-role='next']");
nextButton.fadeOut(200,function(){ $(this).fadeIn(200, function(){
nextButton.fadeOut(200,function(){ $(this).fadeIn(200); });
}); });
return false;
});
},
onEnd: function(t){
// enable scrolling again
$("html").css("overflow","auto");
// enable toolbar links again
$("#wys-editor-toolbar a").unbind('click.disabled');
allowWysToolbarHide = true;
// signal cms that the tour has been seen
$.post(wys_cms_path+'wys/xhr/user_tour_status.php',{'action':'set'})
}
});
bootstrapTour.addStep({
placement: "left",
title: i18next.t('tour.first-step-title'),
content: i18next.t('tour.first-step-content'),
});
bootstrapTour.addStep({
element: "#open-toolbar-step",
placement: "left",
title: i18next.t('tour.open-toolbar-title'),
content: i18next.t('tour.open-toolbar-content'),
backdropPadding: 10,
onShown: function(p){
stepNO = p.getCurrentStep()
elem = $(".popover.tour-tour-"+stepNO)
elem.find("button[data-role='next']").hide();
closeWysToolbar();
$(".tour-step-background")
.css("top",0).css("right",0).css("left","auto")
.css("border-top-right-radius",0)
// use hover over editor as the trigger for next slide
$("#wys-editor-trigger").one("mouseenter click",function(){
setTimeout(function(){
bootstrapTour.next()
},500);
});
}
});
bootstrapTour.addStep({
element: "#wys-cms-dashboard",
backdropPadding: 0,
placement: "left",
title: i18next.t('tour.cms-dashboard-title'),
content: i18next.t('tour.cms-dashboard-content'),
onShown: function(p){ commonStepActions(p); }
});
bootstrapTour.addStep({
element: "#wys-open-editor",
backdropPadding: 0,
placement: "left",
title: i18next.t('tour.cms-editor-title'),
content: i18next.t('tour.cms-editor-content'),
onShown: function(p){ commonStepActions(p); }
});
bootstrapTour.addStep({
element: "#wys-enable-quick-edit-mode",
backdropPadding: 0,
placement: "left",
title: i18next.t('tour.quick-editor-title'),
content: i18next.t('tour.quick-editor-content'),
onShown: function(p){ commonStepActions(p); }
});
bootstrapTour.addStep({
element: "#wys-enable-quick-edit-mode",
backdropPadding: 0,
placement: "left",
title: i18next.t('tour.quick-editor-explanation-title'),
content: i18next.t('tour.quick-editor-explanation-content')
+ "<div class='wys-quick-edit-area-example'><div class='editor'></div></div>",
onShown: function(p){
commonStepActions(p);
new MediumEditor('.wys-quick-edit-area-example')
}
});
bootstrapTour.addStep({
element: "#wys-enable-quick-edit-mode",
backdropPadding: 0,
placement: "left",
title: i18next.t('tour.quick-editor-usage-title'),
content: i18next.t('tour.quick-editor-usage-content')
+ "<div class='wys-quick-edit-area-example'><div class='editor'>"+i18next.t('tour.quick-editor-usage-highlight')+"</div></div>",
onShown: function(p){
commonStepActions(p);
new MediumEditor('.wys-quick-edit-area-example .editor')
}
});
if($("#wys-cms-shortcuts").length > 0){
bootstrapTour.addStep({
element: "#wys-cms-shortcuts",
backdropPadding: 0,
placement: "left",
title: i18next.t('tour.shortcuts-title'),
content: i18next.t('tour.shortcuts-content'),
onShown: function(p){ commonStepActions(p); }
});
}
bootstrapTour.addStep({
element: "#wys-cms-logout",
backdropPadding: 0,
placement: "left",
title: i18next.t('tour.logout-title'),
content: i18next.t('tour.logout-content'),
onShown: function(p){ commonStepActions(p); }
});
bootstrapTour.addStep({
element: "#wys-cms-tour",
backdropPadding: 0,
placement: "left",
title: i18next.t('tour.tour-restart-title'),
content: i18next.t('tour.tour-restart-content'),
onShown: function(p){
stepNO = p.getCurrentStep()
elem = $(".popover.tour-tour-"+stepNO)
elem.find("button[data-role='next']").hide();
commonStepActions(p);
}
});
// bind first extension to jquery to allow disabling all
// events temporarily
$.fn.bindFirst = function(name, fn) {
var elem, handlers, i, _len;
this.bind(name, fn);
for (i = 0, _len = this.length; i < _len; i++) {
elem = this[i];
handlers = jQuery._data(elem).events[name.split('.')[0]];
handlers.unshift(handlers.pop());
}
};
if(!bootstrapTour.ended() && $(window).width() > 500){
$.post(wys_cms_path+'wys/xhr/user_tour_status.php',{'action':'get'},function(response){
response = $.parseJSON(response);
// continue if user has not been given the tour
if(response.status == "not_seen"){
startWysTour()
}
});
}
}