Commit 55e52901 authored by Pedro Eduardo Trujillo's avatar Pedro Eduardo Trujillo
Browse files

Generaliza detección de clicks y refactoriza

La implementación de detectar si un click pertenece a un nodo concreto
se ha generalizado, simplificando esta funcionalidad en innerApp y
Notification. Además, queda disponible para cualquier módulo.
parent 25c9dd08
Loading
Loading
Loading
Loading
+4 −14
Original line number Diff line number Diff line
@@ -218,7 +218,7 @@ define([

			this._contentContainer = put(this.domNode, 'div.' + this.contentContainerClass);

			put(this.domNode, 'div.' + this.overlaySidebarBackgroundClass);
			this._overlaySidebarBackground = put(this.domNode, 'div.' + this.overlaySidebarBackgroundClass);
		},

		_createListeners: function() {
@@ -300,23 +300,13 @@ define([

		_onAppClicked: function(evt) {

			var clickedNode = evt.target,
				targets = this._getClickTargets(evt),
				nodeDoesNotBelongToMainSidebar = targets.indexOf(this.sidebar.domNode) === -1,
				nodeDoesNotBelongToToggleButton = !this._findCollapseButtonNode(targets).length;
			var nodeDoesNotBelongToMainSidebar = !this._checkClickBelongsToNode(evt, this.sidebar.domNode),
				nodeBelongsToSidebarOverlay = this._checkClickBelongsToNode(evt, this._overlaySidebarBackground);

			if (nodeDoesNotBelongToMainSidebar && nodeDoesNotBelongToToggleButton) {
			if (nodeDoesNotBelongToMainSidebar && nodeBelongsToSidebarOverlay) {
				this._appClickHandler.pause();
				this._collapseMainSidebar();
			}
		},

		_findCollapseButtonNode: function(nodes) {

			return nodes.filter(lang.hitch(this, function(target) {

				return target && target.classList && target.classList.contains(this.collapseButtonClass);
			}));
		}
	});
});
+7 −0
Original line number Diff line number Diff line
@@ -23,6 +23,13 @@ define([
			}

			return targets.concat(targetPath);
		},

		_checkClickBelongsToNode: function(event, node) {

			var targets = this._getClickTargets(event);

			return targets.indexOf(node) !== -1;
		}
	});
});
+6 −8
Original line number Diff line number Diff line
@@ -133,16 +133,14 @@ define([

		_onCloseNotificationSidebar: function(evt) {

			var clickedNode = evt.target,
				targets = this._getClickTargets(evt),
				nodeDoesNotBelongToNotificationButton = targets.indexOf(this.domNode) === -1 &&
					clickedNode !== this.domNode,
			var nodeBelongsToNotificationButton = this._checkClickBelongsToNode(evt, this.domNode),
				nodeBelongsToNotificationSidebar = this._checkClickBelongsToNode(evt, this.notificationSidebarNode);

				nodeDoesNotBelongToNotificationSidebar = targets.indexOf(this.notificationSidebarNode) === -1;
			if (nodeBelongsToNotificationButton || nodeBelongsToNotificationSidebar) {
				return;
			}

			if (nodeDoesNotBelongToNotificationButton && nodeDoesNotBelongToNotificationSidebar) {
			this._clickNotification(evt);
			}
		},

		_clickNotification: function(evt) {