summaryrefslogtreecommitdiffstats
path: root/wmlcards.html
blob: ba174ec427d5378a065c279635594b8de3c18774 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
    <title>Anchor Jumps</title>
    <style type="text/css">
        p { color:gray; }
        div.card { background-color:cyan; }
    </style>
    <script type="text/javascript">
    function cardHistory() {
        this.redo = new Array(); // backward history
        this.undo = new Array(); // forward history
        this.get  = "";
        this.post = "";
        this.requestheaders = "";

        this.pushUndo = function(url) { // save a url to history
            // hitting this function results in discarded forward history
            if (this.redo.length > 0)
                this.redo = [];

            this.undo.push(url);
            return true;
        }
        this.pushRedo = function(url) { // saves url to redo list (forward)
            this.redo.push(url);
            return true;
        }

        // pops the url from undo stack to redo stack
        this.goBack = function() {
            if (this.undo.length > 0) {
                var back = this.undo.pop();
                this.redo.push(back);
                this.jump(back);
            }
        }

        // pushes the url from redo stack to undo stack (history stack)
        this.goForward = function() {
            if (this.redo.length > 0) {
                this.pushUndo(this.redo.pop());
                this.jump();
            }
        }

        this.jump = function(url) {
            // go to what's on top of history stack
            if (url.indexOf('#') != 0)
                window.location.href = url; // jumping to an url
            else
                window.location.hash = url; // jumping to an hash anchor
        }

        this.undoTop = function() {
            return this.undo[this.undo.length-1];
        }
        this.redoTop = function() {
            return this.redo[this.redo.length-1];
        }
    }

    var trackHistory = new cardHistory();
    </script>
</head>

<body>
    <!--
    - form should have unique id
    - everytime we leave a card we should push that chanhe onto undo stack

    onsubmit="return trackHistory.pushUndo(document.getElementById('card1_form').action);"
    -->

    <div id="card1" class="card">
        <h2>Card 1</h2>
        <p>This is Card 1.</p>
        Here is just some text below Card 1.<br />
        More text to kill window space.<br />
        <button onclick="trackHistory.goBack();">Prev</button>
        <form id="card1_form" action="#card2" onsubmit="return trackHistory.pushUndo(window.location.href);">
            <button type="submit">Next</button>
        </form>

    </div>

    <div id="card2" class="card">
        <h2>Card 2</h2>
        <p>This is Card 2.</p>
        Here is just some text below Card 2.<br />
        More text to kill window space.<br />
        <button onclick="trackHistory.goBack();">Prev</button>
        <form id="card2_form" action="#card3" onsubmit="return trackHistory.pushUndo(window.location.href);">
            <button type="submit">Next</button>
        </form>
    </div>

    <div id="card3" class="card">
        <h2>Card 3</h2>
        <p>This is Card 3.</p>
        Here is just some text below Card 3.<br />
        More text to kill window space.<br />
        <button onclick="trackHistory.goBack();">Prev</button>
        <form id="card3_form" action="#card4" onsubmit="return trackHistory.pushUndo(window.location.href);">
            <button type="submit">Next</button>
        </form>
    </div>

    <div id="card4" class="card">
        <h2>Card 4</h2>
        <p>This is Card 4.</p>
        Here is just some text below Card 4.<br />
        More text to kill window space.<br />
        <a href="#card6" onclick="trackHistory.pushUndo(window.location.href);">Go to Card 6</a><br />
        <button onclick="trackHistory.goBack();">Prev</button>
        <form id="card4_form" action="#card5" onsubmit="return trackHistory.pushUndo(window.location.href);">
            <button type="submit">Next</button>
        </form>
    </div>

    <div id="card5" class="card">
        <h2>Card 5</h2>
        <p>This is Card 5.</p>
        Here is just some text below Card 5.<br />
        More text to kill window space.<br />
        <button onclick="trackHistory.goBack();">Prev</button>
        <form id="card5_form" action="#card6" onsubmit="return trackHistory.pushUndo(window.location.href);">
            <button type="submit">Next</button>
        </form>
    </div>

    <div id="card6" class="card">
        <h2>Card 6</h2>
        <p>This is Card 6.</p>
        Here is just some text below Card 6.<br />
        More text to kill window space.<br />
        <button onclick="trackHistory.goBack();">Prev</button>
        <form id="card6_form" action="#card7" onsubmit="return trackHistory.pushUndo(window.location.href);">
            <button type="submit">Next</button>
        </form>
    </div>

    <div id="card7" class="card">
        <h2>Card 7</h2>
        <p>This is Card 7.</p>
        Here is just some text below Card 7.<br />
        More text to kill window space.<br />
        <button onclick="trackHistory.goBack();">Prev</button>
        <form id="card7_form" action="#card1" onsubmit="return trackHistory.pushUndo(window.location.href);">
            <button type="submit">Go to Card 1</button>
        </form>
    </div>
</body>
</html>