Can't find event definitions

181
August 20, 2017, at 08:28 AM

I have this function in my codebase:

let touch = true;
function init() {
    let firstMousemoveHasOccured = false;
    $(window).on('mousemove.touchdetection', () => {
        if (firstMousemoveHasOccured) {
            touch = false;
            $(window).off('mousemove.touchdetection touchend.touchdetection');
        } else {
            firstMousemoveHasOccured = true;
        }
    });
    $(window).on('touchend.touchdetection', () => {
        touch = true;
        $(window).off('mousemove.touchdetection touchend.touchdetection');
    });
}

The event mousemove.touchdetection is not a standard event, so where is this coming from?

Answer 1

These are jQuery namespaced events

The first part of the event name mousemove is the event that, when fired calls the callback. The second part touchdetection is meaningless, except it allows you a mechanism to turn off a specific class or group of mousemove events, easily.

$(document).off('mousemove'); //turns off all callbacks attached to the `mousemove` event.
$(document).off('mousemove.touchdetection'); //turns of all callbacks attached to the mousemove event that have been attached with the touchdetection namespace

The purpose of this, as you'll see from reading the API docs is to allow you to easily modify your listeners in your application without affecting listeners attached by third party code.

Rent Charter Buses Company
READ ALSO
My jquery code is set to not execute if an element has a certain class, however, I found out that I can change the class in the inspector

My jquery code is set to not execute if an element has a certain class, however, I found out that I can change the class in the inspector

My jquery code is set to not execute if an element has a certain class, however, I found out that I can change the class in inspector and still submit and call ajax which results in a change to the databaseThis means a user can vote unlimited times even

167
CanvasJS data formatting, adding text to X/Y labels

CanvasJS data formatting, adding text to X/Y labels

I've got a big problem with number formatting in CanvasJS and I tried almost every combination but can't get the result I wantAs you can see on the SS for point 2 on X label I got result 28,

319
jQuery AJAX post to my ASP.NET webservice with JSON.stringify

jQuery AJAX post to my ASP.NET webservice with JSON.stringify

I'm trying to trigger a jQuery AJAX post to my ASPNET webservice

236