|
1 |
| -/* global jQuery*/ |
| 1 | +/* global jQuery,setInterval, clearInterval*/ |
2 | 2 | 'use strict';
|
3 | 3 |
|
4 | 4 | (function($){
|
|
15 | 15 | base.options = $.extend({},$.introJs.defaultOptions, options);
|
16 | 16 | };
|
17 | 17 |
|
| 18 | + function trackElementChange(element){ |
| 19 | + var boundingClientRectOld = $(element).get(0).getBoundingClientRect(); |
| 20 | + var interval = setInterval(function _checkForChange(){ |
| 21 | + var boundingClientRectNew = $(element).get(0).getBoundingClientRect(); |
| 22 | + if(!angular.equals(boundingClientRectOld, boundingClientRectNew)){ |
| 23 | + $(element).trigger('changed.introjs'); |
| 24 | + } |
| 25 | + boundingClientRectOld = boundingClientRectNew; |
| 26 | + }, 1000); |
| 27 | + $(element).data('introjsInterval', interval); |
| 28 | + } |
| 29 | + |
| 30 | + function untrackElementChange(element){ |
| 31 | + clearInterval($(element).data('introjsInterval')); |
| 32 | + } |
| 33 | + |
18 | 34 | function innerPositionElement(element, target, position, duration){
|
19 | 35 | var defer = jQuery.Deferred();
|
20 | 36 | var xPos = position.split(' ')[0];
|
|
92 | 108 |
|
93 | 109 | function outerPositionElement(element, target, position, offsetX, offsetY){
|
94 | 110 | var offset = convertOuterPositionToOffset(element, target, position);
|
95 |
| - offset.left += offsetX; |
96 |
| - offset.top += offsetY; |
| 111 | + offset.left += Number(offsetX || 0); |
| 112 | + offset.top += Number(offsetY || 0); |
97 | 113 | offset = fitOffsetToScreen(offset, element.outerWidth());
|
98 | 114 | return element.offset(offset);
|
99 | 115 | }
|
|
115 | 131 | var tooltip = $('<div><div class="intro-tooltip-content"></div><div class="intro-tooltip-arrow"></div></div>')
|
116 | 132 | .addClass('intro-tooltip');
|
117 | 133 | tooltip.hide();
|
| 134 | + |
118 | 135 | $('body').append(tooltip);
|
119 | 136 | return tooltip;
|
120 | 137 | }
|
|
165 | 182 | }
|
166 | 183 |
|
167 | 184 | function createHint(){
|
168 |
| - var hintClasses = 'intro-circle'; |
| 185 | + var hint = $('<div class="intro-hint"></div>'); |
169 | 186 | if (base.options.hintClass) {
|
170 |
| - hintClasses += ' ' + base.options.hintClass; |
| 187 | + hint.addClass(base.options.hintClass); |
171 | 188 | }
|
172 |
| - var hint = $('<div class="intro-hint"><div class="'+ hintClasses +'"></div></div>'); |
173 | 189 | hint.hide();
|
174 | 190 | $('body').append(hint);
|
| 191 | + trackElementChange(hint); |
| 192 | + $(hint).on('changed.introjs', that.render); |
175 | 193 | return hint;
|
176 | 194 | }
|
177 | 195 |
|
178 | 196 | function repositionTooltip(){
|
179 | 197 | var tooltipArrowElement = getTooltipArrowElement();
|
180 | 198 | var offsetX = 0, offsetY = 0;
|
| 199 | + |
| 200 | + if(tooltip.css('display') === 'none'){ |
| 201 | + tooltip.show(); |
| 202 | + } |
| 203 | + |
181 | 204 | if(tooltipPosition === 'top'){
|
182 | 205 | offsetY = -(tooltipArrowElement.outerHeight());
|
183 | 206 | }else if(tooltipPosition === 'bottom'){
|
|
195 | 218 |
|
196 | 219 | this.hideTooltip = function(){
|
197 | 220 | tooltip.hide();
|
| 221 | + tooltip.css('opacity', 0); |
198 | 222 | };
|
199 | 223 |
|
200 | 224 | this.setTarget = function(element){
|
|
214 | 238 | };
|
215 | 239 |
|
216 | 240 | this.destroy = function(){
|
| 241 | + untrackElementChange(this.element); |
217 | 242 | this.element.remove();
|
218 | 243 | tooltip.remove();
|
219 | 244 | };
|
220 | 245 |
|
| 246 | + this.isVisible = function(){ |
| 247 | + return Number($(tooltip).css('opacity')) > 0; |
| 248 | + }; |
| 249 | + |
221 | 250 | this.render = function(){
|
222 | 251 | var defer = jQuery.Deferred();
|
223 |
| - var duration = wasRendered ? 800 : 0; |
| 252 | + var duration = wasRendered ? 500 : 0; |
224 | 253 |
|
225 | 254 | that.element.show();
|
226 | 255 | innerPositionElement(that.element, targetElement, hintPosition, duration).then(function(){
|
227 | 256 | getTooltipArrowElement().attr('position', tooltipPosition);
|
228 |
| - tooltip.css('opacity', 0).show(); |
229 | 257 | repositionTooltip();
|
230 |
| - tooltip.animate({'opacity': 1}); |
| 258 | + |
| 259 | + if(!that.isVisible()){ |
| 260 | + tooltip.css('opacity', 0).show(); |
| 261 | + tooltip.animate({'opacity': 1}); |
| 262 | + }else{ |
| 263 | + tooltip.show(); |
| 264 | + } |
231 | 265 | defer.resolve();
|
232 | 266 | });
|
233 | 267 | wasRendered = true;
|
|
256 | 290 |
|
257 | 291 | function unhighlighElement(element){
|
258 | 292 | $(element).removeClass('intro-element');
|
| 293 | + $(element).removeClass('intro-element-disabled'); |
| 294 | + $(element).removeClass('intro-element-relative'); |
259 | 295 | $(element).parents('.intro-fixparent').removeClass('intro-fixparent');
|
260 | 296 | }
|
261 | 297 |
|
262 |
| - function highlightElement(element){ |
| 298 | + function highlightElement(element, interactive){ |
263 | 299 | $(element).addClass('intro-element');
|
| 300 | + if(!interactive){ |
| 301 | + $(element).addClass('intro-element-disabled'); |
| 302 | + } |
| 303 | + if($(element).css('position') === 'static'){ |
| 304 | + $(element).addClass('intro-element-relative'); |
| 305 | + } |
264 | 306 | var parentElm = $(element).parent();
|
265 | 307 | while (parentElm.length > 0) {
|
266 | 308 | if (parentElm.get(0).tagName.toLowerCase() === 'body'){
|
|
314 | 356 | }else{
|
315 | 357 | intro = step.intro;
|
316 | 358 | }
|
| 359 | + console.log($(step.element)); |
317 | 360 | if(step.element){
|
318 |
| - $(step.element).get(0).scrollIntoView(); |
| 361 | + $(step.element).get(0).scrollIntoView(false); |
319 | 362 | }
|
320 | 363 | hint.setTarget(step.element || $('body'));
|
321 | 364 | hint.setPosition(step.hintPosition);
|
322 | 365 | hint.setTooltipPosition(step.tooltipPosition);
|
323 | 366 | hint.setContent(intro);
|
324 |
| - highlightElement(step.element); |
| 367 | + highlightElement(step.element, base.options.highlightInteractivity); |
325 | 368 | return hint.render();
|
326 | 369 | };
|
327 | 370 |
|
|
0 commit comments