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