3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js">if(typeof YAHOO == "undefined"){
9 throw "Unable to load Ext, core YUI utilities (yahoo, dom, event) not found.";
13 var E = YAHOO.util.Event,
15 CN = YAHOO.util.Connect,
16 ES = YAHOO.util.Easing,
19 version = YAHOO.env.getVersion('yahoo').version.split('.'),
20 mouseEnterSupported = parseInt(version[0]) >= 3,
22 isXUL = Ext.isGecko ? function(node){
23 return Object.prototype.toString.call(node) == '[object XULElement]';
25 }, isTextNode = Ext.isGecko ? function(node){
27 return node.nodeType == 3;
32 return node.nodeType == 3;
33 }, elContains = function(parent, child){
34 if(parent && parent.firstChild){
40 child = child.parentNode;
44 if(child && (child.nodeType != 1)){
50 }, checkRelatedTarget = function(e){
51 var related = Ext.lib.Event.getRelatedTarget(e);
52 return !(isXUL(related) || elContains(e.currentTarget, related));
56 getViewWidth : function(full){
57 return full ? D.getDocumentWidth() : D.getViewportWidth();
60 getViewHeight : function(full){
61 return full ? D.getDocumentHeight() : D.getViewportHeight();
64 isAncestor : function(haystack, needle){
65 return D.isAncestor(haystack, needle);
68 getRegion : function(el){
69 return D.getRegion(el);
73 return this.getXY(el)[1];
77 return this.getXY(el)[0];
80 // original version based on YahooUI getXY
81 // this version fixes several issues in Safari and FF
82 // and boosts performance by removing the batch overhead, repetitive dom lookups and array index calls
84 var p, pe, b, scroll, bd = (document.body || document.documentElement);
91 if (el.getBoundingClientRect) {
92 b = el.getBoundingClientRect();
93 scroll = fly(document).getScroll();
94 return [Math.round(b.left + scroll.left), Math.round(b.top + scroll.top)];
100 var hasAbsolute = fly(el).getStyle("position") == "absolute";
107 if (!hasAbsolute && fly(p).getStyle("position") == "absolute") {
114 var bt = parseInt(pe.getStyle("borderTopWidth"), 10) || 0;
115 var bl = parseInt(pe.getStyle("borderLeftWidth"), 10) || 0;
122 if (p != el && pe.getStyle('overflow') != 'visible') {
130 if (Ext.isSafari && hasAbsolute) {
135 if (Ext.isGecko && !hasAbsolute) {
137 x += parseInt(dbd.getStyle("borderLeftWidth"), 10) || 0;
138 y += parseInt(dbd.getStyle("borderTopWidth"), 10) || 0;
142 while (p && p != bd) {
143 if (!Ext.isOpera || (p.tagName != 'TR' && fly(p).getStyle("display") != "inline")) {
152 setXY : function(el, xy){
153 el = Ext.fly(el, '_setXY');
155 var pts = el.translatePoints(xy);
157 el.dom.style.left = pts.left + "px";
160 el.dom.style.top = pts.top + "px";
164 setX : function(el, x){
165 this.setXY(el, [x, false]);
168 setY : function(el, y){
169 this.setXY(el, [false, y]);
174 getPageX : function(e){
175 return E.getPageX(e.browserEvent || e);
178 getPageY : function(e){
179 return E.getPageY(e.browserEvent || e);
183 return E.getXY(e.browserEvent || e);
186 getTarget : function(e){
187 return E.getTarget(e.browserEvent || e);
190 getRelatedTarget : function(e){
191 return E.getRelatedTarget(e.browserEvent || e);
194 on : function(el, eventName, fn, scope, override){
195 if((eventName == 'mouseenter' || eventName == 'mouseleave') && !mouseEnterSupported){
196 var item = mouseCache[el.id] || (mouseCache[el.id] = {});
197 item[eventName] = fn;
198 fn = fn.createInterceptor(checkRelatedTarget);
199 eventName = (eventName == 'mouseenter') ? 'mouseover' : 'mouseout';
201 E.on(el, eventName, fn, scope, override);
204 un : function(el, eventName, fn){
205 if((eventName == 'mouseenter' || eventName == 'mouseleave') && !mouseEnterSupported){
206 var item = mouseCache[el.id],
207 ev = item && item[eventName];
211 delete item[eventName];
212 eventName = (eventName == 'mouseenter') ? 'mouseover' : 'mouseout';
215 E.removeListener(el, eventName, fn);;
218 purgeElement : function(el){
222 preventDefault : function(e){
223 E.preventDefault(e.browserEvent || e);
226 stopPropagation : function(e){
227 E.stopPropagation(e.browserEvent || e);
230 stopEvent : function(e){
231 E.stopEvent(e.browserEvent || e);
234 onAvailable : function(el, fn, scope, override){
235 return E.onAvailable(el, fn, scope, override);
240 request : function(method, uri, cb, data, options){
242 var hs = options.headers;
245 if(hs.hasOwnProperty(h)){
246 CN.initHeader(h, hs[h], false);
251 if (!hs || !hs['Content-Type']){
252 CN.initHeader('Content-Type', 'text/xml', false);
254 method = (method ? method : (options.method ? options.method : 'POST'));
255 data = options.xmlData;
256 }else if(options.jsonData){
257 if (!hs || !hs['Content-Type']){
258 CN.initHeader('Content-Type', 'application/json', false);
260 method = (method ? method : (options.method ? options.method : 'POST'));
261 data = typeof options.jsonData == 'object' ? Ext.encode(options.jsonData) : options.jsonData;
264 return CN.asyncRequest(method, uri, cb, data);
267 formRequest : function(form, uri, cb, data, isUpload, sslUri){
268 CN.setForm(form, isUpload, sslUri);
269 return CN.asyncRequest(Ext.getDom(form).method ||'POST', uri, cb, data);
272 isCallInProgress : function(trans){
273 return CN.isCallInProgress(trans);
276 abort : function(trans){
277 return CN.abort(trans);
280 serializeForm : function(form){
281 var d = CN.setForm(form.dom || form);
287 Ext.lib.Region = YAHOO.util.Region;
288 Ext.lib.Point = YAHOO.util.Point;
292 scroll : function(el, args, duration, easing, cb, scope){
293 this.run(el, args, duration, easing, cb, scope, YAHOO.util.Scroll);
296 motion : function(el, args, duration, easing, cb, scope){
297 this.run(el, args, duration, easing, cb, scope, YAHOO.util.Motion);
300 color : function(el, args, duration, easing, cb, scope){
301 this.run(el, args, duration, easing, cb, scope, YAHOO.util.ColorAnim);
304 run : function(el, args, duration, easing, cb, scope, type){
305 type = type || YAHOO.util.Anim;
306 if(typeof easing == "string"){
307 easing = YAHOO.util.Easing[easing];
309 var anim = new type(el, args, duration, easing);
310 anim.animateX(function(){
311 Ext.callback(cb, scope);
317 // all lib flyweight calls use their own flyweight to prevent collisions with developer flyweights
320 libFlyweight = new Ext.Element.Flyweight();
322 libFlyweight.dom = el;
328 function fnCleanUp() {
329 var p = Function.prototype;
330 delete p.createSequence;
332 delete p.createDelegate;
333 delete p.createCallback;
334 delete p.createInterceptor;
336 window.detachEvent("onunload", fnCleanUp);
338 window.attachEvent("onunload", fnCleanUp);
342 // add ability for callbacks with animations
344 YAHOO.util.Anim.prototype.animateX = function(callback, scope){
346 this.onComplete.unsubscribe(f);
347 if(typeof callback == "function"){
348 callback.call(scope || this, this);
351 this.onComplete.subscribe(f, this, true);
356 if(YAHOO.util.DragDrop && Ext.dd.DragDrop){
357 YAHOO.util.DragDrop.defaultPadding = Ext.dd.DragDrop.defaultPadding;
358 YAHOO.util.DragDrop.constrainTo = Ext.dd.DragDrop.constrainTo;
361 YAHOO.util.Dom.getXY = function(el) {
362 var f = function(el) {
363 return Ext.lib.Dom.getXY(el);
365 return YAHOO.util.Dom.batch(el, f, YAHOO.util.Dom, true);
369 // workaround for Safari anim duration speed problems
370 if(YAHOO.util.AnimMgr){
371 YAHOO.util.AnimMgr.fps = 1000;
374 YAHOO.util.Region.prototype.adjust = function(t, l, b, r){
382 YAHOO.util.Region.prototype.constrainTo = function(r) {
383 this.top = this.top.constrain(r.top, r.bottom);
384 this.bottom = this.bottom.constrain(r.top, r.bottom);
385 this.left = this.left.constrain(r.left, r.right);
386 this.right = this.right.constrain(r.left, r.right);