Mercurial > defr > drupal > core
comparison misc/farbtastic/farbtastic.js @ 7:fff6d4c8c043 6.3
Drupal 6.3
author | Franck Deroche <webmaster@defr.org> |
---|---|
date | Tue, 23 Dec 2008 14:30:28 +0100 |
parents | c1f4ac30525a |
children |
comparison
equal
deleted
inserted
replaced
6:2cfdc3c92142 | 7:fff6d4c8c043 |
---|---|
1 // $Id: farbtastic.js,v 1.4 2007/06/01 09:05:45 unconed Exp $ | 1 // $Id: farbtastic.js,v 1.4.2.1 2008/06/25 09:34:17 goba Exp $ |
2 // Farbtastic 1.2 | 2 // Farbtastic 1.2 |
3 | 3 |
4 jQuery.fn.farbtastic = function (callback) { | 4 jQuery.fn.farbtastic = function (callback) { |
5 $.farbtastic(this, callback); | 5 $.farbtastic(this, callback); |
6 return this; | 6 return this; |
102 */ | 102 */ |
103 fb.widgetCoords = function (event) { | 103 fb.widgetCoords = function (event) { |
104 var x, y; | 104 var x, y; |
105 var el = event.target || event.srcElement; | 105 var el = event.target || event.srcElement; |
106 var reference = fb.wheel; | 106 var reference = fb.wheel; |
107 | 107 |
108 if (typeof event.offsetX != 'undefined') { | 108 // If the offset from the relative element is undefined calculate it. |
109 // Use offset coordinates and find common offsetParent | 109 if ( typeof event.offsetX == 'undefined' && typeof event.offsetY == 'undefined' ) { |
110 var pos = { x: event.offsetX, y: event.offsetY }; | 110 var offset = $(event.target).offset(false); |
111 | 111 event.offsetX = event.pageX - offset.left; |
112 // Send the coordinates upwards through the offsetParent chain. | 112 event.offsetY = event.pageY - offset.top; |
113 var e = el; | 113 } |
114 while (e) { | 114 |
115 e.mouseX = pos.x; | 115 // Use offset coordinates and find common offsetParent |
116 e.mouseY = pos.y; | 116 var pos = { x: event.offsetX, y: event.offsetY }; |
117 pos.x += e.offsetLeft; | 117 |
118 pos.y += e.offsetTop; | 118 // Send the coordinates upwards through the offsetParent chain. |
119 e = e.offsetParent; | 119 var e = el; |
120 while (e) { | |
121 e.mouseX = pos.x; | |
122 e.mouseY = pos.y; | |
123 pos.x += e.offsetLeft; | |
124 pos.y += e.offsetTop; | |
125 e = e.offsetParent; | |
126 } | |
127 | |
128 // Look for the coordinates starting from the wheel widget. | |
129 var e = reference; | |
130 var offset = { x: 0, y: 0 }; | |
131 while (e) { | |
132 if (typeof e.mouseX != 'undefined') { | |
133 x = e.mouseX - offset.x; | |
134 y = e.mouseY - offset.y; | |
135 break; | |
120 } | 136 } |
121 | 137 offset.x += e.offsetLeft; |
122 // Look for the coordinates starting from the wheel widget. | 138 offset.y += e.offsetTop; |
123 var e = reference; | 139 e = e.offsetParent; |
124 var offset = { x: 0, y: 0 }; | 140 } |
125 while (e) { | 141 |
126 if (typeof e.mouseX != 'undefined') { | 142 // Reset stored coordinates |
127 x = e.mouseX - offset.x; | 143 e = el; |
128 y = e.mouseY - offset.y; | 144 while (e) { |
129 break; | 145 e.mouseX = undefined; |
130 } | 146 e.mouseY = undefined; |
131 offset.x += e.offsetLeft; | 147 e = e.offsetParent; |
132 offset.y += e.offsetTop; | 148 } |
133 e = e.offsetParent; | 149 |
134 } | |
135 | |
136 // Reset stored coordinates | |
137 e = el; | |
138 while (e) { | |
139 e.mouseX = undefined; | |
140 e.mouseY = undefined; | |
141 e = e.offsetParent; | |
142 } | |
143 } | |
144 else { | |
145 // Use absolute coordinates | |
146 var pos = fb.absolutePosition(reference); | |
147 x = (event.pageX || 0*(event.clientX + $('html').get(0).scrollLeft)) - pos.x; | |
148 y = (event.pageY || 0*(event.clientY + $('html').get(0).scrollTop)) - pos.y; | |
149 } | |
150 // Subtract distance to middle | 150 // Subtract distance to middle |
151 return { x: x - fb.width / 2, y: y - fb.width / 2 }; | 151 return { x: x - fb.width / 2, y: y - fb.width / 2 }; |
152 }; | 152 }; |
153 | 153 |
154 /** | 154 /** |
236 }); | 236 }); |
237 } | 237 } |
238 else if (typeof fb.callback == 'function') { | 238 else if (typeof fb.callback == 'function') { |
239 fb.callback.call(fb, fb.color); | 239 fb.callback.call(fb, fb.color); |
240 } | 240 } |
241 }; | |
242 | |
243 /** | |
244 * Get absolute position of element | |
245 */ | |
246 fb.absolutePosition = function (el) { | |
247 var r = { x: el.offsetLeft, y: el.offsetTop }; | |
248 // Resolve relative to offsetParent | |
249 if (el.offsetParent) { | |
250 var tmp = fb.absolutePosition(el.offsetParent); | |
251 r.x += tmp.x; | |
252 r.y += tmp.y; | |
253 } | |
254 return r; | |
255 }; | 241 }; |
256 | 242 |
257 /* Various color utility functions */ | 243 /* Various color utility functions */ |
258 fb.pack = function (rgb) { | 244 fb.pack = function (rgb) { |
259 var r = Math.round(rgb[0] * 255); | 245 var r = Math.round(rgb[0] * 255); |