Merge all changes from the naturaldocs sandbox. This brings all the work that

has been done in the NaturalDocs branch back to trunk. Thanks to everyone who
helped out in making this happen. (I could list people, but the list would
be long, and I'm already mentally on vacation.)


git-svn-id: http://svn.openlayers.org/trunk/openlayers@3545 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2007-06-29 15:59:20 +00:00
parent f1c61fd0d6
commit 3948913bfc
107 changed files with 8658 additions and 4011 deletions

View File

@@ -37,16 +37,19 @@ OpenLayers.nullHandler = function(request) {
alert("Unhandled request return " + request.statusText);
};
/** Background load a document
*
* @param {String} uri URI of source doc
* @param {String} params Params on get (doesnt seem to work)
* @param {Object} caller object which gets callbacks
* @param {Function} onComplete callback for success
* @param {Function} onFailure callback for failure
*
* Both callbacks optional (though silly)
*/
/**
* Function: loadURL
* Background load a document.
*
* Parameters:
* uri - {String} URI of source doc
* params - {String} Params on get (doesnt seem to work)
* caller - {Object} object which gets callbacks
* onComplete - {Function} callback for success
* onFailure - {Function} callback for failure
*
* Both callbacks optional (though silly)
*/
OpenLayers.loadURL = function(uri, params, caller,
onComplete, onFailure) {
@@ -70,12 +73,16 @@ OpenLayers.loadURL = function(uri, params, caller,
);
};
/** Parse XML into a doc structure
* @param {String} text
*
* @returns Parsed Ajax Response ??
* @type ?
*/
/**
* Function: parseXMLString
* Parse XML into a doc structure
*
* Parameters:
* text - {String}
*
* Return:
* {?} Parsed AJAX Responsev
*/
OpenLayers.parseXMLString = function(text) {
//MS sucks, if the server is bad it dies
@@ -108,224 +115,413 @@ OpenLayers.parseXMLString = function(text) {
return ajaxResponse;
};
/**
* Namespace: OpenLayers.Ajax
*/
OpenLayers.Ajax = {
emptyFunction: function () {},
getTransport: function() {
return OpenLayers.Util.Try(
function() {return new ActiveXObject('Msxml2.XMLHTTP')},
function() {return new ActiveXObject('Microsoft.XMLHTTP')},
function() {return new XMLHttpRequest()}
) || false;
},
/**
* Method: emptyFunction
*/
emptyFunction: function () {},
activeRequestCount: 0
/**
* Method: getTransport
*
* Return:
* {Object} Transport mechanism for whichever browser we're in, or false if
* none available.
*/
getTransport: function() {
return OpenLayers.Util.Try(
function() {return new ActiveXObject('Msxml2.XMLHTTP')},
function() {return new ActiveXObject('Microsoft.XMLHTTP')},
function() {return new XMLHttpRequest()}
) || false;
},
/**
* Property: activeRequestCount
* {Integer}
*/
activeRequestCount: 0
};
/**
* Namespace: OpenLayers.Ajax.Responders
* {Object}
*/
OpenLayers.Ajax.Responders = {
responders: [],
/**
* Property: responders
* {Array}
*/
responders: [],
register: function(responderToAdd) {
for (var i = 0; i < this.responders.length; i++)
if (responderToAdd == this.responders[i])
return;
this.responders.push(responderToAdd);
},
/**
* Method: register
*
* Parameters:
* responderToAdd - {?}
*/
register: function(responderToAdd) {
for (var i = 0; i < this.responders.length; i++)
if (responderToAdd == this.responders[i])
return;
this.responders.push(responderToAdd);
},
dispatch: function(callback, request, transport, json) {
for (var i = 0; i < this.responders.length; i++) {
responder = this.responders[i];
if (responder[callback] && typeof responder[callback] == 'function') {
try {
responder[callback].apply(responder, [request, transport, json]);
} catch (e) {}
}
/**
* Method: dispatch
*
* Parameters:
* callback - {?}
* request - {?}
* transport - {?}
* json - {?}
*/
dispatch: function(callback, request, transport, json) {
for (var i = 0; i < this.responders.length; i++) {
responder = this.responders[i];
if (responder[callback] &&
typeof responder[callback] == 'function') {
try {
responder[callback].apply(responder,
[request, transport, json]);
} catch (e) {}
}
}
}
}
};
OpenLayers.Ajax.Responders.register({
onCreate: function() {
OpenLayers.Ajax.activeRequestCount++;
},
/**
* Function: onCreate
*/
onCreate: function() {
OpenLayers.Ajax.activeRequestCount++;
},
onComplete: function() {
OpenLayers.Ajax.activeRequestCount--;
}
/**
* Function: onComplete
*/
onComplete: function() {
OpenLayers.Ajax.activeRequestCount--;
}
});
/**
* Namespace: OpenLayers.Ajax.Base
* {Object}
*/
OpenLayers.Ajax.Base = function() {};
OpenLayers.Ajax.Base.prototype = {
setOptions: function(options) {
this.options = {
method: 'post',
asynchronous: true,
parameters: ''
/**
* Function: setOptions
*
* Parameters:
* options - {Object}
*/
setOptions: function(options) {
this.options = {
'method': 'post',
'asynchronous': true,
'parameters': ''
};
OpenLayers.Util.extend(this.options, options || {});
},
/**
* Function: responseIsSuccess
*
* Return:
* {Boolean}
*/
responseIsSuccess: function() {
return this.transport.status == undefined ||
this.transport.status == 0 ||
(this.transport.status >= 200 && this.transport.status < 300);
},
/**
* Function: responseIsFailure
*
* Return:
* {Boolean}
*/
responseIsFailure: function() {
return !this.responseIsSuccess();
}
OpenLayers.Util.extend(this.options, options || {});
},
responseIsSuccess: function() {
return this.transport.status == undefined
|| this.transport.status == 0
|| (this.transport.status >= 200 && this.transport.status < 300);
},
responseIsFailure: function() {
return !this.responseIsSuccess();
}
}
};
/**
* Class: OpenLayers.Ajax.Request
*
* Inherit:
* - <OpenLayers.Ajax.Base>
*/
OpenLayers.Ajax.Request = OpenLayers.Class.create();
/**
* Property: Events
* {Array(String)}
*/
OpenLayers.Ajax.Request.Events =
['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete'];
OpenLayers.Ajax.Request.prototype = OpenLayers.Class.inherit( OpenLayers.Ajax.Base, {
initialize: function(url, options) {
this.transport = OpenLayers.Ajax.getTransport();
this.setOptions(options);
this.request(url);
},
request: function(url) {
var parameters = this.options.parameters || '';
if (parameters.length > 0) parameters += '&_=';
try {
this.url = url;
if (this.options.method == 'get' && parameters.length > 0)
this.url += (this.url.match(/\?/) ? '&' : '?') + parameters;
OpenLayers.Ajax.Responders.dispatch('onCreate', this, this.transport);
this.transport.open(this.options.method, this.url,
this.options.asynchronous);
if (this.options.asynchronous) {
this.transport.onreadystatechange = this.onStateChange.bind(this);
setTimeout((function() {this.respondToReadyState(1)}).bind(this), 10);
}
this.setRequestHeaders();
var body = this.options.postBody ? this.options.postBody : parameters;
this.transport.send(this.options.method == 'post' ? body : null);
/* Force Firefox to handle ready state 4 for synchronous requests */
if (!this.options.asynchronous && this.transport.overrideMimeType) {
this.onStateChange();
}
} catch (e) {
this.dispatchException(e);
}
},
setRequestHeaders: function() {
var requestHeaders =
['X-Requested-With', 'XMLHttpRequest',
'X-Prototype-Version', 'OpenLayers'];
if (this.options.method == 'post' && !this.options.postBody) {
requestHeaders.push('Content-type',
'application/x-www-form-urlencoded');
/* Force "Connection: close" for Mozilla browsers to work around
* a bug where XMLHttpReqeuest sends an incorrect Content-length
* header. See Mozilla Bugzilla #246651.
OpenLayers.Ajax.Request.prototype =
OpenLayers.Class.inherit( OpenLayers.Ajax.Base, {
/**
* Constructor: OpenLayers.Ajax.Request
*
* Parameters:
* url - {String}
* options - {Object}
*/
if (this.transport.overrideMimeType)
requestHeaders.push('Connection', 'close');
initialize: function(url, options) {
this.transport = OpenLayers.Ajax.getTransport();
this.setOptions(options);
this.request(url);
},
/**
* Method: request
*
* Parameters:
* url - {String}
*/
request: function(url) {
var parameters = this.options.parameters || '';
if (parameters.length > 0) parameters += '&_=';
try {
this.url = url;
if (this.options.method == 'get' && parameters.length > 0) {
this.url += (this.url.match(/\?/) ? '&' : '?') + parameters;
}
OpenLayers.Ajax.Responders.dispatch('onCreate',
this,
this.transport);
this.transport.open(this.options.method,
this.url,
this.options.asynchronous);
if (this.options.asynchronous) {
this.transport.onreadystatechange =
this.onStateChange.bind(this);
setTimeout((function() {
this.respondToReadyState(1)
}).bind(this), 10);
}
this.setRequestHeaders();
var body = this.options.postBody ? this.options.postBody
: parameters;
this.transport.send(this.options.method == 'post' ? body : null);
// Force Firefox to handle ready state 4 for synchronous requests
if (!this.options.asynchronous &&
this.transport.overrideMimeType) {
this.onStateChange();
}
} catch (e) {
this.dispatchException(e);
}
},
/**
* Method: setRequestHeaders
*/
setRequestHeaders: function() {
var requestHeaders = [
'X-Requested-With',
'XMLHttpRequest',
'X-Prototype-Version',
'OpenLayers'
];
if (this.options.method == 'post' && !this.options.postBody) {
requestHeaders.push('Content-type',
'application/x-www-form-urlencoded');
// Force "Connection: close" for Mozilla browsers to work around
// a bug where XMLHttpReqeuest sends an incorrect Content-length
// header. See Mozilla Bugzilla #246651.
if (this.transport.overrideMimeType) {
requestHeaders.push('Connection', 'close');
}
}
if (this.options.requestHeaders) {
requestHeaders.push.apply(requestHeaders,
this.options.requestHeaders);
}
for (var i = 0; i < requestHeaders.length; i += 2) {
this.transport.setRequestHeader(requestHeaders[i],
requestHeaders[i+1]);
}
},
/**
* Method: onStateChange
*/
onStateChange: function() {
var readyState = this.transport.readyState;
if (readyState != 1) {
this.respondToReadyState(this.transport.readyState);
}
},
/**
* Method: header
*
* Return:
* {?}
*/
header: function(name) {
try {
return this.transport.getResponseHeader(name);
} catch (e) {}
},
/**
* Method: evalJSON
*
* Return:
* {?}
*/
evalJSON: function() {
try {
return eval(this.header('X-JSON'));
} catch (e) {}
},
/**
* Method: evalResponse
*
* Return:
* {?}
*/
evalResponse: function() {
try {
return eval(this.transport.responseText);
} catch (e) {
this.dispatchException(e);
}
},
/**
* Method: respondToReadyState
*
* Parameters:
* readyState - {?}
*/
respondToReadyState: function(readyState) {
var event = OpenLayers.Ajax.Request.Events[readyState];
var transport = this.transport, json = this.evalJSON();
if (event == 'Complete') {
try {
var responseSuccess = this.responseIsSuccess() ? 'Success'
: 'Failure';
(this.options['on' + this.transport.status] ||
this.options['on' + responseSuccess] ||
OpenLayers.Ajax.emptyFunction)(transport, json);
} catch (e) {
this.dispatchException(e);
}
var contentType = this.header('Content-type') || '';
if (contentType.match(/^text\/javascript/i)) {
this.evalResponse();
}
}
try {
(this.options['on' + event] ||
OpenLayers.Ajax.emptyFunction)(transport, json);
OpenLayers.Ajax.Responders.dispatch('on' + event,
this,
transport,
json);
} catch (e) {
this.dispatchException(e);
}
// Avoid memory leak in MSIE: clean up the oncomplete event handler
if (event == 'Complete') {
this.transport.onreadystatechange = OpenLayers.Ajax.emptyFunction;
}
},
/**
* Method: dispatchException
*
* Parameters:
* exception - {?}
*/
dispatchException: function(exception) {
if (this.options.onException) {
this.options.onException(this, exception);
} else {
// if we get here, Responders.dispatch('onException') will never
// be called. too bad. we should probably take out the Responders
// stuff anyway.
throw exception;
}
OpenLayers.Ajax.Responders.dispatch('onException', this, exception);
}
if (this.options.requestHeaders)
requestHeaders.push.apply(requestHeaders, this.options.requestHeaders);
for (var i = 0; i < requestHeaders.length; i += 2)
this.transport.setRequestHeader(requestHeaders[i], requestHeaders[i+1]);
},
onStateChange: function() {
var readyState = this.transport.readyState;
if (readyState != 1)
this.respondToReadyState(this.transport.readyState);
},
header: function(name) {
try {
return this.transport.getResponseHeader(name);
} catch (e) {}
},
evalJSON: function() {
try {
return eval(this.header('X-JSON'));
} catch (e) {}
},
evalResponse: function() {
try {
return eval(this.transport.responseText);
} catch (e) {
this.dispatchException(e);
}
},
respondToReadyState: function(readyState) {
var event = OpenLayers.Ajax.Request.Events[readyState];
var transport = this.transport, json = this.evalJSON();
if (event == 'Complete') {
try {
(this.options['on' + this.transport.status]
|| this.options['on' + (this.responseIsSuccess() ? 'Success' : 'Failure')]
|| OpenLayers.Ajax.emptyFunction)(transport, json);
} catch (e) {
this.dispatchException(e);
}
if ((this.header('Content-type') || '').match(/^text\/javascript/i))
this.evalResponse();
}
try {
(this.options['on' + event] || OpenLayers.Ajax.emptyFunction)(transport, json);
OpenLayers.Ajax.Responders.dispatch('on' + event, this, transport, json);
} catch (e) {
this.dispatchException(e);
}
/* Avoid memory leak in MSIE: clean up the oncomplete event handler */
if (event == 'Complete')
this.transport.onreadystatechange = OpenLayers.Ajax.emptyFunction;
},
dispatchException: function(exception) {
if (this.options.onException) {
this.options.onException(this, exception);
} else {
// if we get here, Responders.dispatch('onException') will never
// be called. too bad. we should probably take out the Responders
// stuff anyway.
throw exception;
}
OpenLayers.Ajax.Responders.dispatch('onException', this, exception);
}
});
OpenLayers.Ajax.getElementsByTagNameNS = function(parentnode, nsuri, nsprefix, tagname) {
return parentnode.getElementsByTagNameNS ?
parentnode.getElementsByTagNameNS(nsuri, tagname)
: parentnode.getElementsByTagName(nsprefix + ':' + tagname);
}
/**
* Function: getElementsByTagNameNS
*
* Parameters:
* parentnode - {?}
* nsuri - {?}
* nsprefix - {?}
* tagname - {?}
*
* Return:
* {?}
*/
OpenLayers.Ajax.getElementsByTagNameNS = function(parentnode, nsuri,
nsprefix, tagname) {
var elem = null;
if (parentnode.getElementsByTagNameNS) {
elem = parentnode.getElementsByTagNameNS(nsuri, tagname);
} else {
elem = parentnode.getElementsByTagName(nsprefix + ':' + tagname);
}
return elem;
};
/**
* Function: serializeXMLToString
* Wrapper function around XMLSerializer, which doesn't exist/work in
* IE/Safari. We need to come up with a way to serialize in those browser:
* for now, these browsers will just fail.
* #535, #536
* IE/Safari. We need to come up with a way to serialize in those browser:
* for now, these browsers will just fail. #535, #536
*
* @param {XMLNode} xmldom xml dom to serialize
* Parameters:
* xmldom {XMLNode} xml dom to serialize
*
* Return:
* {?}
*/
OpenLayers.Ajax.serializeXMLToString = function(xmldom) {
var serializer = new XMLSerializer();