jquery-plugins-rails 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +65 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/jquery-plugins-rails.gemspec +20 -0
- data/lib/jquery-plugins-rails.rb +1 -0
- data/lib/jquery-plugins/rails.rb +6 -0
- data/lib/jquery-plugins/rails/engine.rb +7 -0
- data/lib/jquery-plugins/rails/version.rb +5 -0
- data/vendor/assets/javascripts/jquery/event/drag.js +388 -0
- data/vendor/assets/javascripts/jquery/event/drop.js +341 -0
- data/vendor/assets/javascripts/jquery/livequery.js +226 -0
- data/vendor/assets/javascripts/jquery/metadata.js +120 -0
- metadata +82 -0
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm --create ruby-1.9.3-p0@jquery-plugins-rails
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
jquery-plugins-rails (0.1.0)
|
5
|
+
jquery-rails
|
6
|
+
railties (~> 3.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actionpack (3.2.1)
|
12
|
+
activemodel (= 3.2.1)
|
13
|
+
activesupport (= 3.2.1)
|
14
|
+
builder (~> 3.0.0)
|
15
|
+
erubis (~> 2.7.0)
|
16
|
+
journey (~> 1.0.1)
|
17
|
+
rack (~> 1.4.0)
|
18
|
+
rack-cache (~> 1.1)
|
19
|
+
rack-test (~> 0.6.1)
|
20
|
+
sprockets (~> 2.1.2)
|
21
|
+
activemodel (3.2.1)
|
22
|
+
activesupport (= 3.2.1)
|
23
|
+
builder (~> 3.0.0)
|
24
|
+
activesupport (3.2.1)
|
25
|
+
i18n (~> 0.6)
|
26
|
+
multi_json (~> 1.0)
|
27
|
+
builder (3.0.0)
|
28
|
+
erubis (2.7.0)
|
29
|
+
hike (1.2.1)
|
30
|
+
i18n (0.6.0)
|
31
|
+
journey (1.0.1)
|
32
|
+
jquery-rails (2.0.0)
|
33
|
+
railties (>= 3.2.0.beta, < 5.0)
|
34
|
+
thor (~> 0.14)
|
35
|
+
json (1.6.5)
|
36
|
+
multi_json (1.0.4)
|
37
|
+
rack (1.4.1)
|
38
|
+
rack-cache (1.1)
|
39
|
+
rack (>= 0.4)
|
40
|
+
rack-ssl (1.3.2)
|
41
|
+
rack
|
42
|
+
rack-test (0.6.1)
|
43
|
+
rack (>= 1.0)
|
44
|
+
railties (3.2.1)
|
45
|
+
actionpack (= 3.2.1)
|
46
|
+
activesupport (= 3.2.1)
|
47
|
+
rack-ssl (~> 1.3.2)
|
48
|
+
rake (>= 0.8.7)
|
49
|
+
rdoc (~> 3.4)
|
50
|
+
thor (~> 0.14.6)
|
51
|
+
rake (0.9.2.2)
|
52
|
+
rdoc (3.12)
|
53
|
+
json (~> 1.4)
|
54
|
+
sprockets (2.1.2)
|
55
|
+
hike (~> 1.2)
|
56
|
+
rack (~> 1.0)
|
57
|
+
tilt (~> 1.1, != 1.3.0)
|
58
|
+
thor (0.14.6)
|
59
|
+
tilt (1.3.3)
|
60
|
+
|
61
|
+
PLATFORMS
|
62
|
+
ruby
|
63
|
+
|
64
|
+
DEPENDENCIES
|
65
|
+
jquery-plugins-rails!
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Benedikt Böhm
|
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
|
+
# JqueryPlugins::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-plugins-rails'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install jquery-plugins-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,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/jquery-plugins/rails/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = "jquery-plugins-rails"
|
6
|
+
gem.version = JqueryPlugins::Rails::VERSION
|
7
|
+
gem.authors = ["Benedikt Böhm"]
|
8
|
+
gem.email = ["bb@xnull.de"]
|
9
|
+
gem.description = %q{jQuery plugins for Rails 3.x asset pipeline}
|
10
|
+
gem.summary = %q{jQuery plugins for Rails 3.x asset pipeline}
|
11
|
+
gem.homepage = "https://github.com/zenops/jquery-plugins-rails"
|
12
|
+
|
13
|
+
gem.add_dependency "railties", "~> 3.0"
|
14
|
+
gem.add_dependency "jquery-rails"
|
15
|
+
|
16
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
gem.files = `git ls-files`.split("\n")
|
18
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "jquery-plugins/rails"
|
@@ -0,0 +1,388 @@
|
|
1
|
+
/*!
|
2
|
+
* jquery.event.drag - v 2.0.0
|
3
|
+
* Copyright (c) 2010 Three Dub Media - http://threedubmedia.com
|
4
|
+
* Open Source MIT License - http://threedubmedia.com/code/license
|
5
|
+
*/
|
6
|
+
// Created: 2008-06-04
|
7
|
+
// Updated: 2010-06-07
|
8
|
+
// REQUIRES: jquery 1.4.2+
|
9
|
+
|
10
|
+
;(function( $ ){
|
11
|
+
|
12
|
+
// add the jquery instance method
|
13
|
+
$.fn.drag = function( str, arg, opts ){
|
14
|
+
// figure out the event type
|
15
|
+
var type = typeof str == "string" ? str : "",
|
16
|
+
// figure out the event handler...
|
17
|
+
fn = $.isFunction( str ) ? str : $.isFunction( arg ) ? arg : null;
|
18
|
+
// fix the event type
|
19
|
+
if ( type.indexOf("drag") !== 0 )
|
20
|
+
type = "drag"+ type;
|
21
|
+
// were options passed
|
22
|
+
opts = ( str == fn ? arg : opts ) || {};
|
23
|
+
// trigger or bind event handler
|
24
|
+
return fn ? this.bind( type, opts, fn ) : this.trigger( type );
|
25
|
+
};
|
26
|
+
|
27
|
+
// local refs (increase compression)
|
28
|
+
var $event = $.event,
|
29
|
+
$special = $event.special,
|
30
|
+
// configure the drag special event
|
31
|
+
drag = $special.drag = {
|
32
|
+
|
33
|
+
// these are the default settings
|
34
|
+
defaults: {
|
35
|
+
which: 1, // mouse button pressed to start drag sequence
|
36
|
+
distance: 0, // distance dragged before dragstart
|
37
|
+
not: ':input', // selector to suppress dragging on target elements
|
38
|
+
handle: null, // selector to match handle target elements
|
39
|
+
relative: false, // true to use "position", false to use "offset"
|
40
|
+
drop: true, // false to suppress drop events, true or selector to allow
|
41
|
+
click: false // false to suppress click events after dragend (no proxy)
|
42
|
+
},
|
43
|
+
|
44
|
+
// the key name for stored drag data
|
45
|
+
datakey: "dragdata",
|
46
|
+
|
47
|
+
// the namespace for internal live events
|
48
|
+
livekey: "livedrag",
|
49
|
+
|
50
|
+
// count bound related events
|
51
|
+
add: function( obj ){
|
52
|
+
// read the interaction data
|
53
|
+
var data = $.data( this, drag.datakey ),
|
54
|
+
// read any passed options
|
55
|
+
opts = obj.data || {};
|
56
|
+
// count another realted event
|
57
|
+
data.related += 1;
|
58
|
+
// bind the live "draginit" delegator
|
59
|
+
if ( !data.live && obj.selector ){
|
60
|
+
data.live = true;
|
61
|
+
$event.add( this, "draginit."+ drag.livekey, drag.delegate );
|
62
|
+
}
|
63
|
+
// extend data options bound with this event
|
64
|
+
// don't iterate "opts" in case it is a node
|
65
|
+
$.each( drag.defaults, function( key, def ){
|
66
|
+
if ( opts[ key ] !== undefined )
|
67
|
+
data[ key ] = opts[ key ];
|
68
|
+
});
|
69
|
+
},
|
70
|
+
|
71
|
+
// forget unbound related events
|
72
|
+
remove: function(){
|
73
|
+
$.data( this, drag.datakey ).related -= 1;
|
74
|
+
},
|
75
|
+
|
76
|
+
// configure interaction, capture settings
|
77
|
+
setup: function(){
|
78
|
+
// check for related events
|
79
|
+
if ( $.data( this, drag.datakey ) )
|
80
|
+
return;
|
81
|
+
// initialize the drag data with copied defaults
|
82
|
+
var data = $.extend({ related:0 }, drag.defaults );
|
83
|
+
// store the interaction data
|
84
|
+
$.data( this, drag.datakey, data );
|
85
|
+
// bind the mousedown event, which starts drag interactions
|
86
|
+
$event.add( this, "mousedown", drag.init, data );
|
87
|
+
// prevent image dragging in IE...
|
88
|
+
if ( this.attachEvent )
|
89
|
+
this.attachEvent("ondragstart", drag.dontstart );
|
90
|
+
},
|
91
|
+
|
92
|
+
// destroy configured interaction
|
93
|
+
teardown: function(){
|
94
|
+
// check for related events
|
95
|
+
if ( $.data( this, drag.datakey ).related )
|
96
|
+
return;
|
97
|
+
// remove the stored data
|
98
|
+
$.removeData( this, drag.datakey );
|
99
|
+
// remove the mousedown event
|
100
|
+
$event.remove( this, "mousedown", drag.init );
|
101
|
+
// remove the "live" delegation
|
102
|
+
$event.remove( this, "draginit", drag.delegate );
|
103
|
+
// enable text selection
|
104
|
+
drag.textselect( true );
|
105
|
+
// un-prevent image dragging in IE...
|
106
|
+
if ( this.detachEvent )
|
107
|
+
this.detachEvent("ondragstart", drag.dontstart );
|
108
|
+
},
|
109
|
+
|
110
|
+
// initialize the interaction
|
111
|
+
init: function( event ){
|
112
|
+
// the drag/drop interaction data
|
113
|
+
var dd = event.data, results;
|
114
|
+
// check the which directive
|
115
|
+
if ( dd.which > 0 && event.which != dd.which )
|
116
|
+
return;
|
117
|
+
// check for suppressed selector
|
118
|
+
if ( $( event.target ).is( dd.not ) )
|
119
|
+
return;
|
120
|
+
// check for handle selector
|
121
|
+
if ( dd.handle && !$( event.target ).closest( dd.handle, event.currentTarget ).length )
|
122
|
+
return;
|
123
|
+
// store/reset some initial attributes
|
124
|
+
dd.propagates = 1;
|
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
|
+
$event.add( document, "mousemove mouseup", drag.handler, dd );
|
153
|
+
// helps prevent text selection
|
154
|
+
return false;
|
155
|
+
},
|
156
|
+
// returns an interaction object
|
157
|
+
interaction: function( elem, dd ){
|
158
|
+
return {
|
159
|
+
drag: elem,
|
160
|
+
callback: new drag.callback(),
|
161
|
+
droppable: [],
|
162
|
+
offset: $( elem )[ dd.relative ? "position" : "offset" ]() || { top:0, left:0 }
|
163
|
+
};
|
164
|
+
},
|
165
|
+
// handle drag-releatd DOM events
|
166
|
+
handler: function( event ){
|
167
|
+
// read the data before hijacking anything
|
168
|
+
var dd = event.data;
|
169
|
+
// handle various events
|
170
|
+
switch ( event.type ){
|
171
|
+
// mousemove, check distance, start dragging
|
172
|
+
case !dd.dragging && 'mousemove':
|
173
|
+
// drag tolerance, x� + y� = distance�
|
174
|
+
if ( Math.pow( event.pageX-dd.pageX, 2 ) + Math.pow( event.pageY-dd.pageY, 2 ) < Math.pow( dd.distance, 2 ) )
|
175
|
+
break; // distance tolerance not reached
|
176
|
+
event.target = dd.target; // force target from "mousedown" event (fix distance issue)
|
177
|
+
drag.hijack( event, "dragstart", dd ); // trigger "dragstart"
|
178
|
+
if ( dd.propagates ) // "dragstart" not rejected
|
179
|
+
dd.dragging = true; // activate interaction
|
180
|
+
// mousemove, dragging
|
181
|
+
case 'mousemove':
|
182
|
+
if ( dd.dragging ){
|
183
|
+
// trigger "drag"
|
184
|
+
drag.hijack( event, "drag", dd );
|
185
|
+
if ( dd.propagates ){
|
186
|
+
// manage drop events
|
187
|
+
if ( dd.drop !== false && $special.drop )
|
188
|
+
$special.drop.handler( event, dd ); // "dropstart", "dropend"
|
189
|
+
break; // "drag" not rejected, stop
|
190
|
+
}
|
191
|
+
event.type = "mouseup"; // helps "drop" handler behave
|
192
|
+
}
|
193
|
+
// mouseup, stop dragging
|
194
|
+
case 'mouseup':
|
195
|
+
$event.remove( document, "mousemove mouseup", drag.handler ); // remove page events
|
196
|
+
if ( dd.dragging ){
|
197
|
+
if ( dd.drop !== false && $special.drop )
|
198
|
+
$special.drop.handler( event, dd ); // "drop"
|
199
|
+
drag.hijack( event, "dragend", dd ); // trigger "dragend"
|
200
|
+
}
|
201
|
+
drag.textselect( true ); // enable text selection
|
202
|
+
|
203
|
+
// if suppressing click events...
|
204
|
+
if ( dd.click === false && dd.dragging ){
|
205
|
+
jQuery.event.triggered = true;
|
206
|
+
setTimeout(function(){
|
207
|
+
jQuery.event.triggered = false;
|
208
|
+
}, 20 );
|
209
|
+
dd.dragging = false; // deactivate element
|
210
|
+
}
|
211
|
+
break;
|
212
|
+
}
|
213
|
+
},
|
214
|
+
|
215
|
+
// identify potential delegate elements
|
216
|
+
delegate: function( event ){
|
217
|
+
// local refs
|
218
|
+
var elems = [], target,
|
219
|
+
// element event structure
|
220
|
+
events = $.data( this, "events" ) || {};
|
221
|
+
// query live events
|
222
|
+
$.each( events.live || [], function( i, obj ){
|
223
|
+
// no event type matches
|
224
|
+
if ( obj.preType.indexOf("drag") !== 0 )
|
225
|
+
return;
|
226
|
+
// locate the element to delegate
|
227
|
+
target = $( event.target ).closest( obj.selector, event.currentTarget )[0];
|
228
|
+
// no element found
|
229
|
+
if ( !target )
|
230
|
+
return;
|
231
|
+
// add an event handler
|
232
|
+
$event.add( target, obj.origType+'.'+drag.livekey, obj.origHandler, obj.data );
|
233
|
+
// remember new elements
|
234
|
+
if ( $.inArray( target, elems ) < 0 )
|
235
|
+
elems.push( target );
|
236
|
+
});
|
237
|
+
// if there are no elements, break
|
238
|
+
if ( !elems.length )
|
239
|
+
return false;
|
240
|
+
// return the matched results, and clenup when complete
|
241
|
+
return $( elems ).bind("dragend."+ drag.livekey, function(){
|
242
|
+
$event.remove( this, "."+ drag.livekey ); // cleanup delegation
|
243
|
+
});
|
244
|
+
},
|
245
|
+
|
246
|
+
// re-use event object for custom events
|
247
|
+
hijack: function( event, type, dd, x, elem ){
|
248
|
+
// not configured
|
249
|
+
if ( !dd )
|
250
|
+
return;
|
251
|
+
// remember the original event and type
|
252
|
+
var orig = { event:event.originalEvent, type: event.type },
|
253
|
+
// is the event drag related or drog related?
|
254
|
+
mode = type.indexOf("drop") ? "drag" : "drop",
|
255
|
+
// iteration vars
|
256
|
+
result, i = x || 0, ia, $elems, callback,
|
257
|
+
len = !isNaN( x ) ? x : dd.interactions.length;
|
258
|
+
// modify the event type
|
259
|
+
event.type = type;
|
260
|
+
// remove the original event
|
261
|
+
event.originalEvent = null;
|
262
|
+
// initialize the results
|
263
|
+
dd.results = [];
|
264
|
+
// handle each interacted element
|
265
|
+
do if ( ia = dd.interactions[ i ] ){
|
266
|
+
// validate the interaction
|
267
|
+
if ( type !== "dragend" && ia.cancelled )
|
268
|
+
continue;
|
269
|
+
// set the dragdrop properties on the event object
|
270
|
+
callback = drag.properties( event, dd, ia );
|
271
|
+
// prepare for more results
|
272
|
+
ia.results = [];
|
273
|
+
// handle each element
|
274
|
+
$( elem || ia[ mode ] || dd.droppable ).each(function( p, subject ){
|
275
|
+
// identify drag or drop targets individually
|
276
|
+
callback.target = subject;
|
277
|
+
// handle the event
|
278
|
+
result = subject ? $event.handle.call( subject, event, callback ) : null;
|
279
|
+
// stop the drag interaction for this element
|
280
|
+
if ( result === false ){
|
281
|
+
if ( mode == "drag" ){
|
282
|
+
ia.cancelled = true;
|
283
|
+
dd.propagates -= 1;
|
284
|
+
}
|
285
|
+
if ( type == "drop" ){
|
286
|
+
ia[ mode ][p] = null;
|
287
|
+
}
|
288
|
+
}
|
289
|
+
// assign any dropinit elements
|
290
|
+
else if ( type == "dropinit" )
|
291
|
+
ia.droppable.push( drag.element( result ) || subject );
|
292
|
+
// accept a returned proxy element
|
293
|
+
if ( type == "dragstart" )
|
294
|
+
ia.proxy = $( drag.element( result ) || ia.drag )[0];
|
295
|
+
// remember this result
|
296
|
+
ia.results.push( result );
|
297
|
+
// forget the event result, for recycling
|
298
|
+
delete event.result;
|
299
|
+
// break on cancelled handler
|
300
|
+
if ( type !== "dropinit" )
|
301
|
+
return result;
|
302
|
+
});
|
303
|
+
// flatten the results
|
304
|
+
dd.results[ i ] = drag.flatten( ia.results );
|
305
|
+
// accept a set of valid drop targets
|
306
|
+
if ( type == "dropinit" )
|
307
|
+
ia.droppable = drag.flatten( ia.droppable );
|
308
|
+
// locate drop targets
|
309
|
+
if ( type == "dragstart" && !ia.cancelled )
|
310
|
+
callback.update();
|
311
|
+
}
|
312
|
+
while ( ++i < len )
|
313
|
+
// restore the original event & type
|
314
|
+
event.type = orig.type;
|
315
|
+
event.originalEvent = orig.event;
|
316
|
+
// return all handler results
|
317
|
+
return drag.flatten( dd.results );
|
318
|
+
},
|
319
|
+
|
320
|
+
// extend the callback object with drag/drop properties...
|
321
|
+
properties: function( event, dd, ia ){
|
322
|
+
var obj = ia.callback;
|
323
|
+
// elements
|
324
|
+
obj.drag = ia.drag;
|
325
|
+
obj.proxy = ia.proxy || ia.drag;
|
326
|
+
// starting mouse position
|
327
|
+
obj.startX = dd.pageX;
|
328
|
+
obj.startY = dd.pageY;
|
329
|
+
// current distance dragged
|
330
|
+
obj.deltaX = event.pageX - dd.pageX;
|
331
|
+
obj.deltaY = event.pageY - dd.pageY;
|
332
|
+
// original element position
|
333
|
+
obj.originalX = ia.offset.left;
|
334
|
+
obj.originalY = ia.offset.top;
|
335
|
+
// adjusted element position
|
336
|
+
obj.offsetX = event.pageX - ( dd.pageX - obj.originalX );
|
337
|
+
obj.offsetY = event.pageY - ( dd.pageY - obj.originalY );
|
338
|
+
// assign the drop targets information
|
339
|
+
obj.drop = drag.flatten( ( ia.drop || [] ).slice() );
|
340
|
+
obj.available = drag.flatten( ( ia.droppable || [] ).slice() );
|
341
|
+
return obj;
|
342
|
+
},
|
343
|
+
|
344
|
+
// determine is the argument is an element or jquery instance
|
345
|
+
element: function( arg ){
|
346
|
+
if ( arg && ( arg.jquery || arg.nodeType == 1 ) )
|
347
|
+
return arg;
|
348
|
+
},
|
349
|
+
|
350
|
+
// flatten nested jquery objects and arrays into a single dimension array
|
351
|
+
flatten: function( arr ){
|
352
|
+
return $.map( arr, function( member ){
|
353
|
+
return member && member.jquery ? $.makeArray( member ) :
|
354
|
+
member && member.length ? drag.flatten( member ) : member;
|
355
|
+
});
|
356
|
+
},
|
357
|
+
|
358
|
+
// toggles text selection attributes ON (true) or OFF (false)
|
359
|
+
textselect: function( bool ){
|
360
|
+
$( document )[ bool ? "unbind" : "bind" ]("selectstart", drag.dontstart )
|
361
|
+
.attr("unselectable", bool ? "off" : "on" )
|
362
|
+
.css("MozUserSelect", bool ? "" : "none" );
|
363
|
+
},
|
364
|
+
|
365
|
+
// suppress "selectstart" and "ondragstart" events
|
366
|
+
dontstart: function(){
|
367
|
+
return false;
|
368
|
+
},
|
369
|
+
|
370
|
+
// a callback instance contructor
|
371
|
+
callback: function(){}
|
372
|
+
|
373
|
+
};
|
374
|
+
|
375
|
+
// callback methods
|
376
|
+
drag.callback.prototype = {
|
377
|
+
update: function(){
|
378
|
+
if ( $special.drop && this.available.length )
|
379
|
+
$.each( this.available, function( i ){
|
380
|
+
$special.drop.locate( this, i );
|
381
|
+
});
|
382
|
+
}
|
383
|
+
};
|
384
|
+
|
385
|
+
// share the same special event configuration with related events...
|
386
|
+
$special.draginit = $special.dragstart = $special.dragend = drag;
|
387
|
+
|
388
|
+
})( jQuery );
|
@@ -0,0 +1,341 @@
|
|
1
|
+
/*!
|
2
|
+
* jquery.event.drop - v 2.0.0
|
3
|
+
* Copyright (c) 2010 Three Dub Media - http://threedubmedia.com
|
4
|
+
* Open Source MIT License - http://threedubmedia.com/code/license
|
5
|
+
*/
|
6
|
+
// Created: 2008-06-04
|
7
|
+
// Updated: 2010-06-08
|
8
|
+
// REQUIRES: jquery 1.4.2+, jquery.event.drag 2+
|
9
|
+
|
10
|
+
;(function($){ // secure $ jQuery alias
|
11
|
+
|
12
|
+
// Events: drop, dropinit, dropstart, dropend
|
13
|
+
|
14
|
+
// add the jquery instance method
|
15
|
+
$.fn.drop = function( str, arg, opts ){
|
16
|
+
// figure out the event type
|
17
|
+
var type = typeof str == "string" ? str : "",
|
18
|
+
// figure out the event handler...
|
19
|
+
fn = $.isFunction( str ) ? str : $.isFunction( arg ) ? arg : null;
|
20
|
+
// fix the event type
|
21
|
+
if ( type.indexOf("drop") !== 0 )
|
22
|
+
type = "drop"+ type;
|
23
|
+
// were options passed
|
24
|
+
opts = ( str == fn ? arg : opts ) || {};
|
25
|
+
// trigger or bind event handler
|
26
|
+
return fn ? this.bind( type, opts, fn ) : this.trigger( type );
|
27
|
+
};
|
28
|
+
|
29
|
+
// DROP MANAGEMENT UTILITY
|
30
|
+
// returns filtered drop target elements, caches their positions
|
31
|
+
$.drop = function( opts ){
|
32
|
+
opts = opts || {};
|
33
|
+
// safely set new options...
|
34
|
+
drop.multi = opts.multi === true ? Infinity :
|
35
|
+
opts.multi === false ? 1 : !isNaN( opts.multi ) ? opts.multi : drop.multi;
|
36
|
+
drop.delay = opts.delay || drop.delay;
|
37
|
+
drop.tolerance = $.isFunction( opts.tolerance ) ? opts.tolerance :
|
38
|
+
opts.tolerance === null ? null : drop.tolerance;
|
39
|
+
drop.mode = opts.mode || drop.mode || 'intersect';
|
40
|
+
};
|
41
|
+
|
42
|
+
// local refs (increase compression)
|
43
|
+
var $event = $.event,
|
44
|
+
$special = $event.special,
|
45
|
+
// configure the drop special event
|
46
|
+
drop = $.event.special.drop = {
|
47
|
+
|
48
|
+
// these are the default settings
|
49
|
+
multi: 1, // allow multiple drop winners per dragged element
|
50
|
+
delay: 20, // async timeout delay
|
51
|
+
mode: 'overlap', // drop tolerance mode
|
52
|
+
|
53
|
+
// internal cache
|
54
|
+
targets: [],
|
55
|
+
|
56
|
+
// the key name for stored drop data
|
57
|
+
datakey: "dropdata",
|
58
|
+
|
59
|
+
// the namespace for internal live events
|
60
|
+
livekey: "livedrop",
|
61
|
+
|
62
|
+
// count bound related events
|
63
|
+
add: function( obj ){
|
64
|
+
// read the interaction data
|
65
|
+
var data = $.data( this, drop.datakey );
|
66
|
+
// count another realted event
|
67
|
+
data.related += 1;
|
68
|
+
// bind the live "dropinit" delegator
|
69
|
+
if ( !data.live && obj.selector ){
|
70
|
+
data.live = true;
|
71
|
+
$event.add( this, "dropinit."+ drop.livekey, drop.delegate );
|
72
|
+
}
|
73
|
+
},
|
74
|
+
|
75
|
+
// forget unbound related events
|
76
|
+
remove: function(){
|
77
|
+
$.data( this, drop.datakey ).related -= 1;
|
78
|
+
},
|
79
|
+
|
80
|
+
// configure the interactions
|
81
|
+
setup: function(){
|
82
|
+
// check for related events
|
83
|
+
if ( $.data( this, drop.datakey ) )
|
84
|
+
return;
|
85
|
+
// initialize the drop element data
|
86
|
+
var data = {
|
87
|
+
related: 0,
|
88
|
+
active: [],
|
89
|
+
anyactive: 0,
|
90
|
+
winner: 0,
|
91
|
+
location: {}
|
92
|
+
};
|
93
|
+
// store the drop data on the element
|
94
|
+
$.data( this, drop.datakey, data );
|
95
|
+
// store the drop target in internal cache
|
96
|
+
drop.targets.push( this );
|
97
|
+
},
|
98
|
+
|
99
|
+
// destroy the configure interaction
|
100
|
+
teardown: function(){
|
101
|
+
// check for related events
|
102
|
+
if ( $.data( this, drop.datakey ).related )
|
103
|
+
return;
|
104
|
+
// remove the stored data
|
105
|
+
$.removeData( this, drop.datakey );
|
106
|
+
// remove the "live" delegation
|
107
|
+
$event.remove( this, "dropinit", drop.delegate );
|
108
|
+
// reference the targeted element
|
109
|
+
var element = this;
|
110
|
+
// remove from the internal cache
|
111
|
+
drop.targets = $.grep( drop.targets, function( target ){
|
112
|
+
return ( target !== element );
|
113
|
+
});
|
114
|
+
},
|
115
|
+
|
116
|
+
// shared event handler
|
117
|
+
handler: function( event, dd ){
|
118
|
+
// local vars
|
119
|
+
var results, $targets;
|
120
|
+
// make sure the right data is available
|
121
|
+
if ( !dd )
|
122
|
+
return;
|
123
|
+
// handle various events
|
124
|
+
switch ( event.type ){
|
125
|
+
// draginit, from $.event.special.drag
|
126
|
+
case 'mousedown': // DROPINIT >>
|
127
|
+
// collect and assign the drop targets
|
128
|
+
$targets = $( drop.targets );
|
129
|
+
if ( typeof dd.drop == "string" )
|
130
|
+
$targets = $targets.filter( dd.drop );
|
131
|
+
// reset drop data winner properties
|
132
|
+
$targets.each(function(){
|
133
|
+
var data = $.data( this, drop.datakey );
|
134
|
+
data.active = [];
|
135
|
+
data.anyactive = 0;
|
136
|
+
data.winner = 0;
|
137
|
+
});
|
138
|
+
// set available target elements
|
139
|
+
dd.droppable = $targets;
|
140
|
+
// hold any live elements
|
141
|
+
drop.delegates = [];
|
142
|
+
// activate drop targets for the initial element being dragged
|
143
|
+
$special.drag.hijack( event, "dropinit", dd );
|
144
|
+
// flatten all the live elements
|
145
|
+
drop.delegates = $.unique( $special.drag.flatten( drop.delegates ) );
|
146
|
+
break;
|
147
|
+
// drag, from $.event.special.drag
|
148
|
+
case 'mousemove': // TOLERATE >>
|
149
|
+
drop.event = event; // store the mousemove event
|
150
|
+
if ( !drop.timer )
|
151
|
+
// monitor drop targets
|
152
|
+
drop.tolerate( dd );
|
153
|
+
break;
|
154
|
+
// dragend, from $.event.special.drag
|
155
|
+
case 'mouseup': // DROP >> DROPEND >>
|
156
|
+
drop.timer = clearTimeout( drop.timer ); // delete timer
|
157
|
+
if ( dd.propagates ){
|
158
|
+
$special.drag.hijack( event, "drop", dd );
|
159
|
+
$special.drag.hijack( event, "dropend", dd );
|
160
|
+
// cleanout live events...
|
161
|
+
$.each( drop.delegates || [], function(){
|
162
|
+
$event.remove( this, '.'+ drop.livekey );
|
163
|
+
});
|
164
|
+
}
|
165
|
+
break;
|
166
|
+
}
|
167
|
+
},
|
168
|
+
|
169
|
+
// identify potential delegate elements
|
170
|
+
delegate: function( event ){
|
171
|
+
// local refs
|
172
|
+
var elems = [], $targets,
|
173
|
+
// element event structure
|
174
|
+
events = $.data( this, "events" ) || {};
|
175
|
+
// query live events
|
176
|
+
$.each( events.live || [], function( i, obj ){
|
177
|
+
// no event type matches
|
178
|
+
if ( obj.preType.indexOf("drop") !== 0 )
|
179
|
+
return;
|
180
|
+
// locate the elements to delegate
|
181
|
+
$targets = $( event.currentTarget ).find( obj.selector );
|
182
|
+
// no element found
|
183
|
+
if ( !$targets.length )
|
184
|
+
return;
|
185
|
+
// take each target...
|
186
|
+
$targets.each(function(){
|
187
|
+
// add an event handler
|
188
|
+
$event.add( this, obj.origType +'.'+ drop.livekey, obj.origHandler, obj.data );
|
189
|
+
// remember new elements
|
190
|
+
if ( $.inArray( this, elems ) < 0 )
|
191
|
+
elems.push( this );
|
192
|
+
});
|
193
|
+
});
|
194
|
+
drop.delegates.push( elems );
|
195
|
+
return elems.length ? $( elems ) : false;
|
196
|
+
},
|
197
|
+
|
198
|
+
// returns the location positions of an element
|
199
|
+
locate: function( elem, index ){
|
200
|
+
var data = $.data( elem, drop.datakey ),
|
201
|
+
$elem = $( elem ),
|
202
|
+
posi = $elem.offset() || {},
|
203
|
+
height = $elem.outerHeight(),
|
204
|
+
width = $elem.outerWidth(),
|
205
|
+
location = {
|
206
|
+
elem: elem,
|
207
|
+
width: width,
|
208
|
+
height: height,
|
209
|
+
top: posi.top,
|
210
|
+
left: posi.left,
|
211
|
+
right: posi.left + width,
|
212
|
+
bottom: posi.top + height
|
213
|
+
};
|
214
|
+
// drag elements might not have dropdata
|
215
|
+
if ( data ){
|
216
|
+
data.location = location;
|
217
|
+
data.index = index;
|
218
|
+
data.elem = elem;
|
219
|
+
}
|
220
|
+
return location;
|
221
|
+
},
|
222
|
+
|
223
|
+
// test the location positions of an element against another OR an X,Y coord
|
224
|
+
contains: function( target, test ){ // target { location } contains test [x,y] or { location }
|
225
|
+
return ( ( test[0] || test.left ) >= target.left && ( test[0] || test.right ) <= target.right
|
226
|
+
&& ( test[1] || test.top ) >= target.top && ( test[1] || test.bottom ) <= target.bottom );
|
227
|
+
},
|
228
|
+
|
229
|
+
// stored tolerance modes
|
230
|
+
modes: { // fn scope: "$.event.special.drop" object
|
231
|
+
// target with mouse wins, else target with most overlap wins
|
232
|
+
'intersect': function( event, proxy, target ){
|
233
|
+
return this.contains( target, [ event.pageX, event.pageY ] ) ? // check cursor
|
234
|
+
1e9 : this.modes.overlap.apply( this, arguments ); // check overlap
|
235
|
+
},
|
236
|
+
// target with most overlap wins
|
237
|
+
'overlap': function( event, proxy, target ){
|
238
|
+
// calculate the area of overlap...
|
239
|
+
return Math.max( 0, Math.min( target.bottom, proxy.bottom ) - Math.max( target.top, proxy.top ) )
|
240
|
+
* Math.max( 0, Math.min( target.right, proxy.right ) - Math.max( target.left, proxy.left ) );
|
241
|
+
},
|
242
|
+
// proxy is completely contained within target bounds
|
243
|
+
'fit': function( event, proxy, target ){
|
244
|
+
return this.contains( target, proxy ) ? 1 : 0;
|
245
|
+
},
|
246
|
+
// center of the proxy is contained within target bounds
|
247
|
+
'middle': function( event, proxy, target ){
|
248
|
+
return this.contains( target, [ proxy.left + proxy.width * .5, proxy.top + proxy.height * .5 ] ) ? 1 : 0;
|
249
|
+
}
|
250
|
+
},
|
251
|
+
|
252
|
+
// sort drop target cache by by winner (dsc), then index (asc)
|
253
|
+
sort: function( a, b ){
|
254
|
+
return ( b.winner - a.winner ) || ( a.index - b.index );
|
255
|
+
},
|
256
|
+
|
257
|
+
// async, recursive tolerance execution
|
258
|
+
tolerate: function( dd ){
|
259
|
+
// declare local refs
|
260
|
+
var i, drp, drg, data, arr, len, elem,
|
261
|
+
// interaction iteration variables
|
262
|
+
x = 0, ia, end = dd.interactions.length,
|
263
|
+
// determine the mouse coords
|
264
|
+
xy = [ drop.event.pageX, drop.event.pageY ],
|
265
|
+
// custom or stored tolerance fn
|
266
|
+
tolerance = drop.tolerance || drop.modes[ drop.mode ];
|
267
|
+
// go through each passed interaction...
|
268
|
+
do if ( ia = dd.interactions[x] ){
|
269
|
+
// check valid interaction
|
270
|
+
if ( !ia )
|
271
|
+
return;
|
272
|
+
// initialize or clear the drop data
|
273
|
+
ia.drop = [];
|
274
|
+
// holds the drop elements
|
275
|
+
arr = [];
|
276
|
+
len = ia.droppable.length;
|
277
|
+
// determine the proxy location, if needed
|
278
|
+
if ( tolerance )
|
279
|
+
drg = drop.locate( ia.proxy );
|
280
|
+
// reset the loop
|
281
|
+
i = 0;
|
282
|
+
// loop each stored drop target
|
283
|
+
do if ( elem = ia.droppable[i] ){
|
284
|
+
data = $.data( elem, drop.datakey );
|
285
|
+
drp = data.location;
|
286
|
+
if ( !drp ) continue;
|
287
|
+
// find a winner: tolerance function is defined, call it
|
288
|
+
data.winner = tolerance ? tolerance.call( drop, drop.event, drg, drp )
|
289
|
+
// mouse position is always the fallback
|
290
|
+
: drop.contains( drp, xy ) ? 1 : 0;
|
291
|
+
arr.push( data );
|
292
|
+
} while ( ++i < len ); // loop
|
293
|
+
// sort the drop targets
|
294
|
+
arr.sort( drop.sort );
|
295
|
+
// reset the loop
|
296
|
+
i = 0;
|
297
|
+
// loop through all of the targets again
|
298
|
+
do if ( data = arr[ i ] ){
|
299
|
+
// winners...
|
300
|
+
if ( data.winner && ia.drop.length < drop.multi ){
|
301
|
+
// new winner... dropstart
|
302
|
+
if ( !data.active[x] && !data.anyactive ){
|
303
|
+
// check to make sure that this is not prevented
|
304
|
+
if ( $special.drag.hijack( drop.event, "dropstart", dd, x, data.elem )[0] !== false ){
|
305
|
+
data.active[x] = 1;
|
306
|
+
data.anyactive += 1;
|
307
|
+
}
|
308
|
+
// if false, it is not a winner
|
309
|
+
else
|
310
|
+
data.winner = 0;
|
311
|
+
}
|
312
|
+
// if it is still a winner
|
313
|
+
if ( data.winner )
|
314
|
+
ia.drop.push( data.elem );
|
315
|
+
}
|
316
|
+
// losers...
|
317
|
+
else if ( data.active[x] && data.anyactive == 1 ){
|
318
|
+
// former winner... dropend
|
319
|
+
$special.drag.hijack( drop.event, "dropend", dd, x, data.elem );
|
320
|
+
data.active[x] = 0;
|
321
|
+
data.anyactive -= 1;
|
322
|
+
}
|
323
|
+
} while ( ++i < len ); // loop
|
324
|
+
} while ( ++x < end ) // loop
|
325
|
+
// check if the mouse is still moving or is idle
|
326
|
+
if ( drop.last && xy[0] == drop.last.pageX && xy[1] == drop.last.pageY )
|
327
|
+
delete drop.timer; // idle, don't recurse
|
328
|
+
else // recurse
|
329
|
+
drop.timer = setTimeout(function(){
|
330
|
+
drop.tolerate( dd );
|
331
|
+
}, drop.delay );
|
332
|
+
// remember event, to compare idleness
|
333
|
+
drop.last = drop.event;
|
334
|
+
}
|
335
|
+
|
336
|
+
};
|
337
|
+
|
338
|
+
// share the same special event configuration with related events...
|
339
|
+
$special.dropinit = $special.dropstart = $special.dropend = drop;
|
340
|
+
|
341
|
+
})(jQuery); // confine scope
|
@@ -0,0 +1,226 @@
|
|
1
|
+
/*! Copyright (c) 2010 Brandon Aaron (http://brandonaaron.net)
|
2
|
+
* Dual licensed under the MIT (MIT_LICENSE.txt)
|
3
|
+
* and GPL Version 2 (GPL_LICENSE.txt) licenses.
|
4
|
+
*
|
5
|
+
* Version: 1.1.1
|
6
|
+
* Requires jQuery 1.3+
|
7
|
+
* Docs: http://docs.jquery.com/Plugins/livequery
|
8
|
+
*/
|
9
|
+
|
10
|
+
(function($) {
|
11
|
+
|
12
|
+
$.extend($.fn, {
|
13
|
+
livequery: function(type, fn, fn2) {
|
14
|
+
var self = this, q;
|
15
|
+
|
16
|
+
// Handle different call patterns
|
17
|
+
if ($.isFunction(type))
|
18
|
+
fn2 = fn, fn = type, type = undefined;
|
19
|
+
|
20
|
+
// See if Live Query already exists
|
21
|
+
$.each( $.livequery.queries, function(i, query) {
|
22
|
+
if ( self.selector == query.selector && self.context == query.context &&
|
23
|
+
type == query.type && (!fn || fn.$lqguid == query.fn.$lqguid) && (!fn2 || fn2.$lqguid == query.fn2.$lqguid) )
|
24
|
+
// Found the query, exit the each loop
|
25
|
+
return (q = query) && false;
|
26
|
+
});
|
27
|
+
|
28
|
+
// Create new Live Query if it wasn't found
|
29
|
+
q = q || new $.livequery(this.selector, this.context, type, fn, fn2);
|
30
|
+
|
31
|
+
// Make sure it is running
|
32
|
+
q.stopped = false;
|
33
|
+
|
34
|
+
// Run it immediately for the first time
|
35
|
+
q.run();
|
36
|
+
|
37
|
+
// Contnue the chain
|
38
|
+
return this;
|
39
|
+
},
|
40
|
+
|
41
|
+
expire: function(type, fn, fn2) {
|
42
|
+
var self = this;
|
43
|
+
|
44
|
+
// Handle different call patterns
|
45
|
+
if ($.isFunction(type))
|
46
|
+
fn2 = fn, fn = type, type = undefined;
|
47
|
+
|
48
|
+
// Find the Live Query based on arguments and stop it
|
49
|
+
$.each( $.livequery.queries, function(i, query) {
|
50
|
+
if ( self.selector == query.selector && self.context == query.context &&
|
51
|
+
(!type || type == query.type) && (!fn || fn.$lqguid == query.fn.$lqguid) && (!fn2 || fn2.$lqguid == query.fn2.$lqguid) && !this.stopped )
|
52
|
+
$.livequery.stop(query.id);
|
53
|
+
});
|
54
|
+
|
55
|
+
// Continue the chain
|
56
|
+
return this;
|
57
|
+
}
|
58
|
+
});
|
59
|
+
|
60
|
+
$.livequery = function(selector, context, type, fn, fn2) {
|
61
|
+
this.selector = selector;
|
62
|
+
this.context = context;
|
63
|
+
this.type = type;
|
64
|
+
this.fn = fn;
|
65
|
+
this.fn2 = fn2;
|
66
|
+
this.elements = [];
|
67
|
+
this.stopped = false;
|
68
|
+
|
69
|
+
// The id is the index of the Live Query in $.livequery.queries
|
70
|
+
this.id = $.livequery.queries.push(this)-1;
|
71
|
+
|
72
|
+
// Mark the functions for matching later on
|
73
|
+
fn.$lqguid = fn.$lqguid || $.livequery.guid++;
|
74
|
+
if (fn2) fn2.$lqguid = fn2.$lqguid || $.livequery.guid++;
|
75
|
+
|
76
|
+
// Return the Live Query
|
77
|
+
return this;
|
78
|
+
};
|
79
|
+
|
80
|
+
$.livequery.prototype = {
|
81
|
+
stop: function() {
|
82
|
+
var query = this;
|
83
|
+
|
84
|
+
if ( this.type )
|
85
|
+
// Unbind all bound events
|
86
|
+
this.elements.unbind(this.type, this.fn);
|
87
|
+
else if (this.fn2)
|
88
|
+
// Call the second function for all matched elements
|
89
|
+
this.elements.each(function(i, el) {
|
90
|
+
query.fn2.apply(el);
|
91
|
+
});
|
92
|
+
|
93
|
+
// Clear out matched elements
|
94
|
+
this.elements = [];
|
95
|
+
|
96
|
+
// Stop the Live Query from running until restarted
|
97
|
+
this.stopped = true;
|
98
|
+
},
|
99
|
+
|
100
|
+
run: function() {
|
101
|
+
// Short-circuit if stopped
|
102
|
+
if ( this.stopped ) return;
|
103
|
+
var query = this;
|
104
|
+
|
105
|
+
var oEls = this.elements,
|
106
|
+
els = $(this.selector, this.context),
|
107
|
+
nEls = els.not(oEls);
|
108
|
+
|
109
|
+
// Set elements to the latest set of matched elements
|
110
|
+
this.elements = els;
|
111
|
+
|
112
|
+
if (this.type) {
|
113
|
+
// Bind events to newly matched elements
|
114
|
+
nEls.bind(this.type, this.fn);
|
115
|
+
|
116
|
+
// Unbind events to elements no longer matched
|
117
|
+
if (oEls.length > 0)
|
118
|
+
$.each(oEls, function(i, el) {
|
119
|
+
if ( $.inArray(el, els) < 0 )
|
120
|
+
$.event.remove(el, query.type, query.fn);
|
121
|
+
});
|
122
|
+
}
|
123
|
+
else {
|
124
|
+
// Call the first function for newly matched elements
|
125
|
+
nEls.each(function() {
|
126
|
+
query.fn.apply(this);
|
127
|
+
});
|
128
|
+
|
129
|
+
// Call the second function for elements no longer matched
|
130
|
+
if ( this.fn2 && oEls.length > 0 )
|
131
|
+
$.each(oEls, function(i, el) {
|
132
|
+
if ( $.inArray(el, els) < 0 )
|
133
|
+
query.fn2.apply(el);
|
134
|
+
});
|
135
|
+
}
|
136
|
+
}
|
137
|
+
};
|
138
|
+
|
139
|
+
$.extend($.livequery, {
|
140
|
+
guid: 0,
|
141
|
+
queries: [],
|
142
|
+
queue: [],
|
143
|
+
running: false,
|
144
|
+
timeout: null,
|
145
|
+
|
146
|
+
checkQueue: function() {
|
147
|
+
if ( $.livequery.running && $.livequery.queue.length ) {
|
148
|
+
var length = $.livequery.queue.length;
|
149
|
+
// Run each Live Query currently in the queue
|
150
|
+
while ( length-- )
|
151
|
+
$.livequery.queries[ $.livequery.queue.shift() ].run();
|
152
|
+
}
|
153
|
+
},
|
154
|
+
|
155
|
+
pause: function() {
|
156
|
+
// Don't run anymore Live Queries until restarted
|
157
|
+
$.livequery.running = false;
|
158
|
+
},
|
159
|
+
|
160
|
+
play: function() {
|
161
|
+
// Restart Live Queries
|
162
|
+
$.livequery.running = true;
|
163
|
+
// Request a run of the Live Queries
|
164
|
+
$.livequery.run();
|
165
|
+
},
|
166
|
+
|
167
|
+
registerPlugin: function() {
|
168
|
+
$.each( arguments, function(i,n) {
|
169
|
+
// Short-circuit if the method doesn't exist
|
170
|
+
if (!$.fn[n]) return;
|
171
|
+
|
172
|
+
// Save a reference to the original method
|
173
|
+
var old = $.fn[n];
|
174
|
+
|
175
|
+
// Create a new method
|
176
|
+
$.fn[n] = function() {
|
177
|
+
// Call the original method
|
178
|
+
var r = old.apply(this, arguments);
|
179
|
+
|
180
|
+
// Request a run of the Live Queries
|
181
|
+
$.livequery.run();
|
182
|
+
|
183
|
+
// Return the original methods result
|
184
|
+
return r;
|
185
|
+
}
|
186
|
+
});
|
187
|
+
},
|
188
|
+
|
189
|
+
run: function(id) {
|
190
|
+
if (id != undefined) {
|
191
|
+
// Put the particular Live Query in the queue if it doesn't already exist
|
192
|
+
if ( $.inArray(id, $.livequery.queue) < 0 )
|
193
|
+
$.livequery.queue.push( id );
|
194
|
+
}
|
195
|
+
else
|
196
|
+
// Put each Live Query in the queue if it doesn't already exist
|
197
|
+
$.each( $.livequery.queries, function(id) {
|
198
|
+
if ( $.inArray(id, $.livequery.queue) < 0 )
|
199
|
+
$.livequery.queue.push( id );
|
200
|
+
});
|
201
|
+
|
202
|
+
// Clear timeout if it already exists
|
203
|
+
if ($.livequery.timeout) clearTimeout($.livequery.timeout);
|
204
|
+
// Create a timeout to check the queue and actually run the Live Queries
|
205
|
+
$.livequery.timeout = setTimeout($.livequery.checkQueue, 20);
|
206
|
+
},
|
207
|
+
|
208
|
+
stop: function(id) {
|
209
|
+
if (id != undefined)
|
210
|
+
// Stop are particular Live Query
|
211
|
+
$.livequery.queries[ id ].stop();
|
212
|
+
else
|
213
|
+
// Stop all Live Queries
|
214
|
+
$.each( $.livequery.queries, function(id) {
|
215
|
+
$.livequery.queries[ id ].stop();
|
216
|
+
});
|
217
|
+
}
|
218
|
+
});
|
219
|
+
|
220
|
+
// Register core DOM manipulation methods
|
221
|
+
$.livequery.registerPlugin('append', 'prepend', 'after', 'before', 'wrap', 'attr', 'removeAttr', 'addClass', 'removeClass', 'toggleClass', 'empty', 'remove', 'html');
|
222
|
+
|
223
|
+
// Run Live Queries when the Document is ready
|
224
|
+
$(function() { $.livequery.play(); });
|
225
|
+
|
226
|
+
})(jQuery);
|
@@ -0,0 +1,120 @@
|
|
1
|
+
/*
|
2
|
+
* Metadata - jQuery plugin for parsing metadata from elements
|
3
|
+
*
|
4
|
+
* Copyright (c) 2006 John Resig, Yehuda Katz, Jörn Zaefferer, Paul McLanahan
|
5
|
+
*
|
6
|
+
* Dual licensed under the MIT and GPL licenses:
|
7
|
+
* http://www.opensource.org/licenses/mit-license.php
|
8
|
+
* http://www.gnu.org/licenses/gpl.html
|
9
|
+
*
|
10
|
+
*/
|
11
|
+
|
12
|
+
/**
|
13
|
+
* Sets the type of metadata to use. Metadata is encoded in JSON, and each property
|
14
|
+
* in the JSON will become a property of the element itself.
|
15
|
+
*
|
16
|
+
* There are three supported types of metadata storage:
|
17
|
+
*
|
18
|
+
* attr: Inside an attribute. The name parameter indicates *which* attribute.
|
19
|
+
*
|
20
|
+
* class: Inside the class attribute, wrapped in curly braces: { }
|
21
|
+
*
|
22
|
+
* elem: Inside a child element (e.g. a script tag). The
|
23
|
+
* name parameter indicates *which* element.
|
24
|
+
*
|
25
|
+
* The metadata for an element is loaded the first time the element is accessed via jQuery.
|
26
|
+
*
|
27
|
+
* As a result, you can define the metadata type, use $(expr) to load the metadata into the elements
|
28
|
+
* matched by expr, then redefine the metadata type and run another $(expr) for other elements.
|
29
|
+
*
|
30
|
+
* @name $.metadata.setType
|
31
|
+
*
|
32
|
+
* @example <p id="one" class="some_class {item_id: 1, item_label: 'Label'}">This is a p</p>
|
33
|
+
* @before $.metadata.setType("class")
|
34
|
+
* @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label"
|
35
|
+
* @desc Reads metadata from the class attribute
|
36
|
+
*
|
37
|
+
* @example <p id="one" class="some_class" data="{item_id: 1, item_label: 'Label'}">This is a p</p>
|
38
|
+
* @before $.metadata.setType("attr", "data")
|
39
|
+
* @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label"
|
40
|
+
* @desc Reads metadata from a "data" attribute
|
41
|
+
*
|
42
|
+
* @example <p id="one" class="some_class"><script>{item_id: 1, item_label: 'Label'}</script>This is a p</p>
|
43
|
+
* @before $.metadata.setType("elem", "script")
|
44
|
+
* @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label"
|
45
|
+
* @desc Reads metadata from a nested script element
|
46
|
+
*
|
47
|
+
* @param String type The encoding type
|
48
|
+
* @param String name The name of the attribute to be used to get metadata (optional)
|
49
|
+
* @cat Plugins/Metadata
|
50
|
+
* @descr Sets the type of encoding to be used when loading metadata for the first time
|
51
|
+
* @type undefined
|
52
|
+
* @see metadata()
|
53
|
+
*/
|
54
|
+
|
55
|
+
(function($) {
|
56
|
+
|
57
|
+
$.extend({
|
58
|
+
metadata : {
|
59
|
+
defaults : {
|
60
|
+
type: 'class',
|
61
|
+
name: 'metadata',
|
62
|
+
cre: /({.*})/,
|
63
|
+
single: 'metadata'
|
64
|
+
},
|
65
|
+
setType: function( type, name ){
|
66
|
+
this.defaults.type = type;
|
67
|
+
this.defaults.name = name;
|
68
|
+
},
|
69
|
+
get: function( elem, opts ){
|
70
|
+
var settings = $.extend({},this.defaults,opts);
|
71
|
+
// check for empty string in single property
|
72
|
+
if ( !settings.single.length ) settings.single = 'metadata';
|
73
|
+
|
74
|
+
var data = $.data(elem, settings.single);
|
75
|
+
// returned cached data if it already exists
|
76
|
+
if ( data ) return data;
|
77
|
+
|
78
|
+
data = "{}";
|
79
|
+
|
80
|
+
if ( settings.type == "class" ) {
|
81
|
+
var m = settings.cre.exec( elem.className );
|
82
|
+
if ( m )
|
83
|
+
data = m[1];
|
84
|
+
} else if ( settings.type == "elem" ) {
|
85
|
+
if( !elem.getElementsByTagName )
|
86
|
+
return undefined;
|
87
|
+
var e = elem.getElementsByTagName(settings.name);
|
88
|
+
if ( e.length )
|
89
|
+
data = $.trim(e[0].innerHTML);
|
90
|
+
} else if ( elem.getAttribute != undefined ) {
|
91
|
+
var attr = elem.getAttribute( settings.name );
|
92
|
+
if ( attr )
|
93
|
+
data = attr;
|
94
|
+
}
|
95
|
+
|
96
|
+
if ( data.indexOf( '{' ) <0 )
|
97
|
+
data = "{" + data + "}";
|
98
|
+
|
99
|
+
data = eval("(" + data + ")");
|
100
|
+
|
101
|
+
$.data( elem, settings.single, data );
|
102
|
+
return data;
|
103
|
+
}
|
104
|
+
}
|
105
|
+
});
|
106
|
+
|
107
|
+
/**
|
108
|
+
* Returns the metadata object for the first member of the jQuery object.
|
109
|
+
*
|
110
|
+
* @name metadata
|
111
|
+
* @descr Returns element's metadata object
|
112
|
+
* @param Object opts An object contianing settings to override the defaults
|
113
|
+
* @type jQuery
|
114
|
+
* @cat Plugins/Metadata
|
115
|
+
*/
|
116
|
+
$.fn.metadata = function( opts ){
|
117
|
+
return $.metadata.get( this[0], opts );
|
118
|
+
};
|
119
|
+
|
120
|
+
})(jQuery);
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jquery-plugins-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Benedikt Böhm
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: railties
|
16
|
+
requirement: &20547000 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *20547000
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: jquery-rails
|
27
|
+
requirement: &20545920 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *20545920
|
36
|
+
description: jQuery plugins for Rails 3.x asset pipeline
|
37
|
+
email:
|
38
|
+
- bb@xnull.de
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .rvmrc
|
44
|
+
- Gemfile
|
45
|
+
- Gemfile.lock
|
46
|
+
- LICENSE
|
47
|
+
- README.md
|
48
|
+
- Rakefile
|
49
|
+
- jquery-plugins-rails.gemspec
|
50
|
+
- lib/jquery-plugins-rails.rb
|
51
|
+
- lib/jquery-plugins/rails.rb
|
52
|
+
- lib/jquery-plugins/rails/engine.rb
|
53
|
+
- lib/jquery-plugins/rails/version.rb
|
54
|
+
- vendor/assets/javascripts/jquery/event/drag.js
|
55
|
+
- vendor/assets/javascripts/jquery/event/drop.js
|
56
|
+
- vendor/assets/javascripts/jquery/livequery.js
|
57
|
+
- vendor/assets/javascripts/jquery/metadata.js
|
58
|
+
homepage: https://github.com/zenops/jquery-plugins-rails
|
59
|
+
licenses: []
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 1.8.10
|
79
|
+
signing_key:
|
80
|
+
specification_version: 3
|
81
|
+
summary: jQuery plugins for Rails 3.x asset pipeline
|
82
|
+
test_files: []
|