Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compatible using passive mode #1359

Open
simonjoom opened this issue Sep 17, 2019 · 0 comments
Open

compatible using passive mode #1359

simonjoom opened this issue Sep 17, 2019 · 0 comments

Comments

@simonjoom
Copy link

simonjoom commented Sep 17, 2019

well i changed this post, it's not a bug (if you read what i wrote before the problem was from my implementation)

But i added recently feature passive in zepto, some code that i can share below that i use to help with (new parameter function passive on compatible and disable preventDefault for passive event)


eventMethods = {
		//	preventDefault: 'isDefaultPrevented',
		stopImmediatePropagation: 'isImmediatePropagationStopped',
		stopPropagation: 'isPropagationStopped'
	}

function compatible(event, source, passive) {
	if (source || !event.isDefaultPrevented) {
		source || (source = event)

		$.each(eventMethods, function (val, key) {
			var sourceMethod = source[key]
			event[key] = function () { 
				this[val] = returnTrue; 
				return sourceMethod && sourceMethod.apply(source, arguments);
			}
			event[val] = returnFalse;
		})
		if (!passive) {
			var sourceMethod = source.preventDefault;
			event.preventDefault = function () {
				this.isDefaultPrevented = returnTrue; 
				return sourceMethod && sourceMethod.apply(source, arguments);
			}
			event.isDefaultPrevented = returnFalse;
			//returnFalse;
		} else {
			event.preventDefault = event.isDefaultPrevented = function(){};
		}

		try {
			event.timeStamp || (event.timeStamp = Date.now())
		} catch (ignored) { }

		if (source.defaultPrevented !== undefined ? source.defaultPrevented :
			'returnValue' in source ? source.returnValue === false :
				source.getPreventDefault && source.getPreventDefault())
			event.isDefaultPrevented = returnTrue
	}
	return event
}
@simonjoom simonjoom changed the title Hello event preventdefault not working as expected found bug and resolved Event preventdefault not working as expected found bug and resolved Sep 17, 2019
@simonjoom simonjoom changed the title Event preventdefault not working as expected found bug and resolved compatible using passive mode Sep 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant