jquery-drag-rails 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +22 -0
- data/jquery-drag-rails.gemspec +17 -0
- data/lib/jquery-drag-rails.rb +11 -0
- data/lib/jquery-drag-rails/version.rb +7 -0
- data/vendor/assets/javascripts/jquery.event.drag.js +403 -0
- data/vendor/assets/javascripts/jquery.event.drag.live.js +87 -0
- metadata +55 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Charles Lowell
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Jquery::Drag::Rails
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'jquery-drag-rails'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install jquery-drag-rails
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
|
4
|
+
directory TempDir = "tmp"
|
5
|
+
directory JavaScriptsDir = "vendor/assets/javascripts"
|
6
|
+
|
7
|
+
desc "import an upstream archive of the jquery drag event"
|
8
|
+
task "import" => [TempDir, JavaScriptsDir] do
|
9
|
+
archive = ENV['archive'] or fail "specify and archive to import with archive=FILE"
|
10
|
+
fail "no such file #{archive}" unless File.exists?(archive)
|
11
|
+
sh "cp #{archive} tmp"
|
12
|
+
sh "cd tmp && unzip #{archive}"
|
13
|
+
sh "rm -rf #{JavaScriptsDir}/*"
|
14
|
+
Dir['**/*.js'].each do |file|
|
15
|
+
require_name = File.basename(file).gsub(/(.*)-.*\.js$/,'\1.js')
|
16
|
+
sh "cp -f #{file} vendor/assets/javascripts/#{require_name}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
task "clean" do
|
21
|
+
sh "rm -rf tmp/*"
|
22
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/jquery-drag-rails/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Charles Lowell"]
|
6
|
+
gem.email = ["cowboyd@thefrontside.net"]
|
7
|
+
gem.description = %q{Use jquery-drag special events in rails}
|
8
|
+
gem.summary = %q{Adds dragstart, drag, dragend events to any element}
|
9
|
+
gem.homepage = "https://github.com/thefrontside/jquery-drag-rails"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "jquery-drag-rails"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Jquery::Drag::Rails::VERSION
|
17
|
+
end
|
@@ -0,0 +1,403 @@
|
|
1
|
+
// encoding: utf-8
|
2
|
+
/*!
|
3
|
+
* jquery.event.drag - v 2.2
|
4
|
+
* Copyright (c) 2010 Three Dub Media - http://threedubmedia.com
|
5
|
+
* Open Source MIT License - http://threedubmedia.com/code/license
|
6
|
+
*/
|
7
|
+
// Created: 2008-06-04
|
8
|
+
// Updated: 2012-05-21
|
9
|
+
// REQUIRES: jquery 1.7.x
|
10
|
+
|
11
|
+
;(function( $ ){
|
12
|
+
|
13
|
+
// add the jquery instance method
|
14
|
+
$.fn.drag = function( str, arg, opts ){
|
15
|
+
// figure out the event type
|
16
|
+
var type = typeof str == "string" ? str : "",
|
17
|
+
// figure out the event handler...
|
18
|
+
fn = $.isFunction( str ) ? str : $.isFunction( arg ) ? arg : null;
|
19
|
+
// fix the event type
|
20
|
+
if ( type.indexOf("drag") !== 0 )
|
21
|
+
type = "drag"+ type;
|
22
|
+
// were options passed
|
23
|
+
opts = ( str == fn ? arg : opts ) || {};
|
24
|
+
// trigger or bind event handler
|
25
|
+
return fn ? this.bind( type, opts, fn ) : this.trigger( type );
|
26
|
+
};
|
27
|
+
|
28
|
+
// local refs (increase compression)
|
29
|
+
var $event = $.event,
|
30
|
+
$special = $event.special,
|
31
|
+
// configure the drag special event
|
32
|
+
drag = $special.drag = {
|
33
|
+
|
34
|
+
// these are the default settings
|
35
|
+
defaults: {
|
36
|
+
which: 1, // mouse button pressed to start drag sequence
|
37
|
+
distance: 0, // distance dragged before dragstart
|
38
|
+
not: ':input', // selector to suppress dragging on target elements
|
39
|
+
handle: null, // selector to match handle target elements
|
40
|
+
relative: false, // true to use "position", false to use "offset"
|
41
|
+
drop: true, // false to suppress drop events, true or selector to allow
|
42
|
+
click: false // false to suppress click events after dragend (no proxy)
|
43
|
+
},
|
44
|
+
|
45
|
+
// the key name for stored drag data
|
46
|
+
datakey: "dragdata",
|
47
|
+
|
48
|
+
// prevent bubbling for better performance
|
49
|
+
noBubble: true,
|
50
|
+
|
51
|
+
// count bound related events
|
52
|
+
add: function( obj ){
|
53
|
+
// read the interaction data
|
54
|
+
var data = $.data( this, drag.datakey ),
|
55
|
+
// read any passed options
|
56
|
+
opts = obj.data || {};
|
57
|
+
// count another realted event
|
58
|
+
data.related += 1;
|
59
|
+
// extend data options bound with this event
|
60
|
+
// don't iterate "opts" in case it is a node
|
61
|
+
$.each( drag.defaults, function( key, def ){
|
62
|
+
if ( opts[ key ] !== undefined )
|
63
|
+
data[ key ] = opts[ key ];
|
64
|
+
});
|
65
|
+
},
|
66
|
+
|
67
|
+
// forget unbound related events
|
68
|
+
remove: function(){
|
69
|
+
$.data( this, drag.datakey ).related -= 1;
|
70
|
+
},
|
71
|
+
|
72
|
+
// configure interaction, capture settings
|
73
|
+
setup: function(){
|
74
|
+
// check for related events
|
75
|
+
if ( $.data( this, drag.datakey ) )
|
76
|
+
return;
|
77
|
+
// initialize the drag data with copied defaults
|
78
|
+
var data = $.extend({ related:0 }, drag.defaults );
|
79
|
+
// store the interaction data
|
80
|
+
$.data( this, drag.datakey, data );
|
81
|
+
// bind the mousedown event, which starts drag interactions
|
82
|
+
$event.add( this, "touchstart mousedown", drag.init, data );
|
83
|
+
// prevent image dragging in IE...
|
84
|
+
if ( this.attachEvent )
|
85
|
+
this.attachEvent("ondragstart", drag.dontstart );
|
86
|
+
},
|
87
|
+
|
88
|
+
// destroy configured interaction
|
89
|
+
teardown: function(){
|
90
|
+
var data = $.data( this, drag.datakey ) || {};
|
91
|
+
// check for related events
|
92
|
+
if ( data.related )
|
93
|
+
return;
|
94
|
+
// remove the stored data
|
95
|
+
$.removeData( this, drag.datakey );
|
96
|
+
// remove the mousedown event
|
97
|
+
$event.remove( this, "touchstart mousedown", drag.init );
|
98
|
+
// enable text selection
|
99
|
+
drag.textselect( true );
|
100
|
+
// un-prevent image dragging in IE...
|
101
|
+
if ( this.detachEvent )
|
102
|
+
this.detachEvent("ondragstart", drag.dontstart );
|
103
|
+
},
|
104
|
+
|
105
|
+
// initialize the interaction
|
106
|
+
init: function( event ){
|
107
|
+
// sorry, only one touch at a time
|
108
|
+
if ( drag.touched )
|
109
|
+
return;
|
110
|
+
// the drag/drop interaction data
|
111
|
+
var dd = event.data, results;
|
112
|
+
// check the which directive
|
113
|
+
if ( event.which != 0 && dd.which > 0 && event.which != dd.which )
|
114
|
+
return;
|
115
|
+
// check for suppressed selector
|
116
|
+
if ( $( event.target ).is( dd.not ) )
|
117
|
+
return;
|
118
|
+
// check for handle selector
|
119
|
+
if ( dd.handle && !$( event.target ).closest( dd.handle, event.currentTarget ).length )
|
120
|
+
return;
|
121
|
+
|
122
|
+
drag.touched = event.type == 'touchstart' ? this : null;
|
123
|
+
dd.propagates = 1;
|
124
|
+
dd.mousedown = this;
|
125
|
+
dd.interactions = [ drag.interaction( this, dd ) ];
|
126
|
+
dd.target = event.target;
|
127
|
+
dd.pageX = event.pageX;
|
128
|
+
dd.pageY = event.pageY;
|
129
|
+
dd.dragging = null;
|
130
|
+
// handle draginit event...
|
131
|
+
results = drag.hijack( event, "draginit", dd );
|
132
|
+
// early cancel
|
133
|
+
if ( !dd.propagates )
|
134
|
+
return;
|
135
|
+
// flatten the result set
|
136
|
+
results = drag.flatten( results );
|
137
|
+
// insert new interaction elements
|
138
|
+
if ( results && results.length ){
|
139
|
+
dd.interactions = [];
|
140
|
+
$.each( results, function(){
|
141
|
+
dd.interactions.push( drag.interaction( this, dd ) );
|
142
|
+
});
|
143
|
+
}
|
144
|
+
// remember how many interactions are propagating
|
145
|
+
dd.propagates = dd.interactions.length;
|
146
|
+
// locate and init the drop targets
|
147
|
+
if ( dd.drop !== false && $special.drop )
|
148
|
+
$special.drop.handler( event, dd );
|
149
|
+
// disable text selection
|
150
|
+
drag.textselect( false );
|
151
|
+
// bind additional events...
|
152
|
+
if ( drag.touched )
|
153
|
+
$event.add( drag.touched, "touchmove touchend", drag.handler, dd );
|
154
|
+
else
|
155
|
+
$event.add( document, "mousemove mouseup", drag.handler, dd );
|
156
|
+
// helps prevent text selection or scrolling
|
157
|
+
if ( !drag.touched || dd.live )
|
158
|
+
return false;
|
159
|
+
},
|
160
|
+
|
161
|
+
// returns an interaction object
|
162
|
+
interaction: function( elem, dd ){
|
163
|
+
var offset = $( elem )[ dd.relative ? "position" : "offset" ]() || { top:0, left:0 };
|
164
|
+
return {
|
165
|
+
drag: elem,
|
166
|
+
callback: new drag.callback(),
|
167
|
+
droppable: [],
|
168
|
+
offset: offset
|
169
|
+
};
|
170
|
+
},
|
171
|
+
|
172
|
+
// handle drag-releatd DOM events
|
173
|
+
handler: function( event ){
|
174
|
+
// read the data before hijacking anything
|
175
|
+
var dd = event.data;
|
176
|
+
// handle various events
|
177
|
+
switch ( event.type ){
|
178
|
+
// mousemove, check distance, start dragging
|
179
|
+
case !dd.dragging && 'touchmove':
|
180
|
+
event.preventDefault();
|
181
|
+
case !dd.dragging && 'mousemove':
|
182
|
+
|
183
|
+
if ( Math.pow( event.pageX-dd.pageX, 2 ) + Math.pow( event.pageY-dd.pageY, 2 ) < Math.pow( dd.distance, 2 ) )
|
184
|
+
break; // distance tolerance not reached
|
185
|
+
event.target = dd.target; // force target from "mousedown" event (fix distance issue)
|
186
|
+
drag.hijack( event, "dragstart", dd ); // trigger "dragstart"
|
187
|
+
if ( dd.propagates ) // "dragstart" not rejected
|
188
|
+
dd.dragging = true; // activate interaction
|
189
|
+
// mousemove, dragging
|
190
|
+
case 'touchmove':
|
191
|
+
event.preventDefault();
|
192
|
+
case 'mousemove':
|
193
|
+
if ( dd.dragging ){
|
194
|
+
// trigger "drag"
|
195
|
+
drag.hijack( event, "drag", dd );
|
196
|
+
if ( dd.propagates ){
|
197
|
+
// manage drop events
|
198
|
+
if ( dd.drop !== false && $special.drop )
|
199
|
+
$special.drop.handler( event, dd ); // "dropstart", "dropend"
|
200
|
+
break; // "drag" not rejected, stop
|
201
|
+
}
|
202
|
+
event.type = "mouseup"; // helps "drop" handler behave
|
203
|
+
}
|
204
|
+
// mouseup, stop dragging
|
205
|
+
case 'touchend':
|
206
|
+
case 'mouseup':
|
207
|
+
default:
|
208
|
+
if ( drag.touched )
|
209
|
+
$event.remove( drag.touched, "touchmove touchend", drag.handler ); // remove touch events
|
210
|
+
else
|
211
|
+
$event.remove( document, "mousemove mouseup", drag.handler ); // remove page events
|
212
|
+
if ( dd.dragging ){
|
213
|
+
if ( dd.drop !== false && $special.drop )
|
214
|
+
$special.drop.handler( event, dd ); // "drop"
|
215
|
+
drag.hijack( event, "dragend", dd ); // trigger "dragend"
|
216
|
+
}
|
217
|
+
drag.textselect( true ); // enable text selection
|
218
|
+
// if suppressing click events...
|
219
|
+
if ( dd.click === false && dd.dragging )
|
220
|
+
$.data( dd.mousedown, "suppress.click", new Date().getTime() + 5 );
|
221
|
+
dd.dragging = drag.touched = false; // deactivate element
|
222
|
+
break;
|
223
|
+
}
|
224
|
+
},
|
225
|
+
|
226
|
+
// re-use event object for custom events
|
227
|
+
hijack: function( event, type, dd, x, elem ){
|
228
|
+
// not configured
|
229
|
+
if ( !dd )
|
230
|
+
return;
|
231
|
+
// remember the original event and type
|
232
|
+
var orig = { event:event.originalEvent, type:event.type },
|
233
|
+
// is the event drag related or drog related?
|
234
|
+
mode = type.indexOf("drop") ? "drag" : "drop",
|
235
|
+
// iteration vars
|
236
|
+
result, i = x || 0, ia, $elems, callback,
|
237
|
+
len = !isNaN( x ) ? x : dd.interactions.length;
|
238
|
+
// modify the event type
|
239
|
+
event.type = type;
|
240
|
+
// remove the original event
|
241
|
+
event.originalEvent = null;
|
242
|
+
// initialize the results
|
243
|
+
dd.results = [];
|
244
|
+
// handle each interacted element
|
245
|
+
do if ( ia = dd.interactions[ i ] ){
|
246
|
+
// validate the interaction
|
247
|
+
if ( type !== "dragend" && ia.cancelled )
|
248
|
+
continue;
|
249
|
+
// set the dragdrop properties on the event object
|
250
|
+
callback = drag.properties( event, dd, ia );
|
251
|
+
// prepare for more results
|
252
|
+
ia.results = [];
|
253
|
+
// handle each element
|
254
|
+
$( elem || ia[ mode ] || dd.droppable ).each(function( p, subject ){
|
255
|
+
// identify drag or drop targets individually
|
256
|
+
callback.target = subject;
|
257
|
+
// force propagtion of the custom event
|
258
|
+
event.isPropagationStopped = function(){ return false; };
|
259
|
+
// handle the event
|
260
|
+
result = subject ? $event.dispatch.call( subject, event, callback ) : null;
|
261
|
+
// stop the drag interaction for this element
|
262
|
+
if ( result === false ){
|
263
|
+
if ( mode == "drag" ){
|
264
|
+
ia.cancelled = true;
|
265
|
+
dd.propagates -= 1;
|
266
|
+
}
|
267
|
+
if ( type == "drop" ){
|
268
|
+
ia[ mode ][p] = null;
|
269
|
+
}
|
270
|
+
}
|
271
|
+
// assign any dropinit elements
|
272
|
+
else if ( type == "dropinit" )
|
273
|
+
ia.droppable.push( drag.element( result ) || subject );
|
274
|
+
// accept a returned proxy element
|
275
|
+
if ( type == "dragstart" )
|
276
|
+
ia.proxy = $( drag.element( result ) || ia.drag )[0];
|
277
|
+
// remember this result
|
278
|
+
ia.results.push( result );
|
279
|
+
// forget the event result, for recycling
|
280
|
+
delete event.result;
|
281
|
+
// break on cancelled handler
|
282
|
+
if ( type !== "dropinit" )
|
283
|
+
return result;
|
284
|
+
});
|
285
|
+
// flatten the results
|
286
|
+
dd.results[ i ] = drag.flatten( ia.results );
|
287
|
+
// accept a set of valid drop targets
|
288
|
+
if ( type == "dropinit" )
|
289
|
+
ia.droppable = drag.flatten( ia.droppable );
|
290
|
+
// locate drop targets
|
291
|
+
if ( type == "dragstart" && !ia.cancelled )
|
292
|
+
callback.update();
|
293
|
+
}
|
294
|
+
while ( ++i < len )
|
295
|
+
// restore the original event & type
|
296
|
+
event.type = orig.type;
|
297
|
+
event.originalEvent = orig.event;
|
298
|
+
// return all handler results
|
299
|
+
return drag.flatten( dd.results );
|
300
|
+
},
|
301
|
+
|
302
|
+
// extend the callback object with drag/drop properties...
|
303
|
+
properties: function( event, dd, ia ){
|
304
|
+
var obj = ia.callback;
|
305
|
+
// elements
|
306
|
+
obj.drag = ia.drag;
|
307
|
+
obj.proxy = ia.proxy || ia.drag;
|
308
|
+
// starting mouse position
|
309
|
+
obj.startX = dd.pageX;
|
310
|
+
obj.startY = dd.pageY;
|
311
|
+
// current distance dragged
|
312
|
+
obj.deltaX = event.pageX - dd.pageX;
|
313
|
+
obj.deltaY = event.pageY - dd.pageY;
|
314
|
+
// original element position
|
315
|
+
obj.originalX = ia.offset.left;
|
316
|
+
obj.originalY = ia.offset.top;
|
317
|
+
// adjusted element position
|
318
|
+
obj.offsetX = obj.originalX + obj.deltaX;
|
319
|
+
obj.offsetY = obj.originalY + obj.deltaY;
|
320
|
+
// assign the drop targets information
|
321
|
+
obj.drop = drag.flatten( ( ia.drop || [] ).slice() );
|
322
|
+
obj.available = drag.flatten( ( ia.droppable || [] ).slice() );
|
323
|
+
return obj;
|
324
|
+
},
|
325
|
+
|
326
|
+
// determine is the argument is an element or jquery instance
|
327
|
+
element: function( arg ){
|
328
|
+
if ( arg && ( arg.jquery || arg.nodeType == 1 ) )
|
329
|
+
return arg;
|
330
|
+
},
|
331
|
+
|
332
|
+
// flatten nested jquery objects and arrays into a single dimension array
|
333
|
+
flatten: function( arr ){
|
334
|
+
return $.map( arr, function( member ){
|
335
|
+
return member && member.jquery ? $.makeArray( member ) :
|
336
|
+
member && member.length ? drag.flatten( member ) : member;
|
337
|
+
});
|
338
|
+
},
|
339
|
+
|
340
|
+
// toggles text selection attributes ON (true) or OFF (false)
|
341
|
+
textselect: function( bool ){
|
342
|
+
$( document )[ bool ? "unbind" : "bind" ]("selectstart", drag.dontstart )
|
343
|
+
.css("MozUserSelect", bool ? "" : "none" );
|
344
|
+
// .attr("unselectable", bool ? "off" : "on" )
|
345
|
+
document.unselectable = bool ? "off" : "on";
|
346
|
+
},
|
347
|
+
|
348
|
+
// suppress "selectstart" and "ondragstart" events
|
349
|
+
dontstart: function(){
|
350
|
+
return false;
|
351
|
+
},
|
352
|
+
|
353
|
+
// a callback instance contructor
|
354
|
+
callback: function(){}
|
355
|
+
|
356
|
+
};
|
357
|
+
|
358
|
+
// callback methods
|
359
|
+
drag.callback.prototype = {
|
360
|
+
update: function(){
|
361
|
+
if ( $special.drop && this.available.length )
|
362
|
+
$.each( this.available, function( i ){
|
363
|
+
$special.drop.locate( this, i );
|
364
|
+
});
|
365
|
+
}
|
366
|
+
};
|
367
|
+
|
368
|
+
// patch $.event.$dispatch to allow suppressing clicks
|
369
|
+
var $dispatch = $event.dispatch;
|
370
|
+
$event.dispatch = function( event ){
|
371
|
+
if ( $.data( this, "suppress."+ event.type ) - new Date().getTime() > 0 ){
|
372
|
+
$.removeData( this, "suppress."+ event.type );
|
373
|
+
return;
|
374
|
+
}
|
375
|
+
return $dispatch.apply( this, arguments );
|
376
|
+
};
|
377
|
+
|
378
|
+
// event fix hooks for touch events...
|
379
|
+
var touchHooks =
|
380
|
+
$event.fixHooks.touchstart =
|
381
|
+
$event.fixHooks.touchmove =
|
382
|
+
$event.fixHooks.touchend =
|
383
|
+
$event.fixHooks.touchcancel = {
|
384
|
+
props: "clientX clientY pageX pageY screenX screenY".split( " " ),
|
385
|
+
filter: function( event, orig ) {
|
386
|
+
if ( orig ){
|
387
|
+
var touched = ( orig.touches && orig.touches[0] )
|
388
|
+
|| ( orig.changedTouches && orig.changedTouches[0] )
|
389
|
+
|| null;
|
390
|
+
// iOS webkit: touchstart, touchmove, touchend
|
391
|
+
if ( touched )
|
392
|
+
$.each( touchHooks.props, function( i, prop ){
|
393
|
+
event[ prop ] = touched[ prop ];
|
394
|
+
});
|
395
|
+
}
|
396
|
+
return event;
|
397
|
+
}
|
398
|
+
};
|
399
|
+
|
400
|
+
// share the same special event configuration with related events...
|
401
|
+
$special.draginit = $special.dragstart = $special.dragend = drag;
|
402
|
+
|
403
|
+
})( jQuery );
|
@@ -0,0 +1,87 @@
|
|
1
|
+
/*!
|
2
|
+
* jquery.event.drag.live - v 2.2
|
3
|
+
* Copyright (c) 2010 Three Dub Media - http://threedubmedia.com
|
4
|
+
* Open Source MIT License - http://threedubmedia.com/code/license
|
5
|
+
*/
|
6
|
+
// Created: 2010-06-07
|
7
|
+
// Updated: 2012-05-21
|
8
|
+
// REQUIRES: jquery 1.7.x, event.drag 2.2
|
9
|
+
|
10
|
+
;(function( $ ){
|
11
|
+
|
12
|
+
// local refs (increase compression)
|
13
|
+
var $event = $.event,
|
14
|
+
// ref the special event config
|
15
|
+
drag = $event.special.drag,
|
16
|
+
// old drag event add method
|
17
|
+
origadd = drag.add,
|
18
|
+
// old drag event teradown method
|
19
|
+
origteardown = drag.teardown;
|
20
|
+
|
21
|
+
// allow events to bubble for delegation
|
22
|
+
drag.noBubble = false;
|
23
|
+
|
24
|
+
// the namespace for internal live events
|
25
|
+
drag.livekey = "livedrag";
|
26
|
+
|
27
|
+
// new drop event add method
|
28
|
+
drag.add = function( obj ){
|
29
|
+
// call the old method
|
30
|
+
origadd.apply( this, arguments );
|
31
|
+
// read the data
|
32
|
+
var data = $.data( this, drag.datakey );
|
33
|
+
// bind the live "draginit" delegator
|
34
|
+
if ( !data.live && obj.selector ){
|
35
|
+
data.live = true;
|
36
|
+
$event.add( this, "draginit."+ drag.livekey, drag.delegate );
|
37
|
+
}
|
38
|
+
};
|
39
|
+
|
40
|
+
// new drop event teardown method
|
41
|
+
drag.teardown = function(){
|
42
|
+
// call the old method
|
43
|
+
origteardown.apply( this, arguments );
|
44
|
+
// read the data
|
45
|
+
var data = $.data( this, drag.datakey ) || {};
|
46
|
+
// bind the live "draginit" delegator
|
47
|
+
if ( data.live ){
|
48
|
+
// remove the "live" delegation
|
49
|
+
$event.remove( this, "draginit."+ drag.livekey, drag.delegate );
|
50
|
+
data.live = false;
|
51
|
+
}
|
52
|
+
};
|
53
|
+
|
54
|
+
// identify potential delegate elements
|
55
|
+
drag.delegate = function( event ){
|
56
|
+
// local refs
|
57
|
+
var elems = [], target,
|
58
|
+
// element event structure
|
59
|
+
events = $.data( this, "events" ) || {};
|
60
|
+
// query live events
|
61
|
+
$.each( events || [], function( key, arr ){
|
62
|
+
// no event type matches
|
63
|
+
if ( key.indexOf("drag") !== 0 )
|
64
|
+
return;
|
65
|
+
$.each( arr || [], function( i, obj ){
|
66
|
+
// locate the element to delegate
|
67
|
+
target = $( event.target ).closest( obj.selector, event.currentTarget )[0];
|
68
|
+
// no element found
|
69
|
+
if ( !target )
|
70
|
+
return;
|
71
|
+
// add an event handler
|
72
|
+
$event.add( target, obj.origType+'.'+drag.livekey, obj.origHandler || obj.handler, obj.data );
|
73
|
+
// remember new elements
|
74
|
+
if ( $.inArray( target, elems ) < 0 )
|
75
|
+
elems.push( target );
|
76
|
+
});
|
77
|
+
});
|
78
|
+
// if there are no elements, break
|
79
|
+
if ( !elems.length )
|
80
|
+
return false;
|
81
|
+
// return the matched results, and clenup when complete
|
82
|
+
return $( elems ).bind("dragend."+ drag.livekey, function(){
|
83
|
+
$event.remove( this, "."+ drag.livekey ); // cleanup delegation
|
84
|
+
});
|
85
|
+
};
|
86
|
+
|
87
|
+
})( jQuery );
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jquery-drag-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.2.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Charles Lowell
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-06 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Use jquery-drag special events in rails
|
15
|
+
email:
|
16
|
+
- cowboyd@thefrontside.net
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- jquery-drag-rails.gemspec
|
27
|
+
- lib/jquery-drag-rails.rb
|
28
|
+
- lib/jquery-drag-rails/version.rb
|
29
|
+
- vendor/assets/javascripts/jquery.event.drag.js
|
30
|
+
- vendor/assets/javascripts/jquery.event.drag.live.js
|
31
|
+
homepage: https://github.com/thefrontside/jquery-drag-rails
|
32
|
+
licenses: []
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
requirements: []
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 1.8.24
|
52
|
+
signing_key:
|
53
|
+
specification_version: 3
|
54
|
+
summary: Adds dragstart, drag, dragend events to any element
|
55
|
+
test_files: []
|