Code coverage report for taxi/lib/scripts/devicePixelRatio.js

Statements: 3.85% (1 / 26)      Branches: 0% (0 / 2)      Functions: 0% (0 / 2)      Lines: 3.85% (1 / 26)      Ignored: none     

All files » taxi/lib/scripts/ » devicePixelRatio.js
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 741                                                                                                                                                  
module.exports = {
 
    // This is done to fix some issues with Chrome:
    // http://www.quirksmode.org/blog/archives/2012/06/devicepixelrati.html
    // The property window.devicePixelRatio cannot be trusted in most browsers (if even available).
 
    /**
     * Initialize the device-pixel-ratio determination,
     * collecting information that need to be reverted later on and
     * modifying the document for device-pixel-ratio data.
     *
     * @method init
	 * @param {int} horizontalPadding
     */
    init: function (horizontalPadding) {
        var de = document.documentElement,
            body = document.body,
            el, initData;
 
        // Create a div to figure out the size of the view-port across browsers
        el = document.createElement('div');
        el.style.position = "fixed";
        el.style.top = 0;
        el.style.left = 0;
        el.style.bottom = 0;
        el.style.right = 0;
        de.insertBefore(el, de.firstChild);
 
        initData = {
            bodyOverflow: body.style.overflow,
            bodyWidth: body.style.width,
            bodyHeight: body.style.height,
            documentWidth: Math.max(body.scrollWidth, body.offsetWidth, de.clientWidth, de.scrollWidth, de.offsetWidth),
            devicePixelRatio: window.devicePixelRatio || 1,
            padding: body.style.padding,
            viewPortWidth: el.offsetWidth,
			horizontalPadding: horizontalPadding
        };
 
        de.removeChild(el);
 
        // Remove scrollbars
        body.style.overflow = 'hidden';
 
        // Make document only one pixel height and as wide as the view-port
        body.style.width = (initData.viewPortWidth - horizontalPadding) + 'px';
        body.style.height = '1px';
        body.style.minHeight = '0';
        body.style.minWidth = '0';
 
        de.style.width = (initData.viewPortWidth - horizontalPadding) + 'px';
        de.style.height = '1px';
        de.style.minHeight = '0';
        de.style.minWidth = '0';
        de.style.overflow = 'hidden';
 
        return JSON.stringify(initData);
    },
 
    /**
     * Reverts all changes done to the document in the init
     *
     * @method revert
     * @param {object} initData Data gathered during init-phase
     */
    revert: function (initData) {
        var body = document.body;
 
        body.style.overflow = initData.bodyOverflow;
        body.style.width = initData.bodyWidth;
        body.style.height = initData.bodyHeight;
    }
};