blob: cf0857c7ff6b1a2b289a1713586381fce28239d4 [file] [log] [blame]
hebasta75cfca52019-02-19 13:15:27 +01001/**
2 * Guided Tour to explain the UI
3 *
4 * @author Helge Stallkamp
5 */
Akrone51eaa32020-11-10 09:35:53 +01006"use strict";
hebasta75cfca52019-02-19 13:15:27 +01007
Akrone51eaa32020-11-10 09:35:53 +01008define(['lib/intro', 'vc', 'hint', 'menu', 'vc/doc', 'vc/docgroup'],
9 function(introClass, vcClass, hintClass, menuClass, docClass, docGroup) {
hebasta5df796f2019-05-21 15:27:12 +020010
hebasta75cfca52019-02-19 13:15:27 +010011 //needed for localization of labels and contents of the tour
12 const loc = KorAP.Locale;
hebasta5df796f2019-05-21 15:27:12 +020013
hebastaa84c7a92021-10-26 21:12:40 +020014 //labels for nextStep, previousStep and done
hebasta75cfca52019-02-19 13:15:27 +010015 loc.TOUR_lprev = loc.TOUR_lprev || "Back";
16 loc.TOUR_lnext = loc.TOUR_lnext || "Next";
17 loc.TOUR_ldone = loc.TOUR_ldone || "Done";
hebastaca61f812019-11-11 22:25:27 +010018 loc.TOUR_ldoneSearch = loc.TOUR_ldoneSearch || "Search";
19
hebasta5df796f2019-05-21 15:27:12 +020020 //localization guided tour gTstartSearch
hebastaa84c7a92021-10-26 21:12:40 +020021 loc.TOUR_welcti = loc.TOUR_welcti || "<span class='tgreeting'> Welcome to our guided tour! </span>";
22 loc.TOUR_welc = loc.TOUR_welc || "This tour should give you a quick introduction to KorAP. " +
23 "We lead you step by step through an example.";
hebastaee7b8a82020-01-20 12:45:04 +010024 loc.TOUR_sear1 = loc.TOUR_sear1 || "Input field for the query, for example the search for '" + loc.TOUR_Qexample + "'.";
hebastaf95226b2019-09-19 11:37:00 +020025 loc.TOUR_searAnnot = loc.TOUR_searAnnot || "Annotation helper";
26 loc.TOUR_annotAss = loc.TOUR_annotAss || "The assistant displays the annotations of the different layers and helps to formulate queries.";
hebasta94e47cb2019-07-24 22:24:27 +020027 loc.TOUR_vccho1 = loc.TOUR_vccho1 || "Choose corpus";
hebasta75cfca52019-02-19 13:15:27 +010028 loc.TOUR_vccho2 = loc.TOUR_vccho2 || "Define your corpus here.";
hebasta94e47cb2019-07-24 22:24:27 +020029 loc.TOUR_vcStat1 = loc.TOUR_vcStat1 || "Click here to display corpus statistic.";
30 loc.TOUR_vcStat2 = loc.TOUR_vcStat2 || "Corpus statistic";
hebasta1e2d98e2019-10-30 15:58:17 +010031 loc.TOUR_qlfield = loc.TOUR_qlfield|| "Selection of the query language: You can use KorAP with different query languages.";
32 loc.TOUR_help = loc.TOUR_help || "Help and information about KorAP.";
hebastaca61f812019-11-11 22:25:27 +010033 loc.TOUR_glimpse = loc.TOUR_glimpse || "Select this to show only the first hits in undefined order.";
hebasta1e2d98e2019-10-30 15:58:17 +010034 loc.TOUR_seargo = loc.TOUR_seargo || "Start the search";
hebasta87f1b1f2019-07-30 13:03:23 +020035
hebasta5df796f2019-05-21 15:27:12 +020036 //localization guided Tour gTshowResults
hebasta87f1b1f2019-07-30 13:03:23 +020037 loc.TOUR_kwic = loc.TOUR_kwic || "KWIC result (keyword in context)";
38 loc.TOUR_snippet = loc.TOUR_snippet || "Click on a match to show a larger snippet.";
hebasta1e2d98e2019-10-30 15:58:17 +010039 loc.TOUR_snippetb = loc.TOUR_snippetb || "Snippet";
40 loc.TOUR_metadatab = loc.TOUR_metadatab || "Display of metadata";
hebasta87f1b1f2019-07-30 13:03:23 +020041 loc.TOUR_metadata = loc.TOUR_metadata || "Metadata";
hebasta1e2d98e2019-10-30 15:58:17 +010042 loc.TOUR_tokenb = loc.TOUR_tokenb || "Display of token annotations";
hebasta87f1b1f2019-07-30 13:03:23 +020043 loc.TOUR_token = loc.TOUR_token || "KorAP supports multiple annotations.";
hebasta1e2d98e2019-10-30 15:58:17 +010044 loc.TOUR_treeb = loc.TOUR_treeb || "Display further annotations"
hebasta87f1b1f2019-07-30 13:03:23 +020045 loc.TOUR_tree = loc.TOUR_tree || "Further annotations can be displayed as tree and arch views."
46 loc.TOUR_tourdone = loc.TOUR_tourdone || "Have fun with KorAP!";
hebasta75cfca52019-02-19 13:15:27 +010047
48 //localization of button labels
hebastaee7b8a82020-01-20 12:45:04 +010049 let labelOpts= {
hebasta5df796f2019-05-21 15:27:12 +020050 'prevLabel': loc.TOUR_lprev,
51 'nextLabel': loc.TOUR_lnext,
52 'doneLabel': loc.TOUR_ldone,
hebastaee7b8a82020-01-20 12:45:04 +010053 'showStepNumbers': false
54 };
55
56 //usability options of tours
57 let usabilityOpts ={
58 'showBullets': false,
hebastaa84c7a92021-10-26 21:12:40 +020059 'overlayOpacity': 0.5,
hebastaee7b8a82020-01-20 12:45:04 +010060 'exitOnOverlayClick': false,
hebastaa84c7a92021-10-26 21:12:40 +020061 'disableInteraction': true,
62 'tooltipClass': 'customTooltip',
hebastaee7b8a82020-01-20 12:45:04 +010063 'hidePrev': true
hebasta75cfca52019-02-19 13:15:27 +010064 };
hebasta87f1b1f2019-07-30 13:03:23 +020065
66 var doe = document;
hebasta5df796f2019-05-21 15:27:12 +020067
hebasta75cfca52019-02-19 13:15:27 +010068 return{
hebasta5df796f2019-05-21 15:27:12 +020069
hebasta75cfca52019-02-19 13:15:27 +010070 /**
hebasta5df796f2019-05-21 15:27:12 +020071 * Guided Tour gTstartSearch: Explains the search functionality
hebasta75cfca52019-02-19 13:15:27 +010072 */
hebasta5df796f2019-05-21 15:27:12 +020073 gTstartSearch:function(elparam){
hebasta5df796f2019-05-21 15:27:12 +020074 let intro = introClass();
hebastaee7b8a82020-01-20 12:45:04 +010075 intro.setOptions(labelOpts);
hebastaca61f812019-11-11 22:25:27 +010076 /*
77 * Sets button labels for the last step of the tour
78 * Because Kalamar is a multipage webapplication, this tours starts by
79 * completion the gTshowResults Tour. Therefore the label of the done button changed.
80 */
81 intro.setOption('doneLabel', loc.TOUR_ldoneSearch );
hebastaee7b8a82020-01-20 12:45:04 +010082 intro.setOptions(usabilityOpts);
hebastaca61f812019-11-11 22:25:27 +010083
hebasta5df796f2019-05-21 15:27:12 +020084 //for testing purposes
hebasta75cfca52019-02-19 13:15:27 +010085 if(elparam){
86 doe = elparam;
87 }
hebasta5df796f2019-05-21 15:27:12 +020088
hebasta75cfca52019-02-19 13:15:27 +010089 let input = doe.querySelector("#q-field");
90 input.value="";
91
hebasta5df796f2019-05-21 15:27:12 +020092
hebasta75cfca52019-02-19 13:15:27 +010093 //steps of the example tour
94 let Steps =[
95 {
hebastaa84c7a92021-10-26 21:12:40 +020096 title: loc.TOUR_welcti,
hebasta1e2d98e2019-10-30 15:58:17 +010097 intro: loc.TOUR_welc,
98 },
99 {
hebastaf95226b2019-09-19 11:37:00 +0200100 element: '#q-field',
hebasta75cfca52019-02-19 13:15:27 +0100101 intro: loc.TOUR_sear1,
102 position: 'bottom'
103 },
104 {
hebasta75cfca52019-02-19 13:15:27 +0100105 element: '#hint',
106 intro: loc.TOUR_searAnnot,
107 position: 'bottom'
hebasta5df796f2019-05-21 15:27:12 +0200108 },
109 {
hebastaf95226b2019-09-19 11:37:00 +0200110 element: doe.querySelector("#hint > .menu.hint"),
111 intro: loc.TOUR_annotAss,
112 position: 'bottom',
113 },
114 {
hebasta75cfca52019-02-19 13:15:27 +0100115 element:'#vc-choose',
116 intro: loc.TOUR_vccho1,
117 position: "bottom",
hebasta5df796f2019-05-21 15:27:12 +0200118 },
119 {
120 element:'#vc-view',
121 intro: loc.TOUR_vccho2,
122 position: "bottom",
123 },
124 {
hebastad090a512019-07-10 16:36:01 +0200125 element: doe.querySelector('.statistic'),
hebasta94e47cb2019-07-24 22:24:27 +0200126 intro: loc.TOUR_vcStat1,
hebastad090a512019-07-10 16:36:01 +0200127 position: "left",
128 },
129 {
hebasta94e47cb2019-07-24 22:24:27 +0200130 element: doe.querySelector('.stattable'),
131 intro: loc.TOUR_vcStat2,
132 position: "bottom",
133 },
134 {
hebasta5df796f2019-05-21 15:27:12 +0200135 element: doe.querySelector('#ql-field').parentNode,
136 intro: loc.TOUR_qlfield,
137 position: "bottom",
138 },
139 {
hebastabd53f822021-10-26 21:50:06 +0200140 element: doe.querySelector('#glimpse').parentNode,
hebasta5df796f2019-05-21 15:27:12 +0200141 intro: loc.TOUR_glimpse,
142 position: "bottom",
143 },
144 {
145 element:'#view-tutorial',
146 intro: loc.TOUR_help,
147 position: "bottom",
148 },
149 {
150 element: '#qsubmit',
151 intro: loc.TOUR_seargo,
152 position: "bottom",
153 },
154 ];
155
hebasta75cfca52019-02-19 13:15:27 +0100156 //pass in the Steps array created earlier
hebasta87f1b1f2019-07-30 13:03:23 +0200157 intro.setOptions({steps: Steps});
158 this.testPrerequ(Steps, intro);
hebastaca61f812019-11-11 22:25:27 +0100159
hebasta5df796f2019-05-21 15:27:12 +0200160 //changes before executing the single steps
161 intro.onbeforechange(function(targetedElement){
162 switch(targetedElement.id){
hebastaf95226b2019-09-19 11:37:00 +0200163 case "q-field":
hebastad090a512019-07-10 16:36:01 +0200164 /*
165 * TODO:
166 * #268 is not merged at the time beeing:
167 * introJs.currentStep() merge requested https://github.com/usablica/intro.js/pull/268/files
168 */
hebastaf95226b2019-09-19 11:37:00 +0200169 targetedElement.value = loc.TOUR_Qexample;
hebasta5df796f2019-05-21 15:27:12 +0200170 break;
hebasta5df796f2019-05-21 15:27:12 +0200171 case "vc-view":
Akron0b37f3e2021-02-09 10:32:03 +0100172 let vchoo = doe.querySelector("#vc-choose");
173 let vcv = doe.querySelector("#vc-view");
hebasta5df796f2019-05-21 15:27:12 +0200174 KorAP._delete.apply(KorAP.vc.root());
hebasta94e47cb2019-07-24 22:24:27 +0200175
176 KorAP.vc.fromJson(loc.TOUR_vcQuery);
hebasta5df796f2019-05-21 15:27:12 +0200177 if(!(vcv.querySelector(".active"))){
178 vchoo.click();
hebastad090a512019-07-10 16:36:01 +0200179 /*
180 * Intro.js caches elements at the beginning, so element and position has to be set again.
181 */
hebastaee7b8a82020-01-20 12:45:04 +0100182 intro._introItems[6].element = doe.querySelector('.statistic');
183 intro._introItems[6].position = "left";
hebasta5df796f2019-05-21 15:27:12 +0200184 }
185 break;
hebasta75cfca52019-02-19 13:15:27 +0100186
hebasta5df796f2019-05-21 15:27:12 +0200187 }
hebasta94e47cb2019-07-24 22:24:27 +0200188
hebastaee7b8a82020-01-20 12:45:04 +0100189 if(this._currentStep == 7){
hebasta94e47cb2019-07-24 22:24:27 +0200190 let statbut = doe.querySelector('.statistic');
191 statbut.click();
hebastaee7b8a82020-01-20 12:45:04 +0100192 intro._introItems[7].element = doe.querySelector(".stattable");
193 intro._introItems[7].position = "bottom";
hebasta94e47cb2019-07-24 22:24:27 +0200194 }
hebasta75cfca52019-02-19 13:15:27 +0100195 });
hebasta5df796f2019-05-21 15:27:12 +0200196
hebastaf95226b2019-09-19 11:37:00 +0200197 intro.onbeforeexit(function(){
198 if(KorAP.Hint.active() && KorAP.Hint.active().dontHide){
199 KorAP.Hint.unshow();
200 }
201 });
202
203 intro.onchange(function(targetElement) {
204 var that = this;
205 switch(this._currentStep){
206 //hides Hint if back button is pressed
hebastaee7b8a82020-01-20 12:45:04 +0100207 case 2:
hebastaf95226b2019-09-19 11:37:00 +0200208 if(KorAP.Hint.active()){
209 KorAP.Hint.unshow();
210 }
211 break;
hebastaee7b8a82020-01-20 12:45:04 +0100212 case 3:
hebastaf95226b2019-09-19 11:37:00 +0200213 KorAP.Hint.show(false);
214 KorAP.Hint.active().dontHide = true;
hebastaee7b8a82020-01-20 12:45:04 +0100215 intro._introItems[3].element = doe.querySelector(".menu.roll.hint");
216 intro._introItems[3].position = doe.querySelector("bottom");
hebastaf95226b2019-09-19 11:37:00 +0200217 break;
hebastaee7b8a82020-01-20 12:45:04 +0100218 case 4:
hebastaf95226b2019-09-19 11:37:00 +0200219 KorAP.Hint.unshow();
220 break;
221 }
222 });
223
hebasta5df796f2019-05-21 15:27:12 +0200224 // Execute at the end of the tour (By clicking at the done-Button)
225 intro.oncomplete(function(){
226 KorAP.session.set("tour", true);
hebasta94e47cb2019-07-24 22:24:27 +0200227 doe.getElementById("qsubmit").click();
hebasta5df796f2019-05-21 15:27:12 +0200228 });
229
230 return intro;
hebasta75cfca52019-02-19 13:15:27 +0100231 },
hebasta5df796f2019-05-21 15:27:12 +0200232
233
234 /* Guided Tour to explain the different views of the results */
hebastaca61f812019-11-11 22:25:27 +0100235 gTshowResults: function(elparam){
236
237 let tourR = introClass();
hebastaee7b8a82020-01-20 12:45:04 +0100238 tourR.setOptions(usabilityOpts);
hebastaca61f812019-11-11 22:25:27 +0100239
hebasta87f1b1f2019-07-30 13:03:23 +0200240 //for testing purposes
hebasta5df796f2019-05-21 15:27:12 +0200241 if(elparam){
242 doe = elparam;
243 }
hebasta5df796f2019-05-21 15:27:12 +0200244 let StepsSR = [
hebasta87f1b1f2019-07-30 13:03:23 +0200245 //Step 1, intro_item 0
246 {
247 element: '#search',
248 intro: loc.TOUR_kwic ,
249 position: "auto",
250 },
251 //Step 2, intro_item 1
252 {
253 element: doe.querySelector("#search > ol > li"),
254 intro: loc.TOUR_snippet,
255 position: "bottom",
256 },
257 //Step 3, intro_item 2
258 {
259 element: doe.querySelector("#search > ol > li"),
260 intro: loc.TOUR_snippetb,
261 position: "bottom",
262 },
263 //Step 4, intro_item 3
264 {
265 element: doe.querySelector(".action > .metatable"),
266 intro: loc.TOUR_metadatab,
267 position: "bottom",
268 },
269 //Step 5, intro_item 4
270 {
271 element: doe.querySelector(".view.metatable"),
272 intro: loc.TOUR_metadata,
273 position: "auto",
274 },
275 //Step 6, intro_item 5
276 {
277 element: doe.querySelector(".action > .info"),
278 intro: loc.TOUR_tokenb,
279 position: "bottom",
280 },
281 //Step 7, intro_item 6
282 {
283 element: doe.querySelector(".view.tokentable"),
284 intro: loc.TOUR_token,
285 position: "auto",
286 },
287 //Step 8, intro_item 7
hebasta5df796f2019-05-21 15:27:12 +0200288 {
hebasta87f1b1f2019-07-30 13:03:23 +0200289 element: doe.querySelector(".tree"),
290 intro: loc.TOUR_treeb,
291 position: "bottom",
292 },
293 //Step 9, intro_item 8
294 {
hebastaf95226b2019-09-19 11:37:00 +0200295 element: doe.querySelector(".view.relations"),
hebasta87f1b1f2019-07-30 13:03:23 +0200296 intro: loc.TOUR_tree,
hebastaf95226b2019-09-19 11:37:00 +0200297 position: "bottom",
hebasta87f1b1f2019-07-30 13:03:23 +0200298 },
299 //Step 10, intro_item 9
300 {
301 intro: loc.TOUR_tourdone,
302 }
hebasta5df796f2019-05-21 15:27:12 +0200303 ]
hebasta5df796f2019-05-21 15:27:12 +0200304
hebasta87f1b1f2019-07-30 13:03:23 +0200305 tourR.setOptions({steps:StepsSR});
hebastaee7b8a82020-01-20 12:45:04 +0100306 tourR.setOptions(labelOpts);
hebastaf95226b2019-09-19 11:37:00 +0200307
308 tourR.onbeforeexit(function(){
309 KorAP.session.set("tour", false);
hebasta87f1b1f2019-07-30 13:03:23 +0200310 });
hebasta87f1b1f2019-07-30 13:03:23 +0200311 //See also: https://introjs.com/docs/intro/options/
312 tourR.setOption('scrollToElement', true);
313 tourR.setOption('scrollTo','tooltip');
314 this.testPrerequ(StepsSR, tourR);
315
316 //TODO see also: introJS.totalSteps() merge requested: //github.com/usablica/intro.js/pull/268/files
317 tourR.onbeforechange(function(targetedElement){
318
319 if(this._currentStep == 1){
320 KorAP.session.set("tour", false);
321 }
322
323 if(this._currentStep == 2){
324 doe.querySelector("#search > ol > li").click();
325 tourR._introItems[3].element = doe.querySelector('.action > .metatable');
326 tourR._introItems[3].position = "bottom";
327 }
328
329 if(this._currentStep == 4){
330 doe.querySelector(".metatable").click();
331 tourR._introItems[4].element = doe.querySelector('.view.metatable');
332 tourR._introItems[5].element = doe.querySelector('.action > .info');
333 tourR._introItems[5].position = "bottom";
334 }
335
336 if(this._currentStep == 6){
337 doe.querySelector(".info").click();
338 tourR._introItems[6].element = doe.querySelector('.view.tokentable');
339 tourR._introItems[7].element = doe.querySelector('.tree');
340 tourR._introItems[7].position = "bottom";
341 }
342
343 if(this._currentStep == 8){
344 doe.querySelector(".tree").click();
hebasta7fa6f082019-11-17 19:00:52 +0100345 let collect = document.querySelectorAll(".button-group-list")[0].querySelectorAll('li');
346 for(let i = 0; i < collect.length; i++){
347 if (collect[i].innerText == loc.TOUR_Relations) {
348 collect[i].click();
349 break;
350 }
351 }
hebastaf95226b2019-09-19 11:37:00 +0200352 tourR._introItems[8].element = doe.querySelector(".view.relations");
hebasta87f1b1f2019-07-30 13:03:23 +0200353 }
354 });
hebastaf95226b2019-09-19 11:37:00 +0200355
hebasta5df796f2019-05-21 15:27:12 +0200356 return tourR;
357 },
hebasta87f1b1f2019-07-30 13:03:23 +0200358 /*
359 * The total number of steps and the text of the tooltips are needed for jasmine testing.
360 */
361 testPrerequ: function(steps, tour){
362 //TODO see also: introJS.totalSteps() merge requested: //github.com/usablica/intro.js/pull/268/files
363 let StepsT = steps;
364 let gtour = tour;
365 gtour.stepCount = StepsT.length;
366
367 //Array of intro content needed for efficient testing
368 gtour.testIntros = [];
369
370 for(let i = 0; i< StepsT.length; i++){
371 gtour.testIntros.push(StepsT[i].intro);
372 }
373 },
hebasta5df796f2019-05-21 15:27:12 +0200374
hebasta75cfca52019-02-19 13:15:27 +0100375 }
376});