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 | 94e47cb | 2019-07-24 22:24:27 +0200 | [diff] [blame] | 7 | define(['lib/intro', 'vc', 'vc/doc', 'vc/docgroup'], function(introClass, vcClass, docClass, docGroup) { |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 8 | |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 9 | //needed for localization of labels and contents of the tour |
| 10 | const loc = KorAP.Locale; |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 11 | |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 12 | //labels for nextStep, previousStep, done and abort |
| 13 | loc.TOUR_lskip = loc.TOUR_lskip || "Abort"; |
| 14 | loc.TOUR_lprev = loc.TOUR_lprev || "Back"; |
| 15 | loc.TOUR_lnext = loc.TOUR_lnext || "Next"; |
| 16 | loc.TOUR_ldone = loc.TOUR_ldone || "Done"; |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 17 | |
| 18 | //localization guided tour gTstartSearch |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 19 | loc.TOUR_sear1 = loc.TOUR_sear1 || "Enter your search enquiry here."; |
hebasta | d090a51 | 2019-07-10 16:36:01 +0200 | [diff] [blame] | 20 | 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] | 21 | 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] | 22 | 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] | 23 | loc.TOUR_vccho1 = loc.TOUR_vccho1 || "Choose corpus"; |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 24 | loc.TOUR_vccho2 = loc.TOUR_vccho2 || "Define your corpus here."; |
hebasta | 94e47cb | 2019-07-24 22:24:27 +0200 | [diff] [blame] | 25 | loc.TOUR_vcStat1 = loc.TOUR_vcStat1 || "Click here to display corpus statistic."; |
| 26 | loc.TOUR_vcStat2 = loc.TOUR_vcStat2 || "Corpus statistic"; |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 27 | loc.TOUR_qlfield = loc.TOUR_qlfield|| "You can use KorAP with different query languages, select the query language here."; |
| 28 | loc.TOUR_help = loc.TOUR_help || "Help and more information about KorAP."; |
| 29 | loc.TOUR_glimpse = loc.TOUR_glimpse || "Select to show only the first hits in arbitrary order."; |
| 30 | loc.TOUR_seargo = loc.TOUR_seargo || "Start the search."; |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 31 | //localization guided Tour gTshowResults |
| 32 | loc.TOUR_result = loc.TOUR_result || "Have fun with KorAP!"; |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 33 | |
| 34 | //localization of button labels |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 35 | let labelOptions = { |
| 36 | 'skipLabel': loc.TOUR_lskip, |
| 37 | 'prevLabel': loc.TOUR_lprev, |
| 38 | 'nextLabel': loc.TOUR_lnext, |
| 39 | 'doneLabel': loc.TOUR_ldone, |
| 40 | 'showStepNumbers': false, |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 41 | }; |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 42 | |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 43 | return{ |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 44 | |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 45 | /** |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 46 | * Guided Tour gTstartSearch: Explains the search functionality |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 47 | */ |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 48 | gTstartSearch:function(elparam){ |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 49 | let intro = introClass(); |
| 50 | intro.setOptions(labelOptions); |
| 51 | intro.setOption('doneLabel', loc.TOUR_seargo); |
| 52 | |
| 53 | //for testing purposes |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 54 | var doe = document; |
| 55 | if(elparam){ |
| 56 | doe = elparam; |
| 57 | } |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 58 | |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 59 | let input = doe.querySelector("#q-field"); |
| 60 | input.value=""; |
| 61 | |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 62 | |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 63 | //steps of the example tour |
| 64 | let Steps =[ |
| 65 | { |
| 66 | element: '#searchbar', |
| 67 | intro: loc.TOUR_sear1, |
| 68 | position: 'bottom' |
| 69 | }, |
| 70 | { |
| 71 | element: '#searchbar', |
| 72 | intro: loc.TOUR_sear2, |
| 73 | position: 'bottom' |
| 74 | }, |
| 75 | { |
| 76 | element: '#hint', |
| 77 | intro: loc.TOUR_searAnnot, |
| 78 | position: 'bottom' |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 79 | }, |
| 80 | { |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 81 | element:'#vc-choose', |
| 82 | intro: loc.TOUR_vccho1, |
| 83 | position: "bottom", |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 84 | }, |
| 85 | { |
| 86 | element:'#vc-view', |
| 87 | intro: loc.TOUR_vccho2, |
| 88 | position: "bottom", |
| 89 | }, |
| 90 | { |
hebasta | d090a51 | 2019-07-10 16:36:01 +0200 | [diff] [blame] | 91 | element: doe.querySelector('.statistic'), |
hebasta | 94e47cb | 2019-07-24 22:24:27 +0200 | [diff] [blame] | 92 | intro: loc.TOUR_vcStat1, |
hebasta | d090a51 | 2019-07-10 16:36:01 +0200 | [diff] [blame] | 93 | position: "left", |
| 94 | }, |
| 95 | { |
hebasta | 94e47cb | 2019-07-24 22:24:27 +0200 | [diff] [blame] | 96 | element: doe.querySelector('.stattable'), |
| 97 | intro: loc.TOUR_vcStat2, |
| 98 | position: "bottom", |
| 99 | }, |
| 100 | { |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 101 | element: doe.querySelector('#ql-field').parentNode, |
| 102 | intro: loc.TOUR_qlfield, |
| 103 | position: "bottom", |
| 104 | }, |
| 105 | { |
| 106 | element:'#glimpse', |
| 107 | intro: loc.TOUR_glimpse, |
| 108 | position: "bottom", |
| 109 | }, |
| 110 | { |
| 111 | element:'#view-tutorial', |
| 112 | intro: loc.TOUR_help, |
| 113 | position: "bottom", |
| 114 | }, |
| 115 | { |
| 116 | element: '#qsubmit', |
| 117 | intro: loc.TOUR_seargo, |
| 118 | position: "bottom", |
| 119 | }, |
| 120 | ]; |
| 121 | |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 122 | //pass in the Steps array created earlier |
| 123 | intro.setOptions({steps: Steps}); |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 124 | |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 125 | //total number of steps, needed for jasmine tests |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 126 | //TODO see also: introJS.totalSteps() merge requested: //github.com/usablica/intro.js/pull/268/files |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 127 | intro.stepCount = Steps.length; |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 128 | |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 129 | //array of intro content needed for efficient testing |
| 130 | intro.testIntros = []; |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 131 | |
| 132 | for(let i = 0; i< Steps.length; i++){ |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 133 | intro.testIntros.push(Steps[i].intro); |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | //changes before executing the single steps |
| 137 | intro.onbeforechange(function(targetedElement){ |
| 138 | switch(targetedElement.id){ |
| 139 | case "searchbar": |
hebasta | d090a51 | 2019-07-10 16:36:01 +0200 | [diff] [blame] | 140 | /* |
| 141 | * TODO: |
| 142 | * #268 is not merged at the time beeing: |
| 143 | * introJs.currentStep() merge requested https://github.com/usablica/intro.js/pull/268/files |
| 144 | */ |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 145 | if(this._currentStep == 1){ |
| 146 | input = doe.querySelector('#q-field'); |
| 147 | input.value= loc.TOUR_Qexample; |
| 148 | } |
| 149 | break; |
| 150 | |
| 151 | case "vc-view": |
| 152 | vchoo = doe.querySelector("#vc-choose"); |
| 153 | vcv = doe.querySelector("#vc-view"); |
| 154 | KorAP._delete.apply(KorAP.vc.root()); |
hebasta | 94e47cb | 2019-07-24 22:24:27 +0200 | [diff] [blame] | 155 | |
| 156 | KorAP.vc.fromJson(loc.TOUR_vcQuery); |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 157 | if(!(vcv.querySelector(".active"))){ |
| 158 | vchoo.click(); |
hebasta | d090a51 | 2019-07-10 16:36:01 +0200 | [diff] [blame] | 159 | /* |
| 160 | * Intro.js caches elements at the beginning, so element and position has to be set again. |
| 161 | */ |
hebasta | 94e47cb | 2019-07-24 22:24:27 +0200 | [diff] [blame] | 162 | intro._introItems[5].element = doe.querySelector('.statistic'); |
| 163 | intro._introItems[5].position = "left"; |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 164 | } |
| 165 | break; |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 166 | |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 167 | /* |
| 168 | * Sets button labels for the last step of the tour |
| 169 | * Because Kalamar is a multipage webapplication, this tours starts by |
| 170 | * completion the gTshowResults Tour. Therefore, the skip-button is removed |
| 171 | * and the label of the done button changed. |
| 172 | */ |
| 173 | |
| 174 | case "qsubmit": |
| 175 | intro.setOption('hideNext', true); |
| 176 | break; |
| 177 | } |
hebasta | 94e47cb | 2019-07-24 22:24:27 +0200 | [diff] [blame] | 178 | |
| 179 | if(this._currentStep == 6){ |
| 180 | let statbut = doe.querySelector('.statistic'); |
| 181 | statbut.click(); |
| 182 | intro._introItems[6].element = doe.querySelector(".stattable"); |
| 183 | intro._introItems[6].position = "bottom"; |
| 184 | } |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 185 | }); |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 186 | |
| 187 | |
| 188 | // Execute at the end of the tour (By clicking at the done-Button) |
| 189 | intro.oncomplete(function(){ |
| 190 | KorAP.session.set("tour", true); |
hebasta | 94e47cb | 2019-07-24 22:24:27 +0200 | [diff] [blame] | 191 | doe.getElementById("qsubmit").click(); |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 192 | //input.value=""; |
| 193 | //KorAP._delete.apply(KorAP.vc.root()); |
| 194 | }); |
| 195 | |
| 196 | return intro; |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 197 | }, |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 198 | |
| 199 | |
| 200 | /* Guided Tour to explain the different views of the results */ |
| 201 | gTshowResults: function(elparam){ |
| 202 | if(elparam){ |
| 203 | doe = elparam; |
| 204 | } |
| 205 | let tourR = introClass(); |
| 206 | let StepsSR = [ |
| 207 | { |
| 208 | intro: loc.TOUR_result, |
| 209 | } |
| 210 | ] |
| 211 | tourR.setOptions({steps:StepsSR}); |
| 212 | tourR.setOptions(labelOptions); |
| 213 | |
| 214 | tourR.onbeforechange(function (){ |
| 215 | KorAP.session.set("tour", false); |
| 216 | }); |
| 217 | |
| 218 | return tourR; |
| 219 | }, |
| 220 | |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 221 | } |
| 222 | }); |