2.0.7 • Published 9 years ago

aurelia-interactjs v2.0.7

Weekly downloads
138
License
MIT
Repository
github
Last release
9 years ago

aurelia-interactjs

Aurelia plugin to use the interact.js library.

Installation

JSPM

Install the package:

jspm i aurelia-interactjs

Add the following line to src/main.js or src/main.ts:

export function configure(aurelia) {
  aurelia.use
    .standardConfiguration()
    .developmentLogging()
+    .plugin("aurelia-interactjs");

Aurelia-CLI

Install the package:

npm i aurelia-interactjs --save

And perform the following command to add the configuration for aurelia-interactjs to the aurelia.json config:

au interact

Add the following line to src/main.js or src/main.ts:

export function configure(aurelia: Aurelia) {
  aurelia.use
    .standardConfiguration()
    .feature('resources')
+    .plugin('aurelia-interactjs');

  if (environment.debug) {
    aurelia.use.developmentLogging();
  }

Generic attributes

Each attribute can be supplied with custom options that will be pased to interactjs, and are split into 2 types. These are Interactable options and Action options.

See the interactjs documentation for the Action options.

Interactable options are described in the code. See the default values here.

Prior to v2.0.7 only, action options were supported by the wrapper, for example:

Usage:

Action options only (pre and post 2.0.7)

<div interact-draggable.bind="actionOptions" />
let actionOptions = {
  overlap: 0.1
} 

Action and Intreactable options usage:

In v2.0.7 and above both types are supported, for example:

<div interact-draggable.bind="options" />
let options = {
  action: { overlap: 0.1 }, 
  interactable: { preventDefault: 'never' }
} 

NOTE: If you use more than one custom attribute on a HTML element (e.g. draggable and dropzone on the same DIV) you should duplicate the interactable options on both as the fist one that is evaluated creates the interactable which is subsequently cached.

Each event can be used in the following way:

<div interact-draggable interact-dragmove.delegate="func($event)" />
export class Home {
  public func(customEvent: CustomEvent) {
    let event = customEvent.detail;
    console.log("event", event);
  }
}

interact-draggable

The following attributes can be set to catch events

AttributeInteract.js event
interact-dragstartdragstart
interact-dragmovedragmove
interact-draginertiastartdraginertiastart
interact-dragenddragend

interact-dropzone

AttributeInteract.js event
interact-dropactivatedropactivate
interact-dragenterdragenter
interact-dragleavedragleave
interact-dropdrop
interact-dropdeactivatedropdeactivate

interact-gesturable

AttributeInteract.js event
interact-gesturestartgesturestart
interact-gesturemovegesturemove
interact-gestureendgestureend

interact-resizable

AttributeInteract.js event
interact-resizestartresizestart
interact-resizemoveresizemove
interact-resizeinertiastartresizeinertiastart
interact-resizeendresizeend

Custom attributes draggable and dropzone

By default the attributes draggable and dropzone are not loaded (because the use global names).

You can load them by providing the option enableDragDropAttributes in src\main.js or src\main.ts :

export function configure(aurelia) {
  aurelia.use
    .standardConfiguration()
    .developmentLogging()
+    .plugin("aurelia-interactjs", { enableDragDropAttributes: true });
<div draggable.bind="item" style="width: 25px; height: 25px; background-color:${color}; border: 5px solid yellow">drag me</div>

<div dropzone drop.trigger="itemDropped($event.detail, 'green')" style="width:300px; height: 300px; background-color: green"></div>
<div dropzone drop.trigger="itemDropped($event.detail, 'red')" style="width:300px; height: 300px; background-color: red"></div>
export class App {
  item = { name: "some", color: "yellow"};

  updateColor(item, color) {
    item.color = color;
  }

}

By default it will add the following css classes to the element in the following states:

draggable

classstate
getting--draggeddraggable is getting dragged
drop--medraggable entered a dropzone and can be dropped here

dropzone

classstate
can--dropdraggable target can be dropped in the dropzone
can-catchdraggable entered this zone and can be dropped here
caught--itdraggable element is dropped in this zone
2.0.7

9 years ago

2.0.1

9 years ago

1.0.10

9 years ago

1.0.9

9 years ago

1.0.8

9 years ago

1.0.7

9 years ago

1.0.6

9 years ago

1.0.5

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago