@progress/telerik-jquery-report-viewer 21.24.130 → 22.24.514
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +1 -1
- package/dist/cjs/accessibility.js +218 -0
- package/dist/cjs/binder.js +172 -0
- package/dist/cjs/command.js +32 -0
- package/dist/cjs/commandSet.js +167 -0
- package/dist/cjs/controller.js +1207 -0
- package/dist/cjs/documentMapArea.js +168 -0
- package/dist/cjs/domUtils.js +50 -0
- package/dist/cjs/enums.js +52 -0
- package/dist/cjs/event-emitter.js +17 -0
- package/dist/cjs/events.js +23 -0
- package/dist/cjs/globalSettings.js +9 -0
- package/dist/cjs/history.js +131 -0
- package/dist/cjs/index.js +58 -0
- package/dist/cjs/jqueryThrottleDebounce.js +48 -0
- package/dist/cjs/kendo-jquery.js +4 -0
- package/dist/cjs/mainMenu.js +332 -0
- package/dist/cjs/mem-storage.js +44 -0
- package/dist/cjs/pagesArea.js +641 -0
- package/dist/cjs/parameterValidators.js +167 -0
- package/dist/cjs/parameters.js +921 -0
- package/dist/cjs/parametersArea.js +502 -0
- package/dist/cjs/perspectives.js +138 -0
- package/dist/cjs/print.js +166 -0
- package/dist/cjs/report-viewer/report-viewer-settings.js +138 -0
- package/dist/cjs/reportViewer.js +654 -0
- package/dist/cjs/scroll.js +537 -0
- package/dist/cjs/search.js +634 -0
- package/dist/cjs/sendEmail.js +435 -0
- package/dist/cjs/service-client-sentinel.js +52 -0
- package/dist/cjs/serviceClient.js +405 -0
- package/dist/cjs/sideMenu.js +225 -0
- package/dist/cjs/sr.js +164 -0
- package/dist/cjs/stringResources.js +11 -0
- package/dist/cjs/telerikReportViewer.kendo.js +60196 -0
- package/dist/cjs/telerikReportViewer.kendo.min.js +19776 -0
- package/dist/cjs/template-cache.js +39 -0
- package/dist/cjs/touch.js +86 -0
- package/dist/cjs/uiController.js +142 -0
- package/dist/cjs/uiFreezeCoordinator.js +281 -0
- package/dist/cjs/utils.js +492 -0
- package/dist/es/accessibility.js +214 -0
- package/dist/es/binder.js +168 -0
- package/dist/es/command.js +28 -0
- package/dist/es/commandSet.js +163 -0
- package/dist/es/controller.js +1203 -0
- package/dist/es/documentMapArea.js +164 -0
- package/dist/es/domUtils.js +43 -0
- package/dist/es/enums.js +41 -0
- package/dist/es/event-emitter.js +13 -0
- package/dist/es/events.js +19 -0
- package/dist/es/globalSettings.js +5 -0
- package/dist/es/history.js +127 -0
- package/dist/es/index.js +24 -0
- package/dist/es/jqueryThrottleDebounce.js +46 -0
- package/dist/es/kendo-jquery.js +1 -0
- package/dist/es/mainMenu.js +328 -0
- package/dist/es/mem-storage.js +40 -0
- package/dist/es/pagesArea.js +637 -0
- package/dist/es/parameterValidators.js +163 -0
- package/dist/es/parameters.js +916 -0
- package/dist/es/parametersArea.js +498 -0
- package/dist/es/perspectives.js +134 -0
- package/dist/es/print.js +162 -0
- package/dist/es/report-viewer/report-viewer-settings.js +134 -0
- package/dist/es/reportViewer.js +650 -0
- package/dist/es/scroll.js +533 -0
- package/dist/es/search.js +630 -0
- package/dist/es/sendEmail.js +431 -0
- package/dist/es/service-client-sentinel.js +48 -0
- package/dist/es/serviceClient.js +401 -0
- package/dist/es/sideMenu.js +221 -0
- package/dist/es/sr.js +162 -0
- package/dist/es/stringResources.js +7 -0
- package/dist/es/telerikReportViewer.kendo.js +60194 -0
- package/dist/es/telerikReportViewer.kendo.min.js +19774 -0
- package/dist/es/template-cache.js +35 -0
- package/dist/es/touch.js +82 -0
- package/dist/es/uiController.js +138 -0
- package/dist/es/uiFreezeCoordinator.js +277 -0
- package/dist/es/utils.js +447 -0
- package/dist/font/font-icons.css +4 -4
- package/dist/font/font-icons.min.css +3 -3
- package/dist/js/telerikReportViewer.js +8574 -8249
- package/dist/js/telerikReportViewer.min.js +1 -17
- package/dist/js/telerikReportViewer.stringResources.js +166 -173
- package/dist/styles/telerikReportViewer.css +1 -1
- package/dist/styles/telerikReportViewer.min.css +1 -1
- package/dist/templates/telerikReportViewerTemplate-FA.html +3 -3
- package/dist/templates/telerikReportViewerTemplate.html +3 -3
- package/package.json +13 -7
- /package/dist/font/{ReportingIcons-18.0.24.130.ttf → ReportingIcons-18.1.24.514.ttf} +0 -0
@@ -0,0 +1,537 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
4
|
+
|
5
|
+
var utils = require('./utils.js');
|
6
|
+
|
7
|
+
var Scroll = {
|
8
|
+
controller: {},
|
9
|
+
$placeholder: null,
|
10
|
+
$pageContainer: null,
|
11
|
+
pageContainer: null,
|
12
|
+
$pageWrapper: null,
|
13
|
+
pageWrapper: null,
|
14
|
+
viewMode: null,
|
15
|
+
loadedPage: {},
|
16
|
+
scrollInProgress: false,
|
17
|
+
enabled: false,
|
18
|
+
pageCount: 0,
|
19
|
+
additionalTopOffset: 130,
|
20
|
+
pageDistance: 20,
|
21
|
+
oldScrollTopPosition: 0,
|
22
|
+
skeletonTemplate: '<div class="trv-report-page trv-skeleton-page trv-skeleton-{0}" style="{1}" data-page="{0}"><div class="trv-skeleton-wrapper" style="{2}"></div></div>',
|
23
|
+
/**
|
24
|
+
* Initialize the scroll object
|
25
|
+
* Takes two parameters
|
26
|
+
* - placeholder - PageArea dom element
|
27
|
+
* - options - PageArea options
|
28
|
+
*/
|
29
|
+
init: function init(placeholder, options) {
|
30
|
+
var that = this;
|
31
|
+
that.$placeholder = $("[data-selector='" + options.viewerSelector + "']").find(placeholder);
|
32
|
+
that.$pageContainer = this.$placeholder.find(".trv-page-container");
|
33
|
+
that.pageContainer = this.$pageContainer[0];
|
34
|
+
that.$pageWrapper = this.$placeholder.find(".trv-page-wrapper");
|
35
|
+
that.pageWrapper = this.$pageWrapper[0];
|
36
|
+
that.controller = options.controller;
|
37
|
+
that.viewMode = null;
|
38
|
+
that.loadedPage = {};
|
39
|
+
that.scrollInProgress = false;
|
40
|
+
that.enabled = false;
|
41
|
+
that.pageCount = 0;
|
42
|
+
that.controller.scaleChanged(function(e, args) {
|
43
|
+
if (that.enabled) {
|
44
|
+
setTimeout(function() {
|
45
|
+
that._loadMorePages();
|
46
|
+
that._keepCurrentPageInToView();
|
47
|
+
}, 100);
|
48
|
+
}
|
49
|
+
}).loadedReportChange(function(event) {
|
50
|
+
if (that.enabled) {
|
51
|
+
that.disable();
|
52
|
+
if (event.type !== "loadedReportChange") {
|
53
|
+
setTimeout(function() {
|
54
|
+
that.controller.getPageData(1).then(function(newPage) {
|
55
|
+
that.renderPage(newPage);
|
56
|
+
});
|
57
|
+
});
|
58
|
+
}
|
59
|
+
}
|
60
|
+
}).viewModeChanged(function(args) {
|
61
|
+
if (that.enabled) {
|
62
|
+
that.disable();
|
63
|
+
}
|
64
|
+
}).interactiveActionExecuting(function(e, args) {
|
65
|
+
var actionType = args.action.Type;
|
66
|
+
if (that.enabled && (actionType === "sorting" || actionType === "toggleVisibility")) {
|
67
|
+
that.disable();
|
68
|
+
}
|
69
|
+
}).updatePageDimensionsReady(function(event, args) {
|
70
|
+
if (that.enabled && that._currentPageNumber() > 0) {
|
71
|
+
that._keepCurrentPageInToView();
|
72
|
+
}
|
73
|
+
}).pageCountChange(function(event, args) {
|
74
|
+
if (that.enabled && that.pageCount !== args) {
|
75
|
+
if (that._currentPageNumber() > 0 && !that.scrollInProgress) {
|
76
|
+
that._loadMorePages();
|
77
|
+
}
|
78
|
+
if (args > 1) {
|
79
|
+
that._initEvents();
|
80
|
+
}
|
81
|
+
that.pageCount = args;
|
82
|
+
}
|
83
|
+
});
|
84
|
+
},
|
85
|
+
/**
|
86
|
+
* Returns true, when Telerik Report Viewer pageMode is set to CONTINUOUS_SCROLL or it is unset
|
87
|
+
*/
|
88
|
+
isEnabled: function isEnabled() {
|
89
|
+
return this.enabled;
|
90
|
+
},
|
91
|
+
disable: function disable() {
|
92
|
+
this.$pageWrapper.empty();
|
93
|
+
this.enabled = false;
|
94
|
+
this.loadedPage = {};
|
95
|
+
this.pageCount = 0;
|
96
|
+
this.$placeholder.removeClass("scrollable");
|
97
|
+
this._unbind();
|
98
|
+
},
|
99
|
+
enable: function() {
|
100
|
+
this.enabled = true;
|
101
|
+
this.$placeholder.addClass("scrollable");
|
102
|
+
this._initEvents();
|
103
|
+
},
|
104
|
+
/**
|
105
|
+
* Handle the page rendering called from the PageArea
|
106
|
+
* Takes one parameter
|
107
|
+
* page - the page object
|
108
|
+
*/
|
109
|
+
renderPage: function renderPage(page) {
|
110
|
+
var that = this;
|
111
|
+
var pageViewMode = that.controller.getViewMode();
|
112
|
+
var renderedPage = that.$placeholder.find('[data-page="' + page.pageNumber + '"]');
|
113
|
+
if (!that.enabled) {
|
114
|
+
that.enabled = true;
|
115
|
+
that.$placeholder.addClass("scrollable");
|
116
|
+
if (pageViewMode !== that.viewMode || !renderedPage.length) {
|
117
|
+
that._updatePageArea(page);
|
118
|
+
} else {
|
119
|
+
that._render(page, true);
|
120
|
+
this.$pageContainer.scrollTop(3);
|
121
|
+
that._setCurrentPage(page.pageNumber);
|
122
|
+
}
|
123
|
+
that.viewMode = that.controller.getViewMode();
|
124
|
+
that._loadMorePages();
|
125
|
+
} else {
|
126
|
+
if (pageViewMode !== that.viewMode || !renderedPage.length) {
|
127
|
+
that._updatePageArea(page);
|
128
|
+
} else {
|
129
|
+
that._navigateToPage(page, renderedPage);
|
130
|
+
}
|
131
|
+
that.viewMode = that.controller.getViewMode();
|
132
|
+
}
|
133
|
+
},
|
134
|
+
/**
|
135
|
+
* Trigger scrolling animation to the specific element.
|
136
|
+
*/
|
137
|
+
navigateToElement: function navigateToElement(offsetTop, pageNumber) {
|
138
|
+
var that = this;
|
139
|
+
that.scrollInProgress = true;
|
140
|
+
if (that._isSkeletonScreen(null, pageNumber)) {
|
141
|
+
that.controller.getPageData(pageNumber).then(function(newPage) {
|
142
|
+
that._render(newPage, false);
|
143
|
+
that.$pageContainer.animate({ scrollTop: offsetTop }, 500, function() {
|
144
|
+
that._setCurrentPage(pageNumber);
|
145
|
+
setTimeout(function() {
|
146
|
+
that.scrollInProgress = false;
|
147
|
+
}, 100);
|
148
|
+
});
|
149
|
+
});
|
150
|
+
} else {
|
151
|
+
that.$pageContainer.animate({ scrollTop: offsetTop }, 500, function() {
|
152
|
+
that._setCurrentPage(pageNumber);
|
153
|
+
setTimeout(function() {
|
154
|
+
that.scrollInProgress = false;
|
155
|
+
}, 100);
|
156
|
+
});
|
157
|
+
}
|
158
|
+
},
|
159
|
+
_setCurrentPage: function _setCurrentPage(pageNumber) {
|
160
|
+
var that = this;
|
161
|
+
if (pageNumber !== that._currentPageNumber()) {
|
162
|
+
that.controller.setCurrentPageNumber(pageNumber);
|
163
|
+
}
|
164
|
+
if (that.controller.getPageCount() > 1) {
|
165
|
+
that.$placeholder.find(".k-state-default").removeClass("k-state-default");
|
166
|
+
that.$placeholder.find('[data-page="' + pageNumber + '"]').addClass("k-state-default");
|
167
|
+
}
|
168
|
+
that._loadNextPreviousPage(pageNumber);
|
169
|
+
},
|
170
|
+
_updatePageArea: function _updatePageArea(page) {
|
171
|
+
var that = this;
|
172
|
+
var scrollTo = 0;
|
173
|
+
var pageNumber = page.pageNumber;
|
174
|
+
that.scrollInProgress = true;
|
175
|
+
if (pageNumber > 1) {
|
176
|
+
that._generateSkeletonScreens(pageNumber);
|
177
|
+
}
|
178
|
+
that._render(page, false);
|
179
|
+
that._setCurrentPage(page.pageNumber);
|
180
|
+
setTimeout(function() {
|
181
|
+
scrollTo = pageNumber > 1 ? that.$placeholder.find('[data-page="' + pageNumber + '"]').position().top : 0;
|
182
|
+
that.$pageContainer.animate({ scrollTop: scrollTo }, 0, function() {
|
183
|
+
that.scrollInProgress = false;
|
184
|
+
});
|
185
|
+
}, 100);
|
186
|
+
},
|
187
|
+
_navigateToPage: function _navigateToPage(page, renderedPage) {
|
188
|
+
var that = this;
|
189
|
+
that.scrollInProgress = true;
|
190
|
+
var scrollTo = renderedPage.position().top;
|
191
|
+
var pages = that.$placeholder.find(".trv-report-page");
|
192
|
+
var pageNumber = page.pageNumber;
|
193
|
+
$(pages[0]).height();
|
194
|
+
if (that._isSkeletonScreen(renderedPage, pageNumber)) {
|
195
|
+
that.controller.getPageData(pageNumber).then(function(newPage) {
|
196
|
+
that._render(newPage, false);
|
197
|
+
that.$pageContainer.animate({ scrollTop: scrollTo }, 500, function() {
|
198
|
+
setTimeout(function() {
|
199
|
+
that._setCurrentPage(newPage.pageNumber);
|
200
|
+
that.scrollInProgress = false;
|
201
|
+
});
|
202
|
+
});
|
203
|
+
});
|
204
|
+
} else {
|
205
|
+
that._updatePageContent(page, renderedPage);
|
206
|
+
that.$pageContainer.animate({ scrollTop: scrollTo }, 500, function() {
|
207
|
+
setTimeout(function() {
|
208
|
+
that._setCurrentPage(page.pageNumber);
|
209
|
+
that.scrollInProgress = false;
|
210
|
+
});
|
211
|
+
});
|
212
|
+
}
|
213
|
+
},
|
214
|
+
_updatePageContent: function _updatePageContent(page, renderedPage) {
|
215
|
+
this._updatePageStyle(page);
|
216
|
+
var pageNumber = page.pageNumber;
|
217
|
+
var wrapper = $($.parseHTML(page.pageContent));
|
218
|
+
var $pageContent = wrapper.find("div.sheet");
|
219
|
+
var $page = this.$placeholder.find('[data-page="' + pageNumber + '"]');
|
220
|
+
$pageContent.css("margin", 0);
|
221
|
+
$page.append($pageContent).append($('<div class="trv-page-overlay"></div>'));
|
222
|
+
renderedPage.replaceWith($page);
|
223
|
+
this.controller.scrollPageReady({ page, target: $page });
|
224
|
+
},
|
225
|
+
_currentPageNumber: function _currentPageNumber() {
|
226
|
+
return this.controller.getCurrentPageNumber();
|
227
|
+
},
|
228
|
+
_isSkeletonScreen: function _isSkeletonScreen(page, pageNumber) {
|
229
|
+
if (!page) {
|
230
|
+
page = this.$placeholder.find('[data-page="' + pageNumber + '"]');
|
231
|
+
}
|
232
|
+
return page.hasClass("trv-skeleton-" + pageNumber);
|
233
|
+
},
|
234
|
+
_addSkeletonScreen: function _addSkeletonScreen(pageNumber, position) {
|
235
|
+
var that = this;
|
236
|
+
var pageStyleNumber = position ? parseInt(pageNumber + 1) : parseInt(pageNumber - 1);
|
237
|
+
var pageStyleBaseDom = that.$placeholder.find('[data-page="' + pageStyleNumber + '"]');
|
238
|
+
var pageStyle = pageStyleBaseDom.attr("style");
|
239
|
+
var contentStyle = pageStyleBaseDom.find("sheet").attr("style");
|
240
|
+
var skeletonEl = utils.stringFormat(that.skeletonTemplate, [pageNumber, pageStyle, contentStyle]);
|
241
|
+
if (position) {
|
242
|
+
that.$pageWrapper.prepend(skeletonEl);
|
243
|
+
} else {
|
244
|
+
that.$pageWrapper.append(skeletonEl);
|
245
|
+
}
|
246
|
+
},
|
247
|
+
_generateSkeletonScreens: function _generateSkeletonScreens(upToPageNumber) {
|
248
|
+
var that = this;
|
249
|
+
var skeletonEl = "";
|
250
|
+
var pageStyleBaseDom = this.$placeholder.find('[data-page="1"]');
|
251
|
+
var pageStyle = pageStyleBaseDom.attr("style");
|
252
|
+
var contentStyle = pageStyleBaseDom.find("sheet").attr("style");
|
253
|
+
var lastPage = that.$placeholder.find(".trv-report-page").last().attr("data-page");
|
254
|
+
var index = lastPage ? parseInt(lastPage) + 1 : 1;
|
255
|
+
for (index; index < upToPageNumber; index++) {
|
256
|
+
skeletonEl = skeletonEl + utils.stringFormat(that.skeletonTemplate, [index, pageStyle, contentStyle]);
|
257
|
+
}
|
258
|
+
that.$pageWrapper.append($(skeletonEl));
|
259
|
+
},
|
260
|
+
_loadMorePages: function _loadMorePages() {
|
261
|
+
var that = this;
|
262
|
+
var pageCount = that.controller.getPageCount();
|
263
|
+
var isViewPortBiggerThanPageHeight = that.$pageContainer.innerHeight() > that.$pageWrapper.innerHeight();
|
264
|
+
if (pageCount > 1) {
|
265
|
+
if (isViewPortBiggerThanPageHeight) {
|
266
|
+
that.scrollInProgress = true;
|
267
|
+
var lastPage = parseInt(that.$placeholder.find(".trv-report-page").last().attr("data-page"));
|
268
|
+
var nextPage = lastPage + 1;
|
269
|
+
if (nextPage <= pageCount) {
|
270
|
+
that.controller.getPageData(nextPage).then(function(newPage) {
|
271
|
+
that._render(newPage, false);
|
272
|
+
that._loadMorePages();
|
273
|
+
that.scrollInProgress = false;
|
274
|
+
});
|
275
|
+
}
|
276
|
+
} else {
|
277
|
+
that._loadVisiblePages();
|
278
|
+
that.scrollInProgress = false;
|
279
|
+
}
|
280
|
+
}
|
281
|
+
},
|
282
|
+
_loadVisiblePages: function _loadVisiblePages() {
|
283
|
+
var that = this;
|
284
|
+
var pages = that.$placeholder.find(".trv-report-page");
|
285
|
+
$.each(pages, function(index, value) {
|
286
|
+
var pageItem = $(value);
|
287
|
+
var pageNumber = parseInt(pageItem.attr("data-page"));
|
288
|
+
if (that._scrolledInToView(pageItem) && that._isSkeletonScreen(pageItem, pageNumber)) {
|
289
|
+
that.controller.getPageData(pageNumber).then(function(newPage) {
|
290
|
+
that._render(newPage, false);
|
291
|
+
});
|
292
|
+
}
|
293
|
+
});
|
294
|
+
},
|
295
|
+
_scrolledInToView: function _scrolledInToView(elem) {
|
296
|
+
var pageCoords = elem[0].getBoundingClientRect();
|
297
|
+
var parentCoords = elem.closest(".trv-pages-area")[0].getBoundingClientRect();
|
298
|
+
var parentTop = parentCoords.top;
|
299
|
+
var parentBottom = parentCoords.top + parentCoords.height;
|
300
|
+
var pageTop = pageCoords.top;
|
301
|
+
var pageBottom = pageTop + elem.outerHeight(true);
|
302
|
+
var additionalTopOffset = this.additionalTopOffset + parentTop;
|
303
|
+
var topVisible = pageTop > 0 && pageTop < parentBottom;
|
304
|
+
var bottomVisible = pageBottom < parentBottom && pageBottom > additionalTopOffset;
|
305
|
+
return topVisible || bottomVisible;
|
306
|
+
},
|
307
|
+
_render: function _render(page, empty) {
|
308
|
+
var that = this;
|
309
|
+
var pageNumber = page.pageNumber;
|
310
|
+
var pageItem = that.$placeholder.find('[data-page="' + pageNumber + '"]');
|
311
|
+
if (!empty && pageItem && pageItem.length && !that._isSkeletonScreen(pageItem, pageNumber)) {
|
312
|
+
return;
|
313
|
+
}
|
314
|
+
that.loadedPage[pageNumber] = page;
|
315
|
+
that._updatePageStyle(page);
|
316
|
+
var wrapper = $($.parseHTML(page.pageContent));
|
317
|
+
var $pageContent = wrapper.find("div.sheet");
|
318
|
+
var $page = $('<div class="trv-report-page" data-page="' + pageNumber + '"></div>');
|
319
|
+
$pageContent.css("margin", 0);
|
320
|
+
$page.append($pageContent).append($('<div class="trv-page-overlay"></div>'));
|
321
|
+
if (empty) {
|
322
|
+
that.$pageWrapper.empty();
|
323
|
+
}
|
324
|
+
that.$pageWrapper.removeData().data("pageNumber", pageNumber);
|
325
|
+
var $skeletonPage = that.$placeholder.find(".trv-skeleton-" + pageNumber);
|
326
|
+
if ($skeletonPage.length) {
|
327
|
+
$skeletonPage.replaceWith($page);
|
328
|
+
} else {
|
329
|
+
that.$pageWrapper.append($page);
|
330
|
+
}
|
331
|
+
that.controller.scrollPageReady({ page, target: $page });
|
332
|
+
},
|
333
|
+
_updatePageStyle: function _updatePageStyle(page) {
|
334
|
+
var that = this;
|
335
|
+
var lastLoadedPage = that.loadedPage[that._lastLoadedPage()] || page;
|
336
|
+
var styleId = "trv-" + that.controller.clientId() + "-styles";
|
337
|
+
var pageStyles;
|
338
|
+
$("#" + styleId).remove();
|
339
|
+
pageStyles = $("<style id=" + styleId + "></style>");
|
340
|
+
pageStyles.append(lastLoadedPage.pageStyles);
|
341
|
+
pageStyles.appendTo("head");
|
342
|
+
},
|
343
|
+
_lastLoadedPage: function _lastLoadedPage() {
|
344
|
+
var that = this;
|
345
|
+
var lastKey;
|
346
|
+
for (var key in that.loadedPage) {
|
347
|
+
if (that.loadedPage.hasOwnProperty(key)) {
|
348
|
+
lastKey = key;
|
349
|
+
}
|
350
|
+
}
|
351
|
+
return lastKey;
|
352
|
+
},
|
353
|
+
_loadNextPreviousPage: function _loadNextPreviousPage(pageNumber) {
|
354
|
+
var that = this;
|
355
|
+
var nextPage;
|
356
|
+
var previousPage;
|
357
|
+
var nextItem;
|
358
|
+
var previousItem;
|
359
|
+
if (pageNumber < that.controller.getPageCount()) {
|
360
|
+
nextPage = pageNumber + 1;
|
361
|
+
nextItem = that.$placeholder.find('[data-page="' + nextPage + '"]');
|
362
|
+
}
|
363
|
+
if (pageNumber > 1) {
|
364
|
+
previousPage = pageNumber - 1;
|
365
|
+
previousItem = that.$placeholder.find('[data-page="' + previousPage + '"]');
|
366
|
+
}
|
367
|
+
if (previousItem && previousItem.length && that._isSkeletonScreen(previousItem, previousPage)) {
|
368
|
+
that.controller.getPageData(previousPage).then(function(newPage) {
|
369
|
+
that._render(newPage, false);
|
370
|
+
});
|
371
|
+
}
|
372
|
+
if (nextItem && nextItem.length && that._isSkeletonScreen(nextItem, nextPage)) {
|
373
|
+
that.controller.getPageData(nextPage).then(function(newPage) {
|
374
|
+
that._render(newPage, false);
|
375
|
+
});
|
376
|
+
}
|
377
|
+
},
|
378
|
+
_clickPage: function _clickPage(pageDom) {
|
379
|
+
var that = this;
|
380
|
+
var currentPage = that._currentPageNumber();
|
381
|
+
var pageNumber = parseInt(pageDom.attr("data-page"));
|
382
|
+
if (currentPage !== pageNumber) {
|
383
|
+
if (that._isSkeletonScreen(pageDom, pageNumber)) {
|
384
|
+
that.controller.getPageData(pageNumber).then(function(newPage) {
|
385
|
+
that._render(newPage, false, true);
|
386
|
+
that._setCurrentPage(newPage.pageNumber);
|
387
|
+
});
|
388
|
+
} else {
|
389
|
+
that._setCurrentPage(pageNumber);
|
390
|
+
}
|
391
|
+
}
|
392
|
+
},
|
393
|
+
_initEvents: function _initEvents() {
|
394
|
+
var that = this;
|
395
|
+
that.$pageContainer.off("click", ".trv-report-page").on("click", ".trv-report-page", function(e) {
|
396
|
+
that._clickPage($(e.currentTarget));
|
397
|
+
});
|
398
|
+
that.$pageContainer.scroll(function() {
|
399
|
+
var pages = that.$placeholder.find(".trv-report-page");
|
400
|
+
var scrollPosition = parseInt((that.$pageContainer.scrollTop() + that.$pageContainer.innerHeight()).toFixed(0));
|
401
|
+
if (!that.scrollInProgress && that.oldScrollTopPosition !== scrollPosition) {
|
402
|
+
if (that.oldScrollTopPosition > scrollPosition) {
|
403
|
+
that._scrollUp(pages);
|
404
|
+
} else {
|
405
|
+
that._scrollDown(pages, scrollPosition);
|
406
|
+
}
|
407
|
+
}
|
408
|
+
that.oldScrollTopPosition = scrollPosition;
|
409
|
+
});
|
410
|
+
that.$pageContainer.scroll(function() {
|
411
|
+
var pages = that.$placeholder.find(".trv-report-page");
|
412
|
+
var scrollPosition = parseInt((that.$pageContainer.scrollTop() + that.$pageContainer.innerHeight()).toFixed(0));
|
413
|
+
if (!that.scrollInProgress && pages.length && that.oldScrollTopPosition !== scrollPosition) {
|
414
|
+
that._advanceCurrentPage(pages);
|
415
|
+
}
|
416
|
+
});
|
417
|
+
},
|
418
|
+
_unbind: function() {
|
419
|
+
var that = this;
|
420
|
+
that.$pageContainer.off("click", ".trv-report-page");
|
421
|
+
that.$pageContainer.off("scroll");
|
422
|
+
},
|
423
|
+
_advanceCurrentPage: function _advanceCurrentPage(pages) {
|
424
|
+
var that = this;
|
425
|
+
var newCurrentPage = that._findNewCurrentPage(pages);
|
426
|
+
var pageNumber;
|
427
|
+
var currentPageNumber = that._currentPageNumber();
|
428
|
+
var currentPageIsInToView = that._scrolledInToView(that.$placeholder.find('[data-page="' + currentPageNumber + '"]'));
|
429
|
+
if (newCurrentPage !== -1) {
|
430
|
+
newCurrentPage = $(newCurrentPage);
|
431
|
+
pageNumber = parseInt(newCurrentPage.attr("data-page"));
|
432
|
+
if (currentPageNumber !== pageNumber && !currentPageIsInToView) {
|
433
|
+
if (that._isSkeletonScreen(newCurrentPage, pageNumber)) {
|
434
|
+
that.controller.getPageData(pageNumber).then(function(newPage) {
|
435
|
+
that._render(newPage, false, true);
|
436
|
+
that._setCurrentPage(newPage.pageNumber);
|
437
|
+
});
|
438
|
+
} else {
|
439
|
+
that._setCurrentPage(pageNumber);
|
440
|
+
}
|
441
|
+
}
|
442
|
+
} else {
|
443
|
+
console.log("Page not found - ", newCurrentPage);
|
444
|
+
}
|
445
|
+
},
|
446
|
+
// Binary search
|
447
|
+
_findNewCurrentPage: function _findNewCurrentPage(pages) {
|
448
|
+
var that = this;
|
449
|
+
var middleIndex = Math.floor(pages.length / 2);
|
450
|
+
var result = that._findPageInViewPort(middleIndex, pages);
|
451
|
+
if (pages.length === 1) {
|
452
|
+
return pages[0];
|
453
|
+
}
|
454
|
+
if (result === 0) {
|
455
|
+
return pages[middleIndex];
|
456
|
+
} else if (result < 0 && pages.length > 1) {
|
457
|
+
return that._findNewCurrentPage(pages.splice(middleIndex, Number.MAX_VALUE));
|
458
|
+
} else if (result > 0 && pages.length > 1) {
|
459
|
+
return that._findNewCurrentPage(pages.splice(0, middleIndex));
|
460
|
+
} else {
|
461
|
+
return -1;
|
462
|
+
}
|
463
|
+
},
|
464
|
+
_findPageInViewPort: function _findPageInViewPort(index, pages) {
|
465
|
+
var pageItem = this.$placeholder.find(pages[index]);
|
466
|
+
var pageCoords = pageItem[0].getBoundingClientRect();
|
467
|
+
var parentCoords = pageItem.closest(".trv-pages-area")[0].getBoundingClientRect();
|
468
|
+
var parentTop = parentCoords.top;
|
469
|
+
parentCoords.top + parentCoords.height;
|
470
|
+
var pageTop = pageCoords.top;
|
471
|
+
var pageBottom = pageTop + pageItem.outerHeight(true);
|
472
|
+
var additionalTopOffset = this.additionalTopOffset + parentTop;
|
473
|
+
var isCurentPage = pageTop <= additionalTopOffset && additionalTopOffset < pageBottom;
|
474
|
+
if (isCurentPage) {
|
475
|
+
return 0;
|
476
|
+
}
|
477
|
+
if (pageBottom < additionalTopOffset) {
|
478
|
+
return -1;
|
479
|
+
} else {
|
480
|
+
return 1;
|
481
|
+
}
|
482
|
+
},
|
483
|
+
_scrollDown: function _scrollDown(pages, scrollPosition) {
|
484
|
+
var that = this;
|
485
|
+
if (scrollPosition >= that.pageContainer.scrollHeight - 5) {
|
486
|
+
var lastPage = parseInt($(pages[pages.length - 1]).attr("data-page"));
|
487
|
+
var nextPage = lastPage + 1;
|
488
|
+
if (that._currentPageNumber() < nextPage && nextPage <= that.controller.getPageCount()) {
|
489
|
+
that._addSkeletonScreen(nextPage, false);
|
490
|
+
that.controller.getPageData(nextPage).then(function(newPage) {
|
491
|
+
that._render(newPage, false);
|
492
|
+
});
|
493
|
+
}
|
494
|
+
} else {
|
495
|
+
that._advanceCurrentPage(pages);
|
496
|
+
that._loadVisiblePages();
|
497
|
+
}
|
498
|
+
},
|
499
|
+
_scrollUp: function _scrollUp(pages) {
|
500
|
+
var that = this;
|
501
|
+
if (that.$pageContainer.scrollTop() === 0) {
|
502
|
+
var firstPage = $(pages[0]);
|
503
|
+
var pageNumber = parseInt(firstPage.attr("data-page"));
|
504
|
+
var previousPage = pageNumber - 1;
|
505
|
+
if (that._currentPageNumber() > previousPage && previousPage >= 1) {
|
506
|
+
that._addSkeletonScreen(previousPage, true);
|
507
|
+
that.controller.getPageData(previousPage).then(function(newPage) {
|
508
|
+
that._render(newPage, false);
|
509
|
+
that.$pageContainer.scrollTop(3);
|
510
|
+
});
|
511
|
+
}
|
512
|
+
} else {
|
513
|
+
that._advanceCurrentPage(pages);
|
514
|
+
that._loadVisiblePages();
|
515
|
+
}
|
516
|
+
},
|
517
|
+
_keepCurrentPageInToView: function _keepCurrentPageInToView() {
|
518
|
+
var that = this;
|
519
|
+
var currentPage = that.$placeholder.find('[data-page="' + that._currentPageNumber() + '"]');
|
520
|
+
var currentPagePosition = currentPage.position().top;
|
521
|
+
var currentPageHeight = currentPage.innerHeight();
|
522
|
+
var pageContainerHeight = that.$pageContainer.innerHeight();
|
523
|
+
var emptyView;
|
524
|
+
that.scrollInProgress = true;
|
525
|
+
if (currentPageHeight < pageContainerHeight) {
|
526
|
+
emptyView = (pageContainerHeight - currentPageHeight) / 2;
|
527
|
+
currentPagePosition = parseInt(currentPagePosition - emptyView);
|
528
|
+
}
|
529
|
+
that.$pageContainer.animate({ scrollTop: currentPagePosition }, 0, function() {
|
530
|
+
setTimeout(function() {
|
531
|
+
that.scrollInProgress = false;
|
532
|
+
}, 100);
|
533
|
+
});
|
534
|
+
}
|
535
|
+
};
|
536
|
+
|
537
|
+
exports.Scroll = Scroll;
|