Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80668 views
1
/**
2
* jQuery Mobile React Example
3
*
4
* Main application script.
5
* For variety, this example is written in 100% JSHint-compliant JavaScript, not in JSX.
6
*
7
* Component structure:
8
*
9
* - App
10
* |-- JQueryMobilePage (one)
11
* | |-- JQueryMobileHeader
12
* | |-- JQueryMobileContent
13
* | | |-- PageOneContent
14
* | | |-- JQueryMobileButton
15
* | |-- JQueryMobileFooter
16
* |-- JQueryMobilePage (two)
17
* | |-- JQueryMobileHeader
18
* | |-- JQueryMobileContent
19
* | | |-- PageTwoContent
20
* | | |-- JQueryMobileButton
21
* | |-- JQueryMobileFooter
22
* |-- JQueryMobilePage (popup)
23
* |-- JQueryMobileHeader
24
* |-- JQueryMobileContent
25
* | |-- PagePopUpContent
26
* | |-- JQueryMobileButton
27
* |-- JQueryMobileFooter
28
*/
29
30
/* global document, React */
31
32
'use strict';
33
34
/** Main application component. */
35
var App = React.createClass({
36
displayName: 'App',
37
38
render: function() {
39
return React.DOM.div({className:'app'},
40
JQueryMobilePage({id:'one'}, PageOneContent(null)),
41
JQueryMobilePage({id:'two'}, PageTwoContent(null)),
42
JQueryMobilePage({id:'popup', headerTheme:'b'}, PagePopUpContent(null))
43
);
44
}
45
});
46
App = React.createFactory(App);
47
48
/** jQuery Mobile button component. */
49
var JQueryMobileButton = React.createClass({
50
displayName: 'JQueryMobileButton',
51
52
getDefaultProps: function() {
53
return {className:'ui-btn ui-shadow ui-corner-all'};
54
},
55
56
render: function() {
57
return React.DOM.p(null,
58
React.DOM.a(this.props, this.props.children)
59
);
60
}
61
});
62
JQueryMobileButton = React.createFactory(JQueryMobileButton);
63
64
/** jQuery Mobile page content component. */
65
var JQueryMobileContent = React.createClass({
66
displayName: 'JQueryMobileContent',
67
68
render: function() {
69
return React.DOM.div({role:'main', className:'ui-content'},
70
this.props.children
71
);
72
}
73
});
74
JQueryMobileContent = React.createFactory(JQueryMobileContent);
75
76
/** jQuery Mobile footer component. */
77
var JQueryMobileFooter = React.createClass({
78
displayName: 'JQueryMobileFooter',
79
80
render: function() {
81
return React.DOM.div({'data-role':'footer'},
82
React.DOM.h4(null, 'Page footer')
83
);
84
}
85
});
86
JQueryMobileFooter = React.createFactory(JQueryMobileFooter);
87
88
/** jQuery Mobile header component. */
89
var JQueryMobileHeader = React.createClass({
90
displayName: 'JQueryMobileHeader',
91
92
render: function() {
93
return React.DOM.div({'data-role':'header', 'data-theme':this.props.headerTheme},
94
React.DOM.h1(null, this.props.title)
95
);
96
}
97
});
98
JQueryMobileHeader = React.createFactory(JQueryMobileHeader);
99
100
/** jQuery Mobile page component. */
101
var JQueryMobilePage = React.createClass({
102
displayName: 'JQueryMobilePage',
103
104
getDefaultProps: function() {
105
return {'data-role':'page', 'data-theme':'a', headerTheme:'a'};
106
},
107
108
render: function() {
109
var props = {};
110
for (var key in this.props) {
111
props[key] = this.props[key];
112
}
113
return React.DOM.div(props,
114
JQueryMobileHeader({title:'Page ' + this.props.id, headerTheme:this.props.headerTheme}),
115
JQueryMobileContent(null, this.props.children),
116
JQueryMobileFooter(null)
117
);
118
}
119
});
120
JQueryMobilePage = React.createFactory(JQueryMobilePage);
121
122
/** Application page one component. */
123
var PageOneContent = React.createClass({
124
displayName: 'PageOneContent',
125
126
render: function() {
127
return React.DOM.div(null,
128
React.DOM.h2(null, 'One'),
129
React.DOM.p(null,
130
'I have an ',
131
React.DOM.code(null, 'id'),
132
' of "one" on my page container. I\'m first in the source order so I\'m shown when the page loads.'
133
),
134
React.DOM.p(null, 'This is a multi-page boilerplate template that you can copy to build your first jQuery Mobile page. This template contains multiple "page" containers inside, unlike a single page template that has just one page within it.'),
135
React.DOM.p(null, 'Just view the source and copy the code to get started. All the CSS and JS is linked to the jQuery CDN versions so this is super easy to set up. Remember to include a meta viewport tag in the head to set the zoom level.'),
136
React.DOM.p(null,
137
'You link to internal pages by referring to the ',
138
React.DOM.code(null, 'id'),
139
' of the page you want to show. For example, to ',
140
React.DOM.a({href:'#two'}, 'link'),
141
' to the page with an ',
142
React.DOM.code(null, 'id'),
143
' of "two", my link would have a ',
144
React.DOM.code(null, 'href="#two"'),
145
' in the code.'
146
),
147
React.DOM.h3(null, 'Show internal pages:'),
148
JQueryMobileButton({href:'#two'}, 'Show page "two"'),
149
JQueryMobileButton({href:'#popup', 'data-rel':'dialog', 'data-transition':'pop'}, 'Show page "popup" (as a dialog)')
150
);
151
}
152
});
153
PageOneContent = React.createFactory(PageOneContent);
154
155
/** Application page two component. */
156
var PageTwoContent = React.createClass({
157
displayName: 'PageTwoContent',
158
159
render: function() {
160
return React.DOM.div(null,
161
React.DOM.h2(null, 'Two'),
162
React.DOM.p(null, 'I have an id of "two" on my page container. I\'m the second page container in this multi-page template.'),
163
React.DOM.p(null, 'Notice that the theme is different for this page because we\'ve added a few ',
164
React.DOM.code(null, 'data-theme'),
165
' swatch assigments here to show off how flexible it is. You can add any content or widget to these pages, but we\'re keeping these simple.'),
166
JQueryMobileButton({href:'#one', 'data-direction':'reverse', className:'ui-btn ui-shadow ui-corner-all ui-btn-b'}, 'Back to page "one"')
167
);
168
}
169
});
170
PageTwoContent = React.createFactory(PageTwoContent);
171
172
/** Application popup page component. */
173
var PagePopUpContent = React.createClass({
174
displayName: 'PagePopUpContent',
175
176
render: function() {
177
return React.DOM.div(null,
178
React.DOM.h2(null, 'Popup'),
179
React.DOM.p(null, 'I have an id of "popup" on my page container and only look like a dialog because the link to me had a ',
180
React.DOM.code(null, 'data-rel="dialog"'),
181
' attribute which gives me this inset look and a ',
182
React.DOM.code(null, 'data-transition="pop"'),
183
' attribute to change the transition to pop. Without this, I\'d be styled as a normal page.'),
184
JQueryMobileButton({href:'#one', 'data-rel':'back', className:'ui-btn ui-shadow ui-corner-all ui-btn-inline ui-icon-back ui-btn-icon-left'}, 'Back to page "one"')
185
);
186
}
187
});
188
PagePopUpContent = React.createFactory(PagePopUpContent);
189
190
// Render application.
191
React.render(App(null), document.getElementById('content'));
192
193