3 <title>The source code</title>
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 <body onload="prettyPrint();">
8 <pre class="prettyprint lang-js">/*!
10 * Copyright(c) 2006-2009 Ext JS, LLC
12 * http://www.extjs.com/license
14 if(typeof YAHOO == "undefined"){
15 throw "Unable to load Ext, core YUI utilities (yahoo, dom, event) not found.";
19 var E = YAHOO.util.Event,
21 CN = YAHOO.util.Connect,
22 ES = YAHOO.util.Easing,
25 version = YAHOO.env.getVersion('yahoo').version.split('.'),
26 mouseEnterSupported = parseInt(version[0]) >= 3,
28 elContains = function(parent, child){
29 if(parent && parent.firstChild){
34 child = child.parentNode;
35 if(child && (child.nodeType != 1)){
41 }, checkRelatedTarget = function(e){
42 return !elContains(e.currentTarget, Ext.lib.Event.getRelatedTarget(e));
46 getViewWidth : function(full){
47 return full ? D.getDocumentWidth() : D.getViewportWidth();
50 getViewHeight : function(full){
51 return full ? D.getDocumentHeight() : D.getViewportHeight();
54 isAncestor : function(haystack, needle){
55 return D.isAncestor(haystack, needle);
58 getRegion : function(el){
59 return D.getRegion(el);
63 return this.getXY(el)[1];
67 return this.getXY(el)[0];
70 // original version based on YahooUI getXY
71 // this version fixes several issues in Safari and FF
72 // and boosts performance by removing the batch overhead, repetitive dom lookups and array index calls
74 var p, pe, b, scroll, bd = (document.body || document.documentElement);
81 if (el.getBoundingClientRect) {
82 b = el.getBoundingClientRect();
83 scroll = fly(document).getScroll();
84 return [Math.round(b.left + scroll.left), Math.round(b.top + scroll.top)];
90 var hasAbsolute = fly(el).getStyle("position") == "absolute";
97 if (!hasAbsolute && fly(p).getStyle("position") == "absolute") {
104 var bt = parseInt(pe.getStyle("borderTopWidth"), 10) || 0;
105 var bl = parseInt(pe.getStyle("borderLeftWidth"), 10) || 0;
112 if (p != el && pe.getStyle('overflow') != 'visible') {
120 if (Ext.isSafari && hasAbsolute) {
125 if (Ext.isGecko && !hasAbsolute) {
127 x += parseInt(dbd.getStyle("borderLeftWidth"), 10) || 0;
128 y += parseInt(dbd.getStyle("borderTopWidth"), 10) || 0;
132 while (p && p != bd) {
133 if (!Ext.isOpera || (p.tagName != 'TR' && fly(p).getStyle("display") != "inline")) {
142 setXY : function(el, xy){
143 el = Ext.fly(el, '_setXY');
145 var pts = el.translatePoints(xy);
147 el.dom.style.left = pts.left + "px";
150 el.dom.style.top = pts.top + "px";
154 setX : function(el, x){
155 this.setXY(el, [x, false]);
158 setY : function(el, y){
159 this.setXY(el, [false, y]);
164 getPageX : function(e){
165 return E.getPageX(e.browserEvent || e);
168 getPageY : function(e){
169 return E.getPageY(e.browserEvent || e);
173 return E.getXY(e.browserEvent || e);
176 getTarget : function(e){
177 return E.getTarget(e.browserEvent || e);
180 getRelatedTarget : function(e){
181 return E.getRelatedTarget(e.browserEvent || e);
184 on : function(el, eventName, fn, scope, override){
185 if((eventName == 'mouseenter' || eventName == 'mouseleave') && !mouseEnterSupported){
186 var item = mouseCache[el.id] || (mouseCache[el.id] = {});
187 item[eventName] = fn;
188 fn = fn.createInterceptor(checkRelatedTarget);
189 eventName = (eventName == 'mouseenter') ? 'mouseover' : 'mouseout';
191 E.on(el, eventName, fn, scope, override);
194 un : function(el, eventName, fn){
195 if((eventName == 'mouseenter' || eventName == 'mouseleave') && !mouseEnterSupported){
196 var item = mouseCache[el.id],
197 ev = item && item[eventName];
201 delete item[eventName];
202 eventName = (eventName == 'mouseenter') ? 'mouseover' : 'mouseout';
205 E.removeListener(el, eventName, fn);;
208 purgeElement : function(el){
212 preventDefault : function(e){
213 E.preventDefault(e.browserEvent || e);
216 stopPropagation : function(e){
217 E.stopPropagation(e.browserEvent || e);
220 stopEvent : function(e){
221 E.stopEvent(e.browserEvent || e);
224 onAvailable : function(el, fn, scope, override){
225 return E.onAvailable(el, fn, scope, override);
230 request : function(method, uri, cb, data, options){
232 var hs = options.headers;
235 if(hs.hasOwnProperty(h)){
236 CN.initHeader(h, hs[h], false);
241 if (!hs || !hs['Content-Type']){
242 CN.initHeader('Content-Type', 'text/xml', false);
244 method = (method ? method : (options.method ? options.method : 'POST'));
245 data = options.xmlData;
246 }else if(options.jsonData){
247 if (!hs || !hs['Content-Type']){
248 CN.initHeader('Content-Type', 'application/json', false);
250 method = (method ? method : (options.method ? options.method : 'POST'));
251 data = typeof options.jsonData == 'object' ? Ext.encode(options.jsonData) : options.jsonData;
254 return CN.asyncRequest(method, uri, cb, data);
257 formRequest : function(form, uri, cb, data, isUpload, sslUri){
258 CN.setForm(form, isUpload, sslUri);
259 return CN.asyncRequest(Ext.getDom(form).method ||'POST', uri, cb, data);
262 isCallInProgress : function(trans){
263 return CN.isCallInProgress(trans);
266 abort : function(trans){
267 return CN.abort(trans);
270 serializeForm : function(form){
271 var d = CN.setForm(form.dom || form);
277 Ext.lib.Region = YAHOO.util.Region;
278 Ext.lib.Point = YAHOO.util.Point;
282 scroll : function(el, args, duration, easing, cb, scope){
283 this.run(el, args, duration, easing, cb, scope, YAHOO.util.Scroll);
286 motion : function(el, args, duration, easing, cb, scope){
287 this.run(el, args, duration, easing, cb, scope, YAHOO.util.Motion);
290 color : function(el, args, duration, easing, cb, scope){
291 this.run(el, args, duration, easing, cb, scope, YAHOO.util.ColorAnim);
294 run : function(el, args, duration, easing, cb, scope, type){
295 type = type || YAHOO.util.Anim;
296 if(typeof easing == "string"){
297 easing = YAHOO.util.Easing[easing];
299 var anim = new type(el, args, duration, easing);
300 anim.animateX(function(){
301 Ext.callback(cb, scope);
307 // all lib flyweight calls use their own flyweight to prevent collisions with developer flyweights
310 libFlyweight = new Ext.Element.Flyweight();
312 libFlyweight.dom = el;
318 function fnCleanUp() {
319 var p = Function.prototype;
320 delete p.createSequence;
322 delete p.createDelegate;
323 delete p.createCallback;
324 delete p.createInterceptor;
326 window.detachEvent("onunload", fnCleanUp);
328 window.attachEvent("onunload", fnCleanUp);
332 // add ability for callbacks with animations
334 YAHOO.util.Anim.prototype.animateX = function(callback, scope){
336 this.onComplete.unsubscribe(f);
337 if(typeof callback == "function"){
338 callback.call(scope || this, this);
341 this.onComplete.subscribe(f, this, true);
346 if(YAHOO.util.DragDrop && Ext.dd.DragDrop){
347 YAHOO.util.DragDrop.defaultPadding = Ext.dd.DragDrop.defaultPadding;
348 YAHOO.util.DragDrop.constrainTo = Ext.dd.DragDrop.constrainTo;
351 YAHOO.util.Dom.getXY = function(el) {
352 var f = function(el) {
353 return Ext.lib.Dom.getXY(el);
355 return YAHOO.util.Dom.batch(el, f, YAHOO.util.Dom, true);
359 // workaround for Safari anim duration speed problems
360 if(YAHOO.util.AnimMgr){
361 YAHOO.util.AnimMgr.fps = 1000;
364 YAHOO.util.Region.prototype.adjust = function(t, l, b, r){
372 YAHOO.util.Region.prototype.constrainTo = function(r) {
373 this.top = this.top.constrain(r.top, r.bottom);
374 this.bottom = this.bottom.constrain(r.top, r.bottom);
375 this.left = this.left.constrain(r.left, r.right);
376 this.right = this.right.constrain(r.left, r.right);