Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Next button with Close button on last step (Fix issue #572) #603

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions build/js/bootstrap-tour-standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@
};

Tour.prototype._template = function(step, i) {
var $navigation, $next, $prev, $resume, $template, template;
var $end, $navigation, $next, $prev, $resume, $template, template;
template = step.template;
if (this._isOrphan(step) && {}.toString.call(step.orphan) !== '[object Boolean]') {
template = step.orphan;
Expand All @@ -1292,6 +1292,7 @@
$navigation = $template.find('.popover-navigation');
$prev = $navigation.find('[data-role="prev"]');
$next = $navigation.find('[data-role="next"]');
$end = $navigation.find('[data-role="end"]');
$resume = $navigation.find('[data-role="pause-resume"]');
if (this._isOrphan(step)) {
$template.addClass('orphan');
Expand All @@ -1304,7 +1305,8 @@
$prev.addClass('disabled').prop('disabled', true).prop('tabindex', -1);
}
if (step.next < 0) {
$next.addClass('disabled').prop('disabled', true).prop('tabindex', -1);
$next.attr('data-role', 'end').html('Close &times;');
$end.remove();
}
if (!step.duration) {
$resume.remove();
Expand Down
2 changes: 1 addition & 1 deletion build/js/bootstrap-tour-standalone.min.js

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions build/js/bootstrap-tour.js
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@
};

Tour.prototype._template = function(step, i) {
var $navigation, $next, $prev, $resume, $template, template;
var $end, $navigation, $next, $prev, $resume, $template, template;
template = step.template;
if (this._isOrphan(step) && {}.toString.call(step.orphan) !== '[object Boolean]') {
template = step.orphan;
Expand All @@ -602,6 +602,7 @@
$navigation = $template.find('.popover-navigation');
$prev = $navigation.find('[data-role="prev"]');
$next = $navigation.find('[data-role="next"]');
$end = $navigation.find('[data-role="end"]');
$resume = $navigation.find('[data-role="pause-resume"]');
if (this._isOrphan(step)) {
$template.addClass('orphan');
Expand All @@ -614,7 +615,8 @@
$prev.addClass('disabled').prop('disabled', true).prop('tabindex', -1);
}
if (step.next < 0) {
$next.addClass('disabled').prop('disabled', true).prop('tabindex', -1);
$next.attr('data-role', 'end').html('Close &times;');
$end.remove();
}
if (!step.duration) {
$resume.remove();
Expand Down
2 changes: 1 addition & 1 deletion build/js/bootstrap-tour.min.js

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions src/coffee/bootstrap-tour.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@
$navigation = $template.find '.popover-navigation'
$prev = $navigation.find '[data-role="prev"]'
$next = $navigation.find '[data-role="next"]'
$end = $navigation.find '[data-role="end"]'
$resume = $navigation.find '[data-role="pause-resume"]'

$template.addClass 'orphan' if @_isOrphan step
Expand All @@ -552,9 +553,9 @@
.prop('tabindex', -1)

if step.next < 0
$next.addClass('disabled')
.prop('disabled', true)
.prop('tabindex', -1)
$next.attr('data-role','end')
.html('Close &times;')
$end.remove()

$resume.remove() unless step.duration
$template.clone().wrap('<div>').parent().html()
Expand Down
11 changes: 8 additions & 3 deletions src/coffee/bootstrap-tour.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,19 @@ describe 'Bootstrap Tour', ->
@tour.showStep(0)
expect($('.popover').length).toBe 1

it '`getStep` should add disabled classes to the first and last popover buttons', ->
it '`getStep` should add disabled class to the first popover button', ->
@tour = new Tour
@tour.addStep(element: $('<div></div>').appendTo('body'))
@tour.addStep(element: $('<div></div>').appendTo('body'))
@tour.showStep(0)
expect($('.popover [data-role="prev"]').hasClass('disabled')).toBe true

it '`getStep` should replace next button by close on last step', ->
@tour = new Tour
@tour.addStep(element: $('<div></div>').appendTo('body'))
@tour.addStep(element: $('<div></div>').appendTo('body'))
@tour.showStep(1)
expect($('.popover [data-role="next"]').hasClass('disabled')).toBe true
expect($('.popover [data-role="next"]').size()).toBe 0
expect($('.popover [data-role="end"]').size()).toBe 1

it '`setCurrentStep` should set the current step', ->
@tour = new Tour
Expand Down
6 changes: 4 additions & 2 deletions src/docs/assets/js/bootstrap-tour.js
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@
};

Tour.prototype._template = function(step, i) {
var $navigation, $next, $prev, $resume, $template, template;
var $end, $navigation, $next, $prev, $resume, $template, template;
template = step.template;
if (this._isOrphan(step) && {}.toString.call(step.orphan) !== '[object Boolean]') {
template = step.orphan;
Expand All @@ -602,6 +602,7 @@
$navigation = $template.find('.popover-navigation');
$prev = $navigation.find('[data-role="prev"]');
$next = $navigation.find('[data-role="next"]');
$end = $navigation.find('[data-role="end"]');
$resume = $navigation.find('[data-role="pause-resume"]');
if (this._isOrphan(step)) {
$template.addClass('orphan');
Expand All @@ -614,7 +615,8 @@
$prev.addClass('disabled').prop('disabled', true).prop('tabindex', -1);
}
if (step.next < 0) {
$next.addClass('disabled').prop('disabled', true).prop('tabindex', -1);
$next.attr('data-role', 'end').html('Close &times;');
$end.remove();
}
if (!step.duration) {
$resume.remove();
Expand Down
6 changes: 4 additions & 2 deletions test/bootstrap-tour.js
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@
};

Tour.prototype._template = function(step, i) {
var $navigation, $next, $prev, $resume, $template, template;
var $end, $navigation, $next, $prev, $resume, $template, template;
template = step.template;
if (this._isOrphan(step) && {}.toString.call(step.orphan) !== '[object Boolean]') {
template = step.orphan;
Expand All @@ -602,6 +602,7 @@
$navigation = $template.find('.popover-navigation');
$prev = $navigation.find('[data-role="prev"]');
$next = $navigation.find('[data-role="next"]');
$end = $navigation.find('[data-role="end"]');
$resume = $navigation.find('[data-role="pause-resume"]');
if (this._isOrphan(step)) {
$template.addClass('orphan');
Expand All @@ -614,7 +615,8 @@
$prev.addClass('disabled').prop('disabled', true).prop('tabindex', -1);
}
if (step.next < 0) {
$next.addClass('disabled').prop('disabled', true).prop('tabindex', -1);
$next.attr('data-role', 'end').html('Close &times;');
$end.remove();
}
if (!step.duration) {
$resume.remove();
Expand Down