Skip to content

Commit

Permalink
Fixed bugs and added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sorich87 committed Jul 5, 2012
1 parent 206e43e commit 24b2aa9
Show file tree
Hide file tree
Showing 11 changed files with 2,658 additions and 47 deletions.
8 changes: 5 additions & 3 deletions bootstrap-tour.coffee
Expand Up @@ -82,12 +82,14 @@


# Verify if tour is enabled # Verify if tour is enabled
ended: -> ended: ->
@getState("end") !!@getState("end")


# Restart tour # Restart tour
restart: -> restart: ->
@setState("current_step", null) @setState("current_step", null)
@setState("end", null) @setState("end", null)
@setCurrentStep(0)
@start()


# Hide the specified step # Hide the specified step
hideStep: (i) -> hideStep: (i) ->
Expand Down Expand Up @@ -126,7 +128,7 @@
step.onShow(@) if step.onShow? step.onShow(@) if step.onShow?


# Show popover # Show popover
@showPopover(step, i) @_showPopover(step, i)


# Setup current step variable # Setup current step variable
setCurrentStep: (value) -> setCurrentStep: (value) ->
Expand All @@ -152,7 +154,7 @@
@showStep(step.next) @showStep(step.next)


# Show step popover # Show step popover
showPopover: (step, i) -> _showPopover: (step, i) ->
content = "#{step.content}<br /><p>" content = "#{step.content}<br /><p>"
if step.end if step.end
content += "<a href='#' class='end'>End</a>" content += "<a href='#' class='end'>End</a>"
Expand Down
10 changes: 6 additions & 4 deletions bootstrap-tour.js

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

90 changes: 90 additions & 0 deletions deps/bootstrap-alert.js
@@ -0,0 +1,90 @@
/* ==========================================================
* bootstrap-alert.js v2.0.4
* http://twitter.github.com/bootstrap/javascript.html#alerts
* ==========================================================
* Copyright 2012 Twitter, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ========================================================== */


