1 /** 2 * @fileOverview Utility Functions 3 */ 4 5 /** 6 * @namespace Utility Functions 7 */ 8 BTM.Util = {}; 9 10 /** 11 * Compare two URL Strings or Location objects 12 * @param {Object|String} url1 First URL String or Location object (such as window.location) 13 * @param {Object|String} url1 Second URL String or Location object (such as window.location) 14 * @param {Boolean} [compareHash=false] flag to also check matching hash (fragment identifier) properties 15 * @returns {Boolean} whether the two URLs match 16 */ 17 BTM.Util.compareURLs = function compareURLs(url1, url2, compareHash) { 18 compareHash = compareHash || false; 19 url1 = Object.isString(url1) ? url1.parseURL() : url1; 20 url2 = Object.isString(url2) ? url2.parseURL() : url2; 21 22 var result = ((url1.protocol === url2.protocol) && 23 (url1.hostname === url2.hostname) && 24 (url1.port === url2.port) && 25 (url1.pathname === url2.pathname) && 26 (url1.search === url2.search) && 27 (compareHash === false || (url1.hash === url2.hash))); 28 29 return result; 30 }; 31 32 /** 33 * Get an Array of the Hash Loaders in the address 34 * @param {String} [hash=window.location.hash] the String to get Hash Loaders from 35 * @param {String} [split=','] the character used to seperate Hash Loaders 36 * @returns {String[]} the extracted Hash Loaders 37 */ 38 BTM.Util.getHashLoaders = function getHashLoaders(hash, split) { 39 split = split || ','; 40 hash = decodeURIComponent(hash || document.location.hash).replace('#',''); 41 42 if (hash !== '') { 43 return hash.split(split); 44 } 45 else { 46 return []; 47 } 48 };