JQuery text select event

I have the following event handling code:

$('#main').delegate('.slide', 'click', function () { slideshow.next(); }); $('#main').delegate('a', 'click', function (e) { e.stopPropagation(); }); 

.slide is a large div with content. slideshow.next() is called when .slide , unless a link is clicked, in which case stopPropagation() and .slide never receive a click event.

I would like to make it possible to select text on a slide. At the moment, if I click and drag when I release the mouse, the selection works, but .slide registers the click and runs the slideshow.next() function. Is there an event that I can intercept?

The page is available here .


Edit: Interestingly, if a selection spans more than one HTML element, click does not start, but the selection is inside the element, it starts.


Edit2: Ok, here is my solution:

 function setupHandlers() { var prevX = 0; var prevY = 0; $('#main').delegate('.slide', 'click', function (e) { var clickTolerance = 2; var dx = Math.abs(e.pageX - prevX); var dy = Math.abs(e.pageY - prevY); //if mouse has moved less than two pixels in any direction this is a click if (dx < clickTolerance && dy < clickTolerance) { slideshow.next(); } }); $('#main').delegate('.slide', 'mousedown', function (e) { prevX = e.pageX; prevY = e.pageY; }); $('#main').delegate('a', 'click', function (e) { //Clicks on links shouldn't fire '.slide'.click() above e.stopPropagation(); }); } 
+6
jquery events
source share
2 answers

What is the difference between a single click and a click that selects text?

I would say that this may concern the time elapsed between clicking and clicking the mouse. Alternatively, and perhaps more importantly, this could be diagnosed by the difference in position of the mouse screen during the down-press and during the mouse event.

When the mouseDown event fires, write down the values ​​of event.pageX and event.pageY. When the mouseUp event is fired, compare the stored x, y with the current. If they are different, it was a choice of text ... do nothing. If they match, replace your page.

Not sure how to implement this in JScript, unfortunately;)

+2
source share

use $('.slide').select to catch the select event and stop the distribution.

0
source share

All Articles