Files
edx-platform/lms/static/js/pdf-analytics.js
Syed Ali Abbas Zaidi 8480dbc228 chore: apply amnesty on existing not fixable issues (#32215)
* fix: eslint operator-linebreak issue

* fix: eslint quotes issue

* fix: react jsx indent and props issues

* fix: eslint trailing spaces issues

* fix: eslint line around directives issue

* fix: eslint semi rule

* fix: eslint newline per chain rule

* fix: eslint space infix ops rule

* fix: eslint space-in-parens issue

* fix: eslint space before function paren issue

* fix: eslint space before blocks issue

* fix: eslint arrow body style issue

* fix: eslint dot-location issue

* fix: eslint quotes issue

* fix: eslint quote props issue

* fix: eslint operator assignment issue

* fix: eslint new line after import issue

* fix: indent issues

* fix: operator assignment issue

* fix: all autofixable eslint issues

* fix: all react related fixable issues

* fix: autofixable eslint issues

* chore: remove all template literals

* fix: remaining autofixable issues

* chore: apply amnesty on all existing issues

* fix: failing xss-lint issues

* refactor: apply amnesty on remaining issues

* refactor: apply amnesty on new issues

* fix: remove file level suppressions

* refactor: apply amnesty on new issues
2023-08-07 19:13:19 +05:00

104 lines
3.6 KiB
JavaScript

function sendLog(name, data, event_type) {
var message = data || {};
message.chapter = PDF_URL || '';
message.name = 'textbook.pdf.' + name;
Logger.log(event_type || message.name, message);
}
// this event is loaded after the others to accurately represent the order of events:
// click next -> pagechange
$(function() {
var first_page = true;
var scroll = {timeStamp: 0, direction: null};
$(window).bind('pagechange', function(event) {
// log every page render
var page = PDFViewerApplication.page;
var old_page = event.originalEvent.previousPageNumber;
// pagechange is called many times per viewing.
if (old_page !== page || first_page) {
first_page = false;
if ((event.timeStamp - scroll.timeStamp) < 50) {
sendLog('page.scrolled', {page: page, direction: scroll.direction});
}
sendLog('page.loaded', {type: 'gotopage', old: old_page, new: page}, 'book');
scroll.timeStamp = 0;
}
});
$('#viewerContainer').bind('DOMMouseScroll mousewheel', function(event) {
scroll.timeStamp = event.timeStamp;
scroll.direction = PDFViewerApplication.pdfViewer.scroll.down ? 'down' : 'up';
});
});
$('#viewThumbnail,#sidebarToggle').on('click', function() {
sendLog('thumbnails.toggled', {page: PDFViewerApplication.page});
});
$('#thumbnailView a').live('click', function() {
sendLog('thumbnail.navigated', {page: $('#thumbnailView a').index(this) + 1, thumbnail_title: $(this).attr('title')});
});
$('#viewOutline').on('click', function() {
sendLog('outline.toggled', {page: PDFViewerApplication.page});
});
$('#previous').on('click', function() {
sendLog('page.navigatednext', {type: 'prevpage', new: PDFViewerApplication.page - 1}, 'book');
});
$('#next').on('click', function() {
sendLog('page.navigatednext', {type: 'nextpage', new: PDFViewerApplication.page + 1}, 'book');
});
$('#zoomIn,#zoomOut').on('click', function() {
sendLog('zoom.buttons.changed', {direction: $(this).attr('id') == 'zoomIn' ? 'in' : 'out', page: PDFViewerApplication.page});
});
$('#pageNumber').on('change', function() {
sendLog('page.navigated', {page: $(this).val()});
});
var old_amount = 1;
$(window).bind('scalechange', function(event) {
var amount = event.originalEvent.scale;
if (amount !== old_amount) {
sendLog('display.scaled', {amount: amount, page: PDFViewerApplication.page});
old_amount = amount;
}
});
$('#scaleSelect').on('change', function() {
sendLog('zoom.menu.changed', {amount: $('#scaleSelect').val(), page: PDFViewerApplication.page});
});
var search_event = null;
$(window).bind('find findhighlightallchange findagain findcasesensitivitychange', function(event) {
if (search_event && event.type == 'find') {
clearTimeout(search_event);
}
search_event = setTimeout(function() {
var message = event.originalEvent.detail;
message.status = $('#findMsg').text();
message.page = PDFViewerApplication.page;
var event_name = 'search';
// eslint-disable-next-line default-case
switch (event.type) {
case 'find':
event_name += '.executed';
break;
case 'findhighlightallchange':
event_name += '.highlight.toggled';
break;
case 'findagain':
event_name += '.navigatednext';
break;
case 'findcasesensitivitychange':
event_name += 'casesensitivity.toggled';
break;
}
sendLog(event_name, message);
}, 500);
});