Skip to content

Commit

Permalink
allows an object to be passed into buttons as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Geoff Daigle committed Feb 9, 2016
1 parent 445dd4c commit 003c138
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
20 changes: 15 additions & 5 deletions dist/js/shepherd.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,23 +160,33 @@ var Step = (function (_Evented) {
}
}

// Button configuration

var buttonsJson = JSON.stringify(this.options.buttons);
var buttonsAreDefault = buttonsJson === UNDEFINED || buttonsJson === "true";

var buttonsAreEmpty = buttonsJson === "{}" || buttonsJson === "[]" || buttonsJson === "false";

// Default button if not specified
var buttonsAreArray = !buttonsAreDefault && this.options.buttons.constructor === Array;

var buttonsAreObject = !buttonsAreDefault && this.options.buttons.constructor === Object;

// Show default button if undefined or 'true'
if (buttonsAreDefault) {
this.options.buttons = [{
text: 'Next',
action: this.tour.next,
classes: 'btn'
}];

// falsey value or empty array prevents buttons from rendering
} else if (buttonsAreEmpty) {
this.options.buttons = false;
}
// Can pass in an object which will assume asingle button
} else if (!buttonsAreEmpty && buttonsAreObject) {
this.options.buttons = [this.options.buttons];

// Falsey/empty values or non-object values prevent buttons from rendering
} else if (buttonsAreEmpty || !buttonsAreArray) {
this.options.buttons = false;
}
}
}, {
key: 'getTour',
Expand Down
Loading

0 comments on commit 003c138

Please sign in to comment.