|
1 |
| -/* global jQuery, setTimeout*/ |
| 1 | +/* global jQuery*/ |
2 | 2 | 'use strict';
|
3 | 3 |
|
4 | 4 | (function($){
|
|
13 | 13 |
|
14 | 14 | base.init = function(){
|
15 | 15 | base.options = $.extend({},$.introJs.defaultOptions, options);
|
16 |
| - |
17 |
| - // Put your initialization code here |
18 | 16 | };
|
19 | 17 |
|
20 | 18 | function innerPositionElement(element, target, position, duration){
|
|
53 | 51 | return defer.promise();
|
54 | 52 | }
|
55 | 53 |
|
56 |
| - function outerPositionElement(element, target, position){ |
| 54 | + function convertOuterPositionToOffset(element, target, position){ |
57 | 55 | var targetBoundingClientRect = $(target).get(0).getBoundingClientRect();
|
58 |
| - var newOffset = {}; |
| 56 | + var offset = {}; |
59 | 57 |
|
60 | 58 | 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(); |
63 | 61 | }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); |
66 | 64 | }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; |
69 | 67 | }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; |
72 | 83 | }
|
| 84 | + return offset; |
| 85 | + } |
73 | 86 |
|
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); |
75 | 91 | }
|
76 | 92 |
|
77 | 93 |
|
|
83 | 99 | var hintPosition;
|
84 | 100 | var wasRendered = false;
|
85 | 101 |
|
86 |
| - function fitToScreen(xPos, yPos){ |
87 | 102 |
|
88 |
| - } |
89 | 103 |
|
90 | 104 |
|
91 | 105 |
|
|
157 | 171 | init.call(this);
|
158 | 172 | }
|
159 | 173 |
|
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 |
| - |
171 | 174 | function createBackdrop(){
|
172 | 175 | var backdrop = $('<div>')
|
173 | 176 | .addClass('intro-backdrop');
|
|
0 commit comments