Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

197
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda