Commit 102b8a49 authored by Pedro Eduardo Trujillo's avatar Pedro Eduardo Trujillo
Browse files

Unifica referencias al ámbito global

Unifica uso del ámbito global, partiendo siempre desde la base. En el
navegador se trata de window, pero se usa globalThis como referencia
universal (es estándar y se resuelve correctamente para cada entorno).

Hace explícitas las referencias a propiedades y funciones del ámbito
global o de sus hijos, en aquellos casos en que se referenciaran
directamente omitiendo el ámbito global.

Elimina comprobaciones innecesarias, ya que la referencia globalThis se
resuelve automáticamente.
parent 50d5a0dd
Loading
Loading
Loading
Loading
+3 −17
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@ define([
	'dojo/_base/declare'
	, 'dojo/_base/lang'
	, 'dojo/dom'
	, 'dojo/has'
	, 'put-selector/put'
	, 'src/app/component/Analytics'
	, 'src/app/component/Credentials'
@@ -26,7 +25,6 @@ define([
	declare
	, lang
	, dom
	, has
	, put
	, Analytics
	, Credentials
@@ -51,17 +49,6 @@ define([
	var rootNode = dom.byId('rootContainer'),
		nativeLoadingNode = dom.byId('loadingContainer');

	var getGlobalContext = function() {

		if (has('host-browser')) {
			return window;
		} else if (has('host-node')) {
			return global;
		} else {
			console.error('Environment not supported');
		}
	};

	var hideNativeLoadingNode = function() {

		if (nativeLoadingNode) {
@@ -72,7 +59,7 @@ define([

	if (!CheckBrowser.isSupported()) {
		hideNativeLoadingNode();
		getGlobalContext().location.href = '/noSupportBrowser';
		globalThis.location.href = '/noSupportBrowser';

		return declare(null);
	}
@@ -108,7 +95,7 @@ define([
		constructor: function(args) {

			// TODO medida temporal de comienzo de migración de identidad
			var currDomain = getGlobalContext().location.hostname,
			var currDomain = globalThis.location.hostname,
				ecomarcanDomainPattern = /.*ecomarcan\..+/;

			this.config = {
@@ -134,8 +121,7 @@ define([
			var parentChannel = this.getChannel();

			this._router = new Router({
				parentChannel: parentChannel,
				globalContext: getGlobalContext()
				parentChannel: parentChannel
			});

			new CookieLoader();
+1 −1
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@ define([
){
	// Constantes para trakear acciones
	// TODO: sacar a un fichero externo (Necesita ser global)
	window.TRACK = {
	globalThis.TRACK = {
		'type': {
			'event': 'event',
			'page': 'pageview',
+2 −3
Original line number Diff line number Diff line
@@ -159,11 +159,10 @@ define([

			this._setEmptySelectionIds();

			var location = window.location;
			if (location.pathname === this._loginPath) {
			if (globalThis.location.pathname === this._loginPath) {
				this._getCredentials();
			} else {
				location.reload();
				globalThis.location.reload();
			}
		},

+10 −14
Original line number Diff line number Diff line
@@ -25,8 +25,6 @@ define([

		//	paths: Object
		//		Constantes de rutas base
		//	globalContext: Object
		//		Contexto provisto por App para gestionar el entorno de ejecución
		//	_userFound: Boolean
		//		Indica si hay presente algún token de usuario.

@@ -94,7 +92,7 @@ define([
			//	tags:
			//		private

			var gCtx = this.globalContext,
			var gCtx = globalThis,
				dCtx = gCtx.document,
				listenMethod, eventPrefix;

@@ -116,7 +114,7 @@ define([
			//	tags:
			//		private

			var event = evt || this.globalContext.event,
			var event = evt || globalThis.event,
				targets = this._getClickTargets(event);

			for (var i = 0; i < targets.length; i++) {
@@ -137,10 +135,8 @@ define([
			var url = target.pathname + target.search + target.hash;

			if (mouse.isMiddle(event)) {
				var gCtx = this.globalContext,
					newPageUrl = target.protocol + '//' + target.hostname + url;

				gCtx.open(newPageUrl, '_blank');
				var newPageUrl = target.protocol + '//' + target.hostname + url;
				globalThis.open(newPageUrl, '_blank');
			} else {
				this._addHistory(url);
				this._onRouteChange();
@@ -155,12 +151,12 @@ define([

		_addHistory: function(value) {

			this.globalContext.history.pushState(null, null, value);
			globalThis.history.pushState(null, null, value);
		},

		_onRouteChange: function() {

			var locationObj = this.globalContext.location,
			var locationObj = globalThis.location,
				locationPath = locationObj.pathname,
				route = locationPath.substr(1),
				routeIsEmpty = !route || route === '' || route === this.paths.ROOT,
@@ -221,12 +217,12 @@ define([

		_goToRootPage: function() {

			this.globalContext.location.href = this.paths.ROOT;
			globalThis.location.href = this.paths.ROOT;
		},

		_goToErrorPage: function() {

			this.globalContext.location.href = this.paths.ERROR;
			globalThis.location.href = this.paths.ERROR;
		},

		_handleQueryParameters: function(queryString) {
@@ -243,10 +239,10 @@ define([

		_removeQueryParametersFromHref: function() {

			var locationObj = this.globalContext.location,
			var locationObj = globalThis.location,
				href = locationObj.origin + locationObj.pathname + locationObj.hash;

			this.globalContext.history.replaceState(null, null, href);
			globalThis.history.replaceState(null, null, href);
		}
	});
});
+4 −4
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ define([
				ogDescriptionLimit: 200,
				twitterDescriptionLimit: 200,

				_headNode: document.getElementsByTagName('head')[0],
				_headNode: globalThis.document.getElementsByTagName('head')[0],
				_defaultKey: 'default'
			};

@@ -74,7 +74,7 @@ define([
				return;
			}

			var currUrl = window.location.href,
			var currUrl = globalThis.location.href,
				hostname = new URL(currUrl).hostname;

			viewData.hostname = hostname;
@@ -115,7 +115,7 @@ define([
			var customTitle = this._getMetaTagValue('title', viewLocaleMetaTags, viewData);

			// Title nativo
			document.title = customTitle + ' | ' + this.nativeTitleSuffix;
			globalThis.document.title = customTitle + ' | ' + this.nativeTitleSuffix;

			// Open Graph
			var ogTag = 'og:title',
@@ -285,7 +285,7 @@ define([
				metaTagNode = metaTagNodes[0];
				metaTagNode.content = tagContent;
			} else {
				metaTagNode = document.createElement('meta');
				metaTagNode = globalThis.document.createElement('meta');
				metaTagNode.setAttribute(tagIdProperty, tagIdValue);
				metaTagNode.content = tagContent;
				this._headNode.appendChild(metaTagNode);
Loading