-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjquerymx-3.2.custom.js
1438 lines (1323 loc) · 42.3 KB
/
jquerymx-3.2.custom.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//jquery.event.js
//jquery.lang.vector.js
(function($){
var getSetZero = function(v){ return v !== undefined ? (this.array[0] = v) : this.array[0] },
getSetOne = function(v){ return v !== undefined ? (this.array[1] = v) : this.array[1] }
/**
* @class jQuery.Vector
* @parent jquerymx.lang
* A vector class
* @constructor creates a new vector instance from the arguments. Example:
* @codestart
* new jQuery.Vector(1,2)
* @codeend
*
*/
$.Vector = function() {
this.update($.makeArray(arguments));
};
$.Vector.prototype =
/* @Prototype*/
{
/**
* Applys the function to every item in the vector. Returns the new vector.
* @param {Function} f
* @return {jQuery.Vector} new vector class.
*/
app: function( f ) {
var i, vec, newArr = [];
for ( i = 0; i < this.array.length; i++ ) {
newArr.push(f(this.array[i]));
}
vec = new $.Vector();
return vec.update(newArr);
},
/**
* Adds two vectors together. Example:
* @codestart
* new Vector(1,2).plus(2,3) //-> <3,5>
* new Vector(3,5).plus(new Vector(4,5)) //-> <7,10>
* @codeend
* @return {$.Vector}
*/
plus: function() {
var i, args = arguments[0] instanceof $.Vector ? arguments[0].array : $.makeArray(arguments),
arr = this.array.slice(0),
vec = new $.Vector();
for ( i = 0; i < args.length; i++ ) {
arr[i] = (arr[i] ? arr[i] : 0) + args[i];
}
return vec.update(arr);
},
/**
* Like plus but subtracts 2 vectors
* @return {jQuery.Vector}
*/
minus: function() {
var i, args = arguments[0] instanceof $.Vector ? arguments[0].array : $.makeArray(arguments),
arr = this.array.slice(0),
vec = new $.Vector();
for ( i = 0; i < args.length; i++ ) {
arr[i] = (arr[i] ? arr[i] : 0) - args[i];
}
return vec.update(arr);
},
/**
* Returns the current vector if it is equal to the vector passed in.
* False if otherwise.
* @return {jQuery.Vector}
*/
equals: function() {
var i, args = arguments[0] instanceof $.Vector ? arguments[0].array : $.makeArray(arguments),
arr = this.array.slice(0),
vec = new $.Vector();
for ( i = 0; i < args.length; i++ ) {
if ( arr[i] != args[i] ) {
return null;
}
}
return vec.update(arr);
},
/**
* Returns the first value of the vector
* @return {Number}
*/
x: getSetZero,
/**
* same as x()
* @return {Number}
*/
left: getSetZero,
/**
* Returns the first value of the vector
* @return {Number}
*/
width: getSetZero,
/**
* Returns the 2nd value of the vector
* @return {Number}
*/
y: getSetOne,
/**
* Same as y()
* @return {Number}
*/
top: getSetOne,
/**
* Returns the 2nd value of the vector
* @return {Number}
*/
height: getSetOne,
/**
* returns (x,y)
* @return {String}
*/
toString: function() {
return "(" + this.array[0] + "," + this.array[1] + ")";
},
/**
* Replaces the vectors contents
* @param {Object} array
*/
update: function( array ) {
var i;
if ( this.array ) {
for ( i = 0; i < this.array.length; i++ ) {
delete this.array[i];
}
}
this.array = array;
for ( i = 0; i < array.length; i++ ) {
this[i] = this.array[i];
}
return this;
}
};
$.Event.prototype.vector = function() {
if ( this.originalEvent.synthetic ) {
var doc = document.documentElement,
body = document.body;
return new $.Vector(this.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc.clientLeft || 0), this.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc.clientTop || 0));
} else {
return new $.Vector(this.pageX, this.pageY);
}
};
$.fn.offsetv = function() {
if ( this[0] == window ) {
return new $.Vector(window.pageXOffset ? window.pageXOffset : document.documentElement.scrollLeft, window.pageYOffset ? window.pageYOffset : document.documentElement.scrollTop);
} else {
var offset = this.offset();
return new $.Vector(offset.left, offset.top);
}
};
$.fn.dimensionsv = function( which ) {
if ( this[0] == window || !which ) {
return new $.Vector(this.width(), this.height());
}
else {
return new $.Vector(this[which + "Width"](), this[which + "Height"]());
}
};
})(jQuery);
//jquery.event.livehack.js
(function() {
var event = jQuery.event,
//helper that finds handlers by type and calls back a function, this is basically handle
// events - the events object
// types - an array of event types to look for
// callback(type, handlerFunc, selector) - a callback
// selector - an optional selector to filter with, if there, matches by selector
// if null, matches anything, otherwise, matches with no selector
findHelper = function( events, types, callback, selector ) {
var t, type, typeHandlers, all, h, handle,
namespaces, namespace,
match;
for ( t = 0; t < types.length; t++ ) {
type = types[t];
all = type.indexOf(".") < 0;
if (!all ) {
namespaces = type.split(".");
type = namespaces.shift();
namespace = new RegExp("(^|\\.)" + namespaces.slice(0).sort().join("\\.(?:.*\\.)?") + "(\\.|$)");
}
typeHandlers = (events[type] || []).slice(0);
for ( h = 0; h < typeHandlers.length; h++ ) {
handle = typeHandlers[h];
match = (all || namespace.test(handle.namespace));
if(match){
if(selector){
if (handle.selector === selector ) {
callback(type, handle.origHandler || handle.handler);
}
} else if (selector === null){
callback(type, handle.origHandler || handle.handler, handle.selector);
}
else if (!handle.selector ) {
callback(type, handle.origHandler || handle.handler);
}
}
}
}
};
/**
* Finds event handlers of a given type on an element.
* @param {HTMLElement} el
* @param {Array} types an array of event names
* @param {String} [selector] optional selector
* @return {Array} an array of event handlers
*/
event.find = function( el, types, selector ) {
var events = ( $._data(el) || {} ).events,
handlers = [],
t, liver, live;
if (!events ) {
return handlers;
}
findHelper(events, types, function( type, handler ) {
handlers.push(handler);
}, selector);
return handlers;
};
/**
* Finds all events. Group by selector.
* @param {HTMLElement} el the element
* @param {Array} types event types
*/
event.findBySelector = function( el, types ) {
var events = $._data(el).events,
selectors = {},
//adds a handler for a given selector and event
add = function( selector, event, handler ) {
var select = selectors[selector] || (selectors[selector] = {}),
events = select[event] || (select[event] = []);
events.push(handler);
};
if (!events ) {
return selectors;
}
//first check live:
/*$.each(events.live || [], function( i, live ) {
if ( $.inArray(live.origType, types) !== -1 ) {
add(live.selector, live.origType, live.origHandler || live.handler);
}
});*/
//then check straight binds
findHelper(events, types, function( type, handler, selector ) {
add(selector || "", type, handler);
}, null);
return selectors;
};
event.supportTouch = "ontouchend" in document;
$.fn.respondsTo = function( events ) {
if (!this.length ) {
return false;
} else {
//add default ?
return event.find(this[0], $.isArray(events) ? events : [events]).length > 0;
}
};
$.fn.triggerHandled = function( event, data ) {
event = (typeof event == "string" ? $.Event(event) : event);
this.trigger(event, data);
return event.handled;
};
/**
* Only attaches one event handler for all types ...
* @param {Array} types llist of types that will delegate here
* @param {Object} startingEvent the first event to start listening to
* @param {Object} onFirst a function to call
*/
event.setupHelper = function( types, startingEvent, onFirst ) {
if (!onFirst ) {
onFirst = startingEvent;
startingEvent = null;
}
var add = function( handleObj ) {
var bySelector, selector = handleObj.selector || "";
if ( selector ) {
bySelector = event.find(this, types, selector);
if (!bySelector.length ) {
$(this).delegate(selector, startingEvent, onFirst);
}
}
else {
//var bySelector = event.find(this, types, selector);
if (!event.find(this, types, selector).length ) {
event.add(this, startingEvent, onFirst, {
selector: selector,
delegate: this
});
}
}
},
remove = function( handleObj ) {
var bySelector, selector = handleObj.selector || "";
if ( selector ) {
bySelector = event.find(this, types, selector);
if (!bySelector.length ) {
$(this).undelegate(selector, startingEvent, onFirst);
}
}
else {
if (!event.find(this, types, selector).length ) {
event.remove(this, startingEvent, onFirst, {
selector: selector,
delegate: this
});
}
}
};
$.each(types, function() {
event.special[this] = {
add: add,
remove: remove,
setup: function() {},
teardown: function() {}
};
});
};
})(jQuery);
//jquery.event.drag.js
(function( $ ) {
//modify live
//steal the live handler ....
var bind = function( object, method ) {
var args = Array.prototype.slice.call(arguments, 2);
return function() {
var args2 = [this].concat(args, $.makeArray(arguments));
return method.apply(object, args2);
};
},
event = $.event,
clearSelection = window.getSelection ? function(){
window.getSelection().removeAllRanges()
} : function(){};
// var handle = event.handle; //unused
/**
* @class jQuery.Drag
* @parent specialevents
* @plugin jquery/event/drag
* @download http://jmvcsite.heroku.com/pluginify?plugins[]=jquery/event/drag/drag.js
* @test jquery/event/drag/qunit.html
* Provides drag events as a special events to jQuery.
* A jQuery.Drag instance is created on a drag and passed
* as a parameter to the drag event callbacks. By calling
* methods on the drag event, you can alter the drag's
* behavior.
* ## Drag Events
*
* The drag plugin allows you to listen to the following events:
*
* <ul>
* <li><code>dragdown</code> - the mouse cursor is pressed down</li>
* <li><code>draginit</code> - the drag motion is started</li>
* <li><code>dragmove</code> - the drag is moved</li>
* <li><code>dragend</code> - the drag has ended</li>
* <li><code>dragover</code> - the drag is over a drop point</li>
* <li><code>dragout</code> - the drag moved out of a drop point</li>
* </ul>
*
* Just by binding or delegating on one of these events, you make
* the element dragable. You can change the behavior of the drag
* by calling methods on the drag object passed to the callback.
*
* ### Example
*
* Here's a quick example:
*
* //makes the drag vertical
* $(".drags").delegate("draginit", function(event, drag){
* drag.vertical();
* })
* //gets the position of the drag and uses that to set the width
* //of an element
* $(".resize").delegate("dragmove",function(event, drag){
* $(this).width(drag.position.left() - $(this).offset().left )
* })
*
* ## Drag Object
*
* <p>The drag object is passed after the event to drag
* event callback functions. By calling methods
* and changing the properties of the drag object,
* you can alter how the drag behaves.
* </p>
* <p>The drag properties and methods:</p>
* <ul>
* <li><code>[jQuery.Drag.prototype.cancel cancel]</code> - stops the drag motion from happening</li>
* <li><code>[jQuery.Drag.prototype.ghost ghost]</code> - copys the draggable and drags the cloned element</li>
* <li><code>[jQuery.Drag.prototype.horizontal horizontal]</code> - limits the scroll to horizontal movement</li>
* <li><code>[jQuery.Drag.prototype.location location]</code> - where the drag should be on the screen</li>
* <li><code>[jQuery.Drag.prototype.mouseElementPosition mouseElementPosition]</code> - where the mouse should be on the drag</li>
* <li><code>[jQuery.Drag.prototype.only only]</code> - only have drags, no drops</li>
* <li><code>[jQuery.Drag.prototype.representative representative]</code> - move another element in place of this element</li>
* <li><code>[jQuery.Drag.prototype.revert revert]</code> - animate the drag back to its position</li>
* <li><code>[jQuery.Drag.prototype.vertical vertical]</code> - limit the drag to vertical movement</li>
* <li><code>[jQuery.Drag.prototype.limit limit]</code> - limit the drag within an element (*limit plugin)</li>
* <li><code>[jQuery.Drag.prototype.scrolls scrolls]</code> - scroll scrollable areas when dragging near their boundries (*scroll plugin)</li>
* </ul>
* <h2>Demo</h2>
* Now lets see some examples:
* @demo jquery/event/drag/drag.html 1000
* @constructor
* The constructor is never called directly.
*/
$.Drag = function() {};
/**
* @Static
*/
$.extend($.Drag, {
lowerName: "drag",
current: null,
distance: 0,
/**
* Called when someone mouses down on a draggable object.
* Gathers all callback functions and creates a new Draggable.
* @hide
*/
mousedown: function( ev, element ) {
var isLeftButton = ev.button === 0 || ev.button == 1;
if (!isLeftButton || this.current ) {
return;
} //only allows 1 drag at a time, but in future could allow more
//ev.preventDefault();
//create Drag
var drag = new $.Drag(),
delegate = ev.delegateTarget || element,
selector = ev.handleObj.selector,
self = this;
this.current = drag;
drag.setup({
element: element,
delegate: ev.delegateTarget || element,
selector: ev.handleObj.selector,
moved: false,
_distance: this.distance,
callbacks: {
dragdown: event.find(delegate, ["dragdown"], selector),
draginit: event.find(delegate, ["draginit"], selector),
dragover: event.find(delegate, ["dragover"], selector),
dragmove: event.find(delegate, ["dragmove"], selector),
dragout: event.find(delegate, ["dragout"], selector),
dragend: event.find(delegate, ["dragend"], selector)
},
destroyed: function() {
self.current = null;
}
}, ev);
}
});
/**
* @Prototype
*/
$.extend($.Drag.prototype, {
setup: function( options, ev ) {
$.extend(this, options);
this.element = $(this.element);
this.event = ev;
this.moved = false;
this.allowOtherDrags = false;
var mousemove = bind(this, this.mousemove),
mouseup = bind(this, this.mouseup);
this._mousemove = mousemove;
this._mouseup = mouseup;
this._distance = options.distance ? options.distance : 0;
this.mouseStartPosition = ev.vector(); //where the mouse is located
$(document).bind('mousemove', mousemove);
$(document).bind('mouseup', mouseup);
if (!this.callEvents('down', this.element, ev) ) {
this.noSelection(this.delegate);
//this is for firefox
clearSelection();
}
},
/**
* Unbinds listeners and allows other drags ...
* @hide
*/
destroy: function() {
$(document).unbind('mousemove', this._mousemove);
$(document).unbind('mouseup', this._mouseup);
if (!this.moved ) {
this.event = this.element = null;
}
this.selection(this.delegate);
this.destroyed();
},
mousemove: function( docEl, ev ) {
if (!this.moved ) {
var dist = Math.sqrt( Math.pow( ev.pageX - this.event.pageX, 2 ) + Math.pow( ev.pageY - this.event.pageY, 2 ));
if(dist < this._distance){
return false;
}
this.init(this.element, ev);
this.moved = true;
}
var pointer = ev.vector();
if ( this._start_position && this._start_position.equals(pointer) ) {
return;
}
//e.preventDefault();
this.draw(pointer, ev);
},
mouseup: function( docEl, event ) {
//if there is a current, we should call its dragstop
if ( this.moved ) {
this.end(event);
}
this.destroy();
},
/**
* noSelection method turns off text selection during a drag event.
* This method is called by default unless a event is listening to the 'dragdown' event.
*
* ## Example
*
* $('div.drag').bind('dragdown', function(elm,event,drag){
* drag.noSelection();
* });
*
* @param [elm] an element to prevent selection on. Defaults to the dragable element.
*/
noSelection: function(elm) {
elm = elm || this.delegate
document.documentElement.onselectstart = function() {
return false;
};
document.documentElement.unselectable = "on";
this.selectionDisabled = (this.selectionDisabled ? this.selectionDisabled.add(elm) : $(elm));
this.selectionDisabled.css('-moz-user-select', '-moz-none');
},
/**
* selection method turns on text selection that was previously turned off during the drag event.
* This method is called by default in 'destroy' unless a event is listening to the 'dragdown' event.
*
* ## Example
*
* $('div.drag').bind('dragdown', function(elm,event,drag){
* drag.noSelection();
* });
*/
selection: function(elm) {
if(this.selectionDisabled){
document.documentElement.onselectstart = function() {};
document.documentElement.unselectable = "off";
this.selectionDisabled.css('-moz-user-select', '');
}
},
init: function( element, event ) {
element = $(element);
var startElement = (this.movingElement = (this.element = $(element))); //the element that has been clicked on
//if a mousemove has come after the click
this._cancelled = false; //if the drag has been cancelled
this.event = event;
/**
* @attribute mouseElementPosition
* The position of start of the cursor on the element
*/
this.mouseElementPosition = this.mouseStartPosition.minus(this.element.offsetv()); //where the mouse is on the Element
//this.callStart(element, event);
this.callEvents('init', element, event);
//Check what they have set and respond accordingly
// if they canceled
if ( this._cancelled === true ) {
return;
}
//if they set something else as the element
this.startPosition = startElement != this.movingElement ? this.movingElement.offsetv() : this.currentDelta();
this.makePositioned(this.movingElement);
this.oldZIndex = this.movingElement.css('zIndex');
this.movingElement.css('zIndex', 1000);
if (!this._only && this.constructor.responder ) {
this.constructor.responder.compile(event, this);
}
},
makePositioned: function( that ) {
var style, pos = that.css('position');
if (!pos || pos == 'static' ) {
style = {
position: 'relative'
};
if ( window.opera ) {
style.top = '0px';
style.left = '0px';
}
that.css(style);
}
},
callEvents: function( type, element, event, drop ) {
var i, cbs = this.callbacks[this.constructor.lowerName + type];
for ( i = 0; i < cbs.length; i++ ) {
cbs[i].call(element, event, this, drop);
}
return cbs.length;
},
/**
* Returns the position of the movingElement by taking its top and left.
* @hide
* @return {Vector}
*/
currentDelta: function() {
return new $.Vector(parseInt(this.movingElement.css('left'), 10) || 0, parseInt(this.movingElement.css('top'), 10) || 0);
},
//draws the position of the dragmove object
draw: function( pointer, event ) {
// only drag if we haven't been cancelled;
if ( this._cancelled ) {
return;
}
clearSelection();
/**
* @attribute location
* The location of where the element should be in the page. This
* takes into account the start position of the cursor on the element.
*
* If the drag is going to be moved to an unacceptable location, you can call preventDefault in
* dragmove to prevent it from being moved there.
*
* $('.mover').bind("dragmove", function(ev, drag){
* if(drag.location.top() < 100){
* ev.preventDefault()
* }
* });
*
* You can also set the location to where it should be on the page.
*/
this.location = pointer.minus(this.mouseElementPosition); // the offset between the mouse pointer and the representative that the user asked for
// position = mouse - (dragOffset - dragTopLeft) - mousePosition
// call move events
this.move(event);
if ( this._cancelled ) {
return;
}
if (!event.isDefaultPrevented() ) {
this.position(this.location);
}
//fill in
if (!this._only && this.constructor.responder ) {
this.constructor.responder.show(pointer, this, event);
}
},
/**
* Sets the position of this drag.
*
* The limit and scroll plugins
* overwrite this to make sure the drag follows a particular path.
*
* @param {jQuery.Vector} newOffsetv the position of the element (not the mouse)
*/
position: function( newOffsetv ) { //should draw it on the page
var style, dragged_element_css_offset = this.currentDelta(),
// the drag element's current left + top css attributes
dragged_element_position_vector = // the vector between the movingElement's page and css positions
this.movingElement.offsetv().minus(dragged_element_css_offset); // this can be thought of as the original offset
this.required_css_position = newOffsetv.minus(dragged_element_position_vector);
this.offsetv = newOffsetv;
//dragged_element vector can probably be cached.
style = this.movingElement[0].style;
if (!this._cancelled && !this._horizontal ) {
style.top = this.required_css_position.top() + "px";
}
if (!this._cancelled && !this._vertical ) {
style.left = this.required_css_position.left() + "px";
}
},
move: function( event ) {
this.callEvents('move', this.element, event);
},
over: function( event, drop ) {
this.callEvents('over', this.element, event, drop);
},
out: function( event, drop ) {
this.callEvents('out', this.element, event, drop);
},
/**
* Called on drag up
* @hide
* @param {Event} event a mouseup event signalling drag/drop has completed
*/
end: function( event ) {
if ( this._cancelled ) {
return;
}
if (!this._only && this.constructor.responder ) {
this.constructor.responder.end(event, this);
}
this.callEvents('end', this.element, event);
if ( this._revert ) {
var self = this;
this.movingElement.animate({
top: this.startPosition.top() + "px",
left: this.startPosition.left() + "px"
}, function() {
self.cleanup.apply(self, arguments);
});
}
else {
this.cleanup();
}
this.event = null;
},
/**
* Cleans up drag element after drag drop.
* @hide
*/
cleanup: function() {
this.movingElement.css({
zIndex: this.oldZIndex
});
if ( this.movingElement[0] !== this.element[0] &&
!this.movingElement.has(this.element[0]).length &&
!this.element.has(this.movingElement[0]).length ) {
this.movingElement.css({
display: 'none'
});
}
if ( this._removeMovingElement ) {
this.movingElement.remove();
}
this.movingElement = this.element = this.event = null;
},
/**
* Stops drag drop from running.
*/
cancel: function() {
this._cancelled = true;
//this.end(this.event);
if (!this._only && this.constructor.responder ) {
this.constructor.responder.clear(this.event.vector(), this, this.event);
}
this.destroy();
},
/**
* Clones the element and uses it as the moving element.
* @return {jQuery.fn} the ghost
*/
ghost: function( loc ) {
// create a ghost by cloning the source element and attach the clone to the dom after the source element
var ghost = this.movingElement.clone().css('position', 'absolute');
(loc ? $(loc) : this.movingElement).after(ghost);
ghost.width(this.movingElement.width()).height(this.movingElement.height());
// put the ghost in the right location ...
ghost.offset(this.movingElement.offset())
// store the original element and make the ghost the dragged element
this.movingElement = ghost;
this.noSelection(ghost)
this._removeMovingElement = true;
return ghost;
},
/**
* Use a representative element, instead of the movingElement.
* @param {HTMLElement} element the element you want to actually drag
* @param {Number} offsetX the x position where you want your mouse on the object
* @param {Number} offsetY the y position where you want your mouse on the object
*/
representative: function( element, offsetX, offsetY ) {
this._offsetX = offsetX || 0;
this._offsetY = offsetY || 0;
var p = this.mouseStartPosition;
this.movingElement = $(element);
this.movingElement.css({
top: (p.y() - this._offsetY) + "px",
left: (p.x() - this._offsetX) + "px",
display: 'block',
position: 'absolute'
}).show();
this.noSelection(this.movingElement)
this.mouseElementPosition = new $.Vector(this._offsetX, this._offsetY);
},
/**
* Makes the movingElement go back to its original position after drop.
* @codestart
* ".handle dragend" : function( el, ev, drag ) {
* drag.revert()
* }
* @codeend
* @param {Boolean} [val] optional, set to false if you don't want to revert.
*/
revert: function( val ) {
this._revert = val === undefined ? true : val;
return this;
},
/**
* Isolates the drag to vertical movement.
*/
vertical: function() {
this._vertical = true;
return this;
},
/**
* Isolates the drag to horizontal movement.
*/
horizontal: function() {
this._horizontal = true;
return true;
},
/**
* Respondables will not be alerted to this drag.
*/
only: function( only ) {
return (this._only = (only === undefined ? true : only));
},
/**
* Sets the distance from the mouse before the item begins dragging.
* @param {Number} val
*/
distance:function(val){
if(val !== undefined){
this._distance = val;
return this;
}else{
return this._distance
}
}
});
/**
* @add jQuery.event.special
*/
event.setupHelper([
/**
* @attribute dragdown
* <p>Listens for when a drag movement has started on a mousedown.
* If you listen to this, the mousedown's default event (preventing
* text selection) is not prevented. You are responsible for calling it
* if you want it (you probably do). </p>
* <p><b>Why might you not want it?</b></p>
* <p>You might want it if you want to allow text selection on element
* within the drag element. Typically these are input elements.</p>
* <p>Drag events are covered in more detail in [jQuery.Drag].</p>
* @codestart
* $(".handles").delegate("dragdown", function(ev, drag){})
* @codeend
*/
'dragdown',
/**
* @attribute draginit
* Called when the drag starts.
* <p>Drag events are covered in more detail in [jQuery.Drag].</p>
*/
'draginit',
/**
* @attribute dragover
* Called when the drag is over a drop.
* <p>Drag events are covered in more detail in [jQuery.Drag].</p>
*/
'dragover',
/**
* @attribute dragmove
* Called when the drag is moved.
* <p>Drag events are covered in more detail in [jQuery.Drag].</p>
*/
'dragmove',
/**
* @attribute dragout
* When the drag leaves a drop point.
* <p>Drag events are covered in more detail in [jQuery.Drag].</p>
*/
'dragout',
/**
* @attribute dragend
* Called when the drag is done.
* <p>Drag events are covered in more detail in [jQuery.Drag].</p>
*/
'dragend'], "mousedown", function( e ) {
$.Drag.mousedown.call($.Drag, e, this);
});
})(jQuery);
//jquery.dom.js
//jquery.dom.cur_styles.js
(function( $ ) {
var getComputedStyle = document.defaultView && document.defaultView.getComputedStyle,
rupper = /([A-Z])/g,
rdashAlpha = /-([a-z])/ig,
fcamelCase = function( all, letter ) {
return letter.toUpperCase();
},
getStyle = function( elem ) {
if ( getComputedStyle ) {
return getComputedStyle(elem, null);
}
else if ( elem.currentStyle ) {
return elem.currentStyle;
}
},
rfloat = /float/i,
rnumpx = /^-?\d+(?:px)?$/i,
rnum = /^-?\d/;
/**
* @add jQuery
*/
//
/**
* @function curStyles
* @param {HTMLElement} el
* @param {Array} styles An array of style names like <code>['marginTop','borderLeft']</code>
* @return {Object} an object of style:value pairs. Style names are camelCase.
*/
$.curStyles = function( el, styles ) {
if (!el ) {
return null;
}
var currentS = getStyle(el),
oldName, val, style = el.style,
results = {},
i = 0,
left, rsLeft, camelCase, name;
for (; i < styles.length; i++ ) {
name = styles[i];
oldName = name.replace(rdashAlpha, fcamelCase);
if ( rfloat.test(name) ) {
name = jQuery.support.cssFloat ? "float" : "styleFloat";
oldName = "cssFloat";
}
if ( getComputedStyle ) {
name = name.replace(rupper, "-$1").toLowerCase();
val = currentS.getPropertyValue(name);
if ( name === "opacity" && val === "" ) {
val = "1";
}
results[oldName] = val;
} else {
camelCase = name.replace(rdashAlpha, fcamelCase);
results[oldName] = currentS[name] || currentS[camelCase];
if (!rnumpx.test(results[oldName]) && rnum.test(results[oldName]) ) { //convert to px
// Remember the original values
left = style.left;
rsLeft = el.runtimeStyle.left;
// Put in the new values to get a computed value out