implement pinch to zoom

This commit is contained in:
marlon-erler
2026-08-30 16:15:14 +02:00
parent ea50704f8a
commit 7eb02f07dc
160 changed files with 15806 additions and 61 deletions
+2
View File
@@ -0,0 +1,2 @@
components
build
+53
View File
@@ -0,0 +1,53 @@
1.0.10 / 2014-04-01
==================
* component, package: bump component-delegate dependency to 0.2.4
* index: Fall back to require('component-*') for node compat
1.0.9 / 2014-08-01
==================
* component, package: update "delegate" to v0.2.3
1.0.8 / 2014-07-21
==================
* component, package: update "event" to v0.1.4
1.0.7 / 2014-05-27
==================
* component, package: update "component/delegate" to v0.2.2
1.0.6 / 2014-02-10
==================
* package: rename to "component-events"
* component: update "event" to v0.1.3
1.0.5 / 2014-01-22
==================
* update deps
1.0.4 / 2013-07-28
==================
* add delegation support and inline manager
1.0.3 / 2013-05-27
==================
* pin deps
* rename for broken npm tooling
1.0.2 / 2013-01-08
==================
* fix unbind
1.0.1 / 2013-01-08
==================
* fix typo
+11
View File
@@ -0,0 +1,11 @@
build: components index.js
@component build --dev
components: component.json
@component install --dev
clean:
rm -fr build components template.js
.PHONY: clean
+112
View File
@@ -0,0 +1,112 @@
# events
Higher level dom event management with direct and delegate event handling support.
This component makes subscription management easy and unobtrusive since it does not muck with your view prototypes. Unbinding to "clean up" after your view is as simple as invoking `this.events.unbind()`, or more specific unbinds may be performed.
It's design to work with a "host" object, typically a view, that provides callbacks, making callback management much less tedious than libraries like jQuery.
## Installation
$ component install component/events
## Example
```js
var events = require('events');
var el = document.querySelector('.user');
var view = new UserView(el);
function UserView(el) {
this.events = events(el, this);
this.events.bind('click .remove', 'remove');
this.events.bind('click .hide', 'hide');
}
UserView.prototype.remove = function(){
// remove the user
this.hide();
};
UserView.prototype.hide = function(){
// hide the view
};
UserView.prototype.destroy = function(){
// clean up anything you need to
this.events.unbind();
};
```
## API
### Events(el, obj)
Initialize a new events manager targetting the
given element. Methods are delegated to `obj`.
### Events#bind(event, [method])
Bind direct event handlers or delegates with `event` and
invoke `method` when the event occurs, passing the event object.
When `method` is not defined the `event` name prefixed with "on" is used.
For example the following will invoke `onmousedown`, `onmousemove`,
and `onmouseup`:
```js
events.bind('mousedown')
events.bind('mousemove')
events.bind('mouseup')
```
Alternatively you may specify the `method` name:
```js
events.bind('click', 'toggleDisplay')
```
To use event delegation simply pass a selector after the
event name as shown here:
```js
events.bind('click .remove', 'remove')
events.bind('click .close', 'hide')
```
You may bind to the same element with several events if necessary,
for example here perhaps `.remove()` does not manually invoke `.hide()`:
```js
events.bind('click .remove', 'remove')
events.bind('click .remove', 'hide')
events.bind('click .close', 'hide')
```
Addition arguments are passed to the callee, which
is helpful for slight variations of a method, for
example sorting:
```js
events.bind('click .sort-asc', 'sort', 'asc')
events.bind('click .sort-dsc', 'sort', 'dsc')
```
### Events.unbind([event], [method])
There are three flavours of unbinding -- you may unbind _all_
event handlers, all specific to `event`, or all specific to
`event` and the given `method`. For example these are all valid:
```js
events.unbind('click', 'remove')
events.unbind('click', 'hide')
events.unbind('click')
events.unbind()
```
## License
MIT
+20
View File
@@ -0,0 +1,20 @@
{
"name": "events",
"repo": "component/events",
"description": "Higher level dom event management",
"version": "1.0.10",
"keywords": [
"event",
"events",
"subscriptions"
],
"dependencies": {
"component/event": "0.1.4",
"component/delegate": "0.2.4"
},
"development": {},
"license": "MIT",
"scripts": [
"index.js"
]
}
+45
View File
@@ -0,0 +1,45 @@
<html>
<head>
<title>Events</title>
<style>
body {
padding: 150px;
}
ul li {
padding: 5px;
}
</style>
</head>
<body>
<ul>
<li><a href="#">One</a></li>
<li><a href="#">Two</a></li>
<li><a href="#">Three</a></li>
</ul>
<button onclick="unbind()">Unbind</button>
<script src="../build/build.js"></script>
<script>
var Events = require('events');
var ul = document.querySelector('ul');
var events = Events(ul, {
onclick: function(e){
alert('clicked ' + e.target.textContent)
},
first: function(e){
alert('clicked the first');
}
});
events.bind('click li > a');
events.bind('click li:first-child > a', 'first');
function unbind() {
events.unbind('click', 'onclick');
// events.unbind('click');
// events.unbind();
}
</script>
</body>
</html>
+26
View File
@@ -0,0 +1,26 @@
<html>
<head>
<title>Events</title>
</head>
<body>
<button>Click me</button>
<button onclick="unbind()">Unbind</button>
<script src="../build/build.js"></script>
<script>
var Events = require('events');
var button = document.querySelector('button');
var events = Events(button, {
onclick: function(){
alert('clicked')
}
});
events.bind('click');
function unbind() {
events.unbind();
}
</script>
</body>
</html>
+26
View File
@@ -0,0 +1,26 @@
<html>
<head>
<title>Events</title>
</head>
<body>
<button>Click me</button>
<button onclick="unbind()">Unbind</button>
<script src="../build/build.js"></script>
<script>
var Events = require('events');
var button = document.querySelector('button');
var events = Events(button, {
remove: function(){
alert('removed')
}
});
events.bind('click', 'remove');
function unbind() {
events.unbind();
}
</script>
</body>
</html>
+185
View File
@@ -0,0 +1,185 @@
/**
* Module dependencies.
*/
try {
var events = require('event');
} catch(err) {
var events = require('component-event');
}
try {
var delegate = require('delegate');
} catch(err) {
var delegate = require('component-delegate');
}
/**
* Expose `Events`.
*/
module.exports = Events;
/**
* Initialize an `Events` with the given
* `el` object which events will be bound to,
* and the `obj` which will receive method calls.
*
* @param {Object} el
* @param {Object} obj
* @api public
*/
function Events(el, obj) {
if (!(this instanceof Events)) return new Events(el, obj);
if (!el) throw new Error('element required');
if (!obj) throw new Error('object required');
this.el = el;
this.obj = obj;
this._events = {};
}
/**
* Subscription helper.
*/
Events.prototype.sub = function(event, method, cb){
this._events[event] = this._events[event] || {};
this._events[event][method] = cb;
};
/**
* Bind to `event` with optional `method` name.
* When `method` is undefined it becomes `event`
* with the "on" prefix.
*
* Examples:
*
* Direct event handling:
*
* events.bind('click') // implies "onclick"
* events.bind('click', 'remove')
* events.bind('click', 'sort', 'asc')
*
* Delegated event handling:
*
* events.bind('click li > a')
* events.bind('click li > a', 'remove')
* events.bind('click a.sort-ascending', 'sort', 'asc')
* events.bind('click a.sort-descending', 'sort', 'desc')
*
* @param {String} event
* @param {String|function} [method]
* @return {Function} callback
* @api public
*/
Events.prototype.bind = function(event, method){
var e = parse(event);
var el = this.el;
var obj = this.obj;
var name = e.name;
var method = method || 'on' + name;
var args = [].slice.call(arguments, 2);
// callback
function cb(){
var a = [].slice.call(arguments).concat(args);
obj[method].apply(obj, a);
}
// bind
if (e.selector) {
cb = delegate.bind(el, e.selector, name, cb);
} else {
events.bind(el, name, cb);
}
// subscription for unbinding
this.sub(name, method, cb);
return cb;
};
/**
* Unbind a single binding, all bindings for `event`,
* or all bindings within the manager.
*
* Examples:
*
* Unbind direct handlers:
*
* events.unbind('click', 'remove')
* events.unbind('click')
* events.unbind()
*
* Unbind delegate handlers:
*
* events.unbind('click', 'remove')
* events.unbind('click')
* events.unbind()
*
* @param {String|Function} [event]
* @param {String|Function} [method]
* @api public
*/
Events.prototype.unbind = function(event, method){
if (0 == arguments.length) return this.unbindAll();
if (1 == arguments.length) return this.unbindAllOf(event);
// no bindings for this event
var bindings = this._events[event];
if (!bindings) return;
// no bindings for this method
var cb = bindings[method];
if (!cb) return;
events.unbind(this.el, event, cb);
};
/**
* Unbind all events.
*
* @api private
*/
Events.prototype.unbindAll = function(){
for (var event in this._events) {
this.unbindAllOf(event);
}
};
/**
* Unbind all events for `event`.
*
* @param {String} event
* @api private
*/
Events.prototype.unbindAllOf = function(event){
var bindings = this._events[event];
if (!bindings) return;
for (var method in bindings) {
this.unbind(event, method);
}
};
/**
* Parse `event`.
*
* @param {String} event
* @return {Object}
* @api private
*/
function parse(event) {
var parts = event.split(/ +/);
return {
name: parts.shift(),
selector: parts.join(' ')
}
}
+21
View File
@@ -0,0 +1,21 @@
{
"name": "component-events",
"version": "1.0.10",
"dependencies": {
"component-event": "0.1.4",
"component-delegate": "0.2.4"
},
"component": {
"scripts": {
"events/index.js": "index.js"
}
},
"browser": {
"delegate": "component-delegate",
"event": "component-event"
},
"repository": {
"type": "git",
"url": "https://github.com/component/events.git"
}
}