|
1 /** |
|
2 * Interface Elements for jQuery |
|
3 * FX - transfer |
|
4 * |
|
5 * http://interface.eyecon.ro |
|
6 * |
|
7 * Copyright (c) 2006 Stefan Petre |
|
8 * Dual licensed under the MIT (MIT-LICENSE.txt) |
|
9 * and GPL (GPL-LICENSE.txt) licenses. |
|
10 * |
|
11 * |
|
12 */ |
|
13 |
|
14 jQuery.transferHelper = null; |
|
15 /** |
|
16 * |
|
17 * @name TransferTo |
|
18 * @description Animates an new build element to simulate a transfer action from one element to other |
|
19 * @param Hash hash A hash of parameters |
|
20 * @option Mixed to DOMElement or element ID to transfer to |
|
21 * @option String className CSS class to apply to transfer element |
|
22 * @option String duration animation speed, integer for miliseconds, string ['slow' | 'normal' | 'fast'] |
|
23 * @option Function callback (optional) A function to be executed whenever the animation completes. |
|
24 * |
|
25 * @type jQuery |
|
26 * @cat Plugins/Interface |
|
27 * @author Stefan Petre |
|
28 */ |
|
29 jQuery.fn.TransferTo = function(o) |
|
30 { |
|
31 return this.queue('interfaceFX', function(){ |
|
32 new jQuery.fx.itransferTo(this, o); |
|
33 }); |
|
34 }; |
|
35 jQuery.fx.itransferTo = function(e, o) |
|
36 { |
|
37 |
|
38 if(jQuery.transferHelper == null) |
|
39 { |
|
40 jQuery('body', document).append('<div id="transferHelper"></div>'); |
|
41 jQuery.transferHelper = jQuery('#transferHelper'); |
|
42 } |
|
43 jQuery.transferHelper.css('display', 'block').css('position', 'absolute'); |
|
44 |
|
45 var z = this; |
|
46 z.el = jQuery(e); |
|
47 if(!o || !o.to) { |
|
48 return; |
|
49 } |
|
50 |
|
51 if (o.to.constructor == String && document.getElementById(o.to)) { |
|
52 o.to = document.getElementById(o.to); |
|
53 } else if ( !o.to.childNodes ) { |
|
54 return; |
|
55 } |
|
56 |
|
57 if (!o.duration) { |
|
58 o.duration = 500; |
|
59 } |
|
60 z.duration = o.duration; |
|
61 z.to = o.to; |
|
62 z.classname = o.className; |
|
63 z.complete = o.complete; |
|
64 if (z.classname) { |
|
65 jQuery.transferHelper.addClass(z.classname); |
|
66 } |
|
67 z.diffWidth = 0; |
|
68 z.diffHeight = 0; |
|
69 |
|
70 if(jQuery.boxModel) { |
|
71 z.diffWidth = (parseInt(jQuery.transferHelper.css('borderLeftWidth')) || 0 ) |
|
72 + (parseInt(jQuery.transferHelper.css('borderRightWidth')) || 0) |
|
73 + (parseInt(jQuery.transferHelper.css('paddingLeft')) || 0) |
|
74 + (parseInt(jQuery.transferHelper.css('paddingRight')) || 0); |
|
75 z.diffHeight = (parseInt(jQuery.transferHelper.css('borderTopWidth')) || 0 ) |
|
76 + (parseInt(jQuery.transferHelper.css('borderBottomWidth')) || 0) |
|
77 + (parseInt(jQuery.transferHelper.css('paddingTop')) || 0) |
|
78 + (parseInt(jQuery.transferHelper.css('paddingBottom')) || 0); |
|
79 } |
|
80 z.start = jQuery.extend( |
|
81 jQuery.iUtil.getPosition(z.el.get(0)), |
|
82 jQuery.iUtil.getSize(z.el.get(0)) |
|
83 ); |
|
84 z.end = jQuery.extend( |
|
85 jQuery.iUtil.getPosition(z.to), |
|
86 jQuery.iUtil.getSize(z.to) |
|
87 ); |
|
88 z.start.wb -= z.diffWidth; |
|
89 z.start.hb -= z.diffHeight; |
|
90 z.end.wb -= z.diffWidth; |
|
91 z.end.hb -= z.diffHeight; |
|
92 z.callback = o.complete; |
|
93 |
|
94 // Execute the transfer |
|
95 jQuery.transferHelper |
|
96 .css('width', z.start.wb + 'px') |
|
97 .css('height', z.start.hb + 'px') |
|
98 .css('top', z.start.y + 'px') |
|
99 .css('left', z.start.x + 'px') |
|
100 .animate( |
|
101 { |
|
102 top: z.end.y, |
|
103 left: z.end.x, |
|
104 width: z.end.wb, |
|
105 height: z.end.hb |
|
106 }, |
|
107 z.duration, |
|
108 function() |
|
109 { |
|
110 // Set correct classname |
|
111 if(z.classname) |
|
112 jQuery.transferHelper.removeClass(z.classname); |
|
113 jQuery.transferHelper.css('display', 'none'); |
|
114 |
|
115 // Callback |
|
116 if (z.complete && z.complete.constructor == Function) { |
|
117 z.complete.apply(z.el.get(0), [z.to]); |
|
118 } |
|
119 // Done |
|
120 jQuery.dequeue(z.el.get(0), 'interfaceFX'); |
|
121 } |
|
122 ); |
|
123 }; |