Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

190
Views
jQuery's drag and drop - reverse engineering Facebook's uiTokenizer on 'Arts & Interests'

I'm reverse engineering facebook's uiTokenizer using $.special.event.drag and $.special.event.drop and jQuery because jQuery UI's sortable / draggable is heavy and slow.

My question I think is related to the tolerance math for deciding when to inject the placeholder element.

I've cleaned up a lot of this code since I first wrote it but the premise is still there and should work for this question.

Here is the code and logic: http://jsfiddle.net/JoshuaIRL/kf9Qt/ for testing.

The area I need somebody to look at would be the "tolerance" area of the $.drop function if you do find for it.

 $.drop({
      mode:'intersect',
       tolerance: function( event, proxy, target ){
           var testV = event.pageY > ( target.top + target.height / 2 );

           $.data(target.elem, "drop+reorder", testV ? "insertAfter" : "insertBefore" );    
           return this.contains( target, [ event.pageX, event.pageY ] );
       }
 });

Facebook's seems to do an "insertAfter" when your actual cursor hits another element.

I'm thinking this might be the heart of it as well:

if ( drop && $(drop).is('.uiToken') && ( drop != dd.current || method != dd.method ) ){    
      $( this )[ method ]( drop );
      dd.current = drop;
      dd.method = method;
      dd.update();
     refreshTokens(clickOffset);
     placeholder.insertAfter($(this));
}

Also, I need to figure out how to ensure I'm not over-binding my elements with this stupid open-ended $.drop() method ... :-\

Any help you may offer will be greatly appreciated.

UPDATE: To answer your comments... If you go to the JSFiddle link and you drag an element over another element... It should immediately bump it out of the way in all directions. To see a comparison from mine versus Facebook's, checkout theirs at https://www.facebook.com//favorites then click on "Edit" button.

Whether or not the "Tolerance" method is what's wrong, their interests list is what I'm looking to duplicate. I don't even know if the Tolerance area is what's wrong, I want to achieve what they are doing.

I hope this helps!

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

It looks like you are just determining if the draggables right intersects the targets left, and if the draggables top intersects the targets bottom (with some tolerance).

There are 2 ways I would go about this:

  1. Find all intersect elements and find the largest area - in this case the left square of the image below.
  2. If the draggable has the same dimensions as the droppable the 1/4 overlap would suffice - in this case the right square.

enter image description here

The second is by far the easiest to implement but is no means as general as the first. So by having a quick look through your code, I would loop through all the "possible" droppable elements determine the area of the overlap and target the largest.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!