!function ($) {

"use strict"; // jshint ;_;


/* ALERT CLASS DEFINITION
* ====================== */

var dismiss = '[data-dismiss="alert"]'
, Alert = function (el) {
$(el).on('click', dismiss, this.close)
}

Alert.prototype.close = function (e) {
var $this = $(this)
, selector = $this.attr('data-target')
, $parent

if (!selector) {
selector = $this.attr('href')
selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
}

$parent = $(selector)

e && e.preventDefault()

$parent.length || ($parent = $this.hasClass('alert') ? $this : $this.parent())

$parent.trigger(e = $.Event('close'))

if (e.isDefaultPrevented()) return

$parent.removeClass('in')

function removeElement() {
$parent
.trigger('closed')
.remove()
}

$.support.transition && $parent.hasClass('fade') ?
$parent.on($.support.transition.end, removeElement) :
removeElement()
}


/* ALERT PLUGIN DEFINITION
* ======================= */

$.fn.alert = function (option) {
return this.each(function () {
var $this = $(this)
, data = $this.data('alert')
if (!data) $this.data('alert', (data = new Alert(this)))
if (typeof option == 'string') data[option].call($this)
})
}

$.fn.alert.Constructor = Alert


/* ALERT DATA-API
* ============== */

$(function () {
$('body').on('click.alert.data-api', dismiss, Alert.prototype.close)
})

}(window.jQuery);
16 changes: 9 additions & 7 deletions deps/example-tour.js
Expand Up @@ -24,7 +24,7 @@ jQuery(function($) {
+ "complicated things. <br \/>Power to the people! :P" + "complicated things. <br \/>Power to the people! :P"
}); });
tour.addStep({ tour.addStep({
path: "test.html", path: "page.html",
element: "h1", element: "h1",
placement: "bottom", placement: "bottom",
title: "See, you are not restricted to only one page", title: "See, you are not restricted to only one page",
Expand All @@ -42,13 +42,15 @@ jQuery(function($) {
tour.start(); tour.start();


if ( tour.ended() ) { if ( tour.ended() ) {
$(".content").prepend('<div class="alert">\ $('<div class="alert">\
<button class="close" data-dismiss="alert">×</button>\ <button class="close" data-dismiss="alert">×</button>\
You ended the demo tour. <a href="" class="restart">Restart the demo tour.</a>\ You ended the demo tour. <a href="" class="restart">Restart the demo tour.</a>\
</div>'); </div>').prependTo(".content").alert();
} }


$(".restart").click(function () { $(".restart").click(function (e) {
tour.restart() e.preventDefault();
tour.restart();
$(this).parents(".alert").alert("close");
}); });
}); });
1 change: 1 addition & 0 deletions index.html
Expand Up @@ -188,6 +188,7 @@ <h2 id="license">License</h2>
<script src="deps/google-code-prettify/prettify.js"></script> <script src="deps/google-code-prettify/prettify.js"></script>
<script src="deps/bootstrap-tooltip.js"></script> <script src="deps/bootstrap-tooltip.js"></script>
<script src="deps/bootstrap-popover.js"></script> <script src="deps/bootstrap-popover.js"></script>
<script src="deps/bootstrap-alert.js"></script>
<script src="deps/jquery.cookie.js"></script> <script src="deps/jquery.cookie.js"></script>
<script src="bootstrap-tour.js"></script> <script src="bootstrap-tour.js"></script>
<script src="deps/example-tour.js"></script> <script src="deps/example-tour.js"></script>
Expand Down
45 changes: 45 additions & 0 deletions page.html
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Bootstrap Tour, An Extension of Bootstrap from Twitter</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">

<!-- Le styles -->
<link href="deps/bootstrap.css" rel="stylesheet">
<style>
body {
padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
}
</style>
<link href="deps/bootstrap-responsive.css" rel="stylesheet">

<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>

<body>

<div class="container">

<h1>This is just a test.</h1>
<p>Nothing to see here. Move on!</p>

</div> <!-- /container -->

<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="deps/jquery.js"></script>
<script src="deps/bootstrap-tooltip.js"></script>
<script src="deps/bootstrap-popover.js"></script>
<script src="deps/jquery.cookie.js"></script>
<script src="bootstrap-tour.js"></script>
<script src="deps/example-tour.js"></script>

</body>
</html>
46 changes: 13 additions & 33 deletions test.html
@@ -1,45 +1,25 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Bootstrap Tour, An Extension of Bootstrap from Twitter</title> <title>Bootstrap Tour Unit Tests</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="tests/qunit/qunit.css">
<meta name="description" content=""> <script src="tests/qunit/qunit.js"></script>
<meta name="author" content=""> <script src="tests/tests.js"></script>


<!-- Le styles -->
<link href="deps/bootstrap.css" rel="stylesheet"> <link href="deps/bootstrap.css" rel="stylesheet">
<style>
body {
padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
}
</style>
<link href="deps/bootstrap-responsive.css" rel="stylesheet">

<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>

<body>

<div class="container">

<h1>This is just a test.</h1>
<p>Nothing to see here. Move on!</p>

</div> <!-- /container -->

<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="deps/jquery.js"></script> <script src="deps/jquery.js"></script>
<script src="deps/bootstrap-tooltip.js"></script> <script src="deps/bootstrap-tooltip.js"></script>
<script src="deps/bootstrap-popover.js"></script> <script src="deps/bootstrap-popover.js"></script>
<script src="deps/jquery.cookie.js"></script> <script src="deps/jquery.cookie.js"></script>
<script src="bootstrap-tour.js"></script> <script src="bootstrap-tour.js"></script>
<script src="deps/example-tour.js"></script> </head>

<body>
<h1 id="qunit-header">Bootstrap Tour Unit Tests</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture"></div>
</body> </body>
</html> </html>

0 comments on commit 24b2aa9

Please sign in to comment.