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 | |
| 7 | define(['lib/intro', 'vc'], function(introClass, vcClass) { |
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 | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 20 | loc.TOUR_sear2 = loc.TOUR_sear2 || "For example the search for '" + loc.TOUR_Qexample + "'"; |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 21 | loc.TOUR_searAnnot = loc.TOUR_searAnnot || "Annotation helper: By clicking here, the annotations of the differents layers are displayed and can be selected."; |
| 22 | loc.TOUR_annotAss = loc.TOUR_annotAss || "The annoation assistant helps to formulate queries with annotations"; |
| 23 | loc.TOUR_vccho1 = loc.TOUR_vccho1 || "Choose corpus by clicking here."; |
| 24 | loc.TOUR_vccho2 = loc.TOUR_vccho2 || "Define your corpus here."; |
| 25 | loc.TOUR_vcStat = loc.TOUR_vcStat || "Display corpus statistic."; |
| 26 | loc.TOUR_qlfield = loc.TOUR_qlfield|| "You can use KorAP with different query languages, select the query language here."; |
| 27 | loc.TOUR_help = loc.TOUR_help || "Help and more information about KorAP."; |
| 28 | loc.TOUR_glimpse = loc.TOUR_glimpse || "Select to show only the first hits in arbitrary order."; |
| 29 | loc.TOUR_seargo = loc.TOUR_seargo || "Start the search."; |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 30 | //localization guided Tour gTshowResults |
| 31 | loc.TOUR_result = loc.TOUR_result || "Have fun with KorAP!"; |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 32 | |
| 33 | //localization of button labels |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 34 | let labelOptions = { |
| 35 | 'skipLabel': loc.TOUR_lskip, |
| 36 | 'prevLabel': loc.TOUR_lprev, |
| 37 | 'nextLabel': loc.TOUR_lnext, |
| 38 | 'doneLabel': loc.TOUR_ldone, |
| 39 | 'showStepNumbers': false, |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 40 | }; |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 41 | |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 42 | return{ |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 43 | |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 44 | /** |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 45 | * Guided Tour gTstartSearch: Explains the search functionality |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 46 | */ |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 47 | gTstartSearch:function(elparam){ |
| 48 | |
| 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 | { |
| 91 | element: doe.querySelector('#ql-field').parentNode, |
| 92 | intro: loc.TOUR_qlfield, |
| 93 | position: "bottom", |
| 94 | }, |
| 95 | { |
| 96 | element:'#glimpse', |
| 97 | intro: loc.TOUR_glimpse, |
| 98 | position: "bottom", |
| 99 | }, |
| 100 | { |
| 101 | element:'#view-tutorial', |
| 102 | intro: loc.TOUR_help, |
| 103 | position: "bottom", |
| 104 | }, |
| 105 | { |
| 106 | element: '#qsubmit', |
| 107 | intro: loc.TOUR_seargo, |
| 108 | position: "bottom", |
| 109 | }, |
| 110 | ]; |
| 111 | |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 112 | //pass in the Steps array created earlier |
| 113 | intro.setOptions({steps: Steps}); |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 114 | |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 115 | //total number of steps, needed for jasmine tests |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 116 | //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] | 117 | intro.stepCount = Steps.length; |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 118 | |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 119 | //array of intro content needed for efficient testing |
| 120 | intro.testIntros = []; |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 121 | |
| 122 | for(let i = 0; i< Steps.length; i++){ |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 123 | intro.testIntros.push(Steps[i].intro); |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | //changes before executing the single steps |
| 127 | intro.onbeforechange(function(targetedElement){ |
| 128 | switch(targetedElement.id){ |
| 129 | case "searchbar": |
| 130 | if(this._currentStep == 1){ |
| 131 | input = doe.querySelector('#q-field'); |
| 132 | input.value= loc.TOUR_Qexample; |
| 133 | } |
| 134 | break; |
| 135 | |
| 136 | case "vc-view": |
| 137 | vchoo = doe.querySelector("#vc-choose"); |
| 138 | vcv = doe.querySelector("#vc-view"); |
| 139 | KorAP._delete.apply(KorAP.vc.root()); |
| 140 | KorAP.vc.root().key("creationDate").update(); |
| 141 | KorAP.vc.root().value("1820").update(); |
| 142 | if(!(vcv.querySelector(".active"))){ |
| 143 | vchoo.click(); |
| 144 | } |
| 145 | break; |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 146 | |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 147 | /* |
| 148 | * Sets button labels for the last step of the tour |
| 149 | * Because Kalamar is a multipage webapplication, this tours starts by |
| 150 | * completion the gTshowResults Tour. Therefore, the skip-button is removed |
| 151 | * and the label of the done button changed. |
| 152 | */ |
| 153 | |
| 154 | case "qsubmit": |
| 155 | intro.setOption('hideNext', true); |
| 156 | break; |
| 157 | } |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 158 | }); |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 159 | |
| 160 | |
| 161 | // Execute at the end of the tour (By clicking at the done-Button) |
| 162 | intro.oncomplete(function(){ |
| 163 | KorAP.session.set("tour", true); |
| 164 | let form = doe.getElementById("searchform"); |
| 165 | form.submit(); |
| 166 | //input.value=""; |
| 167 | //KorAP._delete.apply(KorAP.vc.root()); |
| 168 | }); |
| 169 | |
| 170 | return intro; |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 171 | }, |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 172 | |
| 173 | |
| 174 | /* Guided Tour to explain the different views of the results */ |
| 175 | gTshowResults: function(elparam){ |
| 176 | if(elparam){ |
| 177 | doe = elparam; |
| 178 | } |
| 179 | let tourR = introClass(); |
| 180 | let StepsSR = [ |
| 181 | { |
| 182 | intro: loc.TOUR_result, |
| 183 | } |
| 184 | ] |
| 185 | tourR.setOptions({steps:StepsSR}); |
| 186 | tourR.setOptions(labelOptions); |
| 187 | |
| 188 | tourR.onbeforechange(function (){ |
| 189 | KorAP.session.set("tour", false); |
| 190 | }); |
| 191 | |
| 192 | return tourR; |
| 193 | }, |
| 194 | |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 195 | } |
| 196 | }); |