|
1 | | -/*! gridster.js - v0.5.1 - 2014-03-26 |
| 1 | +/*! gridster.js - v0.5.2 - 2014-06-16 |
2 | 2 | * http://gridster.net/ |
3 | 3 | * Copyright (c) 2014 ducksboard; Licensed MIT */ |
4 | 4 |
|
|
430 | 430 | var dir_map = { x : 'left', y : 'top' }; |
431 | 431 | var isTouch = !!('ontouchstart' in window); |
432 | 432 | var pointer_events = { |
433 | | - start: isTouch ? 'touchstart.gridster-draggable' : 'mousedown.gridster-draggable', |
434 | | - move: isTouch ? 'touchmove.gridster-draggable' : 'mousemove.gridster-draggable', |
435 | | - end: isTouch ? 'touchend.gridster-draggable' : 'mouseup.gridster-draggable' |
| 433 | + start: 'touchstart.gridster-draggable mousedown.gridster-draggable', |
| 434 | + move: 'touchmove.gridster-draggable mousemove.gridster-draggable', |
| 435 | + end: 'touchend.gridster-draggable mouseup.gridster-draggable' |
436 | 436 | }; |
437 | 437 |
|
438 | 438 | var capitalize = function(str) { |
|
467 | 467 | */ |
468 | 468 | function Draggable(el, options) { |
469 | 469 | this.options = $.extend({}, defaults, options); |
470 | | - this.$body = $(document.body); |
| 470 | + this.$document = $(document); |
471 | 471 | this.$container = $(el); |
472 | 472 | this.$dragitems = $(this.options.items, this.$container); |
473 | 473 | this.is_dragging = false; |
|
495 | 495 | this.$container.on(pointer_events.start, this.options.items, |
496 | 496 | $.proxy(this.drag_handler, this)); |
497 | 497 |
|
498 | | - this.$body.on(pointer_events.end, $.proxy(function(e) { |
| 498 | + this.$document.on(pointer_events.end, $.proxy(function(e) { |
499 | 499 | this.is_dragging = false; |
500 | 500 | if (this.disabled) { return; } |
501 | | - this.$body.off(pointer_events.move); |
| 501 | + this.$document.off(pointer_events.move); |
502 | 502 | if (this.drag_start) { |
503 | 503 | this.on_dragstop(e); |
504 | 504 | } |
|
512 | 512 |
|
513 | 513 |
|
514 | 514 | fn.get_mouse_pos = function(e) { |
515 | | - if (isTouch) { |
| 515 | + if (e.originalEvent && e.originalEvent.touches) { |
516 | 516 | var oe = e.originalEvent; |
517 | 517 | e = oe.touches.length ? oe.touches[0] : oe.changedTouches[0]; |
518 | 518 | } |
|
532 | 532 | var diff_y = Math.round(mouse_actual_pos.top - this.mouse_init_pos.top); |
533 | 533 |
|
534 | 534 | var left = Math.round(this.el_init_offset.left + |
535 | | - diff_x - this.baseX + this.scroll_offset_x); |
| 535 | + diff_x - this.baseX + $(window).scrollLeft() - this.win_offset_x); |
536 | 536 | var top = Math.round(this.el_init_offset.top + |
537 | | - diff_y - this.baseY + this.scroll_offset_y); |
| 537 | + diff_y - this.baseY + $(window).scrollTop() - this.win_offset_y); |
538 | 538 |
|
539 | 539 | if (this.options.limit) { |
540 | 540 | if (left > this.player_max_left) { |
|
552 | 552 | pointer: { |
553 | 553 | left: mouse_actual_pos.left, |
554 | 554 | top: mouse_actual_pos.top, |
555 | | - diff_left: diff_x + this.scroll_offset_x, |
556 | | - diff_top: diff_y + this.scroll_offset_y |
| 555 | + diff_left: diff_x + ($(window).scrollLeft() - this.win_offset_x), |
| 556 | + diff_top: diff_y + ($(window).scrollTop() - this.win_offset_y) |
557 | 557 | } |
558 | 558 | }; |
559 | 559 | }; |
|
636 | 636 |
|
637 | 637 | fn.drag_handler = function(e) { |
638 | 638 | var node = e.target.nodeName; |
| 639 | + // skip if drag is disabled, or click was not done with the mouse primary button |
639 | 640 | if (this.disabled || e.which !== 1 && !isTouch) { |
640 | 641 | return; |
641 | 642 | } |
|
652 | 653 | this.mouse_init_pos = this.get_mouse_pos(e); |
653 | 654 | this.offsetY = this.mouse_init_pos.top - this.el_init_pos.top; |
654 | 655 |
|
655 | | - this.$body.on(pointer_events.move, function(mme) { |
| 656 | + this.$document.on(pointer_events.move, function(mme) { |
656 | 657 | var mouse_actual_pos = self.get_mouse_pos(mme); |
657 | 658 | var diff_x = Math.abs( |
658 | 659 | mouse_actual_pos.left - self.mouse_init_pos.left); |
|
700 | 701 | this.helper = false; |
701 | 702 | } |
702 | 703 |
|
| 704 | + this.win_offset_y = $(window).scrollTop(); |
| 705 | + this.win_offset_x = $(window).scrollLeft(); |
703 | 706 | this.scroll_offset_y = 0; |
704 | 707 | this.scroll_offset_x = 0; |
705 | 708 | this.el_init_offset = this.$player.offset(); |
|
777 | 780 | this.disable(); |
778 | 781 |
|
779 | 782 | this.$container.off('.gridster-draggable'); |
780 | | - this.$body.off('.gridster-draggable'); |
| 783 | + this.$document.off('.gridster-draggable'); |
781 | 784 | $(window).off('.gridster-draggable'); |
782 | 785 |
|
783 | 786 | $.removeData(this.$container, 'drag'); |
|
1028 | 1031 | }else{ |
1029 | 1032 | pos = { |
1030 | 1033 | col: col, |
1031 | | - row: row |
| 1034 | + row: row, |
| 1035 | + size_x: size_x, |
| 1036 | + size_y: size_y |
1032 | 1037 | }; |
1033 | 1038 |
|
1034 | 1039 | this.empty_cells(col, row, size_x, size_y); |
|
3592 | 3597 | (x * opts.widget_base_dimensions[0] + |
3593 | 3598 | (x - 1) * (opts.widget_margins[0] * 2)) + 'px; }\n'); |
3594 | 3599 | } |
3595 | | - |
3596 | | - this.remove_style_tags(); |
| 3600 | + |
| 3601 | + this.remove_style_tags(); |
3597 | 3602 |
|
3598 | 3603 | return this.add_style_tag(styles); |
3599 | 3604 | }; |
|
0 commit comments