hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 1 | /** |
| 2 | * Guided Tour to explain the UI |
| 3 | * |
| 4 | * @author Helge Stallkamp |
| 5 | */ |
| 6 | |
hebasta | 87f1b1f | 2019-07-30 13:03:23 +0200 | [diff] [blame] | 7 | |
| 8 | define(['lib/intro', 'vc', 'hint', 'menu', 'vc/doc', 'vc/docgroup'], function(introClass, vcClass, hintClass, menuClass, docClass, docGroup) { |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 9 | |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 10 | //needed for localization of labels and contents of the tour |
| 11 | const loc = KorAP.Locale; |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 12 | |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 13 | //labels for nextStep, previousStep, done and abort |
| 14 | loc.TOUR_lskip = loc.TOUR_lskip || "Abort"; |
| 15 | loc.TOUR_lprev = loc.TOUR_lprev || "Back"; |
| 16 | loc.TOUR_lnext = loc.TOUR_lnext || "Next"; |
| 17 | loc.TOUR_ldone = loc.TOUR_ldone || "Done"; |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 18 | |
| 19 | //localization guided tour gTstartSearch |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 20 | loc.TOUR_sear1 = loc.TOUR_sear1 || "Enter your search enquiry here."; |
hebasta | d090a51 | 2019-07-10 16:36:01 +0200 | [diff] [blame] | 21 | loc.TOUR_sear2 = loc.TOUR_sear2 || "For example the search for '" + loc.TOUR_Qexample + "'."; |
hebasta | 94e47cb | 2019-07-24 22:24:27 +0200 | [diff] [blame] | 22 | loc.TOUR_searAnnot = loc.TOUR_searAnnot || "Annotation helper: By clicking, the annotations of the differents layers are displayed and can be selected."; |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 23 | loc.TOUR_annotAss = loc.TOUR_annotAss || "The annoation assistant helps to formulate queries with annotations"; |
hebasta | 94e47cb | 2019-07-24 22:24:27 +0200 | [diff] [blame] | 24 | loc.TOUR_vccho1 = loc.TOUR_vccho1 || "Choose corpus"; |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 25 | loc.TOUR_vccho2 = loc.TOUR_vccho2 || "Define your corpus here."; |
hebasta | 94e47cb | 2019-07-24 22:24:27 +0200 | [diff] [blame] | 26 | loc.TOUR_vcStat1 = loc.TOUR_vcStat1 || "Click here to display corpus statistic."; |
| 27 | loc.TOUR_vcStat2 = loc.TOUR_vcStat2 || "Corpus statistic"; |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 28 | loc.TOUR_qlfield = loc.TOUR_qlfield|| "You can use KorAP with different query languages, select the query language here."; |
| 29 | loc.TOUR_help = loc.TOUR_help || "Help and more information about KorAP."; |
| 30 | loc.TOUR_glimpse = loc.TOUR_glimpse || "Select to show only the first hits in arbitrary order."; |
| 31 | loc.TOUR_seargo = loc.TOUR_seargo || "Start the search."; |
hebasta | 87f1b1f | 2019-07-30 13:03:23 +0200 | [diff] [blame] | 32 | |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 33 | //localization guided Tour gTshowResults |
hebasta | 87f1b1f | 2019-07-30 13:03:23 +0200 | [diff] [blame] | 34 | loc.TOUR_kwic = loc.TOUR_kwic || "KWIC result (keyword in context)"; |
| 35 | loc.TOUR_snippet = loc.TOUR_snippet || "Click on a match to show a larger snippet."; |
| 36 | loc.TOUR_snippetb = loc.TOUR_snippetb || "Display of larger snippet"; |
| 37 | loc.TOUR_metadatab = loc.TOUR_metadatab || "Click here to display the metadata."; |
| 38 | loc.TOUR_metadata = loc.TOUR_metadata || "Metadata"; |
| 39 | loc.TOUR_tokenb = loc.TOUR_tokenb || "Click here to display the token annotations."; |
| 40 | loc.TOUR_token = loc.TOUR_token || "KorAP supports multiple annotations."; |
| 41 | loc.TOUR_treeb = loc.TOUR_treeb || "Display further annotations." |
| 42 | loc.TOUR_tree = loc.TOUR_tree || "Further annotations can be displayed as tree and arch views." |
| 43 | loc.TOUR_tourdone = loc.TOUR_tourdone || "Have fun with KorAP!"; |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 44 | |
| 45 | //localization of button labels |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 46 | let labelOptions = { |
| 47 | 'skipLabel': loc.TOUR_lskip, |
| 48 | 'prevLabel': loc.TOUR_lprev, |
| 49 | 'nextLabel': loc.TOUR_lnext, |
| 50 | 'doneLabel': loc.TOUR_ldone, |
| 51 | 'showStepNumbers': false, |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 52 | }; |
hebasta | 87f1b1f | 2019-07-30 13:03:23 +0200 | [diff] [blame] | 53 | |
| 54 | var doe = document; |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 55 | |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 56 | return{ |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 57 | |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 58 | /** |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 59 | * Guided Tour gTstartSearch: Explains the search functionality |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 60 | */ |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 61 | gTstartSearch:function(elparam){ |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 62 | let intro = introClass(); |
| 63 | intro.setOptions(labelOptions); |
| 64 | intro.setOption('doneLabel', loc.TOUR_seargo); |
| 65 | |
| 66 | //for testing purposes |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 67 | if(elparam){ |
| 68 | doe = elparam; |
| 69 | } |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 70 | |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 71 | let input = doe.querySelector("#q-field"); |
| 72 | input.value=""; |
| 73 | |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 74 | |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 75 | //steps of the example tour |
| 76 | let Steps =[ |
| 77 | { |
| 78 | element: '#searchbar', |
| 79 | intro: loc.TOUR_sear1, |
| 80 | position: 'bottom' |
| 81 | }, |
| 82 | { |
| 83 | element: '#searchbar', |
| 84 | intro: loc.TOUR_sear2, |
| 85 | position: 'bottom' |
| 86 | }, |
| 87 | { |
| 88 | element: '#hint', |
| 89 | intro: loc.TOUR_searAnnot, |
| 90 | position: 'bottom' |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 91 | }, |
| 92 | { |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 93 | element:'#vc-choose', |
| 94 | intro: loc.TOUR_vccho1, |
| 95 | position: "bottom", |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 96 | }, |
| 97 | { |
| 98 | element:'#vc-view', |
| 99 | intro: loc.TOUR_vccho2, |
| 100 | position: "bottom", |
| 101 | }, |
| 102 | { |
hebasta | d090a51 | 2019-07-10 16:36:01 +0200 | [diff] [blame] | 103 | element: doe.querySelector('.statistic'), |
hebasta | 94e47cb | 2019-07-24 22:24:27 +0200 | [diff] [blame] | 104 | intro: loc.TOUR_vcStat1, |
hebasta | d090a51 | 2019-07-10 16:36:01 +0200 | [diff] [blame] | 105 | position: "left", |
| 106 | }, |
| 107 | { |
hebasta | 94e47cb | 2019-07-24 22:24:27 +0200 | [diff] [blame] | 108 | element: doe.querySelector('.stattable'), |
| 109 | intro: loc.TOUR_vcStat2, |
| 110 | position: "bottom", |
| 111 | }, |
| 112 | { |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 113 | element: doe.querySelector('#ql-field').parentNode, |
| 114 | intro: loc.TOUR_qlfield, |
| 115 | position: "bottom", |
| 116 | }, |
| 117 | { |
| 118 | element:'#glimpse', |
| 119 | intro: loc.TOUR_glimpse, |
| 120 | position: "bottom", |
| 121 | }, |
| 122 | { |
| 123 | element:'#view-tutorial', |
| 124 | intro: loc.TOUR_help, |
| 125 | position: "bottom", |
| 126 | }, |
| 127 | { |
| 128 | element: '#qsubmit', |
| 129 | intro: loc.TOUR_seargo, |
| 130 | position: "bottom", |
| 131 | }, |
| 132 | ]; |
| 133 | |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 134 | //pass in the Steps array created earlier |
hebasta | 87f1b1f | 2019-07-30 13:03:23 +0200 | [diff] [blame] | 135 | intro.setOptions({steps: Steps}); |
| 136 | this.testPrerequ(Steps, intro); |
| 137 | |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 138 | //changes before executing the single steps |
| 139 | intro.onbeforechange(function(targetedElement){ |
| 140 | switch(targetedElement.id){ |
| 141 | case "searchbar": |
hebasta | d090a51 | 2019-07-10 16:36:01 +0200 | [diff] [blame] | 142 | /* |
| 143 | * TODO: |
| 144 | * #268 is not merged at the time beeing: |
| 145 | * introJs.currentStep() merge requested https://github.com/usablica/intro.js/pull/268/files |
| 146 | */ |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 147 | if(this._currentStep == 1){ |
| 148 | input = doe.querySelector('#q-field'); |
| 149 | input.value= loc.TOUR_Qexample; |
| 150 | } |
| 151 | break; |
| 152 | |
| 153 | case "vc-view": |
| 154 | vchoo = doe.querySelector("#vc-choose"); |
| 155 | vcv = doe.querySelector("#vc-view"); |
| 156 | KorAP._delete.apply(KorAP.vc.root()); |
hebasta | 94e47cb | 2019-07-24 22:24:27 +0200 | [diff] [blame] | 157 | |
| 158 | KorAP.vc.fromJson(loc.TOUR_vcQuery); |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 159 | if(!(vcv.querySelector(".active"))){ |
| 160 | vchoo.click(); |
hebasta | d090a51 | 2019-07-10 16:36:01 +0200 | [diff] [blame] | 161 | /* |
| 162 | * Intro.js caches elements at the beginning, so element and position has to be set again. |
| 163 | */ |
hebasta | 94e47cb | 2019-07-24 22:24:27 +0200 | [diff] [blame] | 164 | intro._introItems[5].element = doe.querySelector('.statistic'); |
| 165 | intro._introItems[5].position = "left"; |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 166 | } |
| 167 | break; |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 168 | |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 169 | /* |
| 170 | * Sets button labels for the last step of the tour |
| 171 | * Because Kalamar is a multipage webapplication, this tours starts by |
| 172 | * completion the gTshowResults Tour. Therefore, the skip-button is removed |
| 173 | * and the label of the done button changed. |
| 174 | */ |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 175 | case "qsubmit": |
| 176 | intro.setOption('hideNext', true); |
| 177 | break; |
| 178 | } |
hebasta | 94e47cb | 2019-07-24 22:24:27 +0200 | [diff] [blame] | 179 | |
| 180 | if(this._currentStep == 6){ |
| 181 | let statbut = doe.querySelector('.statistic'); |
| 182 | statbut.click(); |
| 183 | intro._introItems[6].element = doe.querySelector(".stattable"); |
| 184 | intro._introItems[6].position = "bottom"; |
| 185 | } |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 186 | }); |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 187 | |
| 188 | |
| 189 | // Execute at the end of the tour (By clicking at the done-Button) |
| 190 | intro.oncomplete(function(){ |
| 191 | KorAP.session.set("tour", true); |
hebasta | 94e47cb | 2019-07-24 22:24:27 +0200 | [diff] [blame] | 192 | doe.getElementById("qsubmit").click(); |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 193 | }); |
| 194 | |
| 195 | return intro; |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 196 | }, |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 197 | |
| 198 | |
| 199 | /* Guided Tour to explain the different views of the results */ |
hebasta | 87f1b1f | 2019-07-30 13:03:23 +0200 | [diff] [blame] | 200 | gTshowResults: function(elparam){ |
| 201 | //for testing purposes |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 202 | if(elparam){ |
| 203 | doe = elparam; |
| 204 | } |
| 205 | let tourR = introClass(); |
| 206 | let StepsSR = [ |
hebasta | 87f1b1f | 2019-07-30 13:03:23 +0200 | [diff] [blame] | 207 | //Step 1, intro_item 0 |
| 208 | { |
| 209 | element: '#search', |
| 210 | intro: loc.TOUR_kwic , |
| 211 | position: "auto", |
| 212 | }, |
| 213 | //Step 2, intro_item 1 |
| 214 | { |
| 215 | element: doe.querySelector("#search > ol > li"), |
| 216 | intro: loc.TOUR_snippet, |
| 217 | position: "bottom", |
| 218 | }, |
| 219 | //Step 3, intro_item 2 |
| 220 | { |
| 221 | element: doe.querySelector("#search > ol > li"), |
| 222 | intro: loc.TOUR_snippetb, |
| 223 | position: "bottom", |
| 224 | }, |
| 225 | //Step 4, intro_item 3 |
| 226 | { |
| 227 | element: doe.querySelector(".action > .metatable"), |
| 228 | intro: loc.TOUR_metadatab, |
| 229 | position: "bottom", |
| 230 | }, |
| 231 | //Step 5, intro_item 4 |
| 232 | { |
| 233 | element: doe.querySelector(".view.metatable"), |
| 234 | intro: loc.TOUR_metadata, |
| 235 | position: "auto", |
| 236 | }, |
| 237 | //Step 6, intro_item 5 |
| 238 | { |
| 239 | element: doe.querySelector(".action > .info"), |
| 240 | intro: loc.TOUR_tokenb, |
| 241 | position: "bottom", |
| 242 | }, |
| 243 | //Step 7, intro_item 6 |
| 244 | { |
| 245 | element: doe.querySelector(".view.tokentable"), |
| 246 | intro: loc.TOUR_token, |
| 247 | position: "auto", |
| 248 | }, |
| 249 | //Step 8, intro_item 7 |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 250 | { |
hebasta | 87f1b1f | 2019-07-30 13:03:23 +0200 | [diff] [blame] | 251 | element: doe.querySelector(".tree"), |
| 252 | intro: loc.TOUR_treeb, |
| 253 | position: "bottom", |
| 254 | }, |
| 255 | //Step 9, intro_item 8 |
| 256 | { |
| 257 | element: doe.querySelector("view.relations"), |
| 258 | intro: loc.TOUR_tree, |
| 259 | position: "auto", |
| 260 | }, |
| 261 | //Step 10, intro_item 9 |
| 262 | { |
| 263 | intro: loc.TOUR_tourdone, |
| 264 | } |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 265 | ] |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 266 | |
hebasta | 87f1b1f | 2019-07-30 13:03:23 +0200 | [diff] [blame] | 267 | tourR.setOptions({steps:StepsSR}); |
| 268 | tourR.setOptions(labelOptions); |
| 269 | |
| 270 | tourR.onbeforechange(function (){ |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 271 | KorAP.session.set("tour", false); |
hebasta | 87f1b1f | 2019-07-30 13:03:23 +0200 | [diff] [blame] | 272 | }); |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 273 | |
hebasta | 87f1b1f | 2019-07-30 13:03:23 +0200 | [diff] [blame] | 274 | //See also: https://introjs.com/docs/intro/options/ |
| 275 | tourR.setOption('scrollToElement', true); |
| 276 | tourR.setOption('scrollTo','tooltip'); |
| 277 | this.testPrerequ(StepsSR, tourR); |
| 278 | |
| 279 | //TODO see also: introJS.totalSteps() merge requested: //github.com/usablica/intro.js/pull/268/files |
| 280 | tourR.onbeforechange(function(targetedElement){ |
| 281 | |
| 282 | if(this._currentStep == 1){ |
| 283 | KorAP.session.set("tour", false); |
| 284 | } |
| 285 | |
| 286 | if(this._currentStep == 2){ |
| 287 | doe.querySelector("#search > ol > li").click(); |
| 288 | tourR._introItems[3].element = doe.querySelector('.action > .metatable'); |
| 289 | tourR._introItems[3].position = "bottom"; |
| 290 | } |
| 291 | |
| 292 | if(this._currentStep == 4){ |
| 293 | doe.querySelector(".metatable").click(); |
| 294 | tourR._introItems[4].element = doe.querySelector('.view.metatable'); |
| 295 | tourR._introItems[5].element = doe.querySelector('.action > .info'); |
| 296 | tourR._introItems[5].position = "bottom"; |
| 297 | } |
| 298 | |
| 299 | if(this._currentStep == 6){ |
| 300 | doe.querySelector(".info").click(); |
| 301 | tourR._introItems[6].element = doe.querySelector('.view.tokentable'); |
| 302 | tourR._introItems[7].element = doe.querySelector('.tree'); |
| 303 | tourR._introItems[7].position = "bottom"; |
| 304 | } |
| 305 | |
| 306 | if(this._currentStep == 8){ |
| 307 | doe.querySelector(".tree").click(); |
| 308 | document.querySelectorAll(".button-group-list")[0].querySelectorAll('li')[1].click(); |
| 309 | } |
| 310 | }); |
| 311 | |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 312 | return tourR; |
| 313 | }, |
hebasta | 87f1b1f | 2019-07-30 13:03:23 +0200 | [diff] [blame] | 314 | /* |
| 315 | * The total number of steps and the text of the tooltips are needed for jasmine testing. |
| 316 | */ |
| 317 | testPrerequ: function(steps, tour){ |
| 318 | //TODO see also: introJS.totalSteps() merge requested: //github.com/usablica/intro.js/pull/268/files |
| 319 | let StepsT = steps; |
| 320 | let gtour = tour; |
| 321 | gtour.stepCount = StepsT.length; |
| 322 | |
| 323 | //Array of intro content needed for efficient testing |
| 324 | gtour.testIntros = []; |
| 325 | |
| 326 | for(let i = 0; i< StepsT.length; i++){ |
| 327 | gtour.testIntros.push(StepsT[i].intro); |
| 328 | } |
| 329 | }, |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 330 | |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 331 | } |
| 332 | }); |