Skip to content

compatible using passive mode #1359

Open
@simonjoom

Description

@simonjoom

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions