Skip to content

Commit c5f3f38

Browse files
author
Yaron Nachshon
committed
reposition
1 parent 2e531d4 commit c5f3f38

File tree

3 files changed

+32
-29
lines changed

3 files changed

+32
-29
lines changed

intro.js

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* global jQuery, setTimeout*/
1+
/* global jQuery*/
22
'use strict';
33

44
(function($){
@@ -13,8 +13,6 @@
1313

1414
base.init = function(){
1515
base.options = $.extend({},$.introJs.defaultOptions, options);
16-
17-
// Put your initialization code here
1816
};
1917

2018
function innerPositionElement(element, target, position, duration){
@@ -53,25 +51,43 @@
5351
return defer.promise();
5452
}
5553

56-
function outerPositionElement(element, target, position){
54+
function convertOuterPositionToOffset(element, target, position){
5755
var targetBoundingClientRect = $(target).get(0).getBoundingClientRect();
58-
var newOffset = {};
56+
var offset = {};
5957

6058
if(position === 'top'){
61-
newOffset.left = (targetBoundingClientRect.left + (targetBoundingClientRect.width / 2)) - (element.outerWidth() / 2);
62-
newOffset.top = targetBoundingClientRect.top - element.outerHeight();
59+
offset.left = (targetBoundingClientRect.left + (targetBoundingClientRect.width / 2)) - (element.outerWidth() / 2);
60+
offset.top = targetBoundingClientRect.top - element.outerHeight();
6361
}else if(position === 'right'){
64-
newOffset.left = targetBoundingClientRect.right;
65-
newOffset.top = targetBoundingClientRect.top - (element.outerHeight() / 2);
62+
offset.left = targetBoundingClientRect.right;
63+
offset.top = targetBoundingClientRect.top - (element.outerHeight() / 2) + (targetBoundingClientRect.height / 2);
6664
}else if(position === 'bottom'){
67-
newOffset.left = (targetBoundingClientRect.left + (targetBoundingClientRect.width / 2)) - (element.outerWidth() / 2);
68-
newOffset.top = targetBoundingClientRect.bottom;
65+
offset.left = (targetBoundingClientRect.left + (targetBoundingClientRect.width / 2)) - (element.outerWidth() / 2);
66+
offset.top = targetBoundingClientRect.bottom;
6967
}else if(position === 'left'){
70-
newOffset.left = targetBoundingClientRect.left - element.outerWidth();
71-
newOffset.top = targetBoundingClientRect.top - (element.outerHeight() / 2);
68+
offset.left = targetBoundingClientRect.left - element.outerWidth();
69+
offset.top = targetBoundingClientRect.top - (element.outerHeight() / 2) + (targetBoundingClientRect.height / 2);
70+
}
71+
return offset;
72+
}
73+
74+
function fitOffsetToScreen(offset, width, height){
75+
var bodyBoundingClientRect = $('body').get(0).getBoundingClientRect();
76+
var delta;
77+
if((offset.left + width) > bodyBoundingClientRect.right){
78+
delta = (bodyBoundingClientRect.right - (offset.left + width));
79+
offset.left = offset.left + delta;
80+
}else if(offset.left < bodyBoundingClientRect.left){
81+
delta = bodyBoundingClientRect.left - offset.left;
82+
offset.left = offset.left + delta;
7283
}
84+
return offset;
85+
}
7386

74-
return element.offset(newOffset);
87+
function outerPositionElement(element, target, position){
88+
var offset = convertOuterPositionToOffset(element, target, position);
89+
offset = fitOffsetToScreen(offset, element.outerWidth(), element.outerHeight());
90+
return element.offset(offset);
7591
}
7692

7793

@@ -83,9 +99,7 @@
8399
var hintPosition;
84100
var wasRendered = false;
85101

86-
function fitToScreen(xPos, yPos){
87102

88-
}
89103

90104

91105

@@ -157,17 +171,6 @@
157171
init.call(this);
158172
}
159173

160-
161-
162-
// function repositionElement(stepElement, targetElement){
163-
// var targetBoundingClientRect = $(targetElement).get(0).getBoundingClientRect();
164-
//
165-
// $(stepElement).offset({
166-
// top: targetBoundingClientRect.top + (targetBoundingClientRect.height / 2) - (stepElement.height() / 2),
167-
// left: targetBoundingClientRect.left + (targetBoundingClientRect.width / 2) - (stepElement.width() / 2)
168-
// });
169-
// }
170-
171174
function createBackdrop(){
172175
var backdrop = $('<div>')
173176
.addClass('intro-backdrop');

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ $arrow-size: $arrow-size-border * 2;
6868
}
6969
.intro-tooltip {
7070
position: absolute;
71-
min-width: 200px;
71+
min-width: 400px;
7272
min-height: 200px;
7373
background: rgba(#5F2D4A, .8);
7474
color: #FFF;

0 commit comments

Comments
 (0)