Launch Week Day 5: Introducing Reachability for PHP.Learn More
Socket
Book a DemoSign in
Socket

tonic-mouse-handler

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tonic-mouse-handler - npm Package Compare versions

Comparing version
0.0.5
to
0.0.6
+5
.travis.yml
language: node_js
node_js:
- "0.12"
sudo: false
script: npm build
+23
-19
# MouseHandler
This class allow the user to ease the management of complex mouse interaction
without having to duplicate the coordinate system management and drag logic
across several projects.
This class eases the management of complex mouse and touch
interactions without having to duplicate coordinate-system management
and drag logic across several projects.
## Constructor( domElement )
## constructor(domElement, [options])
This will attach the touch and mouse listener to a given DOM element.
Attaches the touch and mouse listener to a given DOM element.
Options is an object with the keys _pan_ and _pinch_, associated with is an object with
the key _threshold_. You can overwrite _threshold_ or add additional [gesture options](http://hammerjs.github.io/recognizer-pan/) which get
passed to TonicMouseHandler's hammerjs instance.
## enablePinch(enable)
You can enable or disable the __pinch__ handling by calling that method with
true or false. By default, the mouse handler will listen to that event.
Enables or disables the __pinch__ handling by calling that method with
true or false. By default, the mouse handler will be enabled with the event.
## setModifier(modifier)
This method let you override the event modifier so you can simulate a ALT + drag
Overrides the event modifier so you can simulate a ALT + drag
on a mobile device as well.
The modifier code are as follow and use the bitwise logic.
The modifiers are as follows and use the associated bitwise logic.

@@ -31,11 +34,11 @@ - __NONE__: 0

This will detach any listener and free the resources.
The instance is not supposed to work after that.
Detach any listener and free the resources.
The instance should not work after that.
## on(type, callback): subscription
This allow you to bind your own listener to the high level events.
Bind your own listeners to high level events.
We rely on monologue.js for subscribing to the events.
The callback should look like
The callback should look like:

@@ -48,3 +51,3 @@ ```js

The event should look like
The corresponding event should look like:

@@ -82,3 +85,3 @@ ```js

The set of possible topic that you can listen to are:
The set of possible events that you can listen to are:

@@ -93,4 +96,4 @@ - __drag__

This allow to set a modifier by a long press.
The modifiers is an array of modifier that we want to loop over for every long
Sets a modifier by a long press.
Modifiers is an array of modifiers that we want to loop over for every long
press.

@@ -104,6 +107,7 @@

This helper method ease the binding of several listeners to the current
Helper method to ease the binding of several listeners to the current
MouseHandler instance.
The code should explain what that method is doing.
Equivalent to:
```js

@@ -110,0 +114,0 @@ function(listeners) {

@@ -51,3 +51,3 @@ ---

{% highlight bash %}
~ $ npm install {{ site.project }} --save
$ npm install {{ site.project }} --save
{% endhighlight %}

@@ -59,7 +59,7 @@

{% highlight bash %}
~ $ git clone git@github.com:{{site.repository}}.git
~ $ cd {{site.project}}
~/{{site.project}} $ npm install
~/{{site.project}} $ npm test
# => Browse on http://localhost:3000
$ git clone git@github.com:{{site.repository}}.git
$ cd {{site.project}}
$ npm install
$ npm test
# => Open http://localhost:3000 in a browser
{% endhighlight %}

@@ -66,0 +66,0 @@

@@ -531,3 +531,3 @@ /*!

#sidebar {
width: 250px;
width: 300px;
position: absolute;

@@ -628,3 +628,3 @@ overflow-y: auto;

margin:0 auto;
padding:1em 2em 5em 280px;
padding:1em 2em 5em 330px;
}

@@ -631,0 +631,0 @@

@@ -70,5 +70,5 @@ <!DOCTYPE html>

<p>This class allow the user to ease the management of complex mouse interaction
without having to duplicate the coordinate system management and drag logic
across several projects.</p>
<p>This class eases the management of complex mouse and touch
interactions without having to duplicate coordinate-system management
and drag logic across several projects.</p>

@@ -78,3 +78,3 @@ <h2>Table of Contents <a href="#toc" name="toc" class="deep-link">#</a></h2>

<ul>
<li><a href="#Constructor">Constructor()</a></li>
<li><a href="#constructor">constructor()</a></li>
<li><a href="#enablePinch">enablePinch()</a></li>

@@ -88,17 +88,20 @@ <li><a href="#setModifier">setModifier()</a></li>

<h2>Constructor( domElement ) <a href="#Constructor" id="Constructor" class="deep-link">#</a></h2>
<h2>constructor(domElement, [options]) <a href="#constructor" id="constructor" class="deep-link">#</a></h2>
<p>This will attach the touch and mouse listener to a given DOM element.</p>
<p>Attaches the touch and mouse listener to a given DOM element.
Options is an object with the keys <em>pan</em> and <em>pinch</em>, associated with is an object with
the key <em>threshold</em>. You can overwrite <em>threshold</em> or add additional <a href="http://hammerjs.github.io/recognizer-pan/">gesture options</a> which get
passed to TonicMouseHandler's hammerjs instance.</p>
<h2>enablePinch(enable) <a href="#enablePinch" id="enablePinch" class="deep-link">#</a></h2>
<p>You can enable or disable the <strong>pinch</strong> handling by calling that method with
true or false. By default, the mouse handler will listen to that event.</p>
<p>Enables or disables the <strong>pinch</strong> handling by calling that method with
true or false. By default, the mouse handler will be enabled with the event.</p>
<h2>setModifier(modifier) <a href="#setModifier" id="setModifier" class="deep-link">#</a></h2>
<p>This method let you override the event modifier so you can simulate a ALT + drag
<p>Overrides the event modifier so you can simulate a ALT + drag
on a mobile device as well.</p>
<p>The modifier code are as follow and use the bitwise logic.</p>
<p>The modifiers are as follows and use the associated bitwise logic.</p>

@@ -115,11 +118,11 @@ <ul>

<p>This will detach any listener and free the resources.
The instance is not supposed to work after that.</p>
<p>Detach any listener and free the resources.
The instance should not work after that.</p>
<h2>on(type, callback): subscription <a href="#on" id="on" class="deep-link">#</a></h2>
<p>This allow you to bind your own listener to the high level events.
<p>Bind your own listeners to high level events.
We rely on monologue.js for subscribing to the events.</p>
<p>The callback should look like</p>
<p>The callback should look like:</p>

@@ -132,3 +135,3 @@ <pre class="brush:js">

<p>The event should look like</p>
<p>The corresponding event should look like:</p>

@@ -166,3 +169,3 @@ <pre class="brush:js">

<p>The set of possible topic that you can listen to are:</p>
<p>The set of possible events that you can listen to are:</p>

@@ -179,4 +182,4 @@ <ul>

<p>This allow to set a modifier by a long press.
The modifiers is an array of modifier that we want to loop over for every long
<p>Sets a modifier by a long press.
Modifiers is an array of modifiers that we want to loop over for every long
press.</p>

@@ -190,6 +193,7 @@

<p>This helper method ease the binding of several listeners to the current
MouseHandler instance.
The code should explain what that method is doing.</p>
<p>Helper method to ease the binding of several listeners to the current
MouseHandler instance.</p>
<p>Equivalent to:</p>
<pre class="brush:js">

@@ -196,0 +200,0 @@ function(listeners) {

@@ -9,25 +9,27 @@ <div class="hd">

<div class="toc-list">
<a class="toc-item" href="MouseHandler.html#Constructor">
<h4>Constructor( domElement )</h4>
<span class="desc">This will attach the touch and mouse listener to a given DOM element.</span>
<a class="toc-item" href="MouseHandler.html#constructor">
<h4>constructor(domElement, [options])</h4>
<span class="desc">Attaches the touch and mouse listener to a given DOM element. Options is an object with the keys <em>pan</em> and <em>pinch</em>, associated with is an object with
the key <em>threshold</em>. You can overwrite <em>threshold</em> or add additional gesture options which get
passed to TonicMouseHandler's hammerjs instance.</span>
</a>
<a class="toc-item" href="MouseHandler.html#enablePinch">
<h4>enablePinch(enable)</h4>
<span class="desc">You can enable or disable the <strong>pinch</strong> handling by calling that method with true or false. By default, the mouse handler will listen to that event.</span>
<span class="desc">Enables or disables the <strong>pinch</strong> handling by calling that method with true or false. By default, the mouse handler will be enabled with the event.</span>
</a>
<a class="toc-item" href="MouseHandler.html#setModifier">
<h4>setModifier(modifier)</h4>
<span class="desc">This method let you override the event modifier so you can simulate a ALT + drag on a mobile device as well.</span>
<span class="desc">Overrides the event modifier so you can simulate a ALT + drag on a mobile device as well.</span>
</a>
<a class="toc-item" href="MouseHandler.html#destroy">
<h4>destroy()</h4>
<span class="desc">This will detach any listener and free the resources. The instance is not supposed to work after that.</span>
<span class="desc">Detach any listener and free the resources. The instance should not work after that.</span>
</a>
<a class="toc-item" href="MouseHandler.html#on">
<h4>on(type, callback): subscription</h4>
<span class="desc">This allow you to bind your own listener to the high level events. We rely on monologue.js for subscribing to the events.</span>
<span class="desc">Bind your own listeners to high level events. We rely on monologue.js for subscribing to the events.</span>
</a>
<a class="toc-item" href="MouseHandler.html#toggleModifierOnPress">
<h4>toggleModifierOnPress(enable, modifiers)</h4>
<span class="desc">This allow to set a modifier by a long press. The modifiers is an array of modifier that we want to loop over for every long
<span class="desc">Sets a modifier by a long press. Modifiers is an array of modifiers that we want to loop over for every long
press.</span>

@@ -37,4 +39,3 @@ </a>

<h4>attach(listeners): subscriptions</h4>
<span class="desc">This helper method ease the binding of several listeners to the current MouseHandler instance.
The code should explain what that method is doing.</span>
<span class="desc">Helper method to ease the binding of several listeners to the current MouseHandler instance.</span>
</a>

@@ -41,0 +42,0 @@ </div>

@@ -125,4 +125,8 @@ <!DOCTYPE html>

<option value="/tonic-mouse-handler/dev/">Development</option>
<option value="/tonic-mouse-handler/api/">API</option>
<option value="/tonic-mouse-handler/source/MouseHandler.html">Source</option>
</optgroup>

@@ -155,2 +159,8 @@ </select>

<h2>Status</h2>
<p><a href="https://travis-ci.org/Kitware/tonic-mouse-handler"><img src="https://travis-ci.org/Kitware/tonic-mouse-handler.svg" alt="Build Status"></a>
<a href="https://david-dm.org/Kitware/tonic-mouse-handler"><img src="https://david-dm.org/Kitware/tonic-mouse-handler.svg" alt="Dependency Status"></a>
<a href="#"><img src="https://img.shields.io/badge/api_stability-fair-green.svg" alt="api_stability: fair"></a> <a href="#"><img src="https://img.shields.io/badge/feature_complete-%E2%98%85%E2%98%85%E2%98%85%E2%98%85%E2%98%86-green.svg" alt="feature_complete: ★★★★☆"></a> </p>
<script type="text/javascript">

@@ -291,4 +301,8 @@ var xmlhttp = new XMLHttpRequest();

<li><a class="page-link" href="/tonic-mouse-handler/dev/">Development</a></li>
<li><a class="page-link" href="/tonic-mouse-handler/api/">API</a></li>
<li><a class="page-link" href="/tonic-mouse-handler/source/MouseHandler.html">Source</a></li>
</ul>

@@ -295,0 +309,0 @@ </aside>

@@ -125,4 +125,8 @@ <!DOCTYPE html>

<option value="/tonic-mouse-handler/dev/">Development</option>
<option value="/tonic-mouse-handler/api/">API</option>
<option value="/tonic-mouse-handler/source/MouseHandler.html">Source</option>
</optgroup>

@@ -295,4 +299,8 @@ </select>

<li><a class="page-link" href="/tonic-mouse-handler/dev/">Development</a></li>
<li><a class="page-link" href="/tonic-mouse-handler/api/">API</a></li>
<li><a class="page-link" href="/tonic-mouse-handler/source/MouseHandler.html">Source</a></li>
</ul>

@@ -299,0 +307,0 @@ </aside>

@@ -125,4 +125,8 @@ <!DOCTYPE html>

<option value="/tonic-mouse-handler/dev/">Development</option>
<option value="/tonic-mouse-handler/api/">API</option>
<option value="/tonic-mouse-handler/source/MouseHandler.html">Source</option>
</optgroup>

@@ -291,4 +295,8 @@ </select>

<li><a class="page-link" href="/tonic-mouse-handler/dev/">Development</a></li>
<li><a class="page-link" href="/tonic-mouse-handler/api/">API</a></li>
<li><a class="page-link" href="/tonic-mouse-handler/source/MouseHandler.html">Source</a></li>
</ul>

@@ -295,0 +303,0 @@ </aside>

@@ -125,4 +125,8 @@ <!DOCTYPE html>

<option value="/tonic-mouse-handler/dev/">Development</option>
<option value="/tonic-mouse-handler/api/">API</option>
<option value="/tonic-mouse-handler/source/MouseHandler.html">Source</option>
</optgroup>

@@ -322,4 +326,8 @@ </select>

<li><a class="page-link" href="/tonic-mouse-handler/dev/">Development</a></li>
<li><a class="page-link" href="/tonic-mouse-handler/api/">API</a></li>
<li><a class="page-link" href="/tonic-mouse-handler/source/MouseHandler.html">Source</a></li>
</ul>

@@ -326,0 +334,0 @@ </aside>

@@ -8,4 +8,4 @@ <?xml version="1.0" encoding="UTF-8"?>

<atom:link href="/tonic-mouse-handler/feed.xml" rel="self" type="application/rss+xml"/>
<pubDate>Wed, 22 Jul 2015 12:09:19 -0600</pubDate>
<lastBuildDate>Wed, 22 Jul 2015 12:09:19 -0600</lastBuildDate>
<pubDate>Thu, 13 Aug 2015 13:51:48 -0600</pubDate>
<lastBuildDate>Thu, 13 Aug 2015 13:51:48 -0600</lastBuildDate>
<generator>Jekyll v2.5.3</generator>

@@ -12,0 +12,0 @@

@@ -96,3 +96,3 @@ <!DOCTYPE html>

<div class="highlight"><pre><code class="language-bash" data-lang="bash">~ <span class="nv">$ </span>npm install tonic-mouse-handler --save</code></pre></div>
<div class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span>npm install tonic-mouse-handler --save</code></pre></div>

@@ -104,7 +104,7 @@

<div class="highlight"><pre><code class="language-bash" data-lang="bash">~ <span class="nv">$ </span>git clone git@github.com:Kitware/tonic-mouse-handler.git
~ <span class="nv">$ </span><span class="nb">cd </span>tonic-mouse-handler
~/tonic-mouse-handler <span class="nv">$ </span>npm install
~/tonic-mouse-handler <span class="nv">$ </span>npm <span class="nb">test</span>
<span class="c"># =&gt; Browse on http://localhost:3000</span></code></pre></div>
<div class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span>git clone git@github.com:Kitware/tonic-mouse-handler.git
<span class="nv">$ </span><span class="nb">cd </span>tonic-mouse-handler
<span class="nv">$ </span>npm install
<span class="nv">$ </span>npm <span class="nb">test</span>
<span class="c"># =&gt; Open http://localhost:3000 in a browser</span></code></pre></div>

@@ -111,0 +111,0 @@

@@ -60,2 +60,3 @@ <!DOCTYPE html>

Hammer = <span class="hljs-built_in">require</span>(<span class="hljs-string">'hammerjs'</span>),
merge = <span class="hljs-built_in">require</span>(<span class="hljs-string">'mout/src/object/merge'</span>),
handlerCount = <span class="hljs-number">0</span>,

@@ -82,2 +83,9 @@ Modifier = { NONE:<span class="hljs-number">0</span>, ALT:<span class="hljs-number">1</span>, META:<span class="hljs-number">2</span>, SHIFT:<span class="hljs-number">4</span>, CTRL:<span class="hljs-number">8</span> },

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getRelative</span>(<span class="hljs-params">el, event</span>) </span>{
<span class="hljs-keyword">return</span> {
x: event.center.x - (el.getClientRects()[<span class="hljs-number">0</span>].x || el.getClientRects()[<span class="hljs-number">0</span>].left),
y: event.center.y - (el.getClientRects()[<span class="hljs-number">0</span>].y || el.getClientRects()[<span class="hljs-number">0</span>].top)
};
}
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">broadcast</span>(<span class="hljs-params">ctx, topic, event</span>) </span>{

@@ -89,6 +97,3 @@ event.preventDefault();

event.modifier = ctx.modifier ? ctx.modifier : getModifier(event);
event.relative = {
x: event.center.x - (ctx.el.getClientRects()[<span class="hljs-number">0</span>].x || ctx.el.getClientRects()[<span class="hljs-number">0</span>].left),
y: event.center.y - (ctx.el.getClientRects()[<span class="hljs-number">0</span>].y || ctx.el.getClientRects()[<span class="hljs-number">0</span>].top)
}
event.relative = getRelative(ctx.el, event);

@@ -98,3 +103,13 @@ ctx.emit(topic, event);

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">MouseHandler</span>(<span class="hljs-params">domElement</span>) </span>{
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">MouseHandler</span>(<span class="hljs-params">domElement, options</span>) </span>{
<span class="hljs-keyword">var</span> defaultOptions = {
pan: {
threshold: <span class="hljs-number">0</span>
},
pinch: {
threshold: <span class="hljs-number">0</span>
}
};
options = merge(defaultOptions, options);
<span class="hljs-keyword">this</span>.id = <span class="hljs-string">'mouse_handler_'</span> + (++handlerCount);

@@ -183,2 +198,10 @@ <span class="hljs-keyword">this</span>.el = domElement;

<p>set hammer options</p>
<div class='highlight'><pre> <span class="hljs-keyword">this</span>.hammer.get(<span class="hljs-string">'pan'</span>).set(options.pan);
<span class="hljs-keyword">this</span>.hammer.get(<span class="hljs-string">'pinch'</span>).set(options.pinch);</pre></div>
<p>Listen to hammer events</p>

@@ -210,3 +233,5 @@

<span class="hljs-keyword">this</span>.emit(<span class="hljs-string">'modifier.change'</span>, { value: <span class="hljs-keyword">this</span>.modifier, list: Modifier });
e.relative = getRelative(<span class="hljs-keyword">this</span>.el, e);
<span class="hljs-keyword">this</span>.emit(<span class="hljs-string">'modifier.change'</span>, { value: <span class="hljs-keyword">this</span>.modifier, list: Modifier, event: e });
}

@@ -213,0 +238,0 @@ });</pre></div>

// Module dependencies and constants
var Monologue = require('monologue.js'),
Hammer = require('hammerjs'),
merge = require('mout/src/object/merge'),
handlerCount = 0,

@@ -43,3 +44,13 @@ Modifier = { NONE:0, ALT:1, META:2, SHIFT:4, CTRL:8 },

export default function MouseHandler(domElement) {
export default function MouseHandler(domElement, options) {
var defaultOptions = {
pan: {
threshold: 0
},
pinch: {
threshold: 0
}
};
options = merge(defaultOptions, options);
this.id = 'mouse_handler_' + (++handlerCount);

@@ -122,2 +133,6 @@ this.el = domElement;

// set hammer options
this.hammer.get('pan').set(options.pan);
this.hammer.get('pinch').set(options.pinch);
// Listen to hammer events

@@ -124,0 +139,0 @@ this.hammer.on('tap', (e) => {

{
"name": "tonic-mouse-handler",
"description": "JavaScript library used to simplify mouse handling via a consistent API across modern browser.",
"version": "0.0.5",
"version": "0.0.6",
"license": "BSD-3-Clause",

@@ -13,7 +13,7 @@ "main": "./lib/MouseHandler.js",

"hammerjs": "2.0.4",
"monologue.js": "0.3.3"
"monologue.js": "0.3.3",
"mout": "0.11.0"
},
"devDependencies": {
"tonic-site-generator": "Kitware/tonic-site-generator",
"jshint": "2.8.0",

@@ -34,6 +34,4 @@ "jshint-loader": "0.8.3",

"build:release": "webpack -p",
"www": "tonic-site-generator site.config.js",
"www:http" : "tonic-site-generator site.config.js --local-test && serve docs/www",
"www:http": "tonic-site-generator site.config.js --local-test && serve docs/www",
"pretest": "npm run build",

@@ -40,0 +38,0 @@ "test": "cp dist/* tests/ && serve ./tests"

@@ -1,7 +0,12 @@

## Simple mouse interaction handler [Home page](http://kitware.github.io/tonic-mouse-handler/)
# Simple mouse interaction handler
[![Build Status](https://travis-ci.org/Kitware/tonic-mouse-handler.svg)](https://travis-ci.org/Kitware/tonic-mouse-handler)
[![Dependency Status](https://david-dm.org/kitware/tonic-mouse-handler.svg)](https://david-dm.org/kitware/tonic-mouse-handler)
[Home page](http://kitware.github.io/tonic-mouse-handler/)
Tonic Mouse Handler provides a concise and consistent API for mouse interaction
with proper coordinate system and drag callback.
with proper coordinate system and drag callback.
To learn more what _Tonic Mouse Handler_ can do for you read the
To learn more what _Tonic Mouse Handler_ can do for you read the
[Quick start](http://kitware.github.io/tonic-mouse-handler/docs/home/) guide.

@@ -14,7 +19,7 @@

#### Licensing
### Licensing
**tonic-mouse-handler** is licensed under [BSD Clause 3](LICENSE).
#### Getting Involved
### Getting Involved

@@ -21,0 +26,0 @@ Fork our repository and do great things. At [Kitware](http://www.kitware.com),

@@ -22,4 +22,8 @@ module.exports = {

"timezone": "America/Denver",
"project": "tonic-mouse-handler"
"project": "tonic-mouse-handler",
"status": [
{"subject": "api_stability", "status": "fair", "color": "green"},
{"subject": "feature_complete", "status": "★★★★☆", "color": "green"}
]
}
};

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display