blob: cc7caf6a4e378a0e2aa42cbb1438c50c858faacf [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 =[
hebasta2f7e5402021-11-02 20:09:38 +010095 {
96 element: '#link-guided-tour',
hebastaa84c7a92021-10-26 21:12:40 +020097 title: loc.TOUR_welcti,
hebasta1e2d98e2019-10-30 15:58:17 +010098 intro: loc.TOUR_welc,
hebasta2f7e5402021-11-02 20:09:38 +010099 position: 'right',
hebasta1e2d98e2019-10-30 15:58:17 +0100100 },
101 {
hebastaf95226b2019-09-19 11:37:00 +0200102 element: '#q-field',
hebasta75cfca52019-02-19 13:15:27 +0100103 intro: loc.TOUR_sear1,
104 position: 'bottom'
105 },
106 {
hebasta75cfca52019-02-19 13:15:27 +0100107 element: '#hint',
108 intro: loc.TOUR_searAnnot,
109 position: 'bottom'
hebasta5df796f2019-05-21 15:27:12 +0200110 },
111 {
hebastaf95226b2019-09-19 11:37:00 +0200112 element: doe.querySelector("#hint > .menu.hint"),
113 intro: loc.TOUR_annotAss,
114 position: 'bottom',
115 },
116 {
hebasta75cfca52019-02-19 13:15:27 +0100117 element:'#vc-choose',
118 intro: loc.TOUR_vccho1,
119 position: "bottom",
hebasta5df796f2019-05-21 15:27:12 +0200120 },
121 {
122 element:'#vc-view',
123 intro: loc.TOUR_vccho2,
124 position: "bottom",
125 },
126 {
hebastad090a512019-07-10 16:36:01 +0200127 element: doe.querySelector('.statistic'),
hebasta94e47cb2019-07-24 22:24:27 +0200128 intro: loc.TOUR_vcStat1,
hebastad090a512019-07-10 16:36:01 +0200129 position: "left",
130 },
131 {
hebasta94e47cb2019-07-24 22:24:27 +0200132 element: doe.querySelector('.stattable'),
133 intro: loc.TOUR_vcStat2,
134 position: "bottom",
135 },
136 {
hebasta5df796f2019-05-21 15:27:12 +0200137 element: doe.querySelector('#ql-field').parentNode,
138 intro: loc.TOUR_qlfield,
139 position: "bottom",
140 },
141 {
hebastabd53f822021-10-26 21:50:06 +0200142 element: doe.querySelector('#glimpse').parentNode,
hebasta5df796f2019-05-21 15:27:12 +0200143 intro: loc.TOUR_glimpse,
144 position: "bottom",
145 },
146 {
147 element:'#view-tutorial',
148 intro: loc.TOUR_help,
149 position: "bottom",
150 },
151 {
152 element: '#qsubmit',
153 intro: loc.TOUR_seargo,
154 position: "bottom",
155 },
156 ];
157
hebasta75cfca52019-02-19 13:15:27 +0100158 //pass in the Steps array created earlier
hebasta87f1b1f2019-07-30 13:03:23 +0200159 intro.setOptions({steps: Steps});
160 this.testPrerequ(Steps, intro);
hebastaca61f812019-11-11 22:25:27 +0100161
hebasta5df796f2019-05-21 15:27:12 +0200162 //changes before executing the single steps
163 intro.onbeforechange(function(targetedElement){
164 switch(targetedElement.id){
hebastaf95226b2019-09-19 11:37:00 +0200165 case "q-field":
hebastad090a512019-07-10 16:36:01 +0200166 /*
167 * TODO:
168 * #268 is not merged at the time beeing:
169 * introJs.currentStep() merge requested https://github.com/usablica/intro.js/pull/268/files
170 */
hebastaf95226b2019-09-19 11:37:00 +0200171 targetedElement.value = loc.TOUR_Qexample;
hebasta5df796f2019-05-21 15:27:12 +0200172 break;
hebasta5df796f2019-05-21 15:27:12 +0200173 case "vc-view":
Akron0b37f3e2021-02-09 10:32:03 +0100174 let vchoo = doe.querySelector("#vc-choose");
175 let vcv = doe.querySelector("#vc-view");
hebasta5df796f2019-05-21 15:27:12 +0200176 KorAP._delete.apply(KorAP.vc.root());
hebasta94e47cb2019-07-24 22:24:27 +0200177
178 KorAP.vc.fromJson(loc.TOUR_vcQuery);
hebasta5df796f2019-05-21 15:27:12 +0200179 if(!(vcv.querySelector(".active"))){
180 vchoo.click();
hebastad090a512019-07-10 16:36:01 +0200181 /*
182 * Intro.js caches elements at the beginning, so element and position has to be set again.
183 */
hebastaee7b8a82020-01-20 12:45:04 +0100184 intro._introItems[6].element = doe.querySelector('.statistic');
185 intro._introItems[6].position = "left";
hebasta5df796f2019-05-21 15:27:12 +0200186 }
187 break;
hebasta75cfca52019-02-19 13:15:27 +0100188
hebasta5df796f2019-05-21 15:27:12 +0200189 }
hebasta94e47cb2019-07-24 22:24:27 +0200190
hebastaee7b8a82020-01-20 12:45:04 +0100191 if(this._currentStep == 7){
hebasta94e47cb2019-07-24 22:24:27 +0200192 let statbut = doe.querySelector('.statistic');
193 statbut.click();
hebastaee7b8a82020-01-20 12:45:04 +0100194 intro._introItems[7].element = doe.querySelector(".stattable");
195 intro._introItems[7].position = "bottom";
hebasta94e47cb2019-07-24 22:24:27 +0200196 }
hebasta75cfca52019-02-19 13:15:27 +0100197 });
hebasta5df796f2019-05-21 15:27:12 +0200198
hebastaf95226b2019-09-19 11:37:00 +0200199 intro.onbeforeexit(function(){
200 if(KorAP.Hint.active() && KorAP.Hint.active().dontHide){
201 KorAP.Hint.unshow();
202 }
203 });
204
205 intro.onchange(function(targetElement) {
206 var that = this;
207 switch(this._currentStep){
208 //hides Hint if back button is pressed
hebastaee7b8a82020-01-20 12:45:04 +0100209 case 2:
hebastaf95226b2019-09-19 11:37:00 +0200210 if(KorAP.Hint.active()){
211 KorAP.Hint.unshow();
212 }
213 break;
hebastaee7b8a82020-01-20 12:45:04 +0100214 case 3:
hebastaf95226b2019-09-19 11:37:00 +0200215 KorAP.Hint.show(false);
216 KorAP.Hint.active().dontHide = true;
hebastaee7b8a82020-01-20 12:45:04 +0100217 intro._introItems[3].element = doe.querySelector(".menu.roll.hint");
218 intro._introItems[3].position = doe.querySelector("bottom");
hebastaf95226b2019-09-19 11:37:00 +0200219 break;
hebastaee7b8a82020-01-20 12:45:04 +0100220 case 4:
hebastaf95226b2019-09-19 11:37:00 +0200221 KorAP.Hint.unshow();
222 break;
223 }
224 });
225
hebasta5df796f2019-05-21 15:27:12 +0200226 // Execute at the end of the tour (By clicking at the done-Button)
227 intro.oncomplete(function(){
228 KorAP.session.set("tour", true);
hebasta94e47cb2019-07-24 22:24:27 +0200229 doe.getElementById("qsubmit").click();
hebasta5df796f2019-05-21 15:27:12 +0200230 });
231
232 return intro;
hebasta75cfca52019-02-19 13:15:27 +0100233 },
hebasta5df796f2019-05-21 15:27:12 +0200234
235
236 /* Guided Tour to explain the different views of the results */
hebastaca61f812019-11-11 22:25:27 +0100237 gTshowResults: function(elparam){
238
239 let tourR = introClass();
hebastaee7b8a82020-01-20 12:45:04 +0100240 tourR.setOptions(usabilityOpts);
hebastaca61f812019-11-11 22:25:27 +0100241
hebasta87f1b1f2019-07-30 13:03:23 +0200242 //for testing purposes
hebasta5df796f2019-05-21 15:27:12 +0200243 if(elparam){
244 doe = elparam;
245 }
hebasta5df796f2019-05-21 15:27:12 +0200246 let StepsSR = [
hebasta87f1b1f2019-07-30 13:03:23 +0200247 //Step 1, intro_item 0
248 {
249 element: '#search',
250 intro: loc.TOUR_kwic ,
251 position: "auto",
252 },
253 //Step 2, intro_item 1
254 {
255 element: doe.querySelector("#search > ol > li"),
256 intro: loc.TOUR_snippet,
257 position: "bottom",
258 },
259 //Step 3, intro_item 2
260 {
261 element: doe.querySelector("#search > ol > li"),
262 intro: loc.TOUR_snippetb,
263 position: "bottom",
264 },
265 //Step 4, intro_item 3
266 {
267 element: doe.querySelector(".action > .metatable"),
268 intro: loc.TOUR_metadatab,
269 position: "bottom",
270 },
271 //Step 5, intro_item 4
272 {
273 element: doe.querySelector(".view.metatable"),
274 intro: loc.TOUR_metadata,
275 position: "auto",
276 },
277 //Step 6, intro_item 5
278 {
279 element: doe.querySelector(".action > .info"),
280 intro: loc.TOUR_tokenb,
281 position: "bottom",
282 },
283 //Step 7, intro_item 6
284 {
285 element: doe.querySelector(".view.tokentable"),
286 intro: loc.TOUR_token,
287 position: "auto",
288 },
289 //Step 8, intro_item 7
hebasta5df796f2019-05-21 15:27:12 +0200290 {
hebasta87f1b1f2019-07-30 13:03:23 +0200291 element: doe.querySelector(".tree"),
292 intro: loc.TOUR_treeb,
293 position: "bottom",
294 },
295 //Step 9, intro_item 8
296 {
hebastaf95226b2019-09-19 11:37:00 +0200297 element: doe.querySelector(".view.relations"),
hebasta87f1b1f2019-07-30 13:03:23 +0200298 intro: loc.TOUR_tree,
hebastaf95226b2019-09-19 11:37:00 +0200299 position: "bottom",
hebasta87f1b1f2019-07-30 13:03:23 +0200300 },
301 //Step 10, intro_item 9
302 {
303 intro: loc.TOUR_tourdone,
304 }
hebasta5df796f2019-05-21 15:27:12 +0200305 ]
hebasta5df796f2019-05-21 15:27:12 +0200306
hebasta87f1b1f2019-07-30 13:03:23 +0200307 tourR.setOptions({steps:StepsSR});
hebastaee7b8a82020-01-20 12:45:04 +0100308 tourR.setOptions(labelOpts);
hebastaf95226b2019-09-19 11:37:00 +0200309
310 tourR.onbeforeexit(function(){
311 KorAP.session.set("tour", false);
hebasta87f1b1f2019-07-30 13:03:23 +0200312 });
hebasta87f1b1f2019-07-30 13:03:23 +0200313 //See also: https://introjs.com/docs/intro/options/
314 tourR.setOption('scrollToElement', true);
315 tourR.setOption('scrollTo','tooltip');
316 this.testPrerequ(StepsSR, tourR);
317
318 //TODO see also: introJS.totalSteps() merge requested: //github.com/usablica/intro.js/pull/268/files
319 tourR.onbeforechange(function(targetedElement){
320
321 if(this._currentStep == 1){
322 KorAP.session.set("tour", false);
323 }
324
325 if(this._currentStep == 2){
326 doe.querySelector("#search > ol > li").click();
327 tourR._introItems[3].element = doe.querySelector('.action > .metatable');
328 tourR._introItems[3].position = "bottom";
329 }
330
331 if(this._currentStep == 4){
332 doe.querySelector(".metatable").click();
333 tourR._introItems[4].element = doe.querySelector('.view.metatable');
334 tourR._introItems[5].element = doe.querySelector('.action > .info');
335 tourR._introItems[5].position = "bottom";
336 }
337
338 if(this._currentStep == 6){
339 doe.querySelector(".info").click();
340 tourR._introItems[6].element = doe.querySelector('.view.tokentable');
341 tourR._introItems[7].element = doe.querySelector('.tree');
342 tourR._introItems[7].position = "bottom";
343 }
344
345 if(this._currentStep == 8){
346 doe.querySelector(".tree").click();
hebasta7fa6f082019-11-17 19:00:52 +0100347 let collect = document.querySelectorAll(".button-group-list")[0].querySelectorAll('li');
348 for(let i = 0; i < collect.length; i++){
349 if (collect[i].innerText == loc.TOUR_Relations) {
350 collect[i].click();
351 break;
352 }
353 }
hebastaf95226b2019-09-19 11:37:00 +0200354 tourR._introItems[8].element = doe.querySelector(".view.relations");
hebasta87f1b1f2019-07-30 13:03:23 +0200355 }
356 });
hebastaf95226b2019-09-19 11:37:00 +0200357
hebasta5df796f2019-05-21 15:27:12 +0200358 return tourR;
359 },
hebasta87f1b1f2019-07-30 13:03:23 +0200360 /*
361 * The total number of steps and the text of the tooltips are needed for jasmine testing.
362 */
363 testPrerequ: function(steps, tour){
364 //TODO see also: introJS.totalSteps() merge requested: //github.com/usablica/intro.js/pull/268/files
365 let StepsT = steps;
366 let gtour = tour;
367 gtour.stepCount = StepsT.length;
368
369 //Array of intro content needed for efficient testing
370 gtour.testIntros = [];
371
372 for(let i = 0; i< StepsT.length; i++){
373 gtour.testIntros.push(StepsT[i].intro);
374 }
375 },
hebasta5df796f2019-05-21 15:27:12 +0200376
hebasta75cfca52019-02-19 13:15:27 +0100377 }
378});