PHP Cross Reference of WordPress Subversion HEAD |
| [ Index ] [ Classes ] [ Functions ] [ Variables ] [ Constants ] |
[Summary view] [Print] [Text view]
1 var WPAjax = Class.create(); 2 Object.extend(WPAjax.prototype, Ajax.Request.prototype); 3 Object.extend(WPAjax.prototype, { 4 WPComplete: false, // onComplete function 5 WPError: false, // onWPError function 6 defaultUrl: '', // We get these from WPAjaxL10n 7 permText: '', 8 strangeText: '', 9 whoaText: '', 10 11 initialize: function(url, responseEl) { 12 var tempObj = this; 13 this.transport = Ajax.getTransport(); 14 if ( !this.transport ) 15 return false; 16 this.setOptions( { 17 parameters: 'cookie=' + encodeURIComponent(document.cookie), 18 onComplete: function(transport) { // transport = XMLHttpRequest object 19 if ( tempObj.parseAjaxResponse() ) { 20 if ( 'function' == typeof tempObj.WPComplete ) 21 tempObj.WPComplete(transport); 22 } else if ( 'function' == typeof tempObj.WPError ) // if response corresponds to an error (bad data, say, not 404) 23 tempObj.WPError(transport); 24 } 25 }); 26 this.url = url ? url : this.defaultUrl; 27 this.getResponseElement(responseEl); 28 }, 29 addArg: function(key, value) { 30 var a = $H(); 31 a[encodeURIComponent(key)] = encodeURIComponent(value); 32 this.options.parameters = $H(this.options.parameters).merge(a); 33 }, 34 getResponseElement: function(r) { 35 var p = $(r + '-p'); 36 if ( !p ) { 37 new Insertion.Bottom(r, "<span id='" + r + "-p'></span>"); 38 var p = $(r + '-p'); 39 } 40 this.myResponseElement = p; 41 }, 42 parseAjaxResponse: function() { // 1 = good, 0 = strange (bad data?), -1 = you lack permission 43 if ( this.transport.responseXML && typeof this.transport.responseXML == 'object' && ( this.transport.responseXML.xml || 'undefined' == typeof this.transport.responseXML.xml ) ) { 44 var err = this.transport.responseXML.getElementsByTagName('wp_error'); 45 if ( err[0] ) { 46 var msg = $A(err).inject( '', function(a, b) { return a + '<p>' + b.firstChild.nodeValue + '</p>'; } ); 47 Element.update(this.myResponseElement,'<div class="error">' + msg + '</div>'); 48 return false; 49 } 50 return true; 51 } 52 var r = this.transport.responseText; 53 if ( isNaN(r) ) { 54 Element.update(this.myResponseElement,'<div class="error"><p>' + r + '</p></div>'); 55 return false; 56 } 57 var r = parseInt(r,10); 58 if ( -1 == r ) { 59 Element.update(this.myResponseElement,"<div class='error'><p>" + this.permText + "</p></div>"); 60 return false; 61 } else if ( 0 == r ) { 62 Element.update(this.myResponseElement,"<div class='error'><p>" + this.strangeText + "</p></div>"); 63 return false; 64 } 65 return true; 66 }, 67 addOnComplete: function(f) { 68 if ( 'function' == typeof f ) { var of = this.WPComplete; this.WPComplete = function(t) { if ( of ) of(t); f(t); } } 69 }, 70 addOnWPError: function(f) { 71 if ( 'function' == typeof f ) { var of = this.WPError; this.WPError = function(t) { if ( of ) of(t); f(t); } } 72 }, 73 notInitialized: function() { 74 return this.transport ? false : true; 75 } 76 }); 77 78 Event.observe( window, 'load', function() { Object.extend(WPAjax.prototype, WPAjaxL10n); }, false ) 79 80 Ajax.activeSendCount = 0; 81 Ajax.Responders.register( { 82 onCreate: function() { 83 Ajax.activeSendCount++; 84 if ( 1 != Ajax.activeSendCount ) 85 return; 86 wpBeforeUnload = window.onbeforeunload; 87 window.onbeforeunload = function() { 88 return WPAjax.whoaText; 89 } 90 }, 91 onLoading: function() { // Can switch to onLoaded if we lose data 92 Ajax.activeSendCount--; 93 if ( 0 != Ajax.activeSendCount ) 94 return; 95 window.onbeforeunload = wpBeforeUnload; 96 } 97 }); 98 99 //Pretty func adapted from ALA http://www.alistapart.com/articles/gettingstartedwithajax 100 function getNodeValue(tree,el){try { var r = tree.getElementsByTagName(el)[0].firstChild.nodeValue; } catch(err) { var r = null; } return r; }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated Thu Dec 6 06:47:08 2007 for RedAlt XRefs | Cross-referenced by PHPXref 0.6 and RedAlt |