Skip to content

Commit eb021ee

Browse files
committed
Merge pull request usablica#264 from Naycon/additional_position_parameters
Added new bottom alignment options for the tooltip.
2 parents aae3e28 + 4bfeb1f commit eb021ee

File tree

3 files changed

+70
-35
lines changed

3 files changed

+70
-35
lines changed

README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ Intro.js can be added to your site in three simple steps:
2121
2222
**2)** Add `data-intro` and `data-step` to your HTML elements.
2323

24-
For example:
24+
For example:
2525

2626
```html
2727
<a href='http://google.com/' data-intro='Hello step one!'></a>
2828
````
2929

3030
See all attributes [here](https://github.com/usablica/intro.js/#attributes).
31-
31+
3232
**3)** Call this JavaScript function:
3333
```javascript
3434
introJs().start();
3535
````
36-
36+
3737
Optionally, pass one parameter to `introJs` function to limit the presentation section.
3838

3939
**For example** `introJs(".introduction-farm").start();` runs the introduction only for elements with `class='introduction-farm'`.
@@ -314,7 +314,7 @@ introJs().onafterchange(function(targetElement) {
314314
- `data-intro`: The tooltip text of step
315315
- `data-step`: Optionally define the number (priority) of step
316316
- `data-tooltipClass`: Optionally define a CSS class for tooltip
317-
- `data-position`: Optionally define the position of tooltip, `top`, `left`, `right` or `bottom`. Default is `bottom`
317+
- `data-position`: Optionally define the position of tooltip, `top`, `left`, `right`, `bottom`, `bottom-left-aligned` (same as 'bottom'), 'bottom-middle-aligned' and 'bottom-right-aligned'. Default is `bottom`
318318

319319
###Options:
320320

@@ -459,10 +459,10 @@ Want to learn faster and easier? Here we have **Instant IntroJs**, Packt Publish
459459
- Fix show element for elements with position `absolute` or `relative`
460460
- Add `enter` key for navigating in steps
461461
- Code refactoring
462-
463-
464-
* **v0.1.0** - 2013-03-16
465-
- First commit.
462+
463+
464+
* **v0.1.0** - 2013-03-16
465+
- First commit.
466466

467467
## Author
468468
**Afshin Mehrabani**
@@ -481,15 +481,15 @@ Want to learn faster and easier? Here we have **Instant IntroJs**, Packt Publish
481481
## License
482482
> Copyright (C) 2012 Afshin Mehrabani (afshin.meh@gmail.com)
483483

484-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
485-
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
486-
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
484+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
485+
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
486+
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
487487
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
488-
The above copyright notice and this permission notice shall be included in all copies or substantial portions
488+
The above copyright notice and this permission notice shall be included in all copies or substantial portions
489489
of the Software.
490490

491-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
492-
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
493-
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
494-
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
491+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
492+
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
493+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
494+
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
495495
IN THE SOFTWARE.

intro.js

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@
296296
*/
297297
function _previousStep() {
298298
this._direction = 'backward';
299-
299+
300300
if (this._currentStep === 0) {
301301
return false;
302302
}
@@ -319,7 +319,7 @@
319319
function _exitIntro(targetElement) {
320320
//remove overlay layer from the page
321321
var overlayLayer = targetElement.querySelector('.introjs-overlay');
322-
322+
323323
//return if intro already completed or skipped
324324
if (overlayLayer == null) {
325325
return;
@@ -365,7 +365,7 @@
365365
} else if (document.detachEvent) { //IE
366366
document.detachEvent('onkeydown', this._onKeyDown);
367367
}
368-
368+
369369
//set the step to zero
370370
this._currentStep = undefined;
371371
}
@@ -380,6 +380,11 @@
380380
* @param {Object} arrowLayer
381381
*/
382382
function _placeTooltip(targetElement, tooltipLayer, arrowLayer, helperNumberLayer) {
383+
var tooltipCssClass = '',
384+
currentStepObj,
385+
tooltipOffset,
386+
targetElementOffset;
387+
383388
//reset the old style
384389
tooltipLayer.style.top = null;
385390
tooltipLayer.style.right = null;
@@ -398,10 +403,8 @@
398403
//prevent error when `this._currentStep` is undefined
399404
if (!this._introItems[this._currentStep]) return;
400405

401-
var tooltipCssClass = '';
402-
403406
//if we have a custom css class for each step
404-
var currentStepObj = this._introItems[this._currentStep];
407+
currentStepObj = this._introItems[this._currentStep];
405408
if (typeof (currentStepObj.tooltipClass) === 'string') {
406409
tooltipCssClass = currentStepObj.tooltipClass;
407410
} else {
@@ -413,7 +416,7 @@
413416
//custom css class for tooltip boxes
414417
var tooltipCssClass = this._options.tooltipClass;
415418

416-
var currentTooltipPosition = this._introItems[this._currentStep].position;
419+
currentTooltipPosition = this._introItems[this._currentStep].position;
417420
switch (currentTooltipPosition) {
418421
case 'top':
419422
tooltipLayer.style.left = '15px';
@@ -425,7 +428,7 @@
425428
arrowLayer.className = 'introjs-arrow left';
426429
break;
427430
case 'left':
428-
if (this._options.showStepNumbers == true) {
431+
if (this._options.showStepNumbers == true) {
429432
tooltipLayer.style.top = '15px';
430433
}
431434
tooltipLayer.style.right = (_getOffset(targetElement).width + 20) + 'px';
@@ -435,7 +438,7 @@
435438
arrowLayer.style.display = 'none';
436439

437440
//we have to adjust the top and left of layer manually for intro items without element{
438-
var tooltipOffset = _getOffset(tooltipLayer);
441+
tooltipOffset = _getOffset(tooltipLayer);
439442

440443
tooltipLayer.style.left = '50%';
441444
tooltipLayer.style.top = '50%';
@@ -448,6 +451,21 @@
448451
}
449452

450453
break;
454+
case 'bottom-right-aligned':
455+
arrowLayer.className = 'introjs-arrow top-right';
456+
tooltipLayer.style.right = '0px';
457+
tooltipLayer.style.bottom = '-' + (_getOffset(tooltipLayer).height + 10) + 'px';
458+
break;
459+
case 'bottom-middle-aligned':
460+
targetElementOffset = _getOffset(targetElement);
461+
tooltipOffset = _getOffset(tooltipLayer);
462+
463+
arrowLayer.className = 'introjs-arrow top-middle';
464+
tooltipLayer.style.left = (targetElementOffset.width/2 - tooltipOffset.width/2) + 'px';
465+
tooltipLayer.style.bottom = '-' + (tooltipOffset.height + 10) + 'px';
466+
break;
467+
case 'bottom-left-aligned':
468+
// Bottom-left-aligned is the same as the default bottom
451469
case 'bottom':
452470
// Bottom going to follow the default behavior
453471
default:
@@ -469,10 +487,10 @@
469487
//prevent error when `this._currentStep` in undefined
470488
if (!this._introItems[this._currentStep]) return;
471489

472-
var currentElement = this._introItems[this._currentStep];
473-
var elementPosition = _getOffset(currentElement.element);
490+
var currentElement = this._introItems[this._currentStep],
491+
elementPosition = _getOffset(currentElement.element),
492+
widthHeightPadding = 10;
474493

475-
var widthHeightPadding = 10;
476494
if (currentElement.position == 'floating') {
477495
widthHeightPadding = 0;
478496
}
@@ -714,14 +732,14 @@
714732
while (parentElm != null) {
715733
if (parentElm.tagName.toLowerCase() === 'body') break;
716734

717-
//fix The Stacking Contenxt problem.
735+
//fix The Stacking Contenxt problem.
718736
//More detail: https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Understanding_z_index/The_stacking_context
719737
var zIndex = _getPropValue(parentElm, 'z-index');
720738
var opacity = parseFloat(_getPropValue(parentElm, 'opacity'));
721739
if (/[0-9]+/.test(zIndex) || opacity < 1) {
722740
parentElm.className += ' introjs-fixParent';
723741
}
724-
742+
725743
parentElm = parentElm.parentNode;
726744
}
727745

@@ -740,7 +758,7 @@
740758
window.scrollBy(0, bottom + 100); // 70px + 30px padding from edge to look nice
741759
}
742760
}
743-
761+
744762
if (typeof (this._introAfterChangeCallback) !== 'undefined') {
745763
this._introAfterChangeCallback.call(this, targetElement.element);
746764
}

introjs.css

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ tr.introjs-showElement > th {
7676
line-height: 20px;
7777
border: 3px solid white;
7878
border-radius: 50%;
79-
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff3019', endColorstr='#cf0404', GradientType=0); /* IE6-9 */
79+
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff3019', endColorstr='#cf0404', GradientType=0); /* IE6-9 */
8080
filter: progid:DXImageTransform.Microsoft.Shadow(direction=135, strength=2, color=ff0000); /* IE10 text shadows */
8181
box-shadow: 0 2px 5px rgba(0,0,0,.4);
8282
}
@@ -93,6 +93,23 @@ tr.introjs-showElement > th {
9393
border-bottom-color:white;
9494
border-left-color:transparent;
9595
}
96+
.introjs-arrow.top-right {
97+
top: -10px;
98+
right: 10px;
99+
border-top-color:transparent;
100+
border-right-color:transparent;
101+
border-bottom-color:white;
102+
border-left-color:transparent;
103+
}
104+
.introjs-arrow.top-middle {
105+
top: -10px;
106+
left: 50%;
107+
margin-left: -5px;
108+
border-top-color:transparent;
109+
border-right-color:transparent;
110+
border-bottom-color:white;
111+
border-left-color:transparent;
112+
}
96113
.introjs-arrow.right {
97114
right: -10px;
98115
top: 10px;
@@ -136,8 +153,8 @@ tr.introjs-showElement > th {
136153
text-align: right;
137154
}
138155

139-
/*
140-
Buttons style by http://nicolasgallagher.com/lab/css3-github-buttons/
156+
/*
157+
Buttons style by http://nicolasgallagher.com/lab/css3-github-buttons/
141158
Changed by Afshin Mehrabani
142159
*/
143160
.introjs-button {
@@ -174,7 +191,7 @@ tr.introjs-showElement > th {
174191

175192
.introjs-button:hover {
176193
border-color: #bcbcbc;
177-
text-decoration: none;
194+
text-decoration: none;
178195
box-shadow: 0px 1px 1px #e3e3e3;
179196
}
180197

0 commit comments

Comments
 (0)