|
82 | 82 | }
|
83 | 83 |
|
84 | 84 | } else {
|
85 |
| - //use steps from data-* annotations |
86 |
| - |
| 85 | + //use steps from data-* annotations |
87 | 86 | var allIntroSteps = targetElm.querySelectorAll('*[data-intro]');
|
88 | 87 | //if there's no element to intro
|
89 | 88 | if (allIntroSteps.length < 1) {
|
90 | 89 | return false;
|
91 | 90 | }
|
92 | 91 |
|
| 92 | + //first add intro items with data-step |
93 | 93 | for (var i = 0, elmsLength = allIntroSteps.length; i < elmsLength; i++) {
|
94 | 94 | var currentElement = allIntroSteps[i];
|
95 | 95 | var step = parseInt(currentElement.getAttribute('data-step'), 10);
|
96 |
| - introItems.push({ |
97 |
| - element: currentElement, |
98 |
| - intro: currentElement.getAttribute('data-intro'), |
99 |
| - //if step==NaN set step to 100 |
100 |
| - step: step ? step : 100, |
101 |
| - tooltipClass: currentElement.getAttribute('data-tooltipClass'), |
102 |
| - position: currentElement.getAttribute('data-position') || this._options.tooltipPosition |
103 |
| - }); |
| 96 | + |
| 97 | + if (step > 0) { |
| 98 | + introItems[step - 1] = { |
| 99 | + element: currentElement, |
| 100 | + intro: currentElement.getAttribute('data-intro'), |
| 101 | + step: parseInt(currentElement.getAttribute('data-step'), 10), |
| 102 | + tooltipClass: currentElement.getAttribute('data-tooltipClass'), |
| 103 | + position: currentElement.getAttribute('data-position') || this._options.tooltipPosition |
| 104 | + }; |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + //next add intro items without data-step |
| 109 | + //todo: we need a cleanup here, two loops are redundant |
| 110 | + var nextStep = 0; |
| 111 | + for (var i = 0, elmsLength = allIntroSteps.length; i < elmsLength; i++) { |
| 112 | + var currentElement = allIntroSteps[i]; |
| 113 | + |
| 114 | + if (currentElement.getAttribute('data-step') == null) { |
| 115 | + |
| 116 | + while(true) { |
| 117 | + if (typeof introItems[nextStep] == 'undefined') { |
| 118 | + break; |
| 119 | + } else { |
| 120 | + nextStep++; |
| 121 | + } |
| 122 | + } |
| 123 | + |
| 124 | + introItems.push({ |
| 125 | + element: currentElement, |
| 126 | + intro: currentElement.getAttribute('data-intro'), |
| 127 | + step: nextStep + 1, |
| 128 | + tooltipClass: currentElement.getAttribute('data-tooltipClass'), |
| 129 | + position: currentElement.getAttribute('data-position') || this._options.tooltipPosition |
| 130 | + }); |
| 131 | + } |
104 | 132 | }
|
105 | 133 | }
|
106 | 134 |
|
| 135 | + //removing undefined/null elements |
| 136 | + introItems = introItems.filter(function(n){ return n; }); |
| 137 | + |
107 | 138 | //Ok, sort all items with given steps
|
108 | 139 | introItems.sort(function (a, b) {
|
109 | 140 | return a.step - b.step;
|
|
0 commit comments