Skip to content

Commit 70cfdfa

Browse files
author
Ben M
committed
Added .setoptions() and .setoption() along with a few default options.
This addition allows for the labels of the buttons to be set by calling introJs().setoptions({nextLabel: 'This Way', skipLabel: 'Go Away', prevLabel: 'That Way'}).start(); Or, individually like introJs().setoption('nextLabel', 'This Way').start();
1 parent 59661ee commit 70cfdfa

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

intro.js

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
*/
1919
function IntroJs(obj) {
2020
this._targetElement = obj;
21+
22+
this._options = {
23+
nextLabel: 'Next →',
24+
prevLabel: '← Back',
25+
skipLabel: 'Skip'
26+
}
2127
}
2228

2329
/**
@@ -261,7 +267,7 @@
261267

262268
nextTooltipButton.className = "introjs-button introjs-nextbutton";
263269
nextTooltipButton.href = "javascript:void(0);";
264-
nextTooltipButton.innerHTML = "Next →";
270+
nextTooltipButton.innerHTML = this._options.nextLabel;
265271

266272
//previous button
267273
var prevTooltipButton = document.createElement("a");
@@ -272,13 +278,13 @@
272278

273279
prevTooltipButton.className = "introjs-button introjs-prevbutton";
274280
prevTooltipButton.href = "javascript:void(0);";
275-
prevTooltipButton.innerHTML = "← Back";
281+
prevTooltipButton.innerHTML = this._options.prevLabel;
276282

277283
//skip button
278284
var skipTooltipButton = document.createElement("a");
279285
skipTooltipButton.className = "introjs-button introjs-skipbutton";
280286
skipTooltipButton.href = "javascript:void(0);";
281-
skipTooltipButton.innerHTML = "Skip";
287+
skipTooltipButton.innerHTML = this._options.skipLabel;
282288

283289
skipTooltipButton.onclick = function() {
284290
_exitIntro.call(self, self._targetElement);
@@ -421,6 +427,20 @@
421427
return elementPosition;
422428
}
423429

430+
/**
431+
* Overwrites obj1's values with obj2's and adds obj2's if non existent in obj1
432+
* via: http://stackoverflow.com/questions/171251/how-can-i-merge-properties-of-two-javascript-objects-dynamically
433+
* @param obj1
434+
* @param obj2
435+
* @returns obj3 a new object based on obj1 and obj2
436+
*/
437+
function _mergeOptions(obj1,obj2){
438+
var obj3 = {};
439+
for (var attrname in obj1) { obj3[attrname] = obj1[attrname]; }
440+
for (var attrname in obj2) { obj3[attrname] = obj2[attrname]; }
441+
return obj3;
442+
}
443+
424444
var introJs = function (targetElm) {
425445
if (typeof (targetElm) === "object") {
426446
//Ok, create a new instance
@@ -453,6 +473,14 @@
453473
clone: function () {
454474
return new IntroJs(this);
455475
},
476+
setoption: function(option, value){
477+
this._options[option] = value;
478+
return this;
479+
},
480+
setoptions: function(options){
481+
this._options = _mergeOptions(this._options, options);
482+
return this;
483+
},
456484
start: function () {
457485
_introForElement.call(this, this._targetElement);
458486
return this;

0 commit comments

Comments
 (0)