|
71 | 71 | return offset;
|
72 | 72 | }
|
73 | 73 |
|
74 |
| - function fitOffsetToScreen(offset, width, height){ |
| 74 | + function fitOffsetToScreen(offset, width){ |
75 | 75 | var bodyBoundingClientRect = $('body').get(0).getBoundingClientRect();
|
76 | 76 | var delta;
|
77 | 77 | if((offset.left + width) > bodyBoundingClientRect.right){
|
|
86 | 86 |
|
87 | 87 | function outerPositionElement(element, target, position){
|
88 | 88 | var offset = convertOuterPositionToOffset(element, target, position);
|
89 |
| - offset = fitOffsetToScreen(offset, element.outerWidth(), element.outerHeight()); |
| 89 | + offset = fitOffsetToScreen(offset, element.outerWidth()); |
90 | 90 | return element.offset(offset);
|
91 | 91 | }
|
92 | 92 |
|
93 | 93 |
|
| 94 | + |
| 95 | + |
94 | 96 | function Hint(){
|
95 | 97 | var tooltip;
|
96 | 98 | var that = this;
|
|
99 | 101 | var hintPosition;
|
100 | 102 | var wasRendered = false;
|
101 | 103 |
|
| 104 | + function getTooltipArrowElement(){ |
| 105 | + return tooltip.find('.intro-tooltip-arrow'); |
| 106 | + } |
102 | 107 |
|
| 108 | + function difference(a, b) { |
| 109 | + return Math.abs(a - b); |
| 110 | + } |
103 | 111 |
|
| 112 | + function createTooltip(){ |
| 113 | + var tooltip = $('<div><div class="intro-tooltip-content"></div><div class="intro-tooltip-arrow"></div></div>') |
| 114 | + .addClass('intro-tooltip'); |
| 115 | + tooltip.hide(); |
| 116 | + $('body').append(tooltip); |
| 117 | + return tooltip; |
| 118 | + } |
| 119 | + |
| 120 | + function repositionTooltipArrow(){ |
| 121 | + var tooltipArrowElement = getTooltipArrowElement(); |
| 122 | + tooltipArrowElement.css({'left': 0}); |
| 123 | + var elementBoundingClientRect = that.element.get(0).getBoundingClientRect(); |
| 124 | + var tooltipBoundingClientRect = tooltip.get(0).getBoundingClientRect(); |
| 125 | + var delta = difference(elementBoundingClientRect.left, tooltipBoundingClientRect.left); |
| 126 | + |
| 127 | + tooltipArrowElement.css({left: delta}); |
| 128 | + |
| 129 | + } |
104 | 130 |
|
| 131 | + function createHint(){ |
| 132 | + var hint = $('<div class="intro-hint"><div class="intro-circle"></div></div>'); |
| 133 | + hint.hide(); |
| 134 | + $('body').append(hint); |
| 135 | + return hint; |
| 136 | + } |
105 | 137 |
|
106 | 138 | this.element = null;
|
107 | 139 |
|
|
135 | 167 |
|
136 | 168 | that.element.show();
|
137 | 169 | innerPositionElement(that.element, targetElement, hintPosition, duration).then(function(){
|
| 170 | + getTooltipArrowElement().attr('position', tooltipPosition); |
138 | 171 | tooltip.css('opacity', 0).show();
|
139 | 172 | outerPositionElement(tooltip, that.element, tooltipPosition);
|
| 173 | + repositionTooltipArrow(); |
140 | 174 | tooltip.animate({'opacity': 1});
|
141 | 175 | defer.resolve();
|
142 | 176 | });
|
143 | 177 | wasRendered = true;
|
144 | 178 | return defer.promise();
|
145 | 179 | };
|
146 | 180 |
|
147 |
| - function createTooltip(){ |
148 |
| - var tooltip = $('<div><div class="intro-tooltip-content"></div><div class="intro-tooltip-arrow"></div></div>') |
149 |
| - .addClass('intro-tooltip'); |
150 |
| - tooltip.hide(); |
151 |
| - $('body').append(tooltip); |
152 |
| - return tooltip; |
153 |
| - } |
154 |
| - |
155 |
| - function createHint(){ |
156 |
| - var hint = $('<div class="intro-hint"><div class="intro-circle"></div></div>'); |
157 |
| - hint.hide(); |
158 |
| - $('body').append(hint); |
159 |
| - return hint; |
160 |
| - } |
161 | 181 |
|
162 | 182 | function init(){
|
163 | 183 | that.element = createHint();
|
|
225 | 245 |
|
226 | 246 | function showStep(step){
|
227 | 247 | var _showStep = function(){
|
228 |
| - hint = hint || new Hint(); |
| 248 | + hint = hint || new Hint(); |
229 | 249 | backdrop = backdrop || createBackdrop();
|
230 | 250 |
|
231 | 251 | hint.setTarget(step.element || $('body'));
|
|
0 commit comments