Upgrade to MochiKit trunk with upstream XUL DOM code

This commit is contained in:
sayrer%gmail.com 2006-11-06 23:48:11 +00:00
parent f9333ecf69
commit 0985f6a53b
5 changed files with 6240 additions and 38 deletions

View File

@ -341,25 +341,73 @@ MochiKit.Base.update(MochiKit.Async, {
},
/** @id MochiKit.Async.doSimpleXMLHttpRequest */
doSimpleXMLHttpRequest: function (url/*, ...*/) {
/** @id MochiKit.Async.doXHR */
doXHR: function (url, opts) {
var m = MochiKit.Base;
opts = m.update({
method: 'GET',
sendContent: ''
/*
queryString: undefined,
username: undefined,
password: undefined,
headers: undefined,
mimeType: undefined
*/
}, opts);
var self = MochiKit.Async;
var req = self.getXMLHttpRequest();
if (arguments.length > 1) {
var m = MochiKit.Base;
var qs = m.queryString.apply(null, m.extend(null, arguments, 1));
if (opts.queryString) {
var qs = m.queryString(opts.queryString);
if (qs) {
url += "?" + qs;
}
}
req.open("GET", url, true);
return self.sendXMLHttpRequest(req);
req.open(opts.method, url, true, opts.username, opts.password);
if (req.overrideMimeType && opts.mimeType) {
req.overrideMimeType(opts.mimeType);
}
if (opts.headers) {
var headers = opts.headers;
if (!m.isArrayLike(headers)) {
headers = m.items(headers);
}
for (var i = 0; i < headers.length; i++) {
var header = headers[i];
var name = header[0];
var value = header[1];
req.setRequestHeader(name, value);
}
}
return self.sendXMLHttpRequest(req, opts.sendContent);
},
_buildURL: function (url/*, ...*/) {
if (arguments.length > 1) {
var m = MochiKit.Base;
var qs = m.queryString.apply(null, m.extend(null, arguments, 1));
if (qs) {
return url + "?" + qs;
}
}
return url;
},
/** @id MochiKit.Async.doSimpleXMLHttpRequest */
doSimpleXMLHttpRequest: function (url/*, ...*/) {
var self = MochiKit.Async;
url = self._buildURL.apply(self, arguments);
return self.doXHR(url);
},
/** @id MochiKit.Async.loadJSONDoc */
loadJSONDoc: function (url) {
loadJSONDoc: function (url/*, ...*/) {
var self = MochiKit.Async;
var d = self.doSimpleXMLHttpRequest.apply(self, arguments);
url = self._buildURL.apply(self, arguments);
var d = self.doXHR(url, {
'mimeType': 'text/plain',
'headers': [['Accept', 'application/json']]
});
d = d.addCallback(self.evalJSONRequest);
return d;
},
@ -540,7 +588,8 @@ MochiKit.Async.EXPORT = [
"DeferredLock",
"DeferredList",
"gatherResults",
"maybeDeferred"
"maybeDeferred",
"doXHR"
];
MochiKit.Async.EXPORT_OK = [

View File

@ -28,15 +28,6 @@ if (typeof(MochiKit.DOM) == 'undefined') {
MochiKit.DOM = {};
}
var kXHTMLNSURI = "http://www.w3.org/1999/xhtml";
var kXULNSURI = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
if (document.documentElement &&
document.documentElement.namespaceURI == kXULNSURI) {
MochiKit.DOM.useNS = true;
} else {
MochiKit.DOM.useNS = false;
}
MochiKit.DOM.NAME = "MochiKit.DOM";
MochiKit.DOM.VERSION = "1.4";
MochiKit.DOM.__repr__ = function () {
@ -494,6 +485,7 @@ MochiKit.Base.update(MochiKit.DOM, {
}
if (typeof(name) == 'string') {
// Internet Explorer is dumb
var xhtml = self._xhtml;
if (attrs && !self.attributeArray.compliant) {
// http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/name_2.asp
var contents = "";
@ -505,13 +497,15 @@ MochiKit.Base.update(MochiKit.DOM, {
}
if (contents) {
name = "<" + name + contents + ">";
xhtml = false;
}
}
if (self.useNS) {
elem = self._document.createElementNS(kXHTMLNSURI, name);
} else {
elem = self._document.createElement(name);
}
var d = self._document;
if (xhtml && d === document) {
elem = d.createElementNS("http://www.w3.org/1999/xhtml", name);
} else {
elem = d.createElement(name);
}
} else {
elem = name;
}
@ -877,6 +871,10 @@ MochiKit.Base.update(MochiKit.DOM, {
var m = MochiKit.Base;
if (typeof(document) != "undefined") {
this._document = document;
var kXULNSURI = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
this._xhtml = (document.documentElement &&
document.createElementNS &&
document.documentElement.namespaceURI === kXULNSURI);
} else if (MochiKit.MockDOM) {
this._document = MochiKit.MockDOM.document;
}
@ -909,7 +907,9 @@ MochiKit.Base.update(MochiKit.DOM, {
"checked": "defaultChecked",
"usemap": "useMap",
"for": "htmlFor",
"readonly": "readOnly"
"readonly": "readOnly",
"colspan": "colSpan",
"bgcolor": "bgColor"
};
} else {
attributeArray = function (node) {

View File

@ -75,7 +75,7 @@ MochiKit.LoggingPane.LoggingPane = function (inline/* = false */, logger/* = Moc
}
if (!inline) {
// name the popup with the base URL for uniqueness
var url = win.location.href.split("?")[0].replace(/[:\/.><&-]/g, "_");
var url = win.location.href.split("?")[0].replace(/[#:\/.><&-]/g, "_");
var name = uid + "_" + url;
var nwin = win.open("", name, "dependent,resizable,height=200");
if (!nwin) {

View File

@ -578,15 +578,7 @@ MochiKit.Base.update(MochiKit.Signal, {
};
},
/** @id MochiKit.Signal.connect */
connect: function (src, sig, objOrFunc/* optional */, funcOrStr) {
src = MochiKit.DOM.getElement(src);
var self = MochiKit.Signal;
if (typeof(sig) != 'string') {
throw new Error("'sig' must be a string");
}
_getDestPair: function (objOrFunc, funcOrStr) {
var obj = null;
var func = null;
if (typeof(funcOrStr) != 'undefined') {
@ -604,6 +596,22 @@ MochiKit.Base.update(MochiKit.Signal, {
} else {
func = objOrFunc;
}
return [obj, func];
},
/** @id MochiKit.Signal.connect */
connect: function (src, sig, objOrFunc/* optional */, funcOrStr) {
src = MochiKit.DOM.getElement(src);
var self = MochiKit.Signal;
if (typeof(sig) != 'string') {
throw new Error("'sig' must be a string");
}
var destPair = self._getDestPair(objOrFunc, funcOrStr);
var obj = destPair[0];
var func = destPair[1];
if (typeof(obj) == 'undefined' || obj === null) {
obj = src;
}
@ -631,15 +639,21 @@ MochiKit.Base.update(MochiKit.Signal, {
self._observers.push(ident);
if (!isDOM && typeof(src.__connect__) == 'function') {
var args = MochiKit.Base.extend([ident], arguments, 1);
src.__connect__.apply(src, args);
}
return ident;
},
_disconnect: function (ident) {
// check isDOM
if (!ident[3]) { return; }
// already disconnected
if (!ident[6]) { return; }
ident[6] = false;
// check isDOM
if (!ident[3]) { return; }
var src = ident[0];
var sig = ident[1];
var listener = ident[2];
@ -690,6 +704,31 @@ MochiKit.Base.update(MochiKit.Signal, {
return false;
},
/** @id MochiKit.Signal.disconnectAllTo */
disconnectAllTo: function (objOrFunc, /* optional */funcOrStr) {
var self = MochiKit.Signal;
var observers = self._observers;
var disconnect = self._disconnect;
var locked = self._lock;
var dirty = self._dirty;
if (typeof(funcOrStr) === 'undefined') {
funcOrStr = null;
}
for (var i = observers.length - 1; i >= 0; i--) {
var ident = observers[i];
if (ident[4] === objOrFunc &&
(funcOrStr === null || ident[5] === funcOrStr)) {
disconnect(ident);
if (locked) {
dirty = true;
} else {
observers.splice(i, 1);
}
}
}
self._dirty = dirty;
},
/** @id MochiKit.Signal.disconnectAll */
disconnectAll: function (src/* optional */, sig) {
src = MochiKit.DOM.getElement(src);
@ -778,7 +817,8 @@ MochiKit.Signal.EXPORT = [
'connect',
'disconnect',
'signal',
'disconnectAll'
'disconnectAll',
'disconnectAllTo'
];
MochiKit.Signal.__new__ = function (win) {

File diff suppressed because it is too large Load Diff