|
84 | 84 | return offset;
|
85 | 85 | }
|
86 | 86 |
|
87 |
| - function outerPositionElement(element, target, position){ |
| 87 | + function outerPositionElement(element, target, position, offsetX, offsetY){ |
88 | 88 | var offset = convertOuterPositionToOffset(element, target, position);
|
| 89 | + offset.left += offsetX; |
| 90 | + offset.top += offsetY; |
89 | 91 | offset = fitOffsetToScreen(offset, element.outerWidth());
|
90 | 92 | return element.offset(offset);
|
91 | 93 | }
|
92 | 94 |
|
93 | 95 |
|
94 |
| - |
95 |
| - |
96 | 96 | function Hint(){
|
97 | 97 | var tooltip;
|
98 | 98 | var that = this;
|
|
105 | 105 | return tooltip.find('.intro-tooltip-arrow');
|
106 | 106 | }
|
107 | 107 |
|
108 |
| - function difference(a, b) { |
109 |
| - return Math.abs(a - b); |
110 |
| - } |
111 |
| - |
112 | 108 | function createTooltip(){
|
113 | 109 | var tooltip = $('<div><div class="intro-tooltip-content"></div><div class="intro-tooltip-arrow"></div></div>')
|
114 | 110 | .addClass('intro-tooltip');
|
|
119 | 115 |
|
120 | 116 | function repositionTooltipArrow(){
|
121 | 117 | var tooltipArrowElement = getTooltipArrowElement();
|
122 |
| - tooltipArrowElement.css({'left': 0}); |
123 | 118 | 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 |
| - |
| 119 | + var left; |
| 120 | + var top; |
| 121 | + |
| 122 | + if(tooltipPosition === 'bottom'){ |
| 123 | + left = elementBoundingClientRect.left + (elementBoundingClientRect.width / 2) - (tooltipArrowElement.outerWidth() / 2); |
| 124 | + top = -(tooltipArrowElement.outerHeight()); |
| 125 | + tooltipArrowElement.offset({ |
| 126 | + left: left |
| 127 | + }); |
| 128 | + tooltipArrowElement.css({ |
| 129 | + top: top |
| 130 | + }); |
| 131 | + }else if(tooltipPosition === 'top'){ |
| 132 | + left = elementBoundingClientRect.left + (elementBoundingClientRect.width / 2) - (tooltipArrowElement.outerWidth() / 2); |
| 133 | + top = '100%'; |
| 134 | + tooltipArrowElement.offset({ |
| 135 | + left: left |
| 136 | + }); |
| 137 | + tooltipArrowElement.css({ |
| 138 | + top: top |
| 139 | + }); |
| 140 | + }else if(tooltipPosition === 'left'){ |
| 141 | + left = '100%'; |
| 142 | + top = elementBoundingClientRect.top + (elementBoundingClientRect.height / 2) - (tooltipArrowElement.outerHeight() / 2); |
| 143 | + tooltipArrowElement.css({ |
| 144 | + left: left |
| 145 | + }); |
| 146 | + tooltipArrowElement.offset({ |
| 147 | + top: top |
| 148 | + }); |
| 149 | + }else if(tooltipPosition === 'right'){ |
| 150 | + left = -(tooltipArrowElement.outerWidth()); |
| 151 | + top = elementBoundingClientRect.top + (elementBoundingClientRect.height / 2) - (tooltipArrowElement.outerHeight() / 2); |
| 152 | + tooltipArrowElement.css({ |
| 153 | + left: left |
| 154 | + }); |
| 155 | + tooltipArrowElement.offset({ |
| 156 | + top: top |
| 157 | + }); |
| 158 | + } |
129 | 159 | }
|
130 | 160 |
|
131 | 161 | function createHint(){
|
|
135 | 165 | return hint;
|
136 | 166 | }
|
137 | 167 |
|
| 168 | + function repositionTooltip(){ |
| 169 | + var tooltipArrowElement = getTooltipArrowElement(); |
| 170 | + var offsetX = 0, offsetY = 0; |
| 171 | + if(tooltipPosition === 'top'){ |
| 172 | + offsetY = -(tooltipArrowElement.outerHeight()); |
| 173 | + }else if(tooltipPosition === 'bottom'){ |
| 174 | + offsetY = tooltipArrowElement.outerHeight(); |
| 175 | + }else if(tooltipPosition === 'right'){ |
| 176 | + offsetX = tooltipArrowElement.outerWidth(); |
| 177 | + }else if(tooltipPosition === 'left'){ |
| 178 | + offsetX = -(tooltipArrowElement.outerWidth()); |
| 179 | + } |
| 180 | + outerPositionElement(tooltip, that.element, tooltipPosition, offsetX, offsetY); |
| 181 | + repositionTooltipArrow(); |
| 182 | + } |
| 183 | + |
138 | 184 | this.element = null;
|
139 | 185 |
|
140 | 186 | this.hideTooltip = function(){
|
|
169 | 215 | innerPositionElement(that.element, targetElement, hintPosition, duration).then(function(){
|
170 | 216 | getTooltipArrowElement().attr('position', tooltipPosition);
|
171 | 217 | tooltip.css('opacity', 0).show();
|
172 |
| - outerPositionElement(tooltip, that.element, tooltipPosition); |
173 |
| - repositionTooltipArrow(); |
| 218 | + repositionTooltip(); |
174 | 219 | tooltip.animate({'opacity': 1});
|
175 | 220 | defer.resolve();
|
176 | 221 | });
|
|
285 | 330 | showStep(base.currentStep);
|
286 | 331 | };
|
287 | 332 |
|
288 |
| - base.goToStep = function(step){ |
| 333 | + base.goToStep = function(stepIndex) { |
| 334 | + currentStepIndex = stepIndex; |
| 335 | + showStep(base.currentStep); |
289 | 336 | };
|
290 | 337 |
|
291 | 338 | base.setOption = function(option, value){
|
292 | 339 | base.options[option] = value;
|
293 | 340 | };
|
294 | 341 |
|
295 |
| - base.start = function(){ |
296 |
| - currentStepIndex = 0; |
| 342 | + base.start = function(stepIndex){ |
| 343 | + currentStepIndex = stepIndex || 0; |
297 | 344 | showStep(base.currentStep);
|
298 | 345 | };
|
299 | 346 |
|
|
0 commit comments