Event scope in js

General discussion of development ideas and the approaches taken in the 3.x branch of phpBB. The next feature release of phpBB 3 will be 3.2/Rhea followed by 3.3.
Forum rules
Please do not post support questions regarding installing, updating, or upgrading phpBB 3.1. If you need support for phpBB 3.1 please visit the 3.1.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 » Tue Oct 14, 2014 12:23 pm

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