Re: page.js

From disqus.com, 2 Months ago, written in JavaScript, viewed 3 times. This paste is a reply to Re:TimelineFiltersCollection.js from disqus.com - view diff
URL https://pastebin.freepbx.org/view/8c2a17ac Embed
Download Paste or View Raw
  1. define('core/engagement/page',[
  2.     'jquery',
  3.     'underscore',
  4.     'backbone',
  5.     'core/bus',
  6.     'core/utils',
  7.     'core/engagement/vendor/visibly',
  8. ], function (
  9.     $,
  10.     _,
  11.     Backbone,
  12.     bus,
  13.     utils,
  14.     visibly
  15. ) {
  16.     'use strict';
  17.  
  18.     /**
  19.      * This module reports if the user is engaged on the current
  20.      * page through an amalgamation of various HTML standards and
  21.      * best guesses.
  22.      *
  23.      * Do not use this module for UX methods. We are intentionally
  24.      * conservative when marking a user as engaged for reporting reasons.
  25.      *
  26.      * Inspiration from:
  27.      * - https://chartbeat.com/public-release-methodology/
  28.      * - http://upworthy.github.io/2014/06/implementing-attention-minutes-part-1/
  29.      * - http://jsfiddle.net/zanes/mbGBr/
  30.      * - http://static.chartbeat.com/js/chartbeat.js
  31.      * - https://github.com/serkanyersen/ifvisible.js
  32.      */
  33.  
  34.     // Exported Event object w/ initial defaults
  35.     var exports = _.extend(Backbone.Events, {
  36.         _initialized: false,
  37.         isEngaged: false,
  38.         resetTimeout: null,
  39.         ACTIVE_TIMEOUT: 60 * 1000,
  40.     });
  41.  
  42.     exports._markNotEngaged = function () {
  43.         if (!exports.isEngaged)
  44.             return;
  45.  
  46.         exports.isEngaged = false;
  47.         exports.trigger('change:isEngaged', exports.isEngaged, exports);
  48.     };
  49.  
  50.     exports._markIsEngaged = function () {
  51.         // Restart the interaction timeout clock.
  52.         if (exports.resetTimeout)
  53.             exports.resetTimeout();
  54.  
  55.         if (exports.isEngaged)
  56.             return;
  57.  
  58.         exports.isEngaged = true;
  59.         exports.trigger('change:isEngaged', exports.isEngaged, exports);
  60.     };
  61.  
  62.     exports.start = function () {
  63.         if (exports._initialized)
  64.             return;
  65.         exports._initialized = true;
  66.  
  67.         // Page Visibility API
  68.  
  69.         // If the window is currently visible, mark the user as
  70.         // engaged, just to start things off. If it's not, we'll
  71.         // wait for an interaction event to fire first.
  72.         if (!visibly.hidden())
  73.             exports._markIsEngaged();
  74.  
  75.         // On mobile-like user agents all we need is the Page Visibility API.
  76.         visibly.onVisible(exports._markIsEngaged);
  77.         visibly.onHidden(exports._markNotEngaged);
  78.  
  79.         if (utils.isMobileUserAgent())
  80.             return;
  81.  
  82.         // On desktop-like user agents, we'll additionally use interaction events
  83.         // and a timeout clock to more closely track if a user is still
  84.         // engaged on the page. Each time we record an interaction on the page
  85.         // we reset the clock. If the clock reaches it's`ACTIVE_TIMEOUT` time, we
  86.         // mark the user as no longer engaged with the page (see `_markIsEngaged` method).
  87.         exports.resetTimeout = _.debounce(exports._markNotEngaged, exports.ACTIVE_TIMEOUT);
  88.         exports.resetTimeout();
  89.  
  90.         // Bind into interaction events on the current page.
  91.         $(window.document).on('mousemove keyup', exports._markIsEngaged);
  92.         $(window).on('scroll', exports._markIsEngaged);
  93.  
  94.         // Then bind into interaction events from the parent page.
  95.         exports.listenTo(bus.frame, 'window.mousemove window.scroll window.click', exports._markIsEngaged);
  96.     };
  97.  
  98.     exports.stop = function () {
  99.         if (!exports._initialized)
  100.             return;
  101.         exports._initialized = false;
  102.  
  103.         // Clean up the resetTimeout method.
  104.         exports.resetTimeout = null;
  105.  
  106.         // Turn off listeners before changing
  107.         // the state to off.
  108.         exports.stopListening();
  109.         exports.off();
  110.  
  111.         visibly.visibleCallbacks = [];
  112.         visibly.hiddenCallbacks = [];
  113.  
  114.         $(window.document).off('mousemove keyup', exports._markIsEngaged);
  115.         $(window).off('scroll', exports._markIsEngaged);
  116.  
  117.         exports._markNotEngaged();
  118.     };
  119.  
  120.     return exports;
  121. });
  122.  
  123. // https://c.disquscdn.com/next/next-core/core/engagement/page.js

Replies to Re: page.js rss

Title Name Language When
Re: Re: visibly.js disqus.com javascript 2 Months ago.

Reply to "Re: page.js"

Here you can reply to the paste above