Permalink
Browse files

role: start. Issue #96

  • Loading branch information...
finnsson committed Feb 17, 2013
1 parent 8220780 commit b910839b306ae199704a5d232a5676b0467b5808
Showing with 99 additions and 1 deletion.
  1. +16 −1 pager.js
  2. +83 −0 test/should_display_role_start.html
View
@@ -219,8 +219,9 @@
$.each(children(), function (childIndex, child) {
if (!match) {
var id = child.getId();
+ var role = child.getRole();
if (id === currentRoute ||
- ((currentRoute === '' || currentRoute == null) && id === 'start')) {
+ ((currentRoute === '' || currentRoute == null) && (id === 'start' || role === 'start'))) {
match = true;
me.currentChild = child;
}
@@ -1166,6 +1167,20 @@
}
};
+ /**
+ * Return the role of the page (either `next` or `start`).
+ *
+ * <div data-bind="page: {id: 'x', role: 'start'}"></div>
+ *
+ * Specifying role `start` gives the page the same behaviour as if the page
+ * had `{id: 'start'}`.
+ *
+ * @return {String}
+ */
+ p.getRole = function () {
+ return this.val('role') || 'next';
+ };
+
p.nullObject = new pager.Page();
p.nullObject.children = ko.observableArray([]);
@@ -0,0 +1,83 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Should display role start</title>
+ <script type="text/javascript" src="../lib/jquery-1.7.2.min.js"></script>
+ <script type="text/javascript" src="../lib/underscore-min.js"></script>
+ <script type="text/javascript" src="../lib/knockout-2.1.0.js"></script>
+ <script type="text/javascript" src="../lib/jquery.ba-hashchange.min.js"></script>
+ <script type="text/javascript" src="../pager.js"></script>
+
+ <link rel="stylesheet" href="../lib/qunit.css"/>
+</head>
+<body>
+
+<div id="qunit"></div>
+
+<div data-bind="page: {id: 'x', role: 'start'}">
+ <div id="answer" data-bind="text: answer"></div>
+ <div id="question" data-bind="text: question"></div>
+
+
+ <div data-bind="page: {id: 'y', role: 'start'}">
+ <div id="y">Y</div>
+ </div>
+
+ <div data-bind="page: {id: 'z'}">
+ <div id="z">Z</div>
+ </div>
+
+</div>
+
+<script type="text/javascript">
+
+ var viewModel = {
+ answer:42,
+ question:'?'
+ };
+
+ pager.extendWithPage(viewModel);
+ ko.applyBindings(viewModel);
+
+ pager.startHashChange();
+
+ VM = viewModel;
+</script>
+
+<script type="text/javascript" src="../lib/qunit-until.js"></script>
+<script type="text/javascript" src="../lib/qunit.js"></script>
+
+<script type="text/javascript">
+
+ asyncTest("Should display role start", function () {
+
+ // make sure we're on the start page
+ window.location.hash = '#';
+
+ until(function () {
+ return $('#y').is(':visible');
+ }, function () {
+
+ assert.equal($('#z').is(':visible'), false, 'z should be hidden');
+ assert.equal($('#y').is(':visible'), true, 'y should be visible');
+
+ location.hash = '#x/z';
+
+ until(function () {
+ return $('#z').is(':visible');
+ }, function () {
+ assert.equal($('#z').is(':visible'), true, 'z should be visible');
+ assert.equal($('#y').is(':visible'), false, 'y should be hidden');
+ start();
+
+ });
+
+ });
+
+
+ });
+</script>
+
+
+</body>
+</html>

0 comments on commit b910839

Please sign in to comment.