PageState.js.html 4.99 KB
Newer Older
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
157
158
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>JSDoc: Source: PageState.js</title>

    <script src="scripts/prettify/prettify.js"></script>
    <script src="scripts/prettify/lang-css.js"></script>
    <!--[if lt IE 9]>
    <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
    <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>

<body>

<div id="main">

    <h1 class="page-title">Source: PageState.js</h1>


    <section>
        <article>
            <pre class="prettyprint source linenums"><code>/**
                * @author Rafael Ostertag &lt;rafael.ostertag@math.uzh.ch>
                */

                /* @depend QfqEvents.js */
                /* global EventEmitter */

                /**
                * Qfq Namespace
                *
                * @namespace QfqNS
                */
                var QfqNS = QfqNS || {};

                (function (n) {
                'use strict';


                /**
                *
                * @constructor
                * @name QfqNS.PageState
                */
                n.PageState = function () {
                this.pageState = location.hash.slice(1);
                this.data = null;
                this.inPoppingHandler = false;
                this.eventEmitter = new EventEmitter();

                window.addEventListener("popstate", this.popStateHandler.bind(this));
                };

                n.PageState.prototype.on = n.EventEmitter.onMixin;
                /**
                *
                * @param event
                *
                * @private
                */
                n.PageState.prototype.popStateHandler = function (event) {

                n.Log.debug("Enter: PageState.popStateHandler()");

                this.inPoppingHandler = true;
                this.pageState = location.hash.slice(1);
                this.data = window.history.state;

                n.Log.debug("PageState.popStateHandler(): invoke user pop state handler(s)");

                this.eventEmitter.emitEvent('pagestate.state.popped', n.EventEmitter.makePayload(this, null));

                this.inPoppingHandler = false;
                n.Log.debug("Exit: PageState.popStateHandler()");

                };

                n.PageState.prototype.getPageState = function () {
                return this.pageState;
                };

                n.PageState.prototype.getPageData = function () {
                return this.data;
                };

                n.PageState.prototype.setPageState = function (state, data) {
                if (state.startsWith('#')) {
                this.pageState = state.slice(1);
                window.history.replaceState(data, null, state);
                } else {
                this.pageState = state;
                window.history.replaceState(data, null, '#' + state);
                }
                this.data = data;
                };

                n.PageState.prototype.newPageState = function (state, data) {
                if (state.startsWith('#')) {
                this.pageState = state.slice(1);
                window.history.pushState(data, null, state);
                } else {
                this.pageState = state;
                window.history.pushState(data, null, '#' + state);
                }

                this.data = data;
                };

                })(QfqNS);</code></pre>
        </article>
    </section>


</div>

<nav>
    <h2><a href="index.html">Home</a></h2>

    <h3>Classes</h3>
    <ul>
        <li><a href="n.Alert.html">Alert</a></li>
        <li><a href="QfqNS.BSTabs.html">BSTabs</a></li>
        <li><a href="QfqNS.Element.Checkbox.html">Checkbox</a></li>
        <li><a href="QfqNS.Element.FormGroup.html">FormGroup</a></li>
        <li><a href="QfqNS.Element.Radio.html">Radio</a></li>
        <li><a href="QfqNS.Element.Select.html">Select</a></li>
        <li><a href="QfqNS.Element.Textual.html">Textual</a></li>
        <li><a href="QfqNS.FileDelete.html">FileDelete</a></li>
        <li><a href="QfqNS.FileUpload.html">FileUpload</a></li>
        <li><a href="QfqNS.Form.html">Form</a></li>
        <li><a href="QfqNS.PageState.html">PageState</a></li>
        <li><a href="QfqNS.QfqForm.html">QfqForm</a></li>
        <li><a href="QfqNS.QfqPage.html">QfqPage</a></li>
        <li><a href="QfqNS.QfqRecordList.html">QfqRecordList</a></li>
    </ul>
    <h3>Namespaces</h3>
    <ul>
        <li><a href="global.html#QfqNS">QfqNS</a></li>
        <li><a href="QfqNS.Element.html">Element</a></li>
        <li><a href="QfqNS.Helper.html">Helper</a></li>
    </ul>
    <h3><a href="global.html">Global</a></h3>
</nav>

<br class="clear">

<footer>
    Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Mon May 23 2016 12:28:24
    GMT+0200 (CEST)
</footer>

<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"></script>
</body>
</html>