jquery.extension.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //dragdrop
  2. (function($) {
  3. $.fn.dragdrop = function(eventobj)
  4. {
  5. var moveobj = this;
  6. var mouseup = function (e)
  7. {
  8. $(document).unbind("mousemove", mousemove);
  9. $(document).unbind("mouseup", mouseup);
  10. return false;
  11. }
  12. var mousemove = function (e)
  13. {
  14. var position = e.data;
  15. e.pageX = Math.max(0, Math.min(e.pageX, $(window).width()));
  16. e.pageY = Math.max(0, Math.min(e.pageY, $(window).height()));
  17. var newleft = e.pageX - position.left;
  18. var newtop = e.pageY - position.top;
  19. $(moveobj).css("left", newleft + "px");
  20. $(moveobj).css("top", newtop + "px");
  21. }
  22. var mousedown = function (e) {
  23. var left = e.pageX - $(this).offset().left;
  24. var top = e.pageY - $(this).offset().top;
  25. $(document).bind('mousemove', {left: left, top: top} , mousemove);
  26. $(document).bind('mouseup', mouseup);
  27. return false;
  28. }
  29. $(eventobj).bind('mousedown', mousedown);
  30. };
  31. })(jQuery);
  32. /*! Copyright (c) 2009 Brandon Aaron (http://brandonaaron.net)
  33. * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
  34. * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
  35. * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
  36. * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
  37. *
  38. * Version: 3.0.2
  39. *
  40. * Requires: 1.2.2+
  41. */
  42. (function($) {
  43. var types = ['DOMMouseScroll', 'mousewheel'];
  44. $.event.special.mousewheel = {
  45. setup: function() {
  46. if ( this.addEventListener )
  47. for ( var i=types.length; i; )
  48. this.addEventListener( types[--i], handler, false );
  49. else
  50. this.onmousewheel = handler;
  51. },
  52. teardown: function() {
  53. if ( this.removeEventListener )
  54. for ( var i=types.length; i; )
  55. this.removeEventListener( types[--i], handler, false );
  56. else
  57. this.onmousewheel = null;
  58. }
  59. };
  60. $.fn.extend({
  61. mousewheel: function(fn) {
  62. return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
  63. },
  64. unmousewheel: function(fn) {
  65. return this.unbind("mousewheel", fn);
  66. }
  67. });
  68. function handler(event) {
  69. var args = [].slice.call( arguments, 1 ), delta = 0, returnValue = true;
  70. event = $.event.fix(event || window.event);
  71. event.type = "mousewheel";
  72. if ( event.wheelDelta ) delta = event.wheelDelta/120;
  73. if ( event.detail ) delta = -event.detail/3;
  74. // Add events and delta to the front of the arguments
  75. args.unshift(event, delta);
  76. return $.event.handle.apply(this, args);
  77. }
  78. })(jQuery);