Guest User

Untitled

a guest
Jun 23rd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. function create_drop_targets() {
  2. $('li a')
  3. .bind('dropstart', function(event) {
  4. })
  5. .bind('drop', function(event) {
  6. })
  7. .bind('dropend', function(event) {
  8. });
  9. }
  10.  
  11. var drop = $.event.special.drop = {
  12. setup: function(){
  13. drop.$elements = drop.$elements.add( this );
  14. drop.data[ drop.data.length ] = drop.locate( this );
  15. },
  16. locate: function( elem ){ // return { L:left, R:right, T:top, B:bottom, H:height, W:width }
  17. var $el = $(elem), pos = $el.offset(), h = $el.outerHeight(), w = $el.outerWidth();
  18. return { elem: elem, L: pos.left, R: pos.left+w, T: pos.top, B: pos.top+h, W: w, H: h };
  19. }
  20.  
  21. drag: function(draggable, event) {
  22. //If you have a highly dynamic page, you might try this option. It renders positions every time you move the mouse.
  23. if(draggable.options.refreshPositions) $.ui.ddmanager.prepareOffsets(draggable, event);
  24. ...
  25.  
  26. $(".cocktails").draggable({
  27. refreshPositions: true,
  28. });
  29.  
  30. //This will be called every time the user moves the draggable helper.
  31. function onDrag(event, ui) {
  32. //We need to re-aquire the drag handle; we don't
  33. //hardcode it to a selector, so this event can be
  34. //used by multiple draggables.
  35. var dragHandle = $(event.target);
  36.  
  37. //If refreshOptions *was* true, jQueryUI has already refreshed the droppables,
  38. //so we can now switch this option back off.
  39. if (dragHandle.draggable('option', 'refreshPositions')) {
  40. dragHandle.draggable('option', 'refreshPositions', false)
  41. }
  42.  
  43. //Your other drag handling code
  44.  
  45. if (/* logic to determine if your droppables need to be refreshed */) {
  46. dragHandle.draggable('option', 'refreshPositions', true);
  47. }
  48. }
  49.  
  50.  
  51. $("#mydraggable").draggable({
  52. //Your options here, note that refreshPositions is off.
  53. drag: onDrag
  54. });
  55.  
  56. $(window).resize(function () {
  57. $(".draggable").draggable("option", "disabled", true);
  58. $(".draggable").draggable("option", "disabled", false);
  59. });
Add Comment
Please, Sign In to add comment