draggabilly-rails 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 80aa6015d2720f51e7fe357533499cafc56677ff
4
+ data.tar.gz: 50e82ea7f79a40dc58c8d673c8304efcb4b87352
5
+ SHA512:
6
+ metadata.gz: a18807f950cf33100bab594bb58896820bf977c7e0cfbbc23959ee98a19fc090084d448ab4efc12032c5a55c0a54da19ffaa3e78a6fbc5e72fd2d65c8404b17a
7
+ data.tar.gz: a0194004995a4ae32b7acaccb6bb3d9a5e8ee6282983e4ac29ce2ef47c97f83c35db0cf5c1df7b19ce0f129af36ca8ecc847ba9f702eddcbcb2a5f82c39067d0
@@ -0,0 +1 @@
1
+ pkg
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,48 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ draggabilly-rails (1.1.1)
5
+ railties (>= 3.1.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actionpack (4.1.8)
11
+ actionview (= 4.1.8)
12
+ activesupport (= 4.1.8)
13
+ rack (~> 1.5.2)
14
+ rack-test (~> 0.6.2)
15
+ actionview (4.1.8)
16
+ activesupport (= 4.1.8)
17
+ builder (~> 3.1)
18
+ erubis (~> 2.7.0)
19
+ activesupport (4.1.8)
20
+ i18n (~> 0.6, >= 0.6.9)
21
+ json (~> 1.7, >= 1.7.7)
22
+ minitest (~> 5.1)
23
+ thread_safe (~> 0.1)
24
+ tzinfo (~> 1.1)
25
+ builder (3.2.2)
26
+ erubis (2.7.0)
27
+ i18n (0.6.11)
28
+ json (1.8.1)
29
+ minitest (5.4.3)
30
+ rack (1.5.2)
31
+ rack-test (0.6.2)
32
+ rack (>= 1.0)
33
+ railties (4.1.8)
34
+ actionpack (= 4.1.8)
35
+ activesupport (= 4.1.8)
36
+ rake (>= 0.8.7)
37
+ thor (>= 0.18.1, < 2.0)
38
+ rake (10.3.2)
39
+ thor (0.19.1)
40
+ thread_safe (0.3.4)
41
+ tzinfo (1.2.2)
42
+ thread_safe (~> 0.1)
43
+
44
+ PLATFORMS
45
+ ruby
46
+
47
+ DEPENDENCIES
48
+ draggabilly-rails!
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Leonid Beder
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,197 @@
1
+ # draggabilly-rails
2
+
3
+ This is a bundled version of the [draggabilly](https://github.com/desandro/draggabilly) library.
4
+
5
+ ## Install
6
+
7
+ In your Gemfile, add:
8
+
9
+ ```ruby
10
+ gem 'draggabilly-rails'
11
+ ```
12
+
13
+ Add it to your JavaScript manifest file:
14
+
15
+ ``` js
16
+ //= require draggabilly.pkgd
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ``` js
22
+ var elem = document.querySelector('#draggable');
23
+ var draggie = new Draggabilly( elem, {
24
+ // options...
25
+ });
26
+ ```
27
+
28
+ When dragging, Draggabillly will add the class `.is-dragging` to the element.
29
+
30
+ ## Options
31
+
32
+ ### axis
33
+
34
+ **Type:** _String_
35
+
36
+ **Values:** `'x'` or `'y'`
37
+
38
+ ``` js
39
+ axis: 'x'
40
+ ```
41
+
42
+ Constrains movement to horizontal or vertical axis.
43
+
44
+ ### containment
45
+
46
+ **Type:** _Element_, Selector _String_, or _Boolean_
47
+
48
+ ``` js
49
+ containment: '#container'
50
+ ```
51
+
52
+ Contains movement to the bounds of the element. If `true`, the container will be the parent element.
53
+
54
+ ### grid
55
+
56
+ **Type:** _Array_
57
+
58
+ **Values:** `[ x, y ]`
59
+
60
+ ``` js
61
+ grid: [ 20, 20 ]
62
+ ```
63
+
64
+ Snaps the element to a grid, every x and y pixels.
65
+
66
+ ### handle
67
+
68
+ **Type:** Selector _String_
69
+
70
+ ``` js
71
+ handle: '.handle'
72
+ ```
73
+
74
+ Specifies on what element the drag interaction starts.
75
+
76
+ `handle` is useful for when you do not want all inner elements to be used for dragging, like inputs and forms. See [back handle example on CodePen](http://codepen.io/desandro/pen/znAuH).
77
+
78
+ ## Events
79
+
80
+ Draggabilly is an Event Emitter. You can bind event listeners to events.
81
+
82
+ ``` js
83
+ var draggie = new Draggabilly( elem );
84
+
85
+ function onDragMove( instance, event, pointer ) {
86
+ console.log( 'dragMove on ' + event.type +
87
+ pointer.pageX + ', ' + pointer.pageY +
88
+ ' position at ' + instance.position.x + ', ' + instance.position.y );
89
+ }
90
+ // bind event listener
91
+ draggie.on( 'dragMove', onDragMove );
92
+ // un-bind event listener
93
+ draggie.off( 'dragMove', onDragMove );
94
+ // return true to trigger an event listener just once
95
+ draggie.once( 'dragMove', function() {
96
+ console.log('Draggabilly did move, just once');
97
+ });
98
+ ```
99
+
100
+ ### dragStart
101
+
102
+ ```js
103
+ .on( 'dragStart', function( draggieInstance, event, pointer ) { //...
104
+ ```
105
+
106
+ + `draggieInstance` - **Type:** _Draggabilly_ - the Draggabilly instance
107
+ + `event` - **Type:** _Event_ - the original `mousedown` or `touchstart` event
108
+ + `pointer` - **Type:** _MouseEvent_ or _Touch_ - the event object that has `.pageX` and `.pageY`
109
+
110
+ ### dragMove
111
+
112
+ ```js
113
+ .on( 'dragMove', function( draggieInstance, event, pointer ) { //...
114
+ ```
115
+
116
+ + `draggieInstance` - **Type:** _Draggabilly_ - the Draggabilly instance
117
+ + `event` - **Type:** _Event_ - the original `mousemove` or `touchmove` event
118
+ + `pointer` - **Type:** _MouseEvent_ or _Touch_ - the event object that has `.pageX` and `.pageY`
119
+
120
+ ### dragEnd
121
+
122
+ ```js
123
+ .on( 'dragEnd', function( draggieInstance, event, pointer ) { //...
124
+ ```
125
+
126
+ + `draggieInstance` - **Type:** _Draggabilly_ - the Draggabilly instance
127
+ + `event` - **Type:** _Event_ - the original `mouseup` or `touchend` event
128
+ + `pointer` - **Type:** _MouseEvent_ or _Touch_ - the event object that has `.pageX` and `.pageY`
129
+
130
+ ## Methods
131
+
132
+ ### disable
133
+
134
+ ``` js
135
+ draggie.disable()
136
+ ```
137
+
138
+ ### enable
139
+
140
+ ``` js
141
+ draggie.enable()
142
+ ```
143
+
144
+ ## RequireJS
145
+
146
+ Draggabilly works with [RequireJS](http://requirejs.org).
147
+
148
+ You can require [draggabilly.pkgd.js](http://draggabilly.desandro.io/draggabilly.pkgd.js).
149
+
150
+ ``` js
151
+ requirejs( [
152
+ 'path/to/draggabilly.pkgd.js',
153
+ ], function( Draggabilly ) {
154
+ new Draggabilly( ... );
155
+ });
156
+ ```
157
+
158
+ Or, you can manage dependencies with [Bower](http://bower.io). Set `baseUrl` to `bower_components` and set a path config for all your application code.
159
+
160
+ ``` js
161
+ requirejs.config({
162
+ baseUrl: 'bower_components/',
163
+ paths: { // path your your app
164
+ app: '../'
165
+ }
166
+ });
167
+
168
+ requirejs( [
169
+ 'draggabilly/draggabilly',
170
+ 'app/my-component.js'
171
+ ], function( Draggabilly, myComp ) {
172
+ new Draggabilly( ... );
173
+ });
174
+ ```
175
+
176
+ ## License
177
+
178
+ The MIT License (MIT)
179
+
180
+ Copyright (c) 2014
181
+
182
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
183
+ this software and associated documentation files (the "Software"), to deal in
184
+ the Software without restriction, including without limitation the rights to
185
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
186
+ the Software, and to permit persons to whom the Software is furnished to do so,
187
+ subject to the following conditions:
188
+
189
+ The above copyright notice and this permission notice shall be included in all
190
+ copies or substantial portions of the Software.
191
+
192
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
193
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
194
+ FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
195
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
196
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
197
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,19 @@
1
+ $:.push File.expand_path('../lib', __FILE__)
2
+ require 'draggabilly/rails/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'draggabilly-rails'
6
+ s.version = Draggabilly::Rails::VERSION
7
+ s.authors = ['Leonid Beder']
8
+ s.email = ['leonid.beder@gmail.com']
9
+ s.license = 'MIT'
10
+ s.homepage = ''
11
+ s.summary = 'Make that shiz draggable http://draggabilly.desandro.com'
12
+ s.description = 'Make that shiz draggable http://draggabilly.desandro.com.'
13
+ s.files = `git ls-files`.split($/)
14
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
15
+ s.test_files = s.files.grep(%r{^(test|s|features)/})
16
+ s.require_paths = ['lib']
17
+
18
+ s.add_dependency 'railties', '>= 3.1.0'
19
+ end
@@ -0,0 +1,8 @@
1
+ require 'draggabilly/rails/version'
2
+
3
+ module Draggabilly
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Draggabilly
2
+ module Rails
3
+ VERSION = '1.1.1'.freeze
4
+ end
5
+ end
@@ -0,0 +1,1462 @@
1
+ /*!
2
+ * Draggabilly PACKAGED v1.1.1
3
+ * Make that shiz draggable
4
+ * http://draggabilly.desandro.com
5
+ * MIT license
6
+ */
7
+
8
+ /*!
9
+ * classie - class helper functions
10
+ * from bonzo https://github.com/ded/bonzo
11
+ *
12
+ * classie.has( elem, 'my-class' ) -> true/false
13
+ * classie.add( elem, 'my-new-class' )
14
+ * classie.remove( elem, 'my-unwanted-class' )
15
+ * classie.toggle( elem, 'my-class' )
16
+ */
17
+
18
+ /*jshint browser: true, strict: true, undef: true */
19
+ /*global define: false */
20
+
21
+ ( function( window ) {
22
+
23
+
24
+
25
+ // class helper functions from bonzo https://github.com/ded/bonzo
26
+
27
+ function classReg( className ) {
28
+ return new RegExp("(^|\\s+)" + className + "(\\s+|$)");
29
+ }
30
+
31
+ // classList support for class management
32
+ // altho to be fair, the api sucks because it won't accept multiple classes at once
33
+ var hasClass, addClass, removeClass;
34
+
35
+ if ( 'classList' in document.documentElement ) {
36
+ hasClass = function( elem, c ) {
37
+ return elem.classList.contains( c );
38
+ };
39
+ addClass = function( elem, c ) {
40
+ elem.classList.add( c );
41
+ };
42
+ removeClass = function( elem, c ) {
43
+ elem.classList.remove( c );
44
+ };
45
+ }
46
+ else {
47
+ hasClass = function( elem, c ) {
48
+ return classReg( c ).test( elem.className );
49
+ };
50
+ addClass = function( elem, c ) {
51
+ if ( !hasClass( elem, c ) ) {
52
+ elem.className = elem.className + ' ' + c;
53
+ }
54
+ };
55
+ removeClass = function( elem, c ) {
56
+ elem.className = elem.className.replace( classReg( c ), ' ' );
57
+ };
58
+ }
59
+
60
+ function toggleClass( elem, c ) {
61
+ var fn = hasClass( elem, c ) ? removeClass : addClass;
62
+ fn( elem, c );
63
+ }
64
+
65
+ var classie = {
66
+ // full names
67
+ hasClass: hasClass,
68
+ addClass: addClass,
69
+ removeClass: removeClass,
70
+ toggleClass: toggleClass,
71
+ // short names
72
+ has: hasClass,
73
+ add: addClass,
74
+ remove: removeClass,
75
+ toggle: toggleClass
76
+ };
77
+
78
+ // transport
79
+ if ( typeof define === 'function' && define.amd ) {
80
+ // AMD
81
+ define( 'classie/classie',classie );
82
+ } else {
83
+ // browser global
84
+ window.classie = classie;
85
+ }
86
+
87
+ })( window );
88
+
89
+ /*!
90
+ * EventEmitter v4.2.2 - git.io/ee
91
+ * Oliver Caldwell
92
+ * MIT license
93
+ * @preserve
94
+ */
95
+
96
+ (function () {
97
+
98
+
99
+ /**
100
+ * Class for managing events.
101
+ * Can be extended to provide event functionality in other classes.
102
+ *
103
+ * @class EventEmitter Manages event registering and emitting.
104
+ */
105
+ function EventEmitter() {}
106
+
107
+ // Shortcuts to improve speed and size
108
+
109
+ // Easy access to the prototype
110
+ var proto = EventEmitter.prototype;
111
+
112
+ /**
113
+ * Finds the index of the listener for the event in it's storage array.
114
+ *
115
+ * @param {Function[]} listeners Array of listeners to search through.
116
+ * @param {Function} listener Method to look for.
117
+ * @return {Number} Index of the specified listener, -1 if not found
118
+ * @api private
119
+ */
120
+ function indexOfListener(listeners, listener) {
121
+ var i = listeners.length;
122
+ while (i--) {
123
+ if (listeners[i].listener === listener) {
124
+ return i;
125
+ }
126
+ }
127
+
128
+ return -1;
129
+ }
130
+
131
+ /**
132
+ * Alias a method while keeping the context correct, to allow for overwriting of target method.
133
+ *
134
+ * @param {String} name The name of the target method.
135
+ * @return {Function} The aliased method
136
+ * @api private
137
+ */
138
+ function alias(name) {
139
+ return function aliasClosure() {
140
+ return this[name].apply(this, arguments);
141
+ };
142
+ }
143
+
144
+ /**
145
+ * Returns the listener array for the specified event.
146
+ * Will initialise the event object and listener arrays if required.
147
+ * Will return an object if you use a regex search. The object contains keys for each matched event. So /ba[rz]/ might return an object containing bar and baz. But only if you have either defined them with defineEvent or added some listeners to them.
148
+ * Each property in the object response is an array of listener functions.
149
+ *
150
+ * @param {String|RegExp} evt Name of the event to return the listeners from.
151
+ * @return {Function[]|Object} All listener functions for the event.
152
+ */
153
+ proto.getListeners = function getListeners(evt) {
154
+ var events = this._getEvents();
155
+ var response;
156
+ var key;
157
+
158
+ // Return a concatenated array of all matching events if
159
+ // the selector is a regular expression.
160
+ if (typeof evt === 'object') {
161
+ response = {};
162
+ for (key in events) {
163
+ if (events.hasOwnProperty(key) && evt.test(key)) {
164
+ response[key] = events[key];
165
+ }
166
+ }
167
+ }
168
+ else {
169
+ response = events[evt] || (events[evt] = []);
170
+ }
171
+
172
+ return response;
173
+ };
174
+
175
+ /**
176
+ * Takes a list of listener objects and flattens it into a list of listener functions.
177
+ *
178
+ * @param {Object[]} listeners Raw listener objects.
179
+ * @return {Function[]} Just the listener functions.
180
+ */
181
+ proto.flattenListeners = function flattenListeners(listeners) {
182
+ var flatListeners = [];
183
+ var i;
184
+
185
+ for (i = 0; i < listeners.length; i += 1) {
186
+ flatListeners.push(listeners[i].listener);
187
+ }
188
+
189
+ return flatListeners;
190
+ };
191
+
192
+ /**
193
+ * Fetches the requested listeners via getListeners but will always return the results inside an object. This is mainly for internal use but others may find it useful.
194
+ *
195
+ * @param {String|RegExp} evt Name of the event to return the listeners from.
196
+ * @return {Object} All listener functions for an event in an object.
197
+ */
198
+ proto.getListenersAsObject = function getListenersAsObject(evt) {
199
+ var listeners = this.getListeners(evt);
200
+ var response;
201
+
202
+ if (listeners instanceof Array) {
203
+ response = {};
204
+ response[evt] = listeners;
205
+ }
206
+
207
+ return response || listeners;
208
+ };
209
+
210
+ /**
211
+ * Adds a listener function to the specified event.
212
+ * The listener will not be added if it is a duplicate.
213
+ * If the listener returns true then it will be removed after it is called.
214
+ * If you pass a regular expression as the event name then the listener will be added to all events that match it.
215
+ *
216
+ * @param {String|RegExp} evt Name of the event to attach the listener to.
217
+ * @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling.
218
+ * @return {Object} Current instance of EventEmitter for chaining.
219
+ */
220
+ proto.addListener = function addListener(evt, listener) {
221
+ var listeners = this.getListenersAsObject(evt);
222
+ var listenerIsWrapped = typeof listener === 'object';
223
+ var key;
224
+
225
+ for (key in listeners) {
226
+ if (listeners.hasOwnProperty(key) && indexOfListener(listeners[key], listener) === -1) {
227
+ listeners[key].push(listenerIsWrapped ? listener : {
228
+ listener: listener,
229
+ once: false
230
+ });
231
+ }
232
+ }
233
+
234
+ return this;
235
+ };
236
+
237
+ /**
238
+ * Alias of addListener
239
+ */
240
+ proto.on = alias('addListener');
241
+
242
+ /**
243
+ * Semi-alias of addListener. It will add a listener that will be
244
+ * automatically removed after it's first execution.
245
+ *
246
+ * @param {String|RegExp} evt Name of the event to attach the listener to.
247
+ * @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling.
248
+ * @return {Object} Current instance of EventEmitter for chaining.
249
+ */
250
+ proto.addOnceListener = function addOnceListener(evt, listener) {
251
+ return this.addListener(evt, {
252
+ listener: listener,
253
+ once: true
254
+ });
255
+ };
256
+
257
+ /**
258
+ * Alias of addOnceListener.
259
+ */
260
+ proto.once = alias('addOnceListener');
261
+
262
+ /**
263
+ * Defines an event name. This is required if you want to use a regex to add a listener to multiple events at once. If you don't do this then how do you expect it to know what event to add to? Should it just add to every possible match for a regex? No. That is scary and bad.
264
+ * You need to tell it what event names should be matched by a regex.
265
+ *
266
+ * @param {String} evt Name of the event to create.
267
+ * @return {Object} Current instance of EventEmitter for chaining.
268
+ */
269
+ proto.defineEvent = function defineEvent(evt) {
270
+ this.getListeners(evt);
271
+ return this;
272
+ };
273
+
274
+ /**
275
+ * Uses defineEvent to define multiple events.
276
+ *
277
+ * @param {String[]} evts An array of event names to define.
278
+ * @return {Object} Current instance of EventEmitter for chaining.
279
+ */
280
+ proto.defineEvents = function defineEvents(evts) {
281
+ for (var i = 0; i < evts.length; i += 1) {
282
+ this.defineEvent(evts[i]);
283
+ }
284
+ return this;
285
+ };
286
+
287
+ /**
288
+ * Removes a listener function from the specified event.
289
+ * When passed a regular expression as the event name, it will remove the listener from all events that match it.
290
+ *
291
+ * @param {String|RegExp} evt Name of the event to remove the listener from.
292
+ * @param {Function} listener Method to remove from the event.
293
+ * @return {Object} Current instance of EventEmitter for chaining.
294
+ */
295
+ proto.removeListener = function removeListener(evt, listener) {
296
+ var listeners = this.getListenersAsObject(evt);
297
+ var index;
298
+ var key;
299
+
300
+ for (key in listeners) {
301
+ if (listeners.hasOwnProperty(key)) {
302
+ index = indexOfListener(listeners[key], listener);
303
+
304
+ if (index !== -1) {
305
+ listeners[key].splice(index, 1);
306
+ }
307
+ }
308
+ }
309
+
310
+ return this;
311
+ };
312
+
313
+ /**
314
+ * Alias of removeListener
315
+ */
316
+ proto.off = alias('removeListener');
317
+
318
+ /**
319
+ * Adds listeners in bulk using the manipulateListeners method.
320
+ * If you pass an object as the second argument you can add to multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. You can also pass it an event name and an array of listeners to be added.
321
+ * You can also pass it a regular expression to add the array of listeners to all events that match it.
322
+ * Yeah, this function does quite a bit. That's probably a bad thing.
323
+ *
324
+ * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to add to multiple events at once.
325
+ * @param {Function[]} [listeners] An optional array of listener functions to add.
326
+ * @return {Object} Current instance of EventEmitter for chaining.
327
+ */
328
+ proto.addListeners = function addListeners(evt, listeners) {
329
+ // Pass through to manipulateListeners
330
+ return this.manipulateListeners(false, evt, listeners);
331
+ };
332
+
333
+ /**
334
+ * Removes listeners in bulk using the manipulateListeners method.
335
+ * If you pass an object as the second argument you can remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays.
336
+ * You can also pass it an event name and an array of listeners to be removed.
337
+ * You can also pass it a regular expression to remove the listeners from all events that match it.
338
+ *
339
+ * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to remove from multiple events at once.
340
+ * @param {Function[]} [listeners] An optional array of listener functions to remove.
341
+ * @return {Object} Current instance of EventEmitter for chaining.
342
+ */
343
+ proto.removeListeners = function removeListeners(evt, listeners) {
344
+ // Pass through to manipulateListeners
345
+ return this.manipulateListeners(true, evt, listeners);
346
+ };
347
+
348
+ /**
349
+ * Edits listeners in bulk. The addListeners and removeListeners methods both use this to do their job. You should really use those instead, this is a little lower level.
350
+ * The first argument will determine if the listeners are removed (true) or added (false).
351
+ * If you pass an object as the second argument you can add/remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays.
352
+ * You can also pass it an event name and an array of listeners to be added/removed.
353
+ * You can also pass it a regular expression to manipulate the listeners of all events that match it.
354
+ *
355
+ * @param {Boolean} remove True if you want to remove listeners, false if you want to add.
356
+ * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to add/remove from multiple events at once.
357
+ * @param {Function[]} [listeners] An optional array of listener functions to add/remove.
358
+ * @return {Object} Current instance of EventEmitter for chaining.
359
+ */
360
+ proto.manipulateListeners = function manipulateListeners(remove, evt, listeners) {
361
+ var i;
362
+ var value;
363
+ var single = remove ? this.removeListener : this.addListener;
364
+ var multiple = remove ? this.removeListeners : this.addListeners;
365
+
366
+ // If evt is an object then pass each of it's properties to this method
367
+ if (typeof evt === 'object' && !(evt instanceof RegExp)) {
368
+ for (i in evt) {
369
+ if (evt.hasOwnProperty(i) && (value = evt[i])) {
370
+ // Pass the single listener straight through to the singular method
371
+ if (typeof value === 'function') {
372
+ single.call(this, i, value);
373
+ }
374
+ else {
375
+ // Otherwise pass back to the multiple function
376
+ multiple.call(this, i, value);
377
+ }
378
+ }
379
+ }
380
+ }
381
+ else {
382
+ // So evt must be a string
383
+ // And listeners must be an array of listeners
384
+ // Loop over it and pass each one to the multiple method
385
+ i = listeners.length;
386
+ while (i--) {
387
+ single.call(this, evt, listeners[i]);
388
+ }
389
+ }
390
+
391
+ return this;
392
+ };
393
+
394
+ /**
395
+ * Removes all listeners from a specified event.
396
+ * If you do not specify an event then all listeners will be removed.
397
+ * That means every event will be emptied.
398
+ * You can also pass a regex to remove all events that match it.
399
+ *
400
+ * @param {String|RegExp} [evt] Optional name of the event to remove all listeners for. Will remove from every event if not passed.
401
+ * @return {Object} Current instance of EventEmitter for chaining.
402
+ */
403
+ proto.removeEvent = function removeEvent(evt) {
404
+ var type = typeof evt;
405
+ var events = this._getEvents();
406
+ var key;
407
+
408
+ // Remove different things depending on the state of evt
409
+ if (type === 'string') {
410
+ // Remove all listeners for the specified event
411
+ delete events[evt];
412
+ }
413
+ else if (type === 'object') {
414
+ // Remove all events matching the regex.
415
+ for (key in events) {
416
+ if (events.hasOwnProperty(key) && evt.test(key)) {
417
+ delete events[key];
418
+ }
419
+ }
420
+ }
421
+ else {
422
+ // Remove all listeners in all events
423
+ delete this._events;
424
+ }
425
+
426
+ return this;
427
+ };
428
+
429
+ /**
430
+ * Emits an event of your choice.
431
+ * When emitted, every listener attached to that event will be executed.
432
+ * If you pass the optional argument array then those arguments will be passed to every listener upon execution.
433
+ * Because it uses `apply`, your array of arguments will be passed as if you wrote them out separately.
434
+ * So they will not arrive within the array on the other side, they will be separate.
435
+ * You can also pass a regular expression to emit to all events that match it.
436
+ *
437
+ * @param {String|RegExp} evt Name of the event to emit and execute listeners for.
438
+ * @param {Array} [args] Optional array of arguments to be passed to each listener.
439
+ * @return {Object} Current instance of EventEmitter for chaining.
440
+ */
441
+ proto.emitEvent = function emitEvent(evt, args) {
442
+ var listeners = this.getListenersAsObject(evt);
443
+ var listener;
444
+ var i;
445
+ var key;
446
+ var response;
447
+
448
+ for (key in listeners) {
449
+ if (listeners.hasOwnProperty(key)) {
450
+ i = listeners[key].length;
451
+
452
+ while (i--) {
453
+ // If the listener returns true then it shall be removed from the event
454
+ // The function is executed either with a basic call or an apply if there is an args array
455
+ listener = listeners[key][i];
456
+ response = listener.listener.apply(this, args || []);
457
+ if (response === this._getOnceReturnValue() || listener.once === true) {
458
+ this.removeListener(evt, listener.listener);
459
+ }
460
+ }
461
+ }
462
+ }
463
+
464
+ return this;
465
+ };
466
+
467
+ /**
468
+ * Alias of emitEvent
469
+ */
470
+ proto.trigger = alias('emitEvent');
471
+
472
+ /**
473
+ * Subtly different from emitEvent in that it will pass its arguments on to the listeners, as opposed to taking a single array of arguments to pass on.
474
+ * As with emitEvent, you can pass a regex in place of the event name to emit to all events that match it.
475
+ *
476
+ * @param {String|RegExp} evt Name of the event to emit and execute listeners for.
477
+ * @param {...*} Optional additional arguments to be passed to each listener.
478
+ * @return {Object} Current instance of EventEmitter for chaining.
479
+ */
480
+ proto.emit = function emit(evt) {
481
+ var args = Array.prototype.slice.call(arguments, 1);
482
+ return this.emitEvent(evt, args);
483
+ };
484
+
485
+ /**
486
+ * Sets the current value to check against when executing listeners. If a
487
+ * listeners return value matches the one set here then it will be removed
488
+ * after execution. This value defaults to true.
489
+ *
490
+ * @param {*} value The new value to check for when executing listeners.
491
+ * @return {Object} Current instance of EventEmitter for chaining.
492
+ */
493
+ proto.setOnceReturnValue = function setOnceReturnValue(value) {
494
+ this._onceReturnValue = value;
495
+ return this;
496
+ };
497
+
498
+ /**
499
+ * Fetches the current value to check against when executing listeners. If
500
+ * the listeners return value matches this one then it should be removed
501
+ * automatically. It will return true by default.
502
+ *
503
+ * @return {*|Boolean} The current value to check for or the default, true.
504
+ * @api private
505
+ */
506
+ proto._getOnceReturnValue = function _getOnceReturnValue() {
507
+ if (this.hasOwnProperty('_onceReturnValue')) {
508
+ return this._onceReturnValue;
509
+ }
510
+ else {
511
+ return true;
512
+ }
513
+ };
514
+
515
+ /**
516
+ * Fetches the events object and creates one if required.
517
+ *
518
+ * @return {Object} The events storage object.
519
+ * @api private
520
+ */
521
+ proto._getEvents = function _getEvents() {
522
+ return this._events || (this._events = {});
523
+ };
524
+
525
+ // Expose the class either via AMD, CommonJS or the global object
526
+ if (typeof define === 'function' && define.amd) {
527
+ define('eventEmitter/EventEmitter',[],function () {
528
+ return EventEmitter;
529
+ });
530
+ }
531
+ else if (typeof module === 'object' && module.exports){
532
+ module.exports = EventEmitter;
533
+ }
534
+ else {
535
+ this.EventEmitter = EventEmitter;
536
+ }
537
+ }.call(this));
538
+
539
+ /*!
540
+ * eventie v1.0.3
541
+ * event binding helper
542
+ * eventie.bind( elem, 'click', myFn )
543
+ * eventie.unbind( elem, 'click', myFn )
544
+ */
545
+
546
+ /*jshint browser: true, undef: true, unused: true */
547
+ /*global define: false */
548
+
549
+ ( function( window ) {
550
+
551
+
552
+
553
+ var docElem = document.documentElement;
554
+
555
+ var bind = function() {};
556
+
557
+ if ( docElem.addEventListener ) {
558
+ bind = function( obj, type, fn ) {
559
+ obj.addEventListener( type, fn, false );
560
+ };
561
+ } else if ( docElem.attachEvent ) {
562
+ bind = function( obj, type, fn ) {
563
+ obj[ type + fn ] = fn.handleEvent ?
564
+ function() {
565
+ var event = window.event;
566
+ // add event.target
567
+ event.target = event.target || event.srcElement;
568
+ fn.handleEvent.call( fn, event );
569
+ } :
570
+ function() {
571
+ var event = window.event;
572
+ // add event.target
573
+ event.target = event.target || event.srcElement;
574
+ fn.call( obj, event );
575
+ };
576
+ obj.attachEvent( "on" + type, obj[ type + fn ] );
577
+ };
578
+ }
579
+
580
+ var unbind = function() {};
581
+
582
+ if ( docElem.removeEventListener ) {
583
+ unbind = function( obj, type, fn ) {
584
+ obj.removeEventListener( type, fn, false );
585
+ };
586
+ } else if ( docElem.detachEvent ) {
587
+ unbind = function( obj, type, fn ) {
588
+ obj.detachEvent( "on" + type, obj[ type + fn ] );
589
+ try {
590
+ delete obj[ type + fn ];
591
+ } catch ( err ) {
592
+ // can't delete window object properties
593
+ obj[ type + fn ] = undefined;
594
+ }
595
+ };
596
+ }
597
+
598
+ var eventie = {
599
+ bind: bind,
600
+ unbind: unbind
601
+ };
602
+
603
+ // transport
604
+ if ( typeof define === 'function' && define.amd ) {
605
+ // AMD
606
+ define( 'eventie/eventie',eventie );
607
+ } else {
608
+ // browser global
609
+ window.eventie = eventie;
610
+ }
611
+
612
+ })( this );
613
+
614
+ /*!
615
+ * getStyleProperty by kangax
616
+ * http://perfectionkills.com/feature-testing-css-properties/
617
+ */
618
+
619
+ /*jshint browser: true, strict: true, undef: true */
620
+ /*globals define: false */
621
+
622
+ ( function( window ) {
623
+
624
+
625
+
626
+ var prefixes = 'Webkit Moz ms Ms O'.split(' ');
627
+ var docElemStyle = document.documentElement.style;
628
+
629
+ function getStyleProperty( propName ) {
630
+ if ( !propName ) {
631
+ return;
632
+ }
633
+
634
+ // test standard property first
635
+ if ( typeof docElemStyle[ propName ] === 'string' ) {
636
+ return propName;
637
+ }
638
+
639
+ // capitalize
640
+ propName = propName.charAt(0).toUpperCase() + propName.slice(1);
641
+
642
+ // test vendor specific properties
643
+ var prefixed;
644
+ for ( var i=0, len = prefixes.length; i < len; i++ ) {
645
+ prefixed = prefixes[i] + propName;
646
+ if ( typeof docElemStyle[ prefixed ] === 'string' ) {
647
+ return prefixed;
648
+ }
649
+ }
650
+ }
651
+
652
+ // transport
653
+ if ( typeof define === 'function' && define.amd ) {
654
+ // AMD
655
+ define( 'get-style-property/get-style-property',[],function() {
656
+ return getStyleProperty;
657
+ });
658
+ } else {
659
+ // browser global
660
+ window.getStyleProperty = getStyleProperty;
661
+ }
662
+
663
+ })( window );
664
+
665
+ /**
666
+ * getSize v1.1.4
667
+ * measure size of elements
668
+ */
669
+
670
+ /*jshint browser: true, strict: true, undef: true, unused: true */
671
+ /*global define: false */
672
+
673
+ ( function( window, undefined ) {
674
+
675
+
676
+
677
+ // -------------------------- helpers -------------------------- //
678
+
679
+ var defView = document.defaultView;
680
+
681
+ var getStyle = defView && defView.getComputedStyle ?
682
+ function( elem ) {
683
+ return defView.getComputedStyle( elem, null );
684
+ } :
685
+ function( elem ) {
686
+ return elem.currentStyle;
687
+ };
688
+
689
+ // get a number from a string, not a percentage
690
+ function getStyleSize( value ) {
691
+ var num = parseFloat( value );
692
+ // not a percent like '100%', and a number
693
+ var isValid = value.indexOf('%') === -1 && !isNaN( num );
694
+ return isValid && num;
695
+ }
696
+
697
+ // -------------------------- measurements -------------------------- //
698
+
699
+ var measurements = [
700
+ 'paddingLeft',
701
+ 'paddingRight',
702
+ 'paddingTop',
703
+ 'paddingBottom',
704
+ 'marginLeft',
705
+ 'marginRight',
706
+ 'marginTop',
707
+ 'marginBottom',
708
+ 'borderLeftWidth',
709
+ 'borderRightWidth',
710
+ 'borderTopWidth',
711
+ 'borderBottomWidth'
712
+ ];
713
+
714
+ function getZeroSize() {
715
+ var size = {
716
+ width: 0,
717
+ height: 0,
718
+ innerWidth: 0,
719
+ innerHeight: 0,
720
+ outerWidth: 0,
721
+ outerHeight: 0
722
+ };
723
+ for ( var i=0, len = measurements.length; i < len; i++ ) {
724
+ var measurement = measurements[i];
725
+ size[ measurement ] = 0;
726
+ }
727
+ return size;
728
+ }
729
+
730
+
731
+
732
+ function defineGetSize( getStyleProperty ) {
733
+
734
+ // -------------------------- box sizing -------------------------- //
735
+
736
+ var boxSizingProp = getStyleProperty('boxSizing');
737
+ var isBoxSizeOuter;
738
+
739
+ /**
740
+ * WebKit measures the outer-width on style.width on border-box elems
741
+ * IE & Firefox measures the inner-width
742
+ */
743
+ ( function() {
744
+ if ( !boxSizingProp ) {
745
+ return;
746
+ }
747
+
748
+ var div = document.createElement('div');
749
+ div.style.width = '200px';
750
+ div.style.padding = '1px 2px 3px 4px';
751
+ div.style.borderStyle = 'solid';
752
+ div.style.borderWidth = '1px 2px 3px 4px';
753
+ div.style[ boxSizingProp ] = 'border-box';
754
+
755
+ var body = document.body || document.documentElement;
756
+ body.appendChild( div );
757
+ var style = getStyle( div );
758
+
759
+ isBoxSizeOuter = getStyleSize( style.width ) === 200;
760
+ body.removeChild( div );
761
+ })();
762
+
763
+
764
+ // -------------------------- getSize -------------------------- //
765
+
766
+ function getSize( elem ) {
767
+ // use querySeletor if elem is string
768
+ if ( typeof elem === 'string' ) {
769
+ elem = document.querySelector( elem );
770
+ }
771
+
772
+ // do not proceed on non-objects
773
+ if ( !elem || typeof elem !== 'object' || !elem.nodeType ) {
774
+ return;
775
+ }
776
+
777
+ var style = getStyle( elem );
778
+
779
+ // if hidden, everything is 0
780
+ if ( style.display === 'none' ) {
781
+ return getZeroSize();
782
+ }
783
+
784
+ var size = {};
785
+ size.width = elem.offsetWidth;
786
+ size.height = elem.offsetHeight;
787
+
788
+ var isBorderBox = size.isBorderBox = !!( boxSizingProp &&
789
+ style[ boxSizingProp ] && style[ boxSizingProp ] === 'border-box' );
790
+
791
+ // get all measurements
792
+ for ( var i=0, len = measurements.length; i < len; i++ ) {
793
+ var measurement = measurements[i];
794
+ var value = style[ measurement ];
795
+ var num = parseFloat( value );
796
+ // any 'auto', 'medium' value will be 0
797
+ size[ measurement ] = !isNaN( num ) ? num : 0;
798
+ }
799
+
800
+ var paddingWidth = size.paddingLeft + size.paddingRight;
801
+ var paddingHeight = size.paddingTop + size.paddingBottom;
802
+ var marginWidth = size.marginLeft + size.marginRight;
803
+ var marginHeight = size.marginTop + size.marginBottom;
804
+ var borderWidth = size.borderLeftWidth + size.borderRightWidth;
805
+ var borderHeight = size.borderTopWidth + size.borderBottomWidth;
806
+
807
+ var isBorderBoxSizeOuter = isBorderBox && isBoxSizeOuter;
808
+
809
+ // overwrite width and height if we can get it from style
810
+ var styleWidth = getStyleSize( style.width );
811
+ if ( styleWidth !== false ) {
812
+ size.width = styleWidth +
813
+ // add padding and border unless it's already including it
814
+ ( isBorderBoxSizeOuter ? 0 : paddingWidth + borderWidth );
815
+ }
816
+
817
+ var styleHeight = getStyleSize( style.height );
818
+ if ( styleHeight !== false ) {
819
+ size.height = styleHeight +
820
+ // add padding and border unless it's already including it
821
+ ( isBorderBoxSizeOuter ? 0 : paddingHeight + borderHeight );
822
+ }
823
+
824
+ size.innerWidth = size.width - ( paddingWidth + borderWidth );
825
+ size.innerHeight = size.height - ( paddingHeight + borderHeight );
826
+
827
+ size.outerWidth = size.width + marginWidth;
828
+ size.outerHeight = size.height + marginHeight;
829
+
830
+ return size;
831
+ }
832
+
833
+ return getSize;
834
+
835
+ }
836
+
837
+ // transport
838
+ if ( typeof define === 'function' && define.amd ) {
839
+ // AMD
840
+ define( 'get-size/get-size',[ 'get-style-property/get-style-property' ], defineGetSize );
841
+ } else {
842
+ // browser global
843
+ window.getSize = defineGetSize( window.getStyleProperty );
844
+ }
845
+
846
+ })( window );
847
+
848
+ /*!
849
+ * Draggabilly v1.1.1
850
+ * Make that shiz draggable
851
+ * http://draggabilly.desandro.com
852
+ * MIT license
853
+ */
854
+
855
+ ( function( window ) {
856
+
857
+
858
+
859
+ // vars
860
+ var document = window.document;
861
+
862
+ // -------------------------- helpers -------------------------- //
863
+
864
+ // extend objects
865
+ function extend( a, b ) {
866
+ for ( var prop in b ) {
867
+ a[ prop ] = b[ prop ];
868
+ }
869
+ return a;
870
+ }
871
+
872
+ function noop() {}
873
+
874
+ // ----- get style ----- //
875
+
876
+ var defView = document.defaultView;
877
+
878
+ var getStyle = defView && defView.getComputedStyle ?
879
+ function( elem ) {
880
+ return defView.getComputedStyle( elem, null );
881
+ } :
882
+ function( elem ) {
883
+ return elem.currentStyle;
884
+ };
885
+
886
+
887
+ // http://stackoverflow.com/a/384380/182183
888
+ var isElement = ( typeof HTMLElement === 'object' ) ?
889
+ function isElementDOM2( obj ) {
890
+ return obj instanceof HTMLElement;
891
+ } :
892
+ function isElementQuirky( obj ) {
893
+ return obj && typeof obj === 'object' &&
894
+ obj.nodeType === 1 && typeof obj.nodeName === 'string';
895
+ };
896
+
897
+ // -------------------------- requestAnimationFrame -------------------------- //
898
+
899
+ // https://gist.github.com/1866474
900
+
901
+ var lastTime = 0;
902
+ var prefixes = 'webkit moz ms o'.split(' ');
903
+ // get unprefixed rAF and cAF, if present
904
+ var requestAnimationFrame = window.requestAnimationFrame;
905
+ var cancelAnimationFrame = window.cancelAnimationFrame;
906
+ // loop through vendor prefixes and get prefixed rAF and cAF
907
+ var prefix;
908
+ for( var i = 0; i < prefixes.length; i++ ) {
909
+ if ( requestAnimationFrame && cancelAnimationFrame ) {
910
+ break;
911
+ }
912
+ prefix = prefixes[i];
913
+ requestAnimationFrame = requestAnimationFrame || window[ prefix + 'RequestAnimationFrame' ];
914
+ cancelAnimationFrame = cancelAnimationFrame || window[ prefix + 'CancelAnimationFrame' ] ||
915
+ window[ prefix + 'CancelRequestAnimationFrame' ];
916
+ }
917
+
918
+ // fallback to setTimeout and clearTimeout if either request/cancel is not supported
919
+ if ( !requestAnimationFrame || !cancelAnimationFrame ) {
920
+ requestAnimationFrame = function( callback ) {
921
+ var currTime = new Date().getTime();
922
+ var timeToCall = Math.max( 0, 16 - ( currTime - lastTime ) );
923
+ var id = window.setTimeout( function() {
924
+ callback( currTime + timeToCall );
925
+ }, timeToCall );
926
+ lastTime = currTime + timeToCall;
927
+ return id;
928
+ };
929
+
930
+ cancelAnimationFrame = function( id ) {
931
+ window.clearTimeout( id );
932
+ };
933
+ }
934
+
935
+ // -------------------------- definition -------------------------- //
936
+
937
+ function draggabillyDefinition( classie, EventEmitter, eventie, getStyleProperty, getSize ) {
938
+
939
+ // -------------------------- support -------------------------- //
940
+
941
+ var transformProperty = getStyleProperty('transform');
942
+ // TODO fix quick & dirty check for 3D support
943
+ var is3d = !!getStyleProperty('perspective');
944
+
945
+ // -------------------------- -------------------------- //
946
+
947
+ function Draggabilly( element, options ) {
948
+ // querySelector if string
949
+ this.element = typeof element === 'string' ?
950
+ document.querySelector( element ) : element;
951
+
952
+ this.options = extend( {}, this.options );
953
+ extend( this.options, options );
954
+
955
+ this._create();
956
+ }
957
+
958
+ // inherit EventEmitter methods
959
+ extend( Draggabilly.prototype, EventEmitter.prototype );
960
+
961
+ Draggabilly.prototype.options = {
962
+ };
963
+
964
+ Draggabilly.prototype._create = function() {
965
+
966
+ // properties
967
+ this.position = {};
968
+ this._getPosition();
969
+
970
+ this.startPoint = { x: 0, y: 0 };
971
+ this.dragPoint = { x: 0, y: 0 };
972
+
973
+ this.startPosition = extend( {}, this.position );
974
+
975
+ // set relative positioning
976
+ var style = getStyle( this.element );
977
+ if ( style.position !== 'relative' && style.position !== 'absolute' ) {
978
+ this.element.style.position = 'relative';
979
+ }
980
+
981
+ this.enable();
982
+ this.setHandles();
983
+
984
+ };
985
+
986
+ /**
987
+ * set this.handles and bind start events to 'em
988
+ */
989
+ Draggabilly.prototype.setHandles = function() {
990
+ this.handles = this.options.handle ?
991
+ this.element.querySelectorAll( this.options.handle ) : [ this.element ];
992
+
993
+ for ( var i=0, len = this.handles.length; i < len; i++ ) {
994
+ var handle = this.handles[i];
995
+ // bind pointer start event
996
+ if ( window.navigator.pointerEnabled ) {
997
+ // W3C Pointer Events, IE11. See https://coderwall.com/p/mfreca
998
+ eventie.bind( handle, 'pointerdown', this );
999
+ // disable scrolling on the element
1000
+ handle.style.touchAction = 'none';
1001
+ } else if ( window.navigator.msPointerEnabled ) {
1002
+ // IE10 Pointer Events
1003
+ eventie.bind( handle, 'MSPointerDown', this );
1004
+ // disable scrolling on the element
1005
+ handle.style.msTouchAction = 'none';
1006
+ } else {
1007
+ // listen for both, for devices like Chrome Pixel
1008
+ // which has touch and mouse events
1009
+ eventie.bind( handle, 'mousedown', this );
1010
+ eventie.bind( handle, 'touchstart', this );
1011
+ disableImgOndragstart( handle );
1012
+ }
1013
+ }
1014
+ };
1015
+
1016
+ // remove default dragging interaction on all images in IE8
1017
+ // IE8 does its own drag thing on images, which messes stuff up
1018
+
1019
+ function noDragStart() {
1020
+ return false;
1021
+ }
1022
+
1023
+ // TODO replace this with a IE8 test
1024
+ var isIE8 = 'attachEvent' in document.documentElement;
1025
+
1026
+ // IE8 only
1027
+ var disableImgOndragstart = !isIE8 ? noop : function( handle ) {
1028
+
1029
+ if ( handle.nodeName === 'IMG' ) {
1030
+ handle.ondragstart = noDragStart;
1031
+ }
1032
+
1033
+ var images = handle.querySelectorAll('img');
1034
+ for ( var i=0, len = images.length; i < len; i++ ) {
1035
+ var img = images[i];
1036
+ img.ondragstart = noDragStart;
1037
+ }
1038
+ };
1039
+
1040
+
1041
+ // get left/top position from style
1042
+ Draggabilly.prototype._getPosition = function() {
1043
+ // properties
1044
+ var style = getStyle( this.element );
1045
+
1046
+ var x = parseInt( style.left, 10 );
1047
+ var y = parseInt( style.top, 10 );
1048
+
1049
+ // clean up 'auto' or other non-integer values
1050
+ this.position.x = isNaN( x ) ? 0 : x;
1051
+ this.position.y = isNaN( y ) ? 0 : y;
1052
+
1053
+ this._addTransformPosition( style );
1054
+ };
1055
+
1056
+ // add transform: translate( x, y ) to position
1057
+ Draggabilly.prototype._addTransformPosition = function( style ) {
1058
+ if ( !transformProperty ) {
1059
+ return;
1060
+ }
1061
+ var transform = style[ transformProperty ];
1062
+ // bail out if value is 'none'
1063
+ if ( transform.indexOf('matrix') !== 0 ) {
1064
+ return;
1065
+ }
1066
+ // split matrix(1, 0, 0, 1, x, y)
1067
+ var matrixValues = transform.split(',');
1068
+ // translate X value is in 12th or 4th position
1069
+ var xIndex = transform.indexOf('matrix3d') === 0 ? 12 : 4;
1070
+ var translateX = parseInt( matrixValues[ xIndex ], 10 );
1071
+ // translate Y value is in 13th or 5th position
1072
+ var translateY = parseInt( matrixValues[ xIndex + 1 ], 10 );
1073
+ this.position.x += translateX;
1074
+ this.position.y += translateY;
1075
+ };
1076
+
1077
+ // -------------------------- events -------------------------- //
1078
+
1079
+ // trigger handler methods for events
1080
+ Draggabilly.prototype.handleEvent = function( event ) {
1081
+ var method = 'on' + event.type;
1082
+ if ( this[ method ] ) {
1083
+ this[ method ]( event );
1084
+ }
1085
+ };
1086
+
1087
+ // returns the touch that we're keeping track of
1088
+ Draggabilly.prototype.getTouch = function( touches ) {
1089
+ for ( var i=0, len = touches.length; i < len; i++ ) {
1090
+ var touch = touches[i];
1091
+ if ( touch.identifier === this.pointerIdentifier ) {
1092
+ return touch;
1093
+ }
1094
+ }
1095
+ };
1096
+
1097
+ // ----- start event ----- //
1098
+
1099
+ Draggabilly.prototype.onmousedown = function( event ) {
1100
+ // dismiss clicks from right or middle buttons
1101
+ var button = event.button;
1102
+ if ( button && ( button !== 0 && button !== 1 ) ) {
1103
+ return;
1104
+ }
1105
+ this.dragStart( event, event );
1106
+ };
1107
+
1108
+ Draggabilly.prototype.ontouchstart = function( event ) {
1109
+ // disregard additional touches
1110
+ if ( this.isDragging ) {
1111
+ return;
1112
+ }
1113
+
1114
+ this.dragStart( event, event.changedTouches[0] );
1115
+ };
1116
+
1117
+ Draggabilly.prototype.onMSPointerDown =
1118
+ Draggabilly.prototype.onpointerdown = function( event ) {
1119
+ // disregard additional touches
1120
+ if ( this.isDragging ) {
1121
+ return;
1122
+ }
1123
+
1124
+ this.dragStart( event, event );
1125
+ };
1126
+
1127
+ function setPointerPoint( point, pointer ) {
1128
+ point.x = pointer.pageX !== undefined ? pointer.pageX : pointer.clientX;
1129
+ point.y = pointer.pageY !== undefined ? pointer.pageY : pointer.clientY;
1130
+ }
1131
+
1132
+ // hash of events to be bound after start event
1133
+ var postStartEvents = {
1134
+ mousedown: [ 'mousemove', 'mouseup' ],
1135
+ touchstart: [ 'touchmove', 'touchend', 'touchcancel' ],
1136
+ pointerdown: [ 'pointermove', 'pointerup', 'pointercancel' ],
1137
+ MSPointerDown: [ 'MSPointerMove', 'MSPointerUp', 'MSPointerCancel' ]
1138
+ };
1139
+
1140
+ /**
1141
+ * drag start
1142
+ * @param {Event} event
1143
+ * @param {Event or Touch} pointer
1144
+ */
1145
+ Draggabilly.prototype.dragStart = function( event, pointer ) {
1146
+ if ( !this.isEnabled ) {
1147
+ return;
1148
+ }
1149
+
1150
+ if ( event.preventDefault ) {
1151
+ event.preventDefault();
1152
+ } else {
1153
+ event.returnValue = false;
1154
+ }
1155
+
1156
+ // save pointer identifier to match up touch events
1157
+ this.pointerIdentifier = pointer.pointerId !== undefined ?
1158
+ // pointerId for pointer events, touch.indentifier for touch events
1159
+ pointer.pointerId : pointer.identifier;
1160
+
1161
+ this._getPosition();
1162
+
1163
+ this.measureContainment();
1164
+
1165
+ // point where drag began
1166
+ setPointerPoint( this.startPoint, pointer );
1167
+ // position _when_ drag began
1168
+ this.startPosition.x = this.position.x;
1169
+ this.startPosition.y = this.position.y;
1170
+
1171
+ // reset left/top style
1172
+ this.setLeftTop();
1173
+
1174
+ this.dragPoint.x = 0;
1175
+ this.dragPoint.y = 0;
1176
+
1177
+ // bind move and end events
1178
+ this._bindEvents({
1179
+ // get proper events to match start event
1180
+ events: postStartEvents[ event.type ],
1181
+ // IE8 needs to be bound to document
1182
+ node: event.preventDefault ? window : document
1183
+ });
1184
+
1185
+ classie.add( this.element, 'is-dragging' );
1186
+
1187
+ // reset isDragging flag
1188
+ this.isDragging = true;
1189
+
1190
+ this.emitEvent( 'dragStart', [ this, event, pointer ] );
1191
+
1192
+ // start animation
1193
+ this.animate();
1194
+ };
1195
+
1196
+ Draggabilly.prototype._bindEvents = function( args ) {
1197
+ for ( var i=0, len = args.events.length; i < len; i++ ) {
1198
+ var event = args.events[i];
1199
+ eventie.bind( args.node, event, this );
1200
+ }
1201
+ // save these arguments
1202
+ this._boundEvents = args;
1203
+ };
1204
+
1205
+ Draggabilly.prototype._unbindEvents = function() {
1206
+ var args = this._boundEvents;
1207
+ // IE8 can trigger dragEnd twice, check for _boundEvents
1208
+ if ( !args || !args.events ) {
1209
+ return;
1210
+ }
1211
+
1212
+ for ( var i=0, len = args.events.length; i < len; i++ ) {
1213
+ var event = args.events[i];
1214
+ eventie.unbind( args.node, event, this );
1215
+ }
1216
+ delete this._boundEvents;
1217
+ };
1218
+
1219
+ Draggabilly.prototype.measureContainment = function() {
1220
+ var containment = this.options.containment;
1221
+ if ( !containment ) {
1222
+ return;
1223
+ }
1224
+
1225
+ this.size = getSize( this.element );
1226
+ var elemRect = this.element.getBoundingClientRect();
1227
+
1228
+ // use element if element
1229
+ var container = isElement( containment ) ? containment :
1230
+ // fallback to querySelector if string
1231
+ typeof containment === 'string' ? document.querySelector( containment ) :
1232
+ // otherwise just `true`, use the parent
1233
+ this.element.parentNode;
1234
+
1235
+ this.containerSize = getSize( container );
1236
+ var containerRect = container.getBoundingClientRect();
1237
+
1238
+ this.relativeStartPosition = {
1239
+ x: elemRect.left - containerRect.left,
1240
+ y: elemRect.top - containerRect.top
1241
+ };
1242
+ };
1243
+
1244
+ // ----- move event ----- //
1245
+
1246
+ Draggabilly.prototype.onmousemove = function( event ) {
1247
+ this.dragMove( event, event );
1248
+ };
1249
+
1250
+ Draggabilly.prototype.onMSPointerMove =
1251
+ Draggabilly.prototype.onpointermove = function( event ) {
1252
+ if ( event.pointerId === this.pointerIdentifier ) {
1253
+ this.dragMove( event, event );
1254
+ }
1255
+ };
1256
+
1257
+ Draggabilly.prototype.ontouchmove = function( event ) {
1258
+ var touch = this.getTouch( event.changedTouches );
1259
+ if ( touch ) {
1260
+ this.dragMove( event, touch );
1261
+ }
1262
+ };
1263
+
1264
+ /**
1265
+ * drag move
1266
+ * @param {Event} event
1267
+ * @param {Event or Touch} pointer
1268
+ */
1269
+ Draggabilly.prototype.dragMove = function( event, pointer ) {
1270
+
1271
+ setPointerPoint( this.dragPoint, pointer );
1272
+ var dragX = this.dragPoint.x - this.startPoint.x;
1273
+ var dragY = this.dragPoint.y - this.startPoint.y;
1274
+
1275
+ var grid = this.options.grid;
1276
+ var gridX = grid && grid[0];
1277
+ var gridY = grid && grid[1];
1278
+
1279
+ dragX = applyGrid( dragX, gridX );
1280
+ dragY = applyGrid( dragY, gridY );
1281
+
1282
+ dragX = this.containDrag( 'x', dragX, gridX );
1283
+ dragY = this.containDrag( 'y', dragY, gridY );
1284
+
1285
+ // constrain to axis
1286
+ dragX = this.options.axis === 'y' ? 0 : dragX;
1287
+ dragY = this.options.axis === 'x' ? 0 : dragY;
1288
+
1289
+ this.position.x = this.startPosition.x + dragX;
1290
+ this.position.y = this.startPosition.y + dragY;
1291
+ // set dragPoint properties
1292
+ this.dragPoint.x = dragX;
1293
+ this.dragPoint.y = dragY;
1294
+
1295
+ this.emitEvent( 'dragMove', [ this, event, pointer ] );
1296
+ };
1297
+
1298
+ function applyGrid( value, grid, method ) {
1299
+ method = method || 'round';
1300
+ return grid ? Math[ method ]( value / grid ) * grid : value;
1301
+ }
1302
+
1303
+ Draggabilly.prototype.containDrag = function( axis, drag, grid ) {
1304
+ if ( !this.options.containment ) {
1305
+ return drag;
1306
+ }
1307
+ var measure = axis === 'x' ? 'width' : 'height';
1308
+
1309
+ var rel = this.relativeStartPosition[ axis ];
1310
+ var min = applyGrid( -rel, grid, 'ceil' );
1311
+ var max = this.containerSize[ measure ] - rel - this.size[ measure ];
1312
+ max = applyGrid( max, grid, 'floor' );
1313
+ return Math.min( max, Math.max( min, drag ) );
1314
+ };
1315
+
1316
+ // ----- end event ----- //
1317
+
1318
+ Draggabilly.prototype.onmouseup = function( event ) {
1319
+ this.dragEnd( event, event );
1320
+ };
1321
+
1322
+ Draggabilly.prototype.onMSPointerUp =
1323
+ Draggabilly.prototype.onpointerup = function( event ) {
1324
+ if ( event.pointerId === this.pointerIdentifier ) {
1325
+ this.dragEnd( event, event );
1326
+ }
1327
+ };
1328
+
1329
+ Draggabilly.prototype.ontouchend = function( event ) {
1330
+ var touch = this.getTouch( event.changedTouches );
1331
+ if ( touch ) {
1332
+ this.dragEnd( event, touch );
1333
+ }
1334
+ };
1335
+
1336
+ /**
1337
+ * drag end
1338
+ * @param {Event} event
1339
+ * @param {Event or Touch} pointer
1340
+ */
1341
+ Draggabilly.prototype.dragEnd = function( event, pointer ) {
1342
+ this.isDragging = false;
1343
+
1344
+ delete this.pointerIdentifier;
1345
+
1346
+ // use top left position when complete
1347
+ if ( transformProperty ) {
1348
+ this.element.style[ transformProperty ] = '';
1349
+ this.setLeftTop();
1350
+ }
1351
+
1352
+ // remove events
1353
+ this._unbindEvents();
1354
+
1355
+ classie.remove( this.element, 'is-dragging' );
1356
+
1357
+ this.emitEvent( 'dragEnd', [ this, event, pointer ] );
1358
+
1359
+ };
1360
+
1361
+ // ----- cancel event ----- //
1362
+
1363
+ // coerce to end event
1364
+
1365
+ Draggabilly.prototype.onMSPointerCancel =
1366
+ Draggabilly.prototype.onpointercancel = function( event ) {
1367
+ if ( event.pointerId === this.pointerIdentifier ) {
1368
+ this.dragEnd( event, event );
1369
+ }
1370
+ };
1371
+
1372
+ Draggabilly.prototype.ontouchcancel = function( event ) {
1373
+ var touch = this.getTouch( event.changedTouches );
1374
+ this.dragEnd( event, touch );
1375
+ };
1376
+
1377
+ // -------------------------- animation -------------------------- //
1378
+
1379
+ Draggabilly.prototype.animate = function() {
1380
+ // only render and animate if dragging
1381
+ if ( !this.isDragging ) {
1382
+ return;
1383
+ }
1384
+
1385
+ this.positionDrag();
1386
+
1387
+ var _this = this;
1388
+ requestAnimationFrame( function animateFrame() {
1389
+ _this.animate();
1390
+ });
1391
+
1392
+ };
1393
+
1394
+ // transform translate function
1395
+ var translate = is3d ?
1396
+ function( x, y ) {
1397
+ return 'translate3d( ' + x + 'px, ' + y + 'px, 0)';
1398
+ } :
1399
+ function( x, y ) {
1400
+ return 'translate( ' + x + 'px, ' + y + 'px)';
1401
+ };
1402
+
1403
+ // left/top positioning
1404
+ Draggabilly.prototype.setLeftTop = function() {
1405
+ this.element.style.left = this.position.x + 'px';
1406
+ this.element.style.top = this.position.y + 'px';
1407
+ };
1408
+
1409
+ Draggabilly.prototype.positionDrag = transformProperty ?
1410
+ function() {
1411
+ // position with transform
1412
+ this.element.style[ transformProperty ] = translate( this.dragPoint.x, this.dragPoint.y );
1413
+ } : Draggabilly.prototype.setLeftTop;
1414
+
1415
+ Draggabilly.prototype.enable = function() {
1416
+ this.isEnabled = true;
1417
+ };
1418
+
1419
+ Draggabilly.prototype.disable = function() {
1420
+ this.isEnabled = false;
1421
+ if ( this.isDragging ) {
1422
+ this.dragEnd();
1423
+ }
1424
+ };
1425
+
1426
+ return Draggabilly;
1427
+
1428
+ } // end definition
1429
+
1430
+ // -------------------------- transport -------------------------- //
1431
+
1432
+ if ( typeof define === 'function' && define.amd ) {
1433
+ // AMD
1434
+ define( [
1435
+ 'classie/classie',
1436
+ 'eventEmitter/EventEmitter',
1437
+ 'eventie/eventie',
1438
+ 'get-style-property/get-style-property',
1439
+ 'get-size/get-size'
1440
+ ],
1441
+ draggabillyDefinition );
1442
+ } else if ( typeof exports === 'object' ) {
1443
+ // CommonJS
1444
+ module.exports = draggabillyDefinition(
1445
+ require('desandro-classie'),
1446
+ require('wolfy87-eventemitter'),
1447
+ require('eventie'),
1448
+ require('desandro-get-style-property'),
1449
+ require('get-size')
1450
+ );
1451
+ } else {
1452
+ // browser global
1453
+ window.Draggabilly = draggabillyDefinition(
1454
+ window.classie,
1455
+ window.EventEmitter,
1456
+ window.eventie,
1457
+ window.getStyleProperty,
1458
+ window.getSize
1459
+ );
1460
+ }
1461
+
1462
+ })( window );