Skip to content

Commit

Permalink
Added global onShow and onHide options
Browse files Browse the repository at this point in the history
  • Loading branch information
sorich87 committed Jul 13, 2012
1 parent 6c00cab commit bb8f3fa
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 15 deletions.
18 changes: 11 additions & 7 deletions bootstrap-tour.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
name: 'tour'
afterSetState: (key, value) ->
afterGetState: (key, value) ->
onShow: (tour) ->
onHide: (tour) ->
}, options)

@_steps = []
Expand Down Expand Up @@ -62,14 +64,16 @@
# Get a step by its indice
getStep: (i) ->
$.extend({
path: "",
placement: "right",
title: "",
content: "",
next: i + 1,
prev:i - 1,
end: i == @_steps.length - 1,
path: ""
placement: "right"
title: ""
content: ""
next: i + 1
prev:i - 1
end: i == @_steps.length - 1
animation: true
onShow: @_options.onShow
onHide: @_options.onHide
}, @_steps[i])

# Start tour from current step
Expand Down
8 changes: 6 additions & 2 deletions bootstrap-tour.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 17 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,19 @@ <h3>Initialization Options</h3>
<pre class="prettyprint">
var tour = new Tour({
name: "tour",
afterGetState: function(key, value) {},
afterSetState: function(key, value) {}
afterGetState: function (key, value) {},
afterSetState: function (key, value) {},
onShow: function (tour) {},
onHide: function (tour) {}
});
</pre>
<p>The <code>name</code> option is used to build the name of the

<h4><code>name</code></h4>
<p>This option is used to build the name of the
cookie where the tour state is stored. You can initialize several
tours with different names in the same page and application.</p>

<h4><code>afterGetState</code> and <code>afterSetState</code></h4>
<p>You may want to do something right after
Bootstrap Tour read or write the cookies. Just pass functions to
<code>afterGetState</code> or <code>afterSetState</code>.</p>
Expand Down Expand Up @@ -134,6 +140,12 @@ <h3>Initialization Options</h3>
});
</pre>

<h4><code>onShow</code></h4>
<p>Function to execute right before each step is shown.</p>

<h4><code>onHide</code></h4>
<p>Function to execute right before each step is hidden.</p>

<h3>Step Options</h3>
<p>Default options:</p>
<pre class="prettyprint">
Expand Down Expand Up @@ -182,9 +194,9 @@ <h3>Step Options</h3>
<dt>animation</dt>
<dd>Apply a css fade transition to the tooltip.</dd>
<dt>onShow</dt>
<dd>Function to execute right before the step is shown.</dd>
<dd>Function to execute right before the step is shown. It overrides the global onShow option.</dd>
<dt>onHide</dt>
<dd>Function to execute right before the step is hidden.</dd>
<dd>Function to execute right before the step is hidden. It overrides the global onHide option.</dd>
</dl>

<h2 id="contributing">Contributing</h2>
Expand Down
31 changes: 31 additions & 0 deletions tests/tests.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,35 @@ test "Tour.addStep should add a step", ->
deepEqual(tour._steps, [step], "tour adds steps")
clearTour(tour)

test "Tour with onShow option should run the callback before showing the step", ->
tour_test = 0
tour = new Tour({
onShow: ->
tour_test += 2
})
tour.addStep({element: $("<div></div>").appendTo("#qunit-fixture")})
tour.addStep({element: $("<div></div>").appendTo("#qunit-fixture")})
tour.start()
strictEqual(tour_test, 2, "tour runs onShow when first step shown")
tour.next()
strictEqual(tour_test, 4, "tour runs onShow when next step shown")
clearTour(tour)

test "Tour with onHide option should run the callback before hiding the step", ->
tour_test = 0
tour = new Tour({
onHide: ->
tour_test += 2
})
tour.addStep({element: $("<div></div>").appendTo("#qunit-fixture")})
tour.addStep({element: $("<div></div>").appendTo("#qunit-fixture")})
tour.start()
tour.next()
strictEqual(tour_test, 2, "tour runs onHide when first step hidden")
tour.hideStep(1)
strictEqual(tour_test, 4, "tour runs onHide when next step hidden")
clearTour(tour)

test "Tour.addStep with onShow option should run the callback before showing the step", ->
tour_test = 0
tour = new Tour()
Expand Down Expand Up @@ -93,6 +122,8 @@ test "Tour.getStep should get a step", ->
next: 2
end: false
animation: false
onShow: (tour) ->
onHide: (tour) ->
}
tour.addStep(step)
deepEqual(tour.getStep(0), step, "tour gets a step")
Expand Down
47 changes: 46 additions & 1 deletion tests/tests.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bb8f3fa

Please sign in to comment.