<commit_before>/**
 * Created by azu on 2014/09/24.
 * LICENSE : MIT
 */
"use strict";
var pdfURL = './test/fixtures/sourcemap.pdf';
var throttle = require("lodash.throttle");
// define lang
PDFJS.cMapUrl = "../cmaps/";
PDFJS.cMapPacked = true;
var PDFController = require("./lib/pdf-controller");
var container = document.getElementById("pdf-container");
var controller = new PDFController(container);

function getCornerColor(context) {
    var canvasColor = context.getImageData(0, 0, 1, 1);
    var pixels = canvasColor.data;
    var r = pixels[0];
    var g = pixels[1];
    var b = pixels[2];
    return "rgb(" + r + ',' + g + ',' + b + ")";
}
controller.loadDocument(pdfURL).then(function () {
    document.getElementById('js-prev').addEventListener('click', controller.prevPage.bind(controller));
    document.getElementById('js-next').addEventListener('click', controller.nextPage.bind(controller));
}).catch(function (error) {
    console.error(error);
});
container.addEventListener(controller.events.before_pdf_rendering, function (event) {
    var context = controller.canvasContext;
    var cornerColor = getCornerColor(context);
    container.style.backgroundColor = cornerColor;
    document.body.style.backgroundColor = cornerColor;
    controller.domMapObject.canvas.style.visibility = "hidden";
});
container.addEventListener(controller.events.after_pdf_rendering, function (event) {
    var context = controller.canvasContext;
    var cornerColor = getCornerColor(context);
    container.style.backgroundColor = cornerColor;
    document.body.style.backgroundColor = cornerColor;
    controller.domMapObject.canvas.style.visibility = "visible";
});

document.onkeydown = function (event) {
    var kc = event.keyCode;
    if (event.shiftKey || event.ctrlKey || event.metaKey) {
        return;
    }
    if (kc === 37 || kc === 40 || kc === 8 || kc === 72) {
        // left, down, H, J, backspace, PgUp - BACK
        event.preventDefault();
        controller.prevPage();
    } else if (kc === 38 || kc === 39 || kc === 32 || kc === 75 || kc === 76 || kc === 34) {
        // up, right, K, L, space, PgDn - FORWARD
        event.preventDefault();
        controller.nextPage();
    }
};

window.addEventListener("resize", throttle(function (event) {
    controller.fitItSize();
}, 100));

// swipe
var hammertime = new Hammer(document.body);
hammertime.on('swipeleft', function(event) {
    controller.nextPage();
});

hammertime.on('swiperight', function(event) {
    controller.prevPage();

});<commit_msg>fix(slide): fix event listener<commit_after>/**
 * Created by azu on 2014/09/24.
 * LICENSE : MIT
 */
"use strict";
var pdfURL = './test/fixtures/sourcemap.pdf';
var throttle = require("lodash.throttle");
// define lang
PDFJS.cMapUrl = "../cmaps/";
PDFJS.cMapPacked = true;
var PDFController = require("./lib/pdf-controller");
var container = document.getElementById("pdf-container");
var controller = new PDFController(container);

function getCornerColor(context) {
    var canvasColor = context.getImageData(0, 0, 1, 1);
    var pixels = canvasColor.data;
    var r = pixels[0];
    var g = pixels[1];
    var b = pixels[2];
    return "rgb(" + r + ',' + g + ',' + b + ")";
}
controller.loadDocument(pdfURL).then(initializedEvent).catch(function (error) {
    console.error(error);
});
container.addEventListener(controller.events.before_pdf_rendering, function (event) {
    var context = controller.canvasContext;
    var cornerColor = getCornerColor(context);
    container.style.backgroundColor = cornerColor;
    document.body.style.backgroundColor = cornerColor;
    controller.domMapObject.canvas.style.visibility = "hidden";
});
container.addEventListener(controller.events.after_pdf_rendering, function (event) {
    var context = controller.canvasContext;
    var cornerColor = getCornerColor(context);
    container.style.backgroundColor = cornerColor;
    document.body.style.backgroundColor = cornerColor;
    controller.domMapObject.canvas.style.visibility = "visible";
});

function initializedEvent() {
    document.getElementById('js-prev').addEventListener('click', controller.prevPage.bind(controller));
    document.getElementById('js-next').addEventListener('click', controller.nextPage.bind(controller));

    window.addEventListener("resize", throttle(function (event) {
        controller.fitItSize();
    }, 100));
    document.onkeydown = function (event) {
        var kc = event.keyCode;
        console.log(event.keyCode);
        if (event.shiftKey || event.ctrlKey || event.metaKey) {
            return;
        }
        if (kc === 37 || kc === 40 || kc === 75 || kc === 65) {
            // left, down, K, A
            event.preventDefault();
            controller.prevPage();
        } else if (kc === 38 || kc === 39 || kc === 74 || kc === 83) {
            // up, right, J, S
            event.preventDefault();
            controller.nextPage();
        }

    };
    // swipe
    var hammertime = new Hammer(document.body);
    hammertime.on('swipeleft', function (event) {
        controller.nextPage();
    });

    hammertime.on('swiperight', function (event) {
        controller.prevPage();

    });
}
{'fraction_non_alphanumeric': 0.15444015444015444, 'fraction_numerical': 0.013706563706563707, 'mean_word_length': 3.544736842105263, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5403901', 'n_tokens_mistral': 1584, 'n_tokens_neox': 1517, 'n_words': 323}