dragAnimDemo-jquery.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /**
  2. unavoidable separate file for jquery specific parts of the dragAnimDemo.
  3. */
  4. ;(function() {
  5. jsPlumbDemo.initClearButton = function() {
  6. $("#clear").unbind("click", jsPlumb.detachEveryConnection);
  7. $("#clear").bind("click", jsPlumb.detachEveryConnection );
  8. };
  9. jsPlumbDemo.initAddButton = function() {
  10. $("#add").unbind("click", jsPlumbDemo.addDisc );
  11. $("#add").bind('click', jsPlumbDemo.addDisc );
  12. };
  13. jsPlumbDemo.initHover = function(elId) {
  14. $("#" + elId).hover(
  15. function() { $(this).addClass("bigdot-hover"); },
  16. function() { $(this).removeClass("bigdot-hover"); }
  17. );
  18. };
  19. jsPlumbDemo.initAnimation = function(elId) {
  20. $("#" + elId).bind('click', function(e, ui) {
  21. if ($(this).hasClass("jsPlumb_dragged")) {
  22. $(this).removeClass("jsPlumb_dragged");
  23. return;
  24. }
  25. var o = $(this).offset(),
  26. w = $(this).outerWidth(),
  27. h = $(this).outerHeight(),
  28. c = [o.left + (w/2) - e.pageX, o.top + (h/2) - e.pageY],
  29. oo = [c[0] / w, c[1] / h],
  30. l = oo[0] < 0 ? '+=' : '-=', t = oo[1] < 0 ? "+=" : '-=',
  31. DIST = 450,
  32. l = l + Math.abs(oo[0] * DIST);
  33. t = t + Math.abs(oo[1] * DIST);
  34. // notice the easing here. you can pass any args into this animate call; they
  35. // are passed through to jquery as-is by jsPlumb.
  36. var id = $(this).attr("id");
  37. jsPlumb.animate(id, {left:l, top:t}, { duration:1400, easing:'easeOutBack' });
  38. });
  39. };
  40. })();