client/components/util/util.service.js
/**
 * The Util service is for thin, globally reusable, utility functions
 */
The Util service is for thin, globally reusable, utility functions
The Util service is for thin globally reusable utility functions
function UtilService($window) {
  'ngInject';
  var Util = {
    safeCb(cb) {
      return angular.isFunction(cb) ? cb : angular.noop;
    },
    urlParse(url) {
      var a = document.createElement('a');
      a.href = url;
      if(a.host === '') {
        a.href = a.href;
      }
      return a;
    },
    isSameOrigin(url, origins) {
      url = Util.urlParse(url);
      origins = origins && [].concat(origins) || [];
      origins = origins.map(Util.urlParse);
      origins.push($window.location);
      origins = origins.filter(function(o) {
        let hostnameCheck = url.hostname === o.hostname;
        let protocolCheck = url.protocol === o.protocol;
        let portCheck = url.port === o.port || o.port === '' && (url.port === '80' || url.port
          === '443');
        return hostnameCheck && protocolCheck && portCheck;
      });
      return origins.length >= 1;
    }
  };
  return Util;
}
function UtilService ( $window ) { 'ngInject' ; var Util = { safeCb ( cb ) { return angular . isFunction ( cb ) ? cb : angular . noop ; } , urlParse ( url ) { var a = document . createElement ( 'a' ) ; a . href = url ; if ( a . host === '' ) { a . href = a . href ; } return a ; } , isSameOrigin ( url , origins ) { url = Util . urlParse ( url ) ; origins = origins && [ ] . concat ( origins ) || [ ] ; origins = origins . map ( Util . urlParse ) ; origins . push ( $window . location ) ; origins = origins . filter ( function ( o ) { let hostnameCheck = url . hostname === o . hostname ; let protocolCheck = url . protocol === o . protocol ; let portCheck = url . port === o . port || o . port === '' && ( url . port === '80' || url . port === '443' ) ; return hostnameCheck && protocolCheck && portCheck ; } ) ; return origins . length >= 1 ; } } ; return Util ; }
The Util service is for thin, globally reusable, utility functions
The Util service is for thin globally reusable utility functions
/**
     * Return a callback or noop function
     *
     * @param  {Function|*} cb - a 'potential' function
     * @return {Function}
     */ /**
     * Parse a given url with the use of an anchor element
     *
     * @param  {String} url - the url to parse
     * @return {Object}     - the parsed url, anchor element
     */ // Special treatment for IE, see http://stackoverflow.com/a/13405933 for details /**
     * Test whether or not a given url is same origin
     *
     * @param  {String}           url       - url to test
     * @param  {String|String[]}  [origins] - additional origins to test against
     * @return {Boolean}                    - true if url is same origin
     */ // 2nd part of the special treatment for IE fix (see above): // This part is when using well-known ports 80 or 443 with IE, // when $window.location.port==='' instead of the real port number. // Probably the same cause as this IE bug: https://goo.gl/J9hRta