Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
ng-sortable
Advanced tools
Angular Library for Drag and Drop, supports Sortable and Draggable. No JQuery UI used. Supports Touch devices.
Latest release version 1.3.8
The Angular2 version of this Library is coming soon..
[Simple] (http://a5hik.github.io/ng-sortable/#/kanban)
[Advanced] (http://a5hik.github.io/ng-sortable/#/sprint)
Demo Includes:
The directives are structured like below.
as-sortable --> Items list
as-sortable-item --> Item to sort/drag
as-sortable-item-handle --> Drag Handle
longTouch
option to the sortable, setting to true
will cause the drag and drop functionality to get activated upon long-touch
aka touch-and-hold
on touch devices. This maintains the native scroll by dragging functionality on touch devices. Default is set to false
.as-sortable-placeholder
classadditionalPlaceholderClass
option provided to the as-sortable item. e.g.
in JS:
$scope.sortableOptions = { additionalPlaceholderClass: 'some-class' };
in HTML: ...
</div>```
- A customized placeholder can be provided by specifying the `placeholder` option provided to the as-sortable item. `placeholder` can be both a template string or a function returning a template string.
#### Dragging element CSS
- CSS styling may be applied via the "as-sortable-dragging" class
- When the "as-sortable-item" is being dragged, the CSS class "as-sortable-dragging" is added to all elements.
e.g.
in HTML
```<!--not dragging-->````
```<div class="as-sortable-item"></div>````
```<!--when dragging as-sortable-item-->```
```<div class="as-sortable-item as-sortable-dragging"></div>````
in CSS
.as-sortable-dragging{
border: 1px dotted #000 !important;
}
#### Callbacks:
Following callbacks are defined, and should be overridden to perform custom logic.
- callbacks.accept = function (sourceItemHandleScope, destSortableScope, destItemScope) {}; //used to determine drag zone is allowed are not.
###### Parameters:
sourceItemScope - the scope of the item being dragged.
destScope - the sortable destination scope, the list.
destItemScope - the destination item scope, this is an optional Param.(Must check for undefined).
- callbacks.orderChanged = function({type: Object}) // triggered when item order is changed with in the same column.
- callbacks.itemMoved = function({type: Object}) // triggered when an item is moved across columns.
- callbacks.dragStart = function({type: Object}) // triggered on drag start.
- callbacks.dragEnd = function({type: Object}) // triggered on drag end.
##### Parameters:
Object (event) - structure
source:
index: original index before move.
itemScope: original item scope before move.
sortableScope: original sortable list scope.
dest: index
index: index after move.
sortableScope: destination sortable scope.
##### Some Notable Fixes:
- Touch is allowed on only one Item at a time. Tap is prevented on draggable item.
- Pressing 'Esc' key will Cancel the Drag Event, and moves back the Item to it's Original location.
- Right Click on mouse is prevented on draggable Item.
- A child element inside a draggable Item can be made as non draggable.
##### Usage:
Get the binaries of ng-sortable with any of the following ways.
```sh
bower install ng-sortable
Or for yeoman with bower automatic include:
bower install ng-sortable -save
Or bower.json
{
"dependencies": [..., "ng-sortable: "latest_version eg - "1.1.0" ", ...],
}
Or npm
npm install ng-sortable
Make sure to load the scripts in your html.
<script type="text/javascript" src="dist/ng-sortable.min.js"></script>
<link rel="stylesheet" type="text/css" href="dist/ng-sortable.min.css">
<!-- OPTIONAL: default style -->
<link rel="stylesheet" type="text/css" href="dist/ng-sortable.style.min.css">
And Inject the sortable module as dependency.
angular.module('xyzApp', ['as.sortable', '....']);
Invoke the Directives using below html structure.
<ul data-as-sortable="board.dragControlListeners" data-ng-model="items">
<li data-ng-repeat="item in items" data-as-sortable-item>
<div data-as-sortable-item-handle></div>
</li>
</ul>
Define your callbacks in the invoking controller.
$scope.dragControlListeners = {
accept: function (sourceItemHandleScope, destSortableScope) {return boolean}//override to determine drag is allowed or not. default is true.
itemMoved: function (event) {//Do what you want},
orderChanged: function(event) {//Do what you want},
containment: '#board'//optional param.
clone: true //optional param for clone feature.
allowDuplicates: false //optional param allows duplicates to be dropped.
};
$scope.dragControlListeners1 = {
containment: '#board'//optional param.
allowDuplicates: true //optional param allows duplicates to be dropped.
};
That's all you have to do.
Define the accept callback. and the implementation is your choice. The itemHandleScope(dragged Item) and sortableScope(destination list) is exposed. Compare the scope Objects there like below., If you have to exactly restrict moving between columns.
accept: function (sourceItemHandleScope, destSortableScope) {
return sourceItemHandleScope.itemScope.sortableScope.$id === destSortableScope.$id;
}
If you want to restrict only to certain columns say you have 5 columns and you want the drag to be allowed in only 3 columns, then you need to implement your custom logic there., and that too becomes straight forward as you have your scope Objects in hand.
And reversing the condition, allows you to Drag across Columns but not within same Column.
In case you want the item to be reverted back to its original location after a validation failure You can just do the below. In your itemMoved call back define a 'moveSuccess' and 'moveFailure' callbacks. The move failure Impl here just reverts the moved item to its original location.
itemMoved: function (eventObj) {
var moveSuccess, moveFailure;
/**
* Action to perform after move success.
*/
moveSuccess = function() {};
/**
* Action to perform on move failure.
* remove the item from destination Column.
* insert the item again in original Column.
*/
moveFailure = function() {
eventObj.dest.sortableScope.removeItem(eventObj.dest.index);
eventObj.source.itemScope.sortableScope.insertItem(eventObj.source.index, eventObj.source.itemScope.item);
};
}
Horizontal Drag and Drop can be achieved using the same Library. The Column display can be tweaked to have horizontal items and the same can be achieved via some CSS tweaks (like making the column display style to "inline-block"). Added a sample in the demo source (refer plunker.css/js/html).
Plunkr example link: http://a5hik.github.io/ng-sortable/#/horizontal
Implement dragMove callback and follow https://github.com/a5hik/ng-sortable/issues/13#issuecomment-120388981
The Drag can be controlled at runtime and you can enable/disable it by setting the "is-disabled" property to a boolean value of either true or false.
<div as-sortable is-disabled="is-disabled-boolean-property">..</div>
Clone the master $ git clone https://github.com/a5hik/ng-sortable.git
or Download from Source Master
Install Grunt and Bower. $ sudo npm install -g grunt-cli bower
Run the following commands from the project root directory.
$ npm install
$ bower install
$ grunt build - builds the source and generates the min files in dist.
$ grunt serve - runs a local web server on node.js
$ grunt test - runs the tests (WIP).
$ grunt test:continuous - end to end test (WIP).
To access the local server, enter the following URL into your web browser:
http://localhost:9009/demo/
If you use this module you can give it a thumbs up at http://ngmodules.org/modules/ng-sortable.
For Bug report, and feature request File an Issue here: issue.
MIT, see LICENSE.
FAQs
Angular Library for Drag and Drop, supports Sortable and Draggable.
The npm package ng-sortable receives a total of 7,844 weekly downloads. As such, ng-sortable popularity was classified as popular.
We found that ng-sortable demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.