initial commit
This commit is contained in:
28
node_modules/drag-helper/.npmignore
generated
vendored
Normal file
28
node_modules/drag-helper/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directory
|
||||
# Commenting this out is preferred by some people, see
|
||||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
|
||||
node_modules
|
||||
|
||||
# Users Environment Variables
|
||||
.lock-wscript
|
||||
9
node_modules/drag-helper/DragHelper.sublime-project
generated
vendored
Normal file
9
node_modules/drag-helper/DragHelper.sublime-project
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"folders":
|
||||
[
|
||||
{
|
||||
"follow_symlinks": true,
|
||||
"path": "."
|
||||
}
|
||||
]
|
||||
}
|
||||
1894
node_modules/drag-helper/DragHelper.sublime-workspace
generated
vendored
Normal file
1894
node_modules/drag-helper/DragHelper.sublime-workspace
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
22
node_modules/drag-helper/LICENSE
generated
vendored
Normal file
22
node_modules/drag-helper/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Radu Brehar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
12
node_modules/drag-helper/README.md
generated
vendored
Normal file
12
node_modules/drag-helper/README.md
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
# DragHelper
|
||||
|
||||
> A drag utility
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
$ npm install drag-helper
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
206
node_modules/drag-helper/index.js
generated
vendored
Normal file
206
node_modules/drag-helper/index.js
generated
vendored
Normal file
@@ -0,0 +1,206 @@
|
||||
'use strict';
|
||||
|
||||
var assign = require('object-assign')
|
||||
var Region = require('region-align')
|
||||
var hasTouch = require('has-touch')
|
||||
var once = require('./utils/once')
|
||||
|
||||
var mobileTest = global.navigator ?
|
||||
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(global.navigator.userAgent) :
|
||||
false
|
||||
|
||||
var isMobile = hasTouch && mobileTest;
|
||||
|
||||
var Helper = function(config){
|
||||
this.config = config
|
||||
}
|
||||
|
||||
var EVENTS = {
|
||||
move: isMobile? 'touchmove': 'mousemove',
|
||||
up : isMobile? 'touchend' : 'mouseup'
|
||||
}
|
||||
|
||||
function emptyFn(){}
|
||||
|
||||
function getPageCoords(event){
|
||||
var firstTouch
|
||||
|
||||
var pageX = event.pageX
|
||||
var pageY = event.pageY
|
||||
|
||||
if (isMobile && event.touches && (firstTouch = event.touches[0])){
|
||||
pageX = firstTouch.pageX
|
||||
pageY = firstTouch.pageY
|
||||
}
|
||||
|
||||
return {
|
||||
pageX: pageX,
|
||||
pageY: pageY
|
||||
}
|
||||
}
|
||||
|
||||
assign(Helper.prototype, {
|
||||
|
||||
/**
|
||||
* Should be called on a mousedown event
|
||||
*
|
||||
* @param {Event} event
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
initDrag: function(event) {
|
||||
|
||||
this.onDragInit(event)
|
||||
|
||||
var events = this.config.events || EVENTS
|
||||
|
||||
var onDragStart = once(this.onDragStart, this)
|
||||
var target = isMobile?
|
||||
event.target:
|
||||
global
|
||||
|
||||
var mouseMoveListener = (function(event){
|
||||
onDragStart(event)
|
||||
this.onDrag(event)
|
||||
}).bind(this)
|
||||
|
||||
var mouseUpListener = (function(event){
|
||||
|
||||
this.onDrop(event)
|
||||
|
||||
target.removeEventListener(events.move, mouseMoveListener)
|
||||
target.removeEventListener(events.up, mouseUpListener)
|
||||
}).bind(this)
|
||||
|
||||
target.addEventListener(events.move, mouseMoveListener, false)
|
||||
target.addEventListener(events.up, mouseUpListener)
|
||||
},
|
||||
|
||||
onDragInit: function(event){
|
||||
|
||||
var config = {
|
||||
diff: {
|
||||
left: 0,
|
||||
top : 0
|
||||
}
|
||||
}
|
||||
this.state = {
|
||||
config: config
|
||||
}
|
||||
|
||||
if (this.config.region){
|
||||
this.state.initialRegion = Region.from(this.config.region)
|
||||
this.state.dragRegion =
|
||||
config.dragRegion =
|
||||
this.state.initialRegion.clone()
|
||||
}
|
||||
if (this.config.constrainTo){
|
||||
this.state.constrainTo = Region.from(this.config.constrainTo)
|
||||
}
|
||||
|
||||
this.callConfig('onDragInit', event)
|
||||
},
|
||||
|
||||
/**
|
||||
* Called when the first mousemove event occurs after drag is initialized
|
||||
* @param {Event} event
|
||||
*/
|
||||
onDragStart: function(event){
|
||||
this.state.initPageCoords = getPageCoords(event)
|
||||
|
||||
this.state.didDrag = this.state.config.didDrag = true
|
||||
this.callConfig('onDragStart', event)
|
||||
},
|
||||
|
||||
/**
|
||||
* Called on all mousemove events after drag is initialized.
|
||||
*
|
||||
* @param {Event} event
|
||||
*/
|
||||
onDrag: function(event){
|
||||
|
||||
var config = this.state.config
|
||||
|
||||
var initPageCoords = this.state.initPageCoords
|
||||
var eventCoords = getPageCoords(event)
|
||||
|
||||
var diff = config.diff = {
|
||||
left: eventCoords.pageX - initPageCoords.pageX,
|
||||
top : eventCoords.pageY - initPageCoords.pageY
|
||||
}
|
||||
|
||||
if (this.state.initialRegion){
|
||||
var dragRegion = config.dragRegion
|
||||
|
||||
//set the dragRegion to initial coords
|
||||
dragRegion.set(this.state.initialRegion)
|
||||
|
||||
//shift it to the new position
|
||||
dragRegion.shift(diff)
|
||||
|
||||
if (this.state.constrainTo){
|
||||
//and finally constrain it if it's the case
|
||||
var boolConstrained = dragRegion.constrainTo(this.state.constrainTo)
|
||||
|
||||
diff.left = dragRegion.left - this.state.initialRegion.left
|
||||
diff.top = dragRegion.top - this.state.initialRegion.top
|
||||
|
||||
// console.log(diff);
|
||||
}
|
||||
|
||||
config.dragRegion = dragRegion
|
||||
}
|
||||
|
||||
this.callConfig('onDrag', event)
|
||||
},
|
||||
|
||||
/**
|
||||
* Called on the mouseup event on window
|
||||
*
|
||||
* @param {Event} event
|
||||
*/
|
||||
onDrop: function(event){
|
||||
this.callConfig('onDrop', event)
|
||||
|
||||
this.state = null
|
||||
},
|
||||
|
||||
callConfig: function(fnName, event){
|
||||
var config = this.state.config
|
||||
var args = [event, config]
|
||||
|
||||
var fn = this.config[fnName]
|
||||
|
||||
if (fn){
|
||||
fn.apply(this, args)
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
module.exports = function(event, config){
|
||||
|
||||
if (config.scope){
|
||||
var skippedKeys = {
|
||||
scope : 1,
|
||||
region : 1,
|
||||
constrainTo: 1
|
||||
}
|
||||
|
||||
Object.keys(config).forEach(function(key){
|
||||
var value = config[key]
|
||||
|
||||
if (key in skippedKeys){
|
||||
return
|
||||
}
|
||||
|
||||
if (typeof value == 'function'){
|
||||
config[key] = value.bind(config.scope)
|
||||
}
|
||||
})
|
||||
}
|
||||
var helper = new Helper(config)
|
||||
|
||||
helper.initDrag(event)
|
||||
|
||||
return helper
|
||||
}
|
||||
32
node_modules/drag-helper/package.json
generated
vendored
Normal file
32
node_modules/drag-helper/package.json
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"name": "drag-helper",
|
||||
"version": "1.3.6",
|
||||
"description": "A drag & drop utility",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "make"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/radubrehar/DragHelper.git"
|
||||
},
|
||||
"keywords": [
|
||||
"drag",
|
||||
"drop",
|
||||
"drag&drop",
|
||||
"drag-drop",
|
||||
"bounding",
|
||||
"rect",
|
||||
"region"
|
||||
],
|
||||
"author": "Radu Brehar",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/radubrehar/DragHelper/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"has-touch": "^1.0.0",
|
||||
"object-assign": "^4.1.0",
|
||||
"region-align": "^2.1.3"
|
||||
}
|
||||
}
|
||||
17
node_modules/drag-helper/utils/once.js
generated
vendored
Normal file
17
node_modules/drag-helper/utils/once.js
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
'use once'
|
||||
|
||||
module.exports = function once(fn, scope){
|
||||
|
||||
var called
|
||||
var result
|
||||
|
||||
return function(){
|
||||
if (called){
|
||||
return result
|
||||
}
|
||||
|
||||
called = true
|
||||
|
||||
return result = fn.apply(scope || this, arguments)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user