Re:utils.js

From disqus.com, 2 Months ago, written in JavaScript, viewed 3 times. This paste is a reply to Re: Re: Iframe.js from disqus.com - view diff
URL https://pastebin.freepbx.org/view/00344c50 Embed
Download Paste or View Raw
  1. define('core/common/kernel/utils',['require'],function (require) {
  2.     'use strict';
  3.  
  4.     var document = window.document;
  5.     var anchor = document.createElement('a');
  6.  
  7.     function getContainer(container) {
  8.         // This function assumes that document.body is defined. So if this
  9.         // function is called in the <head> section and before <body> gets
  10.         // defined, it will return documentElement which is weird but okay.
  11.         return document.getElementById(container) ||
  12.                document.body || document.documentElement;
  13.     }
  14.  
  15.     function getHost(url) {
  16.         anchor.href = url;
  17.  
  18.         return anchor.hostname;
  19.     }
  20.  
  21.     function getOffset(elem, container) {
  22.         container = container || document.documentElement;
  23.  
  24.         var node = elem;
  25.         var left = 0;
  26.         var top = 0;
  27.  
  28.         // Stop if we reach the container (or body)
  29.         while (node && node !== container) {
  30.             left += node.offsetLeft;
  31.             top += node.offsetTop;
  32.             node = node.offsetParent;
  33.         }
  34.  
  35.         return {
  36.             top: top,
  37.             left: left,
  38.             height: elem.offsetHeight,
  39.             width: elem.offsetWidth,
  40.         };
  41.     }
  42.  
  43.     return {
  44.         getContainer: getContainer,
  45.         getHost: getHost,
  46.         getOffset: getOffset,
  47.     };
  48. });
  49.  
  50. // https://c.disquscdn.com/next/next-core/core/common/kernel/utils.js

Replies to Re:utils.js rss

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

Reply to "Re:utils.js"

Here you can reply to the paste above