Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

152 строки
4.0 KiB

  1. /*!
  2. * jQuery UI Mouse 1.8
  3. *
  4. * Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)
  5. * Dual licensed under the MIT (MIT-LICENSE.txt)
  6. * and GPL (GPL-LICENSE.txt) licenses.
  7. *
  8. * http://docs.jquery.com/UI/Mouse
  9. *
  10. * Depends:
  11. * jquery.ui.widget.js
  12. */
  13. (function($) {
  14. $.widget("ui.mouse", {
  15. options: {
  16. cancel: ':input,option',
  17. distance: 1,
  18. delay: 0
  19. },
  20. _mouseInit: function() {
  21. var self = this;
  22. this.element
  23. .bind('mousedown.'+this.widgetName, function(event) {
  24. return self._mouseDown(event);
  25. })
  26. .bind('click.'+this.widgetName, function(event) {
  27. if(self._preventClickEvent) {
  28. self._preventClickEvent = false;
  29. event.stopImmediatePropagation();
  30. return false;
  31. }
  32. });
  33. this.started = false;
  34. },
  35. // TODO: make sure destroying one instance of mouse doesn't mess with
  36. // other instances of mouse
  37. _mouseDestroy: function() {
  38. this.element.unbind('.'+this.widgetName);
  39. },
  40. _mouseDown: function(event) {
  41. // don't let more than one widget handle mouseStart
  42. // TODO: figure out why we have to use originalEvent
  43. event.originalEvent = event.originalEvent || {};
  44. if (event.originalEvent.mouseHandled) { return; }
  45. // we may have missed mouseup (out of window)
  46. (this._mouseStarted && this._mouseUp(event));
  47. this._mouseDownEvent = event;
  48. var self = this,
  49. btnIsLeft = (event.which == 1),
  50. elIsCancel = (typeof this.options.cancel == "string" ? $(event.target).parents().add(event.target).filter(this.options.cancel).length : false);
  51. if (!btnIsLeft || elIsCancel || !this._mouseCapture(event)) {
  52. return true;
  53. }
  54. this.mouseDelayMet = !this.options.delay;
  55. if (!this.mouseDelayMet) {
  56. this._mouseDelayTimer = setTimeout(function() {
  57. self.mouseDelayMet = true;
  58. }, this.options.delay);
  59. }
  60. if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
  61. this._mouseStarted = (this._mouseStart(event) !== false);
  62. if (!this._mouseStarted) {
  63. event.preventDefault();
  64. return true;
  65. }
  66. }
  67. // these delegates are required to keep context
  68. this._mouseMoveDelegate = function(event) {
  69. return self._mouseMove(event);
  70. };
  71. this._mouseUpDelegate = function(event) {
  72. return self._mouseUp(event);
  73. };
  74. $(document)
  75. .bind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
  76. .bind('mouseup.'+this.widgetName, this._mouseUpDelegate);
  77. // preventDefault() is used to prevent the selection of text here -
  78. // however, in Safari, this causes select boxes not to be selectable
  79. // anymore, so this fix is needed
  80. ($.browser.safari || event.preventDefault());
  81. event.originalEvent.mouseHandled = true;
  82. return true;
  83. },
  84. _mouseMove: function(event) {
  85. // IE mouseup check - mouseup happened when mouse was out of window
  86. if ($.browser.msie && !event.button) {
  87. return this._mouseUp(event);
  88. }
  89. if (this._mouseStarted) {
  90. this._mouseDrag(event);
  91. return event.preventDefault();
  92. }
  93. if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
  94. this._mouseStarted =
  95. (this._mouseStart(this._mouseDownEvent, event) !== false);
  96. (this._mouseStarted ? this._mouseDrag(event) : this._mouseUp(event));
  97. }
  98. return !this._mouseStarted;
  99. },
  100. _mouseUp: function(event) {
  101. $(document)
  102. .unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
  103. .unbind('mouseup.'+this.widgetName, this._mouseUpDelegate);
  104. if (this._mouseStarted) {
  105. this._mouseStarted = false;
  106. this._preventClickEvent = (event.target == this._mouseDownEvent.target);
  107. this._mouseStop(event);
  108. }
  109. return false;
  110. },
  111. _mouseDistanceMet: function(event) {
  112. return (Math.max(
  113. Math.abs(this._mouseDownEvent.pageX - event.pageX),
  114. Math.abs(this._mouseDownEvent.pageY - event.pageY)
  115. ) >= this.options.distance
  116. );
  117. },
  118. _mouseDelayMet: function(event) {
  119. return this.mouseDelayMet;
  120. },
  121. // These are placeholder methods, to be overriden by extending plugin
  122. _mouseStart: function(event) {},
  123. _mouseDrag: function(event) {},
  124. _mouseStop: function(event) {},
  125. _mouseCapture: function(event) { return true; }
  126. });
  127. })(jQuery);