Skip to content

Commit 6cafdcc

Browse files
author
Yaron Nachshon
committed
reposition
1 parent d0b6d6e commit 6cafdcc

File tree

3 files changed

+86
-18
lines changed

3 files changed

+86
-18
lines changed

intro.js

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* global jQuery*/
1+
/* global jQuery,setInterval, clearInterval*/
22
'use strict';
33

44
(function($){
@@ -15,6 +15,22 @@
1515
base.options = $.extend({},$.introJs.defaultOptions, options);
1616
};
1717

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+
1834
function innerPositionElement(element, target, position, duration){
1935
var defer = jQuery.Deferred();
2036
var xPos = position.split(' ')[0];
@@ -92,8 +108,8 @@
92108

93109
function outerPositionElement(element, target, position, offsetX, offsetY){
94110
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);
97113
offset = fitOffsetToScreen(offset, element.outerWidth());
98114
return element.offset(offset);
99115
}
@@ -115,6 +131,7 @@
115131
var tooltip = $('<div><div class="intro-tooltip-content"></div><div class="intro-tooltip-arrow"></div></div>')
116132
.addClass('intro-tooltip');
117133
tooltip.hide();
134+
118135
$('body').append(tooltip);
119136
return tooltip;
120137
}
@@ -165,19 +182,25 @@
165182
}
166183

167184
function createHint(){
168-
var hintClasses = 'intro-circle';
185+
var hint = $('<div class="intro-hint"></div>');
169186
if (base.options.hintClass) {
170-
hintClasses += ' ' + base.options.hintClass;
187+
hint.addClass(base.options.hintClass);
171188
}
172-
var hint = $('<div class="intro-hint"><div class="'+ hintClasses +'"></div></div>');
173189
hint.hide();
174190
$('body').append(hint);
191+
trackElementChange(hint);
192+
$(hint).on('changed.introjs', that.render);
175193
return hint;
176194
}
177195

178196
function repositionTooltip(){
179197
var tooltipArrowElement = getTooltipArrowElement();
180198
var offsetX = 0, offsetY = 0;
199+
200+
if(tooltip.css('display') === 'none'){
201+
tooltip.show();
202+
}
203+
181204
if(tooltipPosition === 'top'){
182205
offsetY = -(tooltipArrowElement.outerHeight());
183206
}else if(tooltipPosition === 'bottom'){
@@ -195,6 +218,7 @@
195218

196219
this.hideTooltip = function(){
197220
tooltip.hide();
221+
tooltip.css('opacity', 0);
198222
};
199223

200224
this.setTarget = function(element){
@@ -214,20 +238,30 @@
214238
};
215239

216240
this.destroy = function(){
241+
untrackElementChange(this.element);
217242
this.element.remove();
218243
tooltip.remove();
219244
};
220245

246+
this.isVisible = function(){
247+
return Number($(tooltip).css('opacity')) > 0;
248+
};
249+
221250
this.render = function(){
222251
var defer = jQuery.Deferred();
223-
var duration = wasRendered ? 800 : 0;
252+
var duration = wasRendered ? 500 : 0;
224253

225254
that.element.show();
226255
innerPositionElement(that.element, targetElement, hintPosition, duration).then(function(){
227256
getTooltipArrowElement().attr('position', tooltipPosition);
228-
tooltip.css('opacity', 0).show();
229257
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+
}
231265
defer.resolve();
232266
});
233267
wasRendered = true;
@@ -256,11 +290,19 @@
256290

257291
function unhighlighElement(element){
258292
$(element).removeClass('intro-element');
293+
$(element).removeClass('intro-element-disabled');
294+
$(element).removeClass('intro-element-relative');
259295
$(element).parents('.intro-fixparent').removeClass('intro-fixparent');
260296
}
261297

262-
function highlightElement(element){
298+
function highlightElement(element, interactive){
263299
$(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+
}
264306
var parentElm = $(element).parent();
265307
while (parentElm.length > 0) {
266308
if (parentElm.get(0).tagName.toLowerCase() === 'body'){
@@ -314,14 +356,15 @@
314356
}else{
315357
intro = step.intro;
316358
}
359+
console.log($(step.element));
317360
if(step.element){
318-
$(step.element).get(0).scrollIntoView();
361+
$(step.element).get(0).scrollIntoView(false);
319362
}
320363
hint.setTarget(step.element || $('body'));
321364
hint.setPosition(step.hintPosition);
322365
hint.setTooltipPosition(step.tooltipPosition);
323366
hint.setContent(intro);
324-
highlightElement(step.element);
367+
highlightElement(step.element, base.options.highlightInteractivity);
325368
return hint.render();
326369
};
327370

introjs.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

introjs.scss

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,15 @@ $arrow-size: $arrow-size-border * 2;
5050

5151
/* intro */
5252
.intro-hint {
53-
$hint-size: 60px;
53+
$hint-size: 52px;
5454
position: absolute;
55-
width: $hint-size;
56-
height: $hint-size;
57-
z-index: 1100;
55+
//width: $hint-size;
56+
//height: $hint-size;
57+
z-index: 110010;
5858
pointer-events: none;
59-
background: #FF3B3B;
59+
background: #FF3B3B !important;
60+
opacity: 0.8 !important;
61+
position: absolute !important;
6062
}
6163
.intro-tooltip {
6264
position: absolute;
@@ -124,6 +126,24 @@ $arrow-size: $arrow-size-border * 2;
124126
}
125127
.intro-element {
126128
z-index: 110000 !important;
129+
box-shadow: 0 0 1px 1px red;
130+
131+
&.intro-element-disabled:after{
132+
content: ' ';
133+
left: 0;
134+
top: 0;
135+
bottom: 0;
136+
right: 0;
137+
z-index: 1;
138+
background: rgba(blue, 0.3);
139+
width: 100%;
140+
height: 100%;
141+
position: absolute;
142+
}
143+
144+
&.intro-element-relative{
145+
position: relative;
146+
}
127147
}
128148

129149
.intro-backdrop {
@@ -143,3 +163,8 @@ $arrow-size: $arrow-size-border * 2;
143163
opacity: 1.0 !important;
144164
transform: none !important;
145165
}
166+
167+
.intro-tooltip-content{
168+
height: 270px;
169+
overflow: auto;
170+
}

0 commit comments

Comments
 (0)