npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

blvd-sortable

v0.1.0

Published

Drag to reorder elements.

Downloads

192

Readme

Sortable

Sortable is an AngularJS module for sorting an arbitrary set of UI elements by dragging them.

License

This software is provided free of charge and without restriction under the MIT License

Demo

https://boulevard.github.io/sortable

Installation

Using Bower

This package is installable through the Bower package manager.

bower install blvd-sortable --save

In your index.html file, include the sortable module.

<script type="text/javascript" src="bower_components/sortable/dist/sortable.min.js"></script>

Include the sortable module as a dependency in your application.

angular.module('myApp', ['sortable']);

Using npm and a Module Bundler (webpack or Browserify or jspm)

In addition, this package may be installed using npm.

npm install blvd-sortable --save

You may use Browserify to inject this module into your application.

angular.module('myApp', [require('blvd-sortable')]);

Usage

Basic Usage

<div>Rank your favorite junk food.</div>

<ol sortable>
  <li>Reeses Peanut Butter Cup</li>
  <li>Hostess Twinkies</li>
  <li>Ben & Jerry's Ice Cream</li>
</ol>

Responding to drag events

class SortableController {
  canSort = true;

  onDragStart = (element) => {
    ...
  }
  
  onDragMove = (element) => {
    ...
  }

  onDragEnd = (element, newIndex, oldIndex, sequence) => {
    ...
  }
}
<div>Rank your favorite junk food.</div>

<ol sortable="$ctrl.canSort" drag-start="$ctrl.onDragStart" drag-move="$ctrl.onDragMove" drag-end="$ctrl.onDragEnd">
  <li>Reeses Peanut Butter Cup</li>
  <li>Hostess Twinkies</li>
  <li>Ben & Jerry's Ice Cream</li>
</ol>

Caveats

Fixed elements are normally positioned relative to the initial containing block established by the viewport; however, when an ancestor of the element has a transform, perspective, or filter property it becomes the containing element. This complicates computing the position of the element being dragged. One solution may be to move the element being dragged to the document body, but that could conflict with computed css styles. For now I would recommend adding the following dragStart callback to manually correct the element's position.

function onDragStart(element) {
  // obtain the culprit element
  var transformedElement = document.querySelector('[style="transform: ..."]');
  var bounds = transformedElement.getBoundingClientRect();

  // correct the element's position
  element.css('left', element.css('left').slice(0, -2) - bounds.left + 'px');
  element.css('top', element.css('top').slice(0, -2) - bounds.top + 'px');
}

API Documentation

Don't forget to kebab-case attributes in your template (e.g. dragEnd should be written drag-end in your template).

Attributes

| Attribute | Type | Details | | :------------------------------------- | :----------- | :------ | | dragEnd (optional) | Function | Callback function on drag end. (see below for arguments) | | dragMove (optional) | Function | Callback function on drag move. (see below for arguments) | | dragStart (optional) | Function | Callback function on drag start. (see below for arguments) | | ngModel (optional) | Array | The array will be reordered as elements are sorted in the UI. | | options (optional) | Object | Configurable options. (see below for details) | | sortable | expression | Will enable sorting if empty or evaluates to true. |

Callbacks

dragStart(element)

| Argument | Type | Details | | :--------- | :-------- | :------ | | element | jqLite | The element being dragged. |

dragMove(element)

| Argument | Type | Details | | :--------- | :-------- | :------ | | element | jqLite | The element being dragged. |

dragEnd(element, newIndex, oldIndex, [sequence])

| Argument | Type | Details | | :--------- | :-------- | :------ | | element | jqLite | The element being dragged. | | newIndex | Integer | The new index of the element. | | oldIndex | Integer | The old index of the element. | | sequence | Array | A reference to the sequence. Requires ngModel |

Options

| Property | Type | Details | | :---------- | :-------- | :------ | | dropzone | String | Provide a template for the drop zone. By default an empty element with the same tag name as the element being dragged will be created. | | sameSize | Boolean | Will make the dropzone the same size as the element being dragged. The default is true | | threshold | Number | The magnitude, in pixels, the user must drag before initiating a drag. The default is 2 |

Styling

The element being dragged will have the dragging class. The drop zone will have the drop-zone class.