Re: base.js

From disqus.com, 2 Months ago, written in JavaScript, viewed 3 times. This paste is a reply to Re: raven.js from disqus.com - view diff
URL https://pastebin.freepbx.org/view/99cde933 Embed
Download Paste or View Raw
  1. define('core/shared/urls',['require','core/utils/object/extend','core/utils/url/serialize','core/utils/url/serializeArgs'],function (require) {
  2.     'use strict';
  3.  
  4.     var extend = require('core/utils/object/extend');
  5.     var serialize = require('core/utils/url/serialize');
  6.     var serializeArgs = require('core/utils/url/serializeArgs');
  7.  
  8.  
  9.     var base = '{{ BASE }}';
  10.  
  11.     // expects protocol-relative URLs, any http-protocol will be stripped
  12.     // if it exists in the URL - this is to ensure HTTPS compatibility
  13.     // `bootloader` expects a file ending with `.load.<MD5_Hash>.js`
  14.     var apps = {
  15.         lounge: '{{ LOUNGE_URL }}',
  16.  
  17.         // remove home/ from url since home also lives in disqus.com/by/<username>
  18.         // TODO: change SECURE_HOME_URL to point to https://disqus.com/
  19.         home: '{{ SECURE_HOME_URL }}'.replace('home/', ''),
  20.  
  21.         recommendations: '{{ RECOMMENDATIONS_URL }}',
  22.     };
  23.  
  24.     var ensureHTTPSProtocol = function (url) {
  25.         // Use string concatenation to ensure correct protocol is used
  26.         // (even if regular expression does not match)
  27.         return 'https://' + url.replace(/^\s*(\w+:)?\/\//, '');
  28.     };
  29.  
  30.     /**
  31.      * Returns a "host app url" that has the same protocol with the current URL
  32.      * Uses the `apps` dictionary above for base URLs, takes in additional
  33.      * parameters to be passed in the query string + the app configuration to be
  34.      * put in the location hash, if desired.
  35.      *
  36.      * @param {string} name Name of the app. Should be in the `apps` dict above.
  37.      * @param {Object} [params] A dictionary of extra QSA params.
  38.      * @param {Object} [hashParams] The configuration of the app, to be passed in the URL hash..
  39.      * @returns {string} The URL for the app, with proper parameters
  40.      */
  41.     var get = function (name, params, hashParams) {
  42.         var appUrl = apps[name];
  43.  
  44.         if (!appUrl)
  45.             throw new Error('Unknown app: ' + name);
  46.  
  47.         var baseUrl = ensureHTTPSProtocol(appUrl);
  48.  
  49.         var urlParams = extend({
  50.             base: base,
  51.         }, params || {});
  52.  
  53.         var hashString = hashParams ? '#' + serializeArgs(hashParams) : '';
  54.  
  55.         return serialize(baseUrl, urlParams) + hashString;
  56.     };
  57.  
  58.     return {
  59.         BASE: base,
  60.         apps: apps,
  61.         get: get,
  62.         ensureHTTPSProtocol: ensureHTTPSProtocol,
  63.     };
  64. });
  65.  
  66.  

Replies to Re: base.js rss

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

Reply to "Re: base.js"

Here you can reply to the paste above