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!
question from:
https://stackoverflow.com/questions/5079715/jquerys-drag-and-drop-reverse-engineering-facebooks-uitokenizer-on-arts-i 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…