Event scope in js

General discussion of development ideas and the approaches taken in the 3.x branch of phpBB. The current feature release of phpBB 3 is 3.3/Proteus.
Forum rules
Please do not post support questions regarding installing, updating, or upgrading phpBB 3.3.x. If you need support for phpBB 3.3.x please visit the 3.3.x Support Forum on phpbb.com.

If you have questions regarding writing extensions please post in Extension Writers Discussion to receive proper guidance from our staff and community.
Post Reply
dcz
Registered User
Posts: 27
Joined: Sat Feb 12, 2005 9:03 pm
Contact:

Event scope in js

Post by dcz »

Hello,

Today I just felt on pieces of JS code like :

Code: Select all

	// Hide active dropdowns when click event happens outside
	$body.click(function(e) {
		var $parents = $(e.target).parents();
		if (!$parents.is(phpbb.dropdownVisibleContainers)) {
			$(phpbb.dropdownHandles).each(phpbb.toggleDropdown);
		}
	});

Code: Select all

$('#phpbb').click(function() {
	var $this = $(this);

	if (!$this.is('.live-search') && !$this.parents().is('.live-search')) {
		$('.live-search').hide();
	}
});
in assets/javascript/core.js

I really think such a wide scope should be avoided as it could easily mess with other click events set at a lower scope. I did not analyse the whole code yet, but just reading this I think we should start thinking about doing this differently.

Post Reply