@@ -78,6 +78,8 @@ export default function fetchIntroSteps(
78
78
return [ ] ;
79
79
}
80
80
81
+ const itemsWithoutStep : IntroStep [ ] = [ ] ;
82
+
81
83
for ( const currentElement of allIntroSteps ) {
82
84
// start intro for groups of elements
83
85
if (
@@ -92,81 +94,50 @@ export default function fetchIntroSteps(
92
94
continue ;
93
95
}
94
96
95
- const step = parseInt ( currentElement . getAttribute ( "data-step" ) || "" , 10 ) ;
97
+ // get the step for the current element or set as 0 if is not present
98
+ const step = parseInt (
99
+ currentElement . getAttribute ( "data-step" ) || "0" ,
100
+ 10
101
+ ) ;
96
102
97
103
disableInteraction = intro . _options . disableInteraction ;
98
104
if ( currentElement . hasAttribute ( "data-disable-interaction" ) ) {
99
105
disableInteraction = ! ! currentElement . getAttribute (
100
106
"data-disable-interaction"
101
107
) ;
102
108
}
109
+ const newIntroStep : IntroStep = {
110
+ step : step ,
111
+ element : currentElement ,
112
+ title : currentElement . getAttribute ( "data-title" ) || "" ,
113
+ intro : currentElement . getAttribute ( "data-intro" ) || "" ,
114
+ tooltipClass :
115
+ currentElement . getAttribute ( "data-tooltip-class" ) || undefined ,
116
+ highlightClass :
117
+ currentElement . getAttribute ( "data-highlight-class" ) || undefined ,
118
+ position : ( currentElement . getAttribute ( "data-position" ) ||
119
+ intro . _options . tooltipPosition ) as TooltipPosition ,
120
+ scrollTo :
121
+ ( currentElement . getAttribute ( "data-scroll-to" ) as ScrollTo ) ||
122
+ intro . _options . scrollTo ,
123
+ disableInteraction,
124
+ } ;
103
125
104
126
if ( step > 0 ) {
105
- introItems [ step - 1 ] = {
106
- step : step ,
107
- element : currentElement ,
108
- title : currentElement . getAttribute ( "data-title" ) || "" ,
109
- intro : currentElement . getAttribute ( "data-intro" ) || "" ,
110
- tooltipClass :
111
- currentElement . getAttribute ( "data-tooltip-class" ) || undefined ,
112
- highlightClass :
113
- currentElement . getAttribute ( "data-highlight-class" ) || undefined ,
114
- position : ( currentElement . getAttribute ( "data-position" ) ||
115
- intro . _options . tooltipPosition ) as TooltipPosition ,
116
- scrollTo :
117
- ( currentElement . getAttribute ( "data-scroll-to" ) as ScrollTo ) ||
118
- intro . _options . scrollTo ,
119
- disableInteraction,
120
- } ;
127
+ introItems [ step - 1 ] = newIntroStep ;
128
+ } else {
129
+ itemsWithoutStep . push ( newIntroStep ) ;
121
130
}
122
131
}
123
132
124
- //next add intro items without data-step
125
- //todo: we need a cleanup here, two loops are redundant
126
- let nextStep = 0 ;
127
-
128
- for ( const currentElement of allIntroSteps ) {
129
- // start intro for groups of elements
130
- if (
131
- intro . _options . group &&
132
- currentElement . getAttribute ( "data-intro-group" ) !== intro . _options . group
133
- ) {
134
- continue ;
135
- }
136
-
137
- if ( currentElement . getAttribute ( "data-step" ) === null ) {
138
- while ( true ) {
139
- if ( typeof introItems [ nextStep ] === "undefined" ) {
140
- break ;
141
- } else {
142
- nextStep ++ ;
143
- }
144
- }
145
-
146
- if ( currentElement . hasAttribute ( "data-disable-interaction" ) ) {
147
- disableInteraction = ! ! currentElement . getAttribute (
148
- "data-disable-interaction"
149
- ) ;
150
- } else {
151
- disableInteraction = intro . _options . disableInteraction ;
152
- }
133
+ //fill items without step in blanks and update their step
134
+ for ( let i = 0 ; itemsWithoutStep . length > 0 ; i ++ ) {
135
+ if ( typeof introItems [ i ] === "undefined" ) {
136
+ const newStep = itemsWithoutStep . shift ( ) ;
137
+ if ( ! newStep ) break ;
153
138
154
- introItems [ nextStep ] = {
155
- element : currentElement ,
156
- title : currentElement . getAttribute ( "data-title" ) || "" ,
157
- intro : currentElement . getAttribute ( "data-intro" ) || "" ,
158
- step : nextStep + 1 ,
159
- tooltipClass :
160
- currentElement . getAttribute ( "data-tooltip-class" ) || undefined ,
161
- highlightClass :
162
- currentElement . getAttribute ( "data-highlight-class" ) || undefined ,
163
- position : ( currentElement . getAttribute ( "data-position" ) ||
164
- intro . _options . tooltipPosition ) as TooltipPosition ,
165
- scrollTo :
166
- ( currentElement . getAttribute ( "data-scroll-to" ) as ScrollTo ) ||
167
- intro . _options . scrollTo ,
168
- disableInteraction,
169
- } ;
139
+ newStep . step = i + 1 ;
140
+ introItems [ i ] = newStep ;
170
141
}
171
142
}
172
143
}
0 commit comments