Skip to content

Commit

Permalink
Merge pull request #5 from highfivedenis/add-read-only-gesture
Browse files Browse the repository at this point in the history
add read only gesture
  • Loading branch information
IcanDivideBy0 committed Mar 27, 2015
2 parents 4c63780 + f857b7e commit d551b12
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/angular-reorderable.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ angular
});

element.on('mousedown', function (event) {
if (itemElement.attr('readonly')) return;

// Prevent default dragging of selected content
event.preventDefault();
isDragging = false;
Expand Down
42 changes: 42 additions & 0 deletions test/angular-reorderable.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,48 @@ describe('angular reorderable', function () {
expect(element.find('[reorderable]')).to.have.css('position', 'relative');
});

it('should do nothing if readOnly is set to true', inject(function ($document) {
template =
'<ul>' +
' <li' +
' ng-repeat="item in collection"' +
' reorderable="rank"' +
' reorderable-handle' +
' ng-readonly="true"' +
' ng-bind="item.name"></li>' +
'</ul>';
var element = createElement();

var dragElement = element.find('[reorderable-handle]:eq(0)');
var dropElement = element.find('[reorderable]:eq(2)');

// Click first element.
dragElement.trigger(jQuery.Event('mousedown', {
clientX: dragElement.get(0).getBoundingClientRect().left,
clientY: dragElement.get(0).getBoundingClientRect().top
}));

// Move mouse to third element.
$document.trigger(jQuery.Event('mousemove', {
clientX: dropElement.get(0).getBoundingClientRect().left,
clientY: dropElement.get(0).getBoundingClientRect().top
}));
scope.$digest();

// Release mouse button (not really needed, but whatever).
$document.trigger('mouseup');

expect(element.find('[reorderable]:eq(0)')).to.have.text('Qux');
expect(element.find('[reorderable]:eq(1)')).to.have.text('Baz');
expect(element.find('[reorderable]:eq(2)')).to.have.text('Bar');
expect(element.find('[reorderable]:eq(3)')).to.have.text('Foo');

expect(scope.collection[0].name).eql('Qux');
expect(scope.collection[1].name).eql('Baz');
expect(scope.collection[2].name).eql('Bar');
expect(scope.collection[3].name).eql('Foo');
}));

it('should allow to move item forward', inject(function ($document) {
template =
'<ul>' +
Expand Down

0 comments on commit d551b12

Please sign in to comment.