Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed sort algo, making sure that if ng-if is used in an ng-repeat,… #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 38 additions & 7 deletions src/angular-sortable-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,44 @@

if($target){
$target.element.removeClass('sv-candidate');
var spliced = originatingPart.model(originatingPart.scope).splice(index, 1);

var srcIndex = index;
var targetIndex = $target.targetIndex;
if($target.view === originatingPart && $target.targetIndex > index)
targetIndex--;
if($target.after)
targetIndex++;
$target.view.model($target.view.scope).splice(targetIndex, 0, spliced[0]);
var direction = ( targetIndex >= index ? 1 : -1 );
var origArray = originatingPart.model( originatingPart.scope );
var visibleArray = getSortableElements( mapKey );

var spliced = [ origArray[ srcIndex ] ];

var copy = origArray[ srcIndex ];
if ( direction > 0 ) {
var prevOrigIndex = null;
visibleArray.forEach( function( e, i ) {
var currOrigIndex = e.getIndex ? e.getIndex() : -1;
if ( currOrigIndex > srcIndex && currOrigIndex <= targetIndex ) {
origArray[ prevOrigIndex ] = origArray[ currOrigIndex ];
}
prevOrigIndex = currOrigIndex;
} );
}
else {
var prevCopy = null;
visibleArray.forEach( function( e, i ) {
var currOrigIndex = e.getIndex ? e.getIndex() : -1;
var currCopy = origArray[ currOrigIndex ];
if ( currOrigIndex > targetIndex && currOrigIndex <= srcIndex ) {
origArray[ currOrigIndex ] = prevCopy;
}
prevCopy = currCopy;
} );
}
origArray[ targetIndex ] = copy;







// sv-on-sort callback
if($target.view !== originatingPart || index !== targetIndex)
Expand Down Expand Up @@ -622,4 +653,4 @@
};
}

})(window, window.angular);
})(window, window.angular);
2 changes: 1 addition & 1 deletion src/angular-sortable-view.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.