コード例 #1
0
ファイル: main.js プロジェクト: easyrider/frontend
const setAdTestCookie = (): void => {
    const queryParams = getUrlVars();

    if (queryParams.adtest === 'clear') {
        removeCookie('adtest');
    } else if (queryParams.adtest) {
        addCookie('adtest', encodeURIComponent(queryParams.adtest), 10);
    }
};
コード例 #2
0
ファイル: main.js プロジェクト: easyrider/frontend
const bootStandard = (): void => {
    markTime('standard start');

    catchErrorsWithContext([
        [
            'ga-user-timing-standard-start',
            () => {
                trackPerformance(
                    'Javascript Load',
                    'standardStart',
                    'Standard start parse time'
                );
            },
        ],
    ]);

    /*
        Add global pooled event listeners
        CAUTION: those are *passive*, which means calls to event.preventDefault
        will be ignored

        Adds a global window:throttledScroll event to mediator, which throttles
        scroll events until there's a spare animationFrame.
        Callbacks of all listeners to window:throttledScroll are run in a
        fastdom.read, meaning they can all perform DOM reads for free
        (after the first one that needs layout triggers it).
        However, this means it's VITAL that all writes in callbacks are
        delegated to fastdom.
    */
    addErrorHandler();
    addScrollHandler();
    addResizeHandler();

    // Set adtest query if url param declares it
    setAdTestCookie();

    // If we turn off the ad-free trial, immediately remove the cookie
    if (!config.get('switches.adFreeSubscriptionTrial')) {
        removeCookie('GU_AF1');
    }

    // set a short-lived cookie to trigger server-side ad-freeness
    // if the user is genuinely ad-free, this one will be overwritten
    // in user-features
    if (window.location.hash.match(/[#&]noadsaf(&.*)?$/)) {
        const daysToLive = 1;
        const isCrossSubDomain = true;
        const forcedAdFreeValidSeconds = 30;
        const forcedAdFreeExpiryTime = new Date();
        forcedAdFreeExpiryTime.setTime(
            forcedAdFreeExpiryTime.getTime() + forcedAdFreeValidSeconds * 1000
        );
        addCookie(
            'GU_AF1',
            forcedAdFreeExpiryTime.getTime().toString(),
            daysToLive,
            isCrossSubDomain
        );
    }

    // set local storage: gu.alreadyVisited
    if (window.guardian.isEnhanced) {
        const key = 'gu.alreadyVisited';
        const alreadyVisited = storage.get(key) || 0;
        storage.set(key, alreadyVisited + 1);
    }

    if (config.get('switches.blockIas') && navigator.serviceWorker) {
        navigator.serviceWorker.ready.then(swreg => {
            const sw = swreg.active;
            const ias = window.location.hash.includes('noias');
            sw.postMessage({ ias });
        });
    }

    // initilaise the email/outbrain check mediator
    initCheckMediator();

    ophan.setEventEmitter(mediator);

    /*  Membership access
        Items with either of the following fields require Membership access
        - membershipAccess=members-only
        - membershipAccess=paid-members-only
        Authenticating requires CORS and withCredentials. If we don't cut the
        mustard then pass through.
    */
    if (config.get('page.requiresMembershipAccess')) {
        handleMembershipAccess();
    }

    identityInit();

    newHeaderInit();

    initAtoms();

    showHiringMessage();

    markTime('standard end');

    catchErrorsWithContext([
        [
            'ga-user-timing-standard-end',
            () => {
                trackPerformance(
                    'Javascript Load',
                    'standardEnd',
                    'Standard end parse time'
                );
            },
        ],
    ]);
};
コード例 #3
0
ファイル: cookies.spec.js プロジェクト: easyrider/frontend
 it('should be able remove cookies', () => {
     removeCookie('cookie-1-name');
     expect(document.cookie).toEqual(
         'cookie-1-name=;path=/;expires=Thu, 01 Jan 1970 00:00:01 GMT; domain=.theguardian.com'
     );
 });