Skip to content

Commit 9e62afc

Browse files
committed
Merge branch 'label_customization' of https://github.com/casiotone/intro.js into casiotone-label_customization
2 parents 4eee2eb + 70cfdfa commit 9e62afc

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
/**
@@ -285,7 +291,7 @@
285291

286292
nextTooltipButton.className = "introjs-button introjs-nextbutton";
287293
nextTooltipButton.href = "javascript:void(0);";
288-
nextTooltipButton.innerHTML = "Next →";
294+
nextTooltipButton.innerHTML = this._options.nextLabel;
289295

290296
//previous button
291297
var prevTooltipButton = document.createElement("a");
@@ -296,13 +302,13 @@
296302

297303
prevTooltipButton.className = "introjs-button introjs-prevbutton";
298304
prevTooltipButton.href = "javascript:void(0);";
299-
prevTooltipButton.innerHTML = "← Back";
305+
prevTooltipButton.innerHTML = this._options.prevLabel;
300306

301307
//skip button
302308
var skipTooltipButton = document.createElement("a");
303309
skipTooltipButton.className = "introjs-button introjs-skipbutton";
304310
skipTooltipButton.href = "javascript:void(0);";
305-
skipTooltipButton.innerHTML = "Skip";
311+
skipTooltipButton.innerHTML = this._options.skipLabel;
306312

307313
skipTooltipButton.onclick = function() {
308314
_exitIntro.call(self, self._targetElement);
@@ -462,6 +468,20 @@
462468
return elementPosition;
463469
}
464470

471+
/**
472+
* Overwrites obj1's values with obj2's and adds obj2's if non existent in obj1
473+
* via: http://stackoverflow.com/questions/171251/how-can-i-merge-properties-of-two-javascript-objects-dynamically
474+
* @param obj1
475+
* @param obj2
476+
* @returns obj3 a new object based on obj1 and obj2
477+
*/
478+
function _mergeOptions(obj1,obj2){
479+
var obj3 = {};
480+
for (var attrname in obj1) { obj3[attrname] = obj1[attrname]; }
481+
for (var attrname in obj2) { obj3[attrname] = obj2[attrname]; }
482+
return obj3;
483+
}
484+
465485
var introJs = function (targetElm) {
466486
if (typeof (targetElm) === "object") {
467487
//Ok, create a new instance
@@ -494,6 +514,14 @@
494514
clone: function () {
495515
return new IntroJs(this);
496516
},
517+
setoption: function(option, value){
518+
this._options[option] = value;
519+
return this;
520+
},
521+
setoptions: function(options){
522+
this._options = _mergeOptions(this._options, options);
523+
return this;
524+
},
497525
start: function () {
498526
_introForElement.call(this, this._targetElement);
499527
return this;

0 commit comments

Comments
 (0)