This repository was archived by the owner on Feb 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.html
221 lines (185 loc) · 8.17 KB
/
index.html
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, target-densitydpi=medium-dpi" >
<meta name="apple-mobile-web-app-capable" content="yes" >
<meta name="apple-mobile-web-app-status-bar-style" content="black" >
<meta name="format-detection" content="telephone=no" >
<title>DrMobile integration example</title>
<link rel="stylesheet" type="text/css" href="vendor/aptoma/alf/alf.css">
<link rel="apple-touch-icon-precomposed" href="gfx/appicon.png"/>
<style type="text/css">
.event-frame {
display: none;
}
</style>
</head>
<body>
<div class="alf-chrome" id="chrome">
<div class="alf-layer alf-layer-1 alf-layer-page" id="alf-layer-1">
<div class="alf-pages">
<div class="alf-page alf-page-1">
<section class="alf-page-loader swiper-page-is-loading"></section>
<section class="alf-page-content alf-is-scrollable-y"></section>
</div>
<div class="alf-page alf-page-2">
<section class="alf-page-loader swiper-page-is-loading"></section>
<section class="alf-page-content alf-is-scrollable-y"></section>
</div>
<div class="alf-page alf-page-3">
<section class="alf-page-loader swiper-page-is-loading"></section>
<section class="alf-page-content alf-is-scrollable-y"></section>
</div>
</div>
</div>
<div class="alf-layer alf-layer-2 alf-layer-fullscreen alf-is-hidden" id="alf-layer-2"></div>
</div>
<iframe width="0" height="0" frameborder="0" class="event-frame"></iframe>
<iframe width="0" height="0" frameborder="0" class="event-frame"></iframe>
<iframe width="0" height="0" frameborder="0" class="event-frame"></iframe>
<iframe width="0" height="0" frameborder="0" class="event-frame"></iframe>
<script type="text/javascript" src="vendor/aptoma/alf/alf.min.js"></script>
<script type="text/javascript">
require(['alf'], function (Alf) {
var app, publicationName, url, assetsBaseUrl;
// The name of the publication in LayoutPreview
publicationName = 'pub_11';
// The name of the format you want to use
formatName = 'ipad_landscape';
// Article URL. Point this to your DrMobile API endpoint (DrLib)
url = 'http://rai-dev.aptoma.no:9000/drmobile.json?formatName=' + formatName + '&publicationName=' + publicationName + '&limit=50&callback=?';
app = {
initialize: function () {
this.pages = [];
this.initBridge();
this.initLayers();
this.initScrollView();
},
/**
* Initialize the bridge used for communication between native and HTML
*
* @return {void}
*/
initBridge: function () {
// This is used to trigger HTML-events by the native layer
this.event = _.extend({}, Alf.Events);
// This is used to send event-data to the native app
this.bridge = _.extend({}, Alf.Events, {
initialize: function () {
this.frameIndex = 0;
this.eventFrames = $('.event-frame');
this.bind('all', this.eventTriggered);
},
/**
* Event triggered
*
* This works like a proxy for all events triggered on this.bridge
* Change the src attribute on any of the iframes so the native wrapper app
* can intercept it and decode the JSON payload in the URL
*
* @return {void}
*/
eventTriggered: function () {
// This is deactivated since normal browsers will display an error when this is run.
// Only activate the line below when this is run in a WebView inside a native wrapper app
// this.eventFrames[this.frameIndex].src = 'event://' + escape(JSON.stringify([].slice.call(arguments)));
this.frameIndex = (this.frameIndex + 1) % this.eventFrames.length;
}
});
this.bridge.initialize();
},
/**
* Initialize layers
*
* This is to enable fullscreen support
* The article/pages and fullscreen elements are rendered in different "layers"
*
* @return {void}
*/
initLayers: function () {
this.layerManager = new Alf.layer.Manager();
this.pageLayer = new Alf.layer.Page({
el: '#alf-layer-1',
manager: this.layerManager
});
this.fullscreenLayer = new Alf.layer.Fullscreen({
el: '#alf-layer-2',
manager: this.layerManager
});
this.pageLayer.render();
this.fullscreenLayer.render();
Alf.hub.on('fullscreenWillAppear', function () {
// Tell the native wrapper app that an element is about to enter fullscreen mode
this.bridge.trigger('fullscreenWillAppear');
}, this);
},
/**
* Initialize the scroll view
*
* This is only needed if you want HTML-navigation
*
* @return {void}
*/
initScrollView: function () {
var that = this;
this.scrollView = new Alf.nav.ScrollView($('#alf-layer-1').get(0), {
numberOfPages: app.compiledPages.length,
overflowScrolling: true
});
this.scrollView.on('pageWillRender', function (el, pageNum) {
// Tell the native wrapper that a page is about to be rendered
that.bridge.trigger('pageWillRender', pageNum);
app.renderPage(el, pageNum);
});
/**
* This will make sure there are no memory leaks when pages are removed
*/
this.scrollView.on('pageWillDestruct', function (el, pageNum) {
app.pages[pageNum] && app.pages[pageNum].tearDown();
delete app.pages[pageNum];
});
this.scrollView.start();
},
/**
* Render the page on screen
*
* Takes the compiled content and uses Alf.layout.Page to do rendering
*
* @param {HTMLElement} el the element to put the page inside
* @param {number} pageNum the page number
* @return {void}
*/
renderPage: function (el, pageNum) {
var page;
this.pages[pageNum] = page = new Alf.layout.Page({
layer: this.pageLayer,
assetsBaseUrl: assetsBaseUrl
});
page.on('loadComplete', function () {
// Tell the native wrapper that a page has finished loading
this.bridge.trigger('loadComplete');
}, this);
page.decompile(this.compiledPages[pageNum], function () {
page.render(el);
});
}
};
/**
* Fetch all articles and pages
*/
$.get(url, function (response) {
app.compiledPages = [];
app.pages = {};
assetsBaseUrl = response.items[0].service.assetsBaseUrl;
// Convert all article-pages into a flat array of pages
response.items.forEach(function (article) {
app.compiledPages = app.compiledPages.concat(article.compiled.pages);
});
app.initialize();
}, 'json');
window.app = app;
});
</script>
</body>
</html>