📄 common.js
字号:
/* Copyright (c) 2004-2006, The Dojo Foundation All Rights Reserved. Licensed under the Academic Free License version 2.1 or above OR the modified BSD license. For more information on Dojo licensing, see: http://dojotoolkit.org/community/licensing.shtml*/dojo.provide("dojo.io.common");dojo.require("dojo.string");dojo.require("dojo.lang.extras");/****************************************************************************** * Notes about dojo.io design: * * The dojo.io.* package has the unenviable task of making a lot of different * types of I/O feel natural, despite a universal lack of good (or even * reasonable!) I/O capability in the host environment. So lets pin this down * a little bit further. * * Rhino: * perhaps the best situation anywhere. Access to Java classes allows you * to do anything one might want in terms of I/O, both synchronously and * async. Can open TCP sockets and perform low-latency client/server * interactions. HTTP transport is available through Java HTTP client and * server classes. Wish it were always this easy. * * xpcshell: * XPCOM for I/O. * * spidermonkey: * S.O.L. * * Browsers: * Browsers generally do not provide any useable filesystem access. We are * therefore limited to HTTP for moving information to and from Dojo * instances living in a browser. * * XMLHTTP: * Sync or async, allows reading of arbitrary text files (including * JS, which can then be eval()'d), writing requires server * cooperation and is limited to HTTP mechanisms (POST and GET). * * <iframe> hacks: * iframe document hacks allow browsers to communicate asynchronously * with a server via HTTP POST and GET operations. With significant * effort and server cooperation, low-latency data transit between * client and server can be acheived via iframe mechanisms (repubsub). * * SVG: * Adobe's SVG viewer implements helpful primitives for XML-based * requests, but receipt of arbitrary text data seems unlikely w/o * <![CDATA[]]> sections. * * * A discussion between Dylan, Mark, Tom, and Alex helped to lay down a lot * the IO API interface. A transcript of it can be found at: * http://dojotoolkit.org/viewcvs/viewcvs.py/documents/irc/irc_io_api_log.txt?rev=307&view=auto * * Also referenced in the design of the API was the DOM 3 L&S spec: * http://www.w3.org/TR/2004/REC-DOM-Level-3-LS-20040407/load-save.html ******************************************************************************/// a map of the available transport options. Transports should add themselves// by calling add(name)dojo.io.transports = [];dojo.io.hdlrFuncNames = [ "load", "error", "timeout" ]; // we're omitting a progress() event for nowdojo.io.Request = function(/*String*/ url, /*String*/ mimetype, /*String*/ transport, /*String or Boolean*/ changeUrl){// summary:// Constructs a Request object that is used by dojo.io.bind().// description:// dojo.io.bind() will create one of these for you if// you call dojo.io.bind() with an plain object containing the bind parameters.// This method can either take the arguments specified, or an Object containing all of the parameters that you// want to use to create the dojo.io.Request (similar to how dojo.io.bind() is called.// The named parameters to this constructor represent the minimum set of parameters need if((arguments.length == 1)&&(arguments[0].constructor == Object)){ this.fromKwArgs(arguments[0]); }else{ this.url = url; if(mimetype){ this.mimetype = mimetype; } if(transport){ this.transport = transport; } if(arguments.length >= 4){ this.changeUrl = changeUrl; } }}dojo.lang.extend(dojo.io.Request, { /** The URL to hit */ url: "", /** The mime type used to interrpret the response body */ mimetype: "text/plain", /** The HTTP method to use */ method: "GET", /** An Object containing key-value pairs to be included with the request */ content: undefined, // Object /** The transport medium to use */ transport: undefined, // String /** If defined the URL of the page is physically changed */ changeUrl: undefined, // String /** A form node to use in the request */ formNode: undefined, // HTMLFormElement /** Whether the request should be made synchronously */ sync: false, bindSuccess: false, /** Cache/look for the request in the cache before attempting to request? * NOTE: this isn't a browser cache, this is internal and would only cache in-page */ useCache: false, /** Prevent the browser from caching this by adding a query string argument to the URL */ preventCache: false, // events stuff load: function(/*String*/type, /*Object*/data, /*Object*/transportImplementation, /*Object*/kwArgs){ // summary: // Called on successful completion of a bind. // type: String // A string with value "load" // data: Object // The object representing the result of the bind. The actual structure // of the data object will depend on the mimetype that was given to bind // in the bind arguments. // transportImplementation: Object // The object that implements a particular transport. Structure is depedent // on the transport. For XMLHTTPTransport (dojo.io.BrowserIO), it will be the // XMLHttpRequest object from the browser. // kwArgs: Object // Object that contains the request parameters that were given to the // bind call. Useful for storing and retrieving state from when bind // was called. }, error: function(/*String*/type, /*Object*/error, /*Object*/transportImplementation, /*Object*/kwArgs){ // summary: // Called when there is an error with a bind. // type: String // A string with value "error" // error: Object // The error object. Should be a dojo.io.Error object, but not guaranteed. // transportImplementation: Object // The object that implements a particular transport. Structure is depedent // on the transport. For XMLHTTPTransport (dojo.io.BrowserIO), it will be the // XMLHttpRequest object from the browser. // kwArgs: Object // Object that contains the request parameters that were given to the // bind call. Useful for storing and retrieving state from when bind // was called. }, timeout: function(/*String*/type, /*Object*/empty, /*Object*/transportImplementation, /*Object*/kwArgs){ // summary: // Called when there is an error with a bind. Only implemented in certain transports at this time. // type: String // A string with value "timeout" // empty: Object // Should be null. Just a spacer argument so that load, error, timeout and handle have the // same signatures. // transportImplementation: Object // The object that implements a particular transport. Structure is depedent // on the transport. For XMLHTTPTransport (dojo.io.BrowserIO), it will be the // XMLHttpRequest object from the browser. May be null for the timeout case for // some transports. // kwArgs: Object // Object that contains the request parameters that were given to the // bind call. Useful for storing and retrieving state from when bind // was called. }, handle: function(/*String*/type, /*Object*/data, /*Object*/transportImplementation, /*Object*/kwArgs){ // summary: // The handle method can be defined instead of defining separate load, error and timeout // callbacks. // type: String // A string with the type of callback: "load", "error", or "timeout". // data: Object // See the above callbacks for what this parameter could be. // transportImplementation: Object // The object that implements a particular transport. Structure is depedent // on the transport. For XMLHTTPTransport (dojo.io.BrowserIO), it will be the // XMLHttpRequest object from the browser. // kwArgs: Object // Object that contains the request parameters that were given to the // bind call. Useful for storing and retrieving state from when bind // was called. }, //FIXME: change IframeIO.js to use timeouts? // The number of seconds to wait until firing a timeout callback. // If it is zero, that means, don't do a timeout check. timeoutSeconds: 0, // the abort method needs to be filled in by the transport that accepts the // bind() request abort: function(){ }, // backButton: function(){ }, // forwardButton: function(){ }, fromKwArgs: function(/*Object*/ kwArgs){ // summary: // Creates a dojo.io.Request from a simple object (kwArgs object). // normalize args if(kwArgs["url"]){ kwArgs.url = kwArgs.url.toString(); } if(kwArgs["formNode"]) { kwArgs.formNode = dojo.byId(kwArgs.formNode); } if(!kwArgs["method"] && kwArgs["formNode"] && kwArgs["formNode"].method) { kwArgs.method = kwArgs["formNode"].method; } // backwards compatibility if(!kwArgs["handle"] && kwArgs["handler"]){ kwArgs.handle = kwArgs.handler; } if(!kwArgs["load"] && kwArgs["loaded"]){ kwArgs.load = kwArgs.loaded; } if(!kwArgs["changeUrl"] && kwArgs["changeURL"]) { kwArgs.changeUrl = kwArgs.changeURL; } // encoding fun! kwArgs.encoding = dojo.lang.firstValued(kwArgs["encoding"], djConfig["bindEncoding"], ""); kwArgs.sendTransport = dojo.lang.firstValued(kwArgs["sendTransport"], djConfig["ioSendTransport"], false); var isFunction = dojo.lang.isFunction; for(var x=0; x<dojo.io.hdlrFuncNames.length; x++){ var fn = dojo.io.hdlrFuncNames[x]; if(kwArgs[fn] && isFunction(kwArgs[fn])){ continue; } if(kwArgs["handle"] && isFunction(kwArgs["handle"])){ kwArgs[fn] = kwArgs.handle; } // handler is aliased above, shouldn't need this check /* else if(dojo.lang.isObject(kwArgs.handler)){ if(isFunction(kwArgs.handler[fn])){ kwArgs[fn] = kwArgs.handler[fn]||kwArgs.handler["handle"]||function(){}; } }*/ } dojo.lang.mixin(this, kwArgs); }});dojo.io.Error = function(/*String*/ msg, /*String*/ type, /*Number*/num){ // summary: // Constructs an object representing a bind error. this.message = msg; this.type = type || "unknown"; // must be one of "io", "parse", "unknown" this.number = num || 0; // per-substrate error number, not normalized}dojo.io.transports.addTransport = function(/*String*/name){ // summary: // Used to register transports that can support bind calls.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -