You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by he...@apache.org on 2006/11/13 23:55:14 UTC
svn commit: r474551 [12/49] - in
/struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo:
./ src/ src/alg/ src/animation/ src/cal/ src/charting/ src/charting/svg/
src/charting/vml/ src/collections/ src/crypto/ src/data/ src/data/cs...
Added: struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/docs.js
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/docs.js?view=auto&rev=474551
==============================================================================
--- struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/docs.js (added)
+++ struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/docs.js Mon Nov 13 14:54:45 2006
@@ -0,0 +1,1048 @@
+/*
+ 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.docs");
+dojo.require("dojo.io.*");
+dojo.require("dojo.event.topic");
+dojo.require("dojo.rpc.JotService");
+dojo.require("dojo.dom");
+dojo.require("dojo.uri.Uri");
+dojo.require("dojo.Deferred");
+dojo.require("dojo.DeferredList");
+
+/*
+ * TODO:
+ *
+ * Package summary needs to compensate for "is"
+ * Handle host environments
+ * Deal with dojo.widget weirdness
+ * Parse parameters
+ * Limit function parameters to only the valid ones (Involves packing parameters onto meta during rewriting)
+ *
+ */
+
+dojo.docs = new function() {
+ this._url = dojo.uri.dojoUri("docscripts");
+ this._rpc = new dojo.rpc.JotService;
+ this._rpc.serviceUrl = dojo.uri.dojoUri("docscripts/jsonrpc.php");
+};
+dojo.lang.mixin(dojo.docs, {
+ _count: 0,
+ _callbacks: {function_names: []},
+ _cache: {}, // Saves the JSON objects in cache
+ require: function(/*String*/ require, /*bool*/ sync) {
+ dojo.debug("require(): " + require);
+ var parts = require.split("/");
+ var size = parts.length;
+ var deferred = new dojo.Deferred;
+ var args = {
+ mimetype: "text/json",
+ load: function(type, data){
+ dojo.debug("require(): loaded");
+
+ if(parts[0] != "function_names") {
+ for(var i = 0, part; part = parts[i]; i++){
+ data = data[part];
+ }
+ }
+ deferred.callback(data);
+ },
+ error: function(){
+ deferred.errback();
+ }
+ };
+
+ if (sync) {
+ args.sync = true;
+ }
+
+ if(location.protocol == "file:"){
+ if(size){
+ if(parts[0] == "function_names"){
+ args.url = [this._url, "local_json", "function_names"].join("/");
+ }else{
+ var dirs = parts[0].split(".");
+ args.url = [this._url, "local_json", dirs[0]].join("/");
+ if(dirs.length > 1){
+ args.url = [args.url, dirs[1]].join(".");
+ }
+ }
+ }
+ }
+
+ dojo.io.bind(args);
+ return deferred;
+ },
+ getFunctionNames: function(){
+ return this.require("function_names"); // dojo.Deferred
+ },
+ unFormat: function(/*String*/ string){
+ var fString = string;
+ if(string.charAt(string.length - 1) == "_"){
+ fString = [string.substring(0, string.length - 1), "*"].join("");
+ }
+ return fString;
+ },
+ getMeta: function(/*mixed*/ selectKey, /*String*/ pkg, /*String*/ name, /*Function*/ callback, /*String?*/ id){
+ // summary: Gets information about a function in regards to its meta data
+ if(typeof name == "function"){
+ // pId: a
+ // pkg: ignore
+ id = callback;
+ callback = name;
+ name = pkg;
+ pkg = null;
+ dojo.debug("getMeta(" + name + ")");
+ }else{
+ dojo.debug("getMeta(" + pkg + "/" + name + ")");
+ }
+
+ if(!id){
+ id = "_";
+ }
+
+ if(!selectKey){
+ selectKey = ++dojo.docs._count;
+ }
+
+ var input;
+ if(typeof selectKey == "object" && selectKey.selectKey){
+ input = selectKey;
+ selectKey = selectKey.selectKey;
+ }else{
+ input = {};
+ }
+
+ dojo.docs._buildCache({
+ type: "meta",
+ callbacks: [dojo.docs._gotMeta, callback],
+ pkg: pkg,
+ name: name,
+ id: id,
+ selectKey: selectKey,
+ input: input
+ });
+ },
+ _withPkg: function(/*String*/ type, /*Object*/ data, /*Object*/ evt, /*Object*/ input, /*String*/ newType){
+ dojo.debug("_withPkg(" + evt.name + ") has package: " + data[0]);
+ evt.pkg = data[0];
+ if("load" == type && evt.pkg){
+ evt.type = newType;
+ dojo.docs._buildCache(evt);
+ }else{
+ if(evt.callbacks && evt.callbacks.length){
+ evt.callbacks.shift()("error", {}, evt, evt.input);
+ }
+ }
+ },
+ _gotMeta: function(/*String*/ type, /*Object*/ data, /*Object*/ evt){
+ dojo.debug("_gotMeta(" + evt.name + ")");
+
+ var cached = dojo.docs._getCache(evt.pkg, evt.name, "meta", "functions", evt.id);
+ if(cached.summary){
+ data.summary = cached.summary;
+ }
+ if(evt.callbacks && evt.callbacks.length){
+ evt.callbacks.shift()(type, data, evt, evt.input);
+ }
+ },
+ getSrc: function(/*mixed*/ selectKey, /*String*/ name, /*Function*/ callback, /*String?*/ id){
+ // summary: Gets src file (created by the doc parser)
+ dojo.debug("getSrc(" + name + ")");
+ if(!id){
+ id = "_";
+ }
+ if(!selectKey){
+ selectKey = ++dojo.docs._count;
+ }
+
+ var input;
+ if(typeof selectKey == "object" && selectKey.selectKey){
+ input = selectKey;
+ selectKey = selectKey.selectKey;
+ }else{
+ input = {};
+ }
+
+ dojo.docs._buildCache({
+ type: "src",
+ callbacks: [callback],
+ name: name,
+ id: id,
+ input: input,
+ selectKey: selectKey
+ });
+ },
+ getDoc: function(/*mixed*/ selectKey, /*String*/ name, /*Function*/ callback, /*String?*/ id){
+ // summary: Gets external documentation stored on Jot for a given function
+ dojo.debug("getDoc(" + name + ")");
+
+ if(!id){
+ id = "_";
+ }
+
+ if(!selectKey){
+ selectKey = ++dojo.docs._count;
+ }
+
+ var input = {};
+ if(typeof selectKey == "object" && selectKey.selectKey){
+ input.input = selectKey;
+ selectKey = selectKey.selectKey;
+ }
+
+ input.type = "doc";
+ input.name = name;
+ input.selectKey = selectKey;
+ input.callbacks = [callback];
+ input.selectKey = selectKey;
+
+ dojo.docs._buildCache(input);
+ },
+ _gotDoc: function(/*String*/ type, /*Array*/ data, /*Object*/ evt, /*Object*/ input){
+ dojo.debug("_gotDoc(" + evt.type + ")");
+
+ evt[evt.type] = data;
+ if(evt.expects && evt.expects.doc){
+ for(var i = 0, expect; expect = evt.expects.doc[i]; i++){
+ if(!(expect in evt)){
+ dojo.debug("_gotDoc() waiting for more data");
+ return;
+ }
+ }
+ }
+
+ var cache = dojo.docs._getCache(evt.pkg, "meta", "functions", evt.name, evt.id, "meta");
+
+ var description = evt.fn.description;
+ cache.description = description;
+ data = {
+ returns: evt.fn.returns,
+ id: evt.id,
+ variables: [],
+ selectKey: evt.selectKey
+ }
+ if(!cache.parameters){
+ cache.parameters = {};
+ }
+ for(var i = 0, param; param = evt.param[i]; i++){
+ var fName = param["DocParamForm/name"];
+ if(!cache.parameters[fName]){
+ cache.parameters[fName] = {};
+ }
+ cache.parameters[fName].description = param["DocParamForm/desc"]
+ }
+
+ data.description = cache.description;
+ data.parameters = cache.parameters;
+
+ evt.type = "doc";
+
+ if(evt.callbacks && evt.callbacks.length){
+ evt.callbacks.shift()("load", data, evt, input);
+ }
+ },
+ getPkgDoc: function(/*mixed*/ selectKey, /*String*/ name, /*Function*/ callback){
+ // summary: Gets external documentation stored on Jot for a given package
+ dojo.debug("getPkgDoc(" + name + ")");
+ var input = {};
+ if(typeof selectKey == "object" && selectKey.selectKey){
+ input = selectKey;
+ selectKey = selectKey.selectKey;
+ }
+ if(!selectKey){
+ selectKey = ++dojo.docs._count;
+ }
+ dojo.docs._buildCache({
+ type: "pkgdoc",
+ callbacks: [callback],
+ name: name,
+ selectKey: selectKey,
+ input: input
+ });
+ },
+ getPkgInfo: function(/*mixed*/ selectKey, /*String*/ name, /*Function*/ callback){
+ // summary: Gets a combination of the metadata and external documentation for a given package
+ dojo.debug("getPkgInfo(" + name + ")");
+ if(!selectKey){
+ selectKey = ++dojo.docs._count;
+ }
+
+ var input = {
+ selectKey: selectKey,
+ expects: {
+ pkginfo: ["pkgmeta", "pkgdoc"]
+ },
+ callback: callback
+ };
+ dojo.docs.getPkgMeta(input, name, dojo.docs._getPkgInfo);
+ dojo.docs.getPkgDoc(input, name, dojo.docs._getPkgInfo);
+ },
+ _getPkgInfo: function(/*String*/ type, /*Object*/ data, /*Object*/ evt){
+ dojo.debug("_getPkgInfo() for " + evt.type);
+ var key = evt.selectKey;
+ var input = {};
+ var results = {};
+ if(typeof key == "object"){
+ input = key;
+ key = key.selectKey;
+ input[evt.type] = data;
+ if(input.expects && input.expects.pkginfo){
+ for(var i = 0, expect; expect = input.expects.pkginfo[i]; i++){
+ if(!(expect in input)){
+ dojo.debug("_getPkgInfo() waiting for more data");
+ return;
+ }
+ }
+ }
+ results = input.pkgmeta;
+ results.description = input.pkgdoc;
+ }
+
+ if(input.callback){
+ input.callback("load", results, evt);
+ }
+ },
+ getInfo: function(/*mixed*/ selectKey, /*String*/ name, /*Function*/ callback){
+ dojo.debug("getInfo(" + name + ")");
+ var input = {
+ expects: {
+ "info": ["meta", "doc"]
+ },
+ selectKey: selectKey,
+ callback: callback
+ }
+ dojo.docs.getMeta(input, name, dojo.docs._getInfo);
+ dojo.docs.getDoc(input, name, dojo.docs._getInfo);
+ },
+ _getInfo: function(/*String*/ type, /*String*/ data, /*Object*/ evt, /*Object*/ input){
+ dojo.debug("_getInfo(" + evt.type + ")");
+ if(input && input.expects && input.expects.info){
+ input[evt.type] = data;
+ for(var i = 0, expect; expect = input.expects.info[i]; i++){
+ if(!(expect in input)){
+ dojo.debug("_getInfo() waiting for more data");
+ return;
+ }
+ }
+ }
+
+ if(input.callback){
+ input.callback("load", dojo.docs._getCache(evt.pkg, "meta", "functions", evt.name, evt.id, "meta"), evt, input);
+ }
+ },
+ _getMainText: function(/*String*/ text){
+ // summary: Grabs the innerHTML from a Jot Rech Text node
+ dojo.debug("_getMainText()");
+ return text.replace(/^<html[^<]*>/, "").replace(/<\/html>$/, "").replace(/<\w+\s*\/>/g, "");
+ },
+ getPackageMeta: function(/*Object*/ input){
+ dojo.debug("getPackageMeta(): " + input.pkg);
+ return this.require(input.pkg + "/meta", input.sync);
+ },
+ OLDgetPkgMeta: function(/*mixed*/ selectKey, /*String*/ name, /*Function*/ callback){
+ dojo.debug("getPkgMeta(" + name + ")");
+ var input = {};
+ if(typeof selectKey == "object" && selectKey.selectKey){
+ input = selectKey;
+ selectKey = selectKey.selectKey;
+ }else if(!selectKey){
+ selectKey = ++dojo.docs._count;
+ }
+ dojo.docs._buildCache({
+ type: "pkgmeta",
+ callbacks: [callback],
+ name: name,
+ selectKey: selectKey,
+ input: input
+ });
+ },
+ OLD_getPkgMeta: function(/*Object*/ input){
+ dojo.debug("_getPkgMeta(" + input.name + ")");
+ input.type = "pkgmeta";
+ dojo.docs._buildCache(input);
+ },
+ _onDocSearch: function(/*Object*/ input){
+ var _this = this;
+ var name = input.name.toLowerCase();
+ if(!name) return;
+
+ this.getFunctionNames().addCallback(function(data){
+ dojo.debug("_onDocSearch(): function names loaded for " + name);
+
+ var output = [];
+ var list = [];
+ var closure = function(pkg, fn) {
+ return function(data){
+ dojo.debug("_onDocSearch(): package meta loaded for: " + pkg);
+ if(data.functions){
+ var functions = data.functions;
+ for(var key in functions){
+ if(fn == key){
+ var ids = functions[key];
+ for(var id in ids){
+ var fnMeta = ids[id];
+ output.push({
+ package: pkg,
+ name: fn,
+ id: id,
+ summary: fnMeta.summary
+ });
+ }
+ }
+ }
+ }
+ return output;
+ }
+ }
+
+ pkgLoop:
+ for(var pkg in data){
+ if(pkg.toLowerCase() == name){
+ name = pkg;
+ dojo.debug("_onDocSearch found a package");
+ //dojo.docs._onDocSelectPackage(input);
+ return;
+ }
+ for(var i = 0, fn; fn = data[pkg][i]; i++){
+ if(fn.toLowerCase().indexOf(name) != -1){
+ dojo.debug("_onDocSearch(): Search matched " + fn);
+ var meta = _this.getPackageMeta({pkg: pkg});
+ meta.addCallback(closure(pkg, fn));
+ list.push(meta);
+
+ // Build a list of all packages that need to be loaded and their loaded state.
+ continue pkgLoop;
+ }
+ }
+ }
+
+ list = new dojo.DeferredList(list);
+ list.addCallback(function(results){
+ dojo.debug("_onDocSearch(): All packages loaded");
+ _this._printFunctionResults(results[0][1]);
+ });
+ });
+ },
+ _onDocSearchFn: function(/*String*/ type, /*Array*/ data, /*Object*/ evt){
+ dojo.debug("_onDocSearchFn(" + evt.name + ")");
+
+ var name = evt.name || evt.pkg;
+
+ dojo.debug("_onDocSearchFn found a function");
+
+ evt.pkgs = packages;
+ evt.pkg = name;
+ evt.loaded = 0;
+ for(var i = 0, pkg; pkg = packages[i]; i++){
+ dojo.docs.getPkgMeta(evt, pkg, dojo.docs._onDocResults);
+ }
+ },
+ _onPkgResults: function(/*String*/ type, /*Object*/ data, /*Object*/ evt, /*Object*/ input){
+ dojo.debug("_onPkgResults(" + evt.type + ")");
+ var description = "";
+ var path = "";
+ var methods = {};
+ var requires = {};
+ if(input){
+ input[evt.type] = data;
+ if(input.expects && input.expects.pkgresults){
+ for(var i = 0, expect; expect = input.expects.pkgresults[i]; i++){
+ if(!(expect in input)){
+ dojo.debug("_onPkgResults() waiting for more data");
+ return;
+ }
+ }
+ }
+ path = input.pkgdoc.path;
+ description = input.pkgdoc.description;
+ methods = input.pkgmeta.methods;
+ requires = input.pkgmeta.requires;
+ }
+ var pkg = evt.name.replace("_", "*");
+ var results = {
+ path: path,
+ description: description,
+ size: 0,
+ methods: [],
+ pkg: pkg,
+ selectKey: evt.selectKey,
+ requires: requires
+ }
+ var rePrivate = /_[^.]+$/;
+ for(var method in methods){
+ if(!rePrivate.test(method)){
+ for(var pId in methods[method]){
+ results.methods.push({
+ pkg: pkg,
+ name: method,
+ id: pId,
+ summary: methods[method][pId].summary
+ })
+ }
+ }
+ }
+ results.size = results.methods.length;
+ dojo.docs._printPkgResult(results);
+ },
+ _onDocResults: function(/*String*/ type, /*Object*/ data, /*Object*/ evt, /*Object*/ input){
+ dojo.debug("_onDocResults(" + evt.name + "/" + input.pkg + ") " + type);
+ ++input.loaded;
+
+ if(input.loaded == input.pkgs.length){
+ var pkgs = input.pkgs;
+ var name = input.pkg;
+ var results = {selectKey: evt.selectKey, methods: []};
+ var rePrivate = /_[^.]+$/;
+ data = dojo.docs._cache;
+
+ for(var i = 0, pkg; pkg = pkgs[i]; i++){
+ var methods = dojo.docs._getCache(pkg, "meta", "methods");
+ for(var fn in methods){
+ if(fn.toLowerCase().indexOf(name) == -1){
+ continue;
+ }
+ if(fn != "requires" && !rePrivate.test(fn)){
+ for(var pId in methods[fn]){
+ var result = {
+ pkg: pkg,
+ name: fn,
+ id: "_",
+ summary: ""
+ }
+ if(methods[fn][pId].summary){
+ result.summary = methods[fn][pId].summary;
+ }
+ results.methods.push(result);
+ }
+ }
+ }
+ }
+
+ dojo.debug("Publishing docResults");
+ dojo.docs._printFnResults(results);
+ }
+ },
+ _printFunctionResults: function(results){
+ dojo.debug("_printFnResults(): called");
+ // summary: Call this function to send the /docs/function/results topic
+ },
+ _printPkgResult: function(results){
+ dojo.debug("_printPkgResult(): called");
+ },
+ _onDocSelectFunction: function(/*Object*/ input){
+ // summary: Get doc, meta, and src
+ var name = input.name;
+ var pkg = input.pkg;
+ dojo.debug("_onDocSelectFunction(" + name + ")");
+ if(!name){
+ return false;
+ }
+ if(!input.selectKey){
+ input.selectKey = ++dojo.docs._count;
+ }
+ input.expects = {
+ "docresults": ["meta", "doc", "pkgmeta"]
+ }
+ dojo.docs.getMeta(input, pkg, name, dojo.docs._onDocSelectResults);
+ dojo.docs.getDoc(input, pkg, name, dojo.docs._onDocSelectResults);
+ },
+ _onDocSelectPackage: function(/*Object*/ input){
+ dojo.debug("_onDocSelectPackage(" + input.name + ")")
+ input.expects = {
+ "pkgresults": ["pkgmeta", "pkgdoc"]
+ };
+ if(!input.selectKey){
+ input.selectKey = ++dojo.docs._count;
+ }
+ dojo.docs.getPkgMeta(input, input.name, dojo.docs._onPkgResults);
+ dojo.docs.getPkgDoc(input, input.name, dojo.docs._onPkgResults);
+ },
+ _onDocSelectResults: function(/*String*/ type, /*Object*/ data, /*Object*/ evt, /*Object*/ input){
+ dojo.debug("_onDocSelectResults(" + evt.type + ", " + evt.name + ")");
+ if(evt.type == "meta"){
+ dojo.docs.getPkgMeta(input, evt.pkg, dojo.docs._onDocSelectResults);
+ }
+ if(input){
+ input[evt.type] = data;
+ if(input.expects && input.expects.docresults){
+ for(var i = 0, expect; expect = input.expects.docresults[i]; i++){
+ if(!(expect in input)){
+ dojo.debug("_onDocSelectResults() waiting for more data");
+ return;
+ }
+ }
+ }
+ }
+
+ dojo.docs._printFunctionDetail(input);
+ },
+
+ _printFunctionDetail: function(results) {
+ // summary: Call this function to send the /docs/function/detail topic event
+ },
+
+ _buildCache: function(/*Object*/ input){
+ dojo.debug("_buildCache(" + input.type + ", " + input.name + ")");
+ // Get stuff from the input object
+ var type = input.type;
+ var pkg = input.pkg;
+ var callbacks = input.callbacks;
+ var id = input.id;
+ if(!id){
+ id = input.id = "_";
+ }
+ var name = input.name;
+ var selectKey = input.selectKey;
+
+ var META = "meta";
+ var METHODS = "methods";
+ var SRC = "src";
+ var DESCRIPTION = "description";
+ var INPUT = "input";
+ var LOAD = "load";
+ var ERROR = "error";
+
+ var docs = dojo.docs;
+ var getCache = docs._getCache;
+
+ // Stuff to pass to RPC
+ var search = [];
+
+ if(type == "doc"){
+ if(!pkg){
+ docs.functionPackages(selectKey, name, function(){ var a = arguments; docs._withPkg.call(this, a[0], a[1], a[2], a[3], "doc"); }, input);
+ return;
+ }else{
+ var cached = getCache(pkg, META, METHODS, name, id, META);
+
+ if(cached[DESCRIPTION]){
+ callbacks.shift()(LOAD, cached[DESCRIPTION], input, input[INPUT]);
+ return;
+ }
+
+ var obj = {};
+ obj.forFormName = "DocFnForm";
+ obj.limit = 1;
+
+ obj.filter = "it/DocFnForm/require = '" + pkg + "' and it/DocFnForm/name = '" + name + "' and ";
+ if(id == "_"){
+ obj.filter += " not(it/DocFnForm/id)";
+ }else{
+ obj.filter += " it/DocFnForm/id = '" + id + "'";
+ }
+
+ obj.load = function(data){
+ var cached = getCache(pkg, META, METHODS, name, id, META);
+
+ var description = "";
+ var returns = "";
+ if(data.list && data.list.length){
+ description = docs._getMainText(data.list[0]["main/text"]);
+ returns = data.list[0]["DocFnForm/returns"];
+ }
+
+ cached[DESCRIPTION] = description;
+ if(!cached.returns){
+ cached.returns = {};
+ }
+ cached.returns.summary = returns;
+
+ input.type = "fn";
+ docs._gotDoc(LOAD, cached, input, input[INPUT]);
+ }
+ obj.error = function(data){
+ input.type = "fn";
+ docs._gotDoc(ERROR, {}, input, input[INPUT]);
+ }
+ search.push(obj);
+
+ obj = {};
+ obj.forFormName = "DocParamForm";
+
+ obj.filter = "it/DocParamForm/fns = '" + pkg + "=>" + name;
+ if(id != "_"){
+ obj.filter += "=>" + id;
+ }
+ obj.filter += "'";
+
+ obj.load = function(data){
+ var cache = getCache(pkg, META, METHODS, name, id, META);
+ for(var i = 0, param; param = data.list[i]; i++){
+ var pName = param["DocParamForm/name"];
+ if(!cache.parameters[pName]){
+ cache.parameters[pName] = {};
+ }
+ cache.parameters[pName].summary = param["DocParamForm/desc"];
+ }
+ input.type = "param";
+ docs._gotDoc(LOAD, cache.parameters, input);
+ }
+ obj.error = function(data){
+ input.type = "param";
+ docs._gotDoc(ERROR, {}, input);
+ }
+ search.push(obj);
+ }
+ }else if(type == "pkgdoc"){
+ var cached = getCache(name, META);
+
+ if(cached[DESCRIPTION]){
+ callbacks.shift()(LOAD, {description: cached[DESCRIPTION], path: cached.path}, input, input.input);
+ return;
+ }
+
+ var obj = {};
+ obj.forFormName = "DocPkgForm";
+ obj.limit = 1;
+ obj.filter = "it/DocPkgForm/require = '" + name + "'";
+
+ obj.load = function(data){
+ var description = "";
+ var list = data.list;
+ if(list && list.length && list[0]["main/text"]){
+ description = docs._getMainText(list[0]["main/text"]);
+ cached[DESCRIPTION] = description;
+ cached.path = list[0].name;
+ }
+
+ if(callbacks && callbacks.length){
+ callbacks.shift()(LOAD, {description: description, path: cached.path}, input, input.input);
+ }
+ }
+ obj.error = function(data){
+ if(callbacks && callbacks.length){
+ callbacks.shift()(ERROR, "", input, input.input);
+ }
+ }
+ search.push(obj);
+ }else if(type == "function_names"){
+ var cached = getCache();
+ if(!cached.function_names){
+ dojo.debug("_buildCache() new cache");
+ if(callbacks && callbacks.length){
+ docs._callbacks.function_names.push([input, callbacks.shift()]);
+ }
+ cached.function_names = {loading: true};
+
+ var obj = {};
+ obj.url = "function_names";
+ obj.load = function(type, data, evt){
+ cached.function_names = data;
+ while(docs._callbacks.function_names.length){
+ var parts = docs._callbacks.function_names.pop();
+ parts[1](LOAD, data, parts[0]);
+ }
+ }
+ obj.error = function(type, data, evt){
+ while(docs._callbacks.function_names.length){
+ var parts = docs._callbacks.function_names.pop();
+ parts[1](LOAD, {}, parts[0]);
+ }
+ }
+ search.push(obj);
+ }else if(cached.function_names.loading){
+ dojo.debug("_buildCache() loading cache, adding to callback list");
+ if(callbacks && callbacks.length){
+ docs._callbacks.function_names.push([input, callbacks.shift()]);
+ }
+ return;
+ }else{
+ dojo.debug("_buildCache() loading from cache");
+ if(callbacks && callbacks.length){
+ callbacks.shift()(LOAD, cached.function_names, input);
+ }
+ return;
+ }
+ }else if(type == META || type == SRC){
+ if(!pkg){
+ if(type == META){
+ docs.functionPackages(selectKey, name, function(){ var a = arguments; docs._withPkg.call(this, a[0], a[1], a[2], a[3], META); }, input);
+ return;
+ }else{
+ docs.functionPackages(selectKey, name, function(){ var a = arguments; docs._withPkg.call(this, a[0], a[1], a[2], a[3], SRC); }, input);
+ return;
+ }
+ }else{
+ var cached = getCache(pkg, META, METHODS, name, id);
+
+ if(cached[type] && cached[type].returns){
+ if(callbacks && callbacks.length){
+ callbacks.shift()(LOAD, cached[type], input);
+ return;
+ }
+ }
+
+ dojo.debug("Finding " + type + " for: " + pkg + ", function: " + name + ", id: " + id);
+
+ var obj = {};
+
+ if(type == SRC){
+ obj.mimetype = "text/plain"
+ }
+ obj.url = pkg + "/" + name + "/" + id + "/" + type;
+ obj.load = function(type, data, evt){
+ dojo.debug("_buildCache() loaded " + input.type);
+
+ if(input.type == SRC){
+ getCache(pkg, META, METHODS, name, id).src = data;
+ if(callbacks && callbacks.length){
+ callbacks.shift()(LOAD, data, input, input[INPUT]);
+ }
+ }else{
+ var cache = getCache(pkg, META, METHODS, name, id, META);
+ if(!cache.parameters){
+ cache.parameters = {};
+ }
+ for(var i = 0, param; param = data.parameters[i]; i++){
+ if(!cache.parameters[param[1]]){
+ cache.parameters[param[1]] = {};
+ }
+ cache.parameters[param[1]].type = param[0];
+ }
+ if(!cache.returns){
+ cache.returns = {};
+ }
+ cache.returns.type = data.returns;
+ }
+
+ if(callbacks && callbacks.length){
+ callbacks.shift()(LOAD, cache, input, input[INPUT]);
+ }
+ }
+ obj.error = function(type, data, evt){
+ if(callbacks && callbacks.length){
+ callbacks.shift()(ERROR, {}, input, input[INPUT]);
+ }
+ }
+ }
+
+ search.push(obj);
+ }else if(type == "pkgmeta"){
+ var cached = getCache(name, "meta");
+
+ if(cached.requires){
+ if(callbacks && callbacks.length){
+ callbacks.shift()(LOAD, cached, input, input[INPUT]);
+ return;
+ }
+ }
+
+ dojo.debug("Finding package meta for: " + name);
+
+ var obj = {};
+
+ obj.url = name + "/meta";
+ obj.load = function(type, data, evt){
+ dojo.debug("_buildCache() loaded for: " + name);
+
+ var methods = data.methods;
+ if(methods){
+ for(var method in methods){
+ if (method == "is") {
+ continue;
+ }
+ for(var pId in methods[method]){
+ getCache(name, META, METHODS, method, pId, META).summary = methods[method][pId];
+ }
+ }
+ }
+
+ var requires = data.requires;
+ var cache = getCache(name, META);
+ if(requires){
+ cache.requires = requires;
+ }
+ if(callbacks && callbacks.length){
+ callbacks.shift()(LOAD, cache, input, input[INPUT]);
+ }
+ }
+ obj.error = function(type, data, evt){
+ if(callbacks && callbacks.length){
+ callbacks.shift()(ERROR, {}, input, input[INPUT]);
+ }
+ }
+ search.push(obj);
+ }
+
+ for(var i = 0, obj; obj = search[i]; i++){
+ var load = obj.load;
+ var error = obj.error;
+ delete obj.load;
+ delete obj.error;
+ var mimetype = obj.mimetype;
+ if(!mimetype){
+ mimetype = "text/json"
+ }
+ if(obj.url){
+ dojo.io.bind({
+ url: new dojo.uri.Uri(docs._url, obj.url),
+ input: input,
+ mimetype: mimetype,
+ error: error,
+ load: load
+ });
+ }else{
+ docs._rpc.callRemote("search", obj).addCallbacks(load, error);
+ }
+ }
+ },
+ selectFunction: function(/*String*/ name, /*String?*/ id){
+ // summary: The combined information
+ },
+ savePackage: function(/*Object*/ callbackObject, /*String*/ callback, /*Object*/ parameters){
+ dojo.event.kwConnect({
+ srcObj: dojo.docs,
+ srcFunc: "_savedPkgRpc",
+ targetObj: callbackObject,
+ targetFunc: callback,
+ once: true
+ });
+
+ var props = {};
+ var cache = dojo.docs._getCache(parameters.pkg, "meta");
+
+ var i = 1;
+
+ if(!cache.path){
+ var path = "id";
+ props[["pname", i].join("")] = "DocPkgForm/require";
+ props[["pvalue", i++].join("")] = parameters.pkg;
+ }else{
+ var path = cache.path;
+ }
+
+ props.form = "//DocPkgForm";
+ props.path = ["/WikiHome/DojoDotDoc/", path].join("");
+
+ if(parameters.description){
+ props[["pname", i].join("")] = "main/text";
+ props[["pvalue", i++].join("")] = parameters.description;
+ }
+
+ dojo.docs._rpc.callRemote("saveForm", props).addCallbacks(dojo.docs._pkgRpc, dojo.docs._pkgRpc);
+ },
+ _pkgRpc: function(data){
+ if(data.name){
+ dojo.docs._getCache(data["DocPkgForm/require"], "meta").path = data.name;
+ dojo.docs._savedPkgRpc("load");
+ }else{
+ dojo.docs._savedPkgRpc("error");
+ }
+ },
+ _savedPkgRpc: function(type){
+ },
+ functionPackages: function(/*mixed*/ selectKey, /*String*/ name, /*Function*/ callback, /*Object*/ input){
+ // summary: Gets the package associated with a function and stores it in the .pkg value of input
+ dojo.debug("functionPackages() name: " + name);
+
+ if(!input){
+ input = {};
+ }
+ if(!input.callbacks){
+ input.callbacks = [];
+ }
+
+ input.type = "function_names";
+ input.name = name;
+ input.callbacks.unshift(callback);
+ input.callbacks.unshift(dojo.docs._functionPackages);
+ dojo.docs._buildCache(input);
+ },
+ _functionPackages: function(/*String*/ type, /*Array*/ data, /*Object*/ evt){
+ dojo.debug("_functionPackages() name: " + evt.name);
+ evt.pkg = '';
+
+ var results = [];
+ var data = dojo.docs._cache['function_names'];
+ for(var key in data){
+ if(dojo.lang.inArray(data[key], evt.name)){
+ dojo.debug("_functionPackages() package: " + key);
+ results.push(key);
+ }
+ }
+
+ if(evt.callbacks && evt.callbacks.length){
+ evt.callbacks.shift()(type, results, evt, evt.input);
+ }
+ },
+ setUserName: function(/*String*/ name){
+ dojo.docs._userName = name;
+ if(name && dojo.docs._password){
+ dojo.docs._logIn();
+ }
+ },
+ setPassword: function(/*String*/ password){
+ dojo.docs._password = password;
+ if(password && dojo.docs._userName){
+ dojo.docs._logIn();
+ }
+ },
+ _logIn: function(){
+ dojo.io.bind({
+ url: dojo.docs._rpc.serviceUrl.toString(),
+ method: "post",
+ mimetype: "text/json",
+ content: {
+ username: dojo.docs._userName,
+ password: dojo.docs._password
+ },
+ load: function(type, data){
+ if(data.error){
+ dojo.docs.logInSuccess();
+ }else{
+ dojo.docs.logInFailure();
+ }
+ },
+ error: function(){
+ dojo.docs.logInFailure();
+ }
+ });
+ },
+ logInSuccess: function(){},
+ logInFailure: function(){},
+ _set: function(/*Object*/ base, /*String...*/ keys, /*String*/ value){
+ var args = [];
+ for(var i = 0, arg; arg = arguments[i]; i++){
+ args.push(arg);
+ }
+
+ if(args.length < 3) return;
+ base = args.shift();
+ value = args.pop();
+ var key = args.pop();
+ for(var i = 0, arg; arg = args[i]; i++){
+ if(typeof base[arg] != "object"){
+ base[arg] = {};
+ }
+ base = base[arg];
+ }
+ base[key] = value;
+ },
+ _getCache: function(/*String...*/ keys){
+ var obj = dojo.docs._cache;
+ for(var i = 0; i < arguments.length; i++){
+ var arg = arguments[i];
+ if(!obj[arg]){
+ obj[arg] = {};
+ }
+ obj = obj[arg];
+ }
+ return obj;
+ }
+});
+
+dojo.event.topic.subscribe("/docs/search", dojo.docs, "_onDocSearch");
+dojo.event.topic.subscribe("/docs/function/select", dojo.docs, "_onDocSelectFunction");
+dojo.event.topic.subscribe("/docs/package/select", dojo.docs, "_onDocSelectPackage");
+
+dojo.event.topic.registerPublisher("/docs/function/results", dojo.docs, "_printFunctionResults");
+dojo.event.topic.registerPublisher("/docs/function/detail", dojo.docs, "_printFunctionDetail");
+dojo.event.topic.registerPublisher("/docs/package/detail", dojo.docs, "_printPkgResult");
\ No newline at end of file
Propchange: struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/docs.js
------------------------------------------------------------------------------
svn:eol-style = native
Modified: struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/dom.js
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/dom.js?view=diff&rev=474551&r1=474550&r2=474551
==============================================================================
--- struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/dom.js (original)
+++ struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/dom.js Mon Nov 13 14:54:45 2006
@@ -1,5 +1,5 @@
/*
- Copyright (c) 2004-2005, The Dojo Foundation
+ Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
Licensed under the Academic Free License version 2.1 or above OR the
@@ -9,7 +9,6 @@
*/
dojo.provide("dojo.dom");
-dojo.require("dojo.lang");
dojo.dom.ELEMENT_NODE = 1;
dojo.dom.ATTRIBUTE_NODE = 2;
@@ -30,6 +29,8 @@
* comprehensive list of XML namespaces
**/
dojo.dom.xmlns = {
+ // summary
+ // aliases for various common XML namespaces
svg : "http://www.w3.org/2000/svg",
smil : "http://www.w3.org/2001/SMIL20/",
mml : "http://www.w3.org/1998/Math/MathML",
@@ -57,73 +58,33 @@
AdobeExtensions : "http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/"
};
-dojo.dom.isNode = dojo.lang.isDomNode = function(wh){
- if(typeof Element == "object") {
+dojo.dom.isNode = function(/* object */wh){
+ // summary
+ // checks to see if wh is actually a node.
+ if(typeof Element == "function") {
try {
- return wh instanceof Element;
+ return wh instanceof Element; // boolean
} catch(E) {}
} else {
// best-guess
- return wh && !isNaN(wh.nodeType);
+ return wh && !isNaN(wh.nodeType); // boolean
}
}
-dojo.lang.whatAmI.custom["node"] = dojo.dom.isNode;
-
-dojo.dom.getTagName = function(node){
- var tagName = node.tagName;
- if(tagName.substr(0,5).toLowerCase()!="dojo:"){
-
- if(tagName.substr(0,4).toLowerCase()=="dojo"){
- // FIXME: this assuumes tag names are always lower case
- return "dojo:" + tagName.substring(4).toLowerCase();
- }
-
- // allow lower-casing
- var djt = node.getAttribute("dojoType")||node.getAttribute("dojotype");
- if(djt){
- return "dojo:"+djt.toLowerCase();
- }
-
- if((node.getAttributeNS)&&(node.getAttributeNS(this.dojoml,"type"))){
- return "dojo:" + node.getAttributeNS(this.dojoml,"type").toLowerCase();
- }
- try{
- // FIXME: IE really really doesn't like this, so we squelch
- // errors for it
- djt = node.getAttribute("dojo:type");
- }catch(e){ /* FIXME: log? */ }
- if(djt){
- return "dojo:"+djt.toLowerCase();
- }
-
- if((!dj_global["djConfig"])||(!djConfig["ignoreClassNames"])){
- // FIXME: should we make this optionally enabled via djConfig?
- var classes = node.className||node.getAttribute("class");
- // FIXME: following line, without check for existence of classes.indexOf
- // breaks firefox 1.5's svg widgets
- if((classes)&&(classes.indexOf)&&(classes.indexOf("dojo-") != -1)){
- var aclasses = classes.split(" ");
- for(var x=0; x<aclasses.length; x++){
- if((aclasses[x].length>5)&&(aclasses[x].indexOf("dojo-")>=0)){
- return "dojo:"+aclasses[x].substr(5).toLowerCase();
- }
- }
- }
- }
-
- }
- return tagName.toLowerCase();
-}
dojo.dom.getUniqueId = function(){
+ // summary
+ // returns a unique string for use with any DOM element
+ var _document = dojo.doc();
do {
var id = "dj_unique_" + (++arguments.callee._idIncrement);
- }while(document.getElementById(id));
- return id;
+ }while(_document.getElementById(id));
+ return id; // string
}
dojo.dom.getUniqueId._idIncrement = 0;
-dojo.dom.firstElement = dojo.dom.getFirstChildElement = function(parentNode, tagName){
+dojo.dom.firstElement = dojo.dom.getFirstChildElement = function(/* Element */parentNode, /* string? */tagName){
+ // summary
+ // returns the first child element matching tagName
var node = parentNode.firstChild;
while(node && node.nodeType != dojo.dom.ELEMENT_NODE){
node = node.nextSibling;
@@ -131,10 +92,12 @@
if(tagName && node && node.tagName && node.tagName.toLowerCase() != tagName.toLowerCase()) {
node = dojo.dom.nextElement(node, tagName);
}
- return node;
+ return node; // Element
}
-dojo.dom.lastElement = dojo.dom.getLastChildElement = function(parentNode, tagName){
+dojo.dom.lastElement = dojo.dom.getLastChildElement = function(/* Element */parentNode, /* string? */tagName){
+ // summary
+ // returns the last child element matching tagName
var node = parentNode.lastChild;
while(node && node.nodeType != dojo.dom.ELEMENT_NODE) {
node = node.previousSibling;
@@ -142,10 +105,12 @@
if(tagName && node && node.tagName && node.tagName.toLowerCase() != tagName.toLowerCase()) {
node = dojo.dom.prevElement(node, tagName);
}
- return node;
+ return node; // Element
}
-dojo.dom.nextElement = dojo.dom.getNextSiblingElement = function(node, tagName){
+dojo.dom.nextElement = dojo.dom.getNextSiblingElement = function(/* Node */node, /* string? */tagName){
+ // summary
+ // returns the next sibling element matching tagName
if(!node) { return null; }
do {
node = node.nextSibling;
@@ -154,10 +119,12 @@
if(node && tagName && tagName.toLowerCase() != node.tagName.toLowerCase()) {
return dojo.dom.nextElement(node, tagName);
}
- return node;
+ return node; // Element
}
-dojo.dom.prevElement = dojo.dom.getPreviousSiblingElement = function(node, tagName){
+dojo.dom.prevElement = dojo.dom.getPreviousSiblingElement = function(/* Node */node, /* string? */tagName){
+ // summary
+ // returns the previous sibling element matching tagName
if(!node) { return null; }
if(tagName) { tagName = tagName.toLowerCase(); }
do {
@@ -167,7 +134,7 @@
if(node && tagName && tagName.toLowerCase() != node.tagName.toLowerCase()) {
return dojo.dom.prevElement(node, tagName);
}
- return node;
+ return node; // Element
}
// TODO: hmph
@@ -179,7 +146,10 @@
}
}*/
-dojo.dom.moveChildren = function(srcNode, destNode, trim){
+dojo.dom.moveChildren = function(/* Element */srcNode, /* Element */destNode, /* boolean? */trim){
+ // summary
+ // Moves children from srcNode to destNode and returns the count of children moved;
+ // will trim off text nodes if trim == true
var count = 0;
if(trim) {
while(srcNode.hasChildNodes() &&
@@ -195,88 +165,138 @@
destNode.appendChild(srcNode.firstChild);
count++;
}
- return count;
+ return count; // number
}
-dojo.dom.copyChildren = function(srcNode, destNode, trim){
+dojo.dom.copyChildren = function(/* Element */srcNode, /* Element */destNode, /* boolean? */trim){
+ // summary
+ // Copies children from srcNde to destNode and returns the count of children copied;
+ // will trim off text nodes if trim == true
var clonedNode = srcNode.cloneNode(true);
- return this.moveChildren(clonedNode, destNode, trim);
+ return this.moveChildren(clonedNode, destNode, trim); // number
}
-dojo.dom.removeChildren = function(node){
+dojo.dom.removeChildren = function(/* Element */node){
+ // summary
+ // removes all children from node and returns the count of children removed.
var count = node.childNodes.length;
while(node.hasChildNodes()){ node.removeChild(node.firstChild); }
- return count;
+ return count; // number
}
-dojo.dom.replaceChildren = function(node, newChild){
+dojo.dom.replaceChildren = function(/* Element */node, /* Node */newChild){
+ // summary
+ // Removes all children of node and appends newChild
// FIXME: what if newChild is an array-like object?
dojo.dom.removeChildren(node);
node.appendChild(newChild);
}
-dojo.dom.removeNode = function(node){
+dojo.dom.removeNode = function(/* Node */node){
+ // summary
+ // if node has a parent, removes node from parent and returns a reference to the removed child.
if(node && node.parentNode){
// return a ref to the removed child
- return node.parentNode.removeChild(node);
+ return node.parentNode.removeChild(node); // Node
}
}
-dojo.dom.getAncestors = function(node, filterFunction, returnFirstHit) {
+dojo.dom.getAncestors = function(/* Node */node, /* function? */filterFunction, /* boolean? */returnFirstHit) {
+ // summary
+ // returns all ancestors matching optional filterFunction; will return only the first if returnFirstHit
var ancestors = [];
- var isFunction = dojo.lang.isFunction(filterFunction);
+ var isFunction = (filterFunction && (filterFunction instanceof Function || typeof filterFunction == "function"));
while(node) {
if (!isFunction || filterFunction(node)) {
ancestors.push(node);
}
- if (returnFirstHit && ancestors.length > 0) { return ancestors[0]; }
+ if (returnFirstHit && ancestors.length > 0) {
+ return ancestors[0]; // Node
+ }
node = node.parentNode;
}
if (returnFirstHit) { return null; }
- return ancestors;
+ return ancestors; // array
}
-dojo.dom.getAncestorsByTag = function(node, tag, returnFirstHit) {
+dojo.dom.getAncestorsByTag = function(/* Node */node, /* string */tag, /* boolean? */returnFirstHit) {
+ // summary
+ // returns all ancestors matching tag (as tagName), will only return first one if returnFirstHit
tag = tag.toLowerCase();
return dojo.dom.getAncestors(node, function(el){
return ((el.tagName)&&(el.tagName.toLowerCase() == tag));
- }, returnFirstHit);
+ }, returnFirstHit); // Node || array
}
-dojo.dom.getFirstAncestorByTag = function(node, tag) {
- return dojo.dom.getAncestorsByTag(node, tag, true);
+dojo.dom.getFirstAncestorByTag = function(/* Node */node, /* string */tag) {
+ // summary
+ // Returns first ancestor of node with tag tagName
+ return dojo.dom.getAncestorsByTag(node, tag, true); // Node
}
-dojo.dom.isDescendantOf = function(node, ancestor, guaranteeDescendant){
+dojo.dom.isDescendantOf = function(/* Node */node, /* Node */ancestor, /* boolean? */guaranteeDescendant){
+ // summary
+ // Returns boolean if node is a descendant of ancestor
// guaranteeDescendant allows us to be a "true" isDescendantOf function
if(guaranteeDescendant && node) { node = node.parentNode; }
while(node) {
- if(node == ancestor){ return true; }
+ if(node == ancestor){
+ return true; // boolean
+ }
node = node.parentNode;
}
- return false;
+ return false; // boolean
}
-dojo.dom.innerXML = function(node){
+dojo.dom.innerXML = function(/* Node */node){
+ // summary
+ // Implementation of MS's innerXML function.
if(node.innerXML){
- return node.innerXML;
+ return node.innerXML; // string
+ }else if (node.xml){
+ return node.xml; // string
}else if(typeof XMLSerializer != "undefined"){
- return (new XMLSerializer()).serializeToString(node);
+ return (new XMLSerializer()).serializeToString(node); // string
+ }
+}
+
+dojo.dom.createDocument = function(){
+ // summary
+ // cross-browser implementation of creating an XML document object.
+ var doc = null;
+ var _document = dojo.doc();
+
+ if(!dj_undef("ActiveXObject")){
+ var prefixes = [ "MSXML2", "Microsoft", "MSXML", "MSXML3" ];
+ for(var i = 0; i<prefixes.length; i++){
+ try{
+ doc = new ActiveXObject(prefixes[i]+".XMLDOM");
+ }catch(e){ /* squelch */ };
+
+ if(doc){ break; }
+ }
+ }else if((_document.implementation)&&
+ (_document.implementation.createDocument)){
+ doc = _document.implementation.createDocument("", "", null);
}
+
+ return doc; // DOMDocument
}
-dojo.dom.createDocumentFromText = function(str, mimetype){
- if(!mimetype) { mimetype = "text/xml"; }
- if(typeof DOMParser != "undefined") {
+dojo.dom.createDocumentFromText = function(/* string */str, /* string? */mimetype){
+ // summary
+ // attempts to create a Document object based on optional mime-type, using str as the contents of the document
+ if(!mimetype){ mimetype = "text/xml"; }
+ if(!dj_undef("DOMParser")){
var parser = new DOMParser();
- return parser.parseFromString(str, mimetype);
- }else if(typeof ActiveXObject != "undefined"){
- var domDoc = new ActiveXObject("Microsoft.XMLDOM");
- if(domDoc) {
+ return parser.parseFromString(str, mimetype); // DOMDocument
+ }else if(!dj_undef("ActiveXObject")){
+ var domDoc = dojo.dom.createDocument();
+ if(domDoc){
domDoc.async = false;
domDoc.loadXML(str);
- return domDoc;
+ return domDoc; // DOMDocument
}else{
dojo.debug("toXml didn't work?");
}
@@ -288,91 +308,106 @@
var mtype = "text/xml";
var xml = '<?xml version="1.0"?>'+str;
var url = "data:"+mtype+";charset=utf-8,"+encodeURIComponent(xml);
- var request = new XMLHttpRequest();
- request.open("GET", url, false);
- request.overrideMimeType(mtype);
- request.send(null);
- return request.responseXML;
+ var req = new XMLHttpRequest();
+ req.open("GET", url, false);
+ req.overrideMimeType(mtype);
+ req.send(null);
+ return req.responseXML;
*/
- }else if(document.createElement){
- // FIXME: this may change all tags to uppercase!
- var tmp = document.createElement("xml");
- tmp.innerHTML = str;
- if(document.implementation && document.implementation.createDocument) {
- var xmlDoc = document.implementation.createDocument("foo", "", null);
- for(var i = 0; i < tmp.childNodes.length; i++) {
- xmlDoc.importNode(tmp.childNodes.item(i), true);
+ }else{
+ var _document = dojo.doc();
+ if(_document.createElement){
+ // FIXME: this may change all tags to uppercase!
+ var tmp = _document.createElement("xml");
+ tmp.innerHTML = str;
+ if(_document.implementation && _document.implementation.createDocument) {
+ var xmlDoc = _document.implementation.createDocument("foo", "", null);
+ for(var i = 0; i < tmp.childNodes.length; i++) {
+ xmlDoc.importNode(tmp.childNodes.item(i), true);
+ }
+ return xmlDoc; // DOMDocument
}
- return xmlDoc;
+ // FIXME: probably not a good idea to have to return an HTML fragment
+ // FIXME: the tmp.doc.firstChild is as tested from IE, so it may not
+ // work that way across the board
+ return ((tmp.document)&&
+ (tmp.document.firstChild ? tmp.document.firstChild : tmp)); // DOMDocument
}
- // FIXME: probably not a good idea to have to return an HTML fragment
- // FIXME: the tmp.doc.firstChild is as tested from IE, so it may not
- // work that way across the board
- return tmp.document && tmp.document.firstChild ?
- tmp.document.firstChild : tmp;
}
return null;
}
-dojo.dom.prependChild = function(node, parent) {
+dojo.dom.prependChild = function(/* Element */node, /* Element */parent) {
+ // summary
+ // prepends node to parent's children nodes
if(parent.firstChild) {
parent.insertBefore(node, parent.firstChild);
} else {
parent.appendChild(node);
}
- return true;
+ return true; // boolean
}
-dojo.dom.insertBefore = function(node, ref, force){
+dojo.dom.insertBefore = function(/* Node */node, /* Node */ref, /* boolean? */force){
+ // summary
+ // Try to insert node before ref
if (force != true &&
(node === ref || node.nextSibling === ref)){ return false; }
var parent = ref.parentNode;
parent.insertBefore(node, ref);
- return true;
+ return true; // boolean
}
-dojo.dom.insertAfter = function(node, ref, force){
+dojo.dom.insertAfter = function(/* Node */node, /* Node */ref, /* boolean? */force){
+ // summary
+ // Try to insert node after ref
var pn = ref.parentNode;
if(ref == pn.lastChild){
if((force != true)&&(node === ref)){
- return false;
+ return false; // boolean
}
pn.appendChild(node);
}else{
- return this.insertBefore(node, ref.nextSibling, force);
+ return this.insertBefore(node, ref.nextSibling, force); // boolean
}
- return true;
+ return true; // boolean
}
-dojo.dom.insertAtPosition = function(node, ref, position){
- if((!node)||(!ref)||(!position)){ return false; }
+dojo.dom.insertAtPosition = function(/* Node */node, /* Node */ref, /* string */position){
+ // summary
+ // attempt to insert node in relation to ref based on position
+ if((!node)||(!ref)||(!position)){
+ return false; // boolean
+ }
switch(position.toLowerCase()){
case "before":
- return dojo.dom.insertBefore(node, ref);
+ return dojo.dom.insertBefore(node, ref); // boolean
case "after":
- return dojo.dom.insertAfter(node, ref);
+ return dojo.dom.insertAfter(node, ref); // boolean
case "first":
if(ref.firstChild){
- return dojo.dom.insertBefore(node, ref.firstChild);
+ return dojo.dom.insertBefore(node, ref.firstChild); // boolean
}else{
ref.appendChild(node);
- return true;
+ return true; // boolean
}
break;
default: // aka: last
ref.appendChild(node);
- return true;
+ return true; // boolean
}
}
-dojo.dom.insertAtIndex = function(node, containingNode, insertionIndex){
+dojo.dom.insertAtIndex = function(/* Node */node, /* Element */containingNode, /* number */insertionIndex){
+ // summary
+ // insert node into child nodes nodelist of containingNode at insertionIndex.
var siblingNodes = containingNode.childNodes;
// if there aren't any kids yet, just add it to the beginning
if (!siblingNodes.length){
containingNode.appendChild(node);
- return true;
+ return true; // boolean
}
// otherwise we need to walk the childNodes
@@ -392,25 +427,25 @@
if (after){
// add it after the node in {after}
- return dojo.dom.insertAfter(node, after);
+ return dojo.dom.insertAfter(node, after); // boolean
}else{
// add it to the start
- return dojo.dom.insertBefore(node, siblingNodes.item(0));
+ return dojo.dom.insertBefore(node, siblingNodes.item(0)); // boolean
}
}
-/**
- * implementation of the DOM Level 3 attribute.
- *
- * @param node The node to scan for text
- * @param text Optional, set the text to this value.
- */
-dojo.dom.textContent = function(node, text){
- if (text) {
- dojo.dom.replaceChildren(node, document.createTextNode(text));
- return text;
+dojo.dom.textContent = function(/* Node */node, /* string */text){
+ // summary
+ // implementation of the DOM Level 3 attribute; scan node for text
+ if (arguments.length>1) {
+ var _document = dojo.doc();
+ dojo.dom.replaceChildren(node, _document.createTextNode(text));
+ return text; // string
} else {
+ if(node.textContent != undefined){ //FF 1.5
+ return node.textContent; // string
+ }
var _result = "";
if (node == null) { return _result; }
for (var i = 0; i < node.childNodes.length; i++) {
@@ -428,26 +463,17 @@
break;
}
}
- return _result;
+ return _result; // string
}
}
-dojo.dom.collectionToArray = function(collection){
- dojo.deprecated("dojo.dom.collectionToArray", "use dojo.lang.toArray instead");
- return dojo.lang.toArray(collection);
-}
-
-dojo.dom.hasParent = function(node) {
- if(!node || !node.parentNode || (node.parentNode && !node.parentNode.tagName)) {
- return false;
- }
- return true;
+dojo.dom.hasParent = function (/* Node */node) {
+ // summary
+ // returns whether or not node is a child of another node.
+ return node && node.parentNode && dojo.dom.isNode(node.parentNode); // boolean
}
/**
- * Determines if node has any of the provided tag names and
- * returns the tag name that matches, empty string otherwise.
- *
* Examples:
*
* myFooNode = <foo />
@@ -456,10 +482,41 @@
* isTag(myFooNode, "FOO"); // returns ""
* isTag(myFooNode, "hey", "foo", "bar"); // returns "foo"
**/
-dojo.dom.isTag = function(node /* ... */) {
+dojo.dom.isTag = function(/* Node */node /* ... */) {
+ // summary
+ // determines if node has any of the provided tag names and returns the tag name that matches, empty string otherwise.
if(node && node.tagName) {
- var arr = dojo.lang.toArray(arguments, 1);
- return arr[ dojo.lang.find(node.tagName, arr) ] || "";
+ for(var i=1; i<arguments.length; i++){
+ if(node.tagName==String(arguments[i])){
+ return String(arguments[i]); // string
+ }
+ }
+ }
+ return ""; // string
+}
+
+dojo.dom.setAttributeNS = function(/* Element */elem, /* string */namespaceURI, /* string */attrName, /* string */attrValue){
+ // summary
+ // implementation of DOM2 setAttributeNS that works cross browser.
+ if(elem == null || ((elem == undefined)&&(typeof elem == "undefined"))){
+ dojo.raise("No element given to dojo.dom.setAttributeNS");
+ }
+
+ if(!((elem.setAttributeNS == undefined)&&(typeof elem.setAttributeNS == "undefined"))){ // w3c
+ elem.setAttributeNS(namespaceURI, attrName, attrValue);
+ }else{ // IE
+ // get a root XML document
+ var ownerDoc = elem.ownerDocument;
+ var attribute = ownerDoc.createNode(
+ 2, // node type
+ attrName,
+ namespaceURI
+ );
+
+ // set value
+ attribute.nodeValue = attrValue;
+
+ // attach to element
+ elem.setAttributeNode(attribute);
}
- return "";
}
Modified: struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/event.js
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/event.js?view=diff&rev=474551&r1=474550&r2=474551
==============================================================================
--- struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/event.js (original)
+++ struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/event.js Mon Nov 13 14:54:45 2006
@@ -1,5 +1,5 @@
/*
- Copyright (c) 2004-2005, The Dojo Foundation
+ Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
Licensed under the Academic Free License version 2.1 or above OR the
@@ -8,477 +8,7 @@
http://dojotoolkit.org/community/licensing.shtml
*/
-dojo.require("dojo.lang");
dojo.provide("dojo.event");
-dojo.event = new function(){
- this.canTimeout = dojo.lang.isFunction(dj_global["setTimeout"])||dojo.lang.isAlien(dj_global["setTimeout"]);
-
- // FIXME: where should we put this method (not here!)?
- function interpolateArgs(args){
- var dl = dojo.lang;
- var ao = {
- srcObj: dj_global,
- srcFunc: null,
- adviceObj: dj_global,
- adviceFunc: null,
- aroundObj: null,
- aroundFunc: null,
- adviceType: (args.length>2) ? args[0] : "after",
- precedence: "last",
- once: false,
- delay: null,
- rate: 0,
- adviceMsg: false
- };
-
- switch(args.length){
- case 0: return;
- case 1: return;
- case 2:
- ao.srcFunc = args[0];
- ao.adviceFunc = args[1];
- break;
- case 3:
- if((dl.isObject(args[0]))&&(dl.isString(args[1]))&&(dl.isString(args[2]))){
- ao.adviceType = "after";
- ao.srcObj = args[0];
- ao.srcFunc = args[1];
- ao.adviceFunc = args[2];
- }else if((dl.isString(args[1]))&&(dl.isString(args[2]))){
- ao.srcFunc = args[1];
- ao.adviceFunc = args[2];
- }else if((dl.isObject(args[0]))&&(dl.isString(args[1]))&&(dl.isFunction(args[2]))){
- ao.adviceType = "after";
- ao.srcObj = args[0];
- ao.srcFunc = args[1];
- var tmpName = dojo.lang.nameAnonFunc(args[2], ao.adviceObj);
- ao.adviceFunc = tmpName;
- }else if((dl.isFunction(args[0]))&&(dl.isObject(args[1]))&&(dl.isString(args[2]))){
- ao.adviceType = "after";
- ao.srcObj = dj_global;
- var tmpName = dojo.lang.nameAnonFunc(args[0], ao.srcObj);
- ao.srcFunc = tmpName;
- ao.adviceObj = args[1];
- ao.adviceFunc = args[2];
- }
- break;
- case 4:
- if((dl.isObject(args[0]))&&(dl.isObject(args[2]))){
- // we can assume that we've got an old-style "connect" from
- // the sigslot school of event attachment. We therefore
- // assume after-advice.
- ao.adviceType = "after";
- ao.srcObj = args[0];
- ao.srcFunc = args[1];
- ao.adviceObj = args[2];
- ao.adviceFunc = args[3];
- }else if((dl.isString(args[0]))&&(dl.isString(args[1]))&&(dl.isObject(args[2]))){
- ao.adviceType = args[0];
- ao.srcObj = dj_global;
- ao.srcFunc = args[1];
- ao.adviceObj = args[2];
- ao.adviceFunc = args[3];
- }else if((dl.isString(args[0]))&&(dl.isFunction(args[1]))&&(dl.isObject(args[2]))){
- ao.adviceType = args[0];
- ao.srcObj = dj_global;
- var tmpName = dojo.lang.nameAnonFunc(args[1], dj_global);
- ao.srcFunc = tmpName;
- ao.adviceObj = args[2];
- ao.adviceFunc = args[3];
- }else if(dl.isObject(args[1])){
- ao.srcObj = args[1];
- ao.srcFunc = args[2];
- ao.adviceObj = dj_global;
- ao.adviceFunc = args[3];
- }else if(dl.isObject(args[2])){
- ao.srcObj = dj_global;
- ao.srcFunc = args[1];
- ao.adviceObj = args[2];
- ao.adviceFunc = args[3];
- }else{
- ao.srcObj = ao.adviceObj = ao.aroundObj = dj_global;
- ao.srcFunc = args[1];
- ao.adviceFunc = args[2];
- ao.aroundFunc = args[3];
- }
- break;
- case 6:
- ao.srcObj = args[1];
- ao.srcFunc = args[2];
- ao.adviceObj = args[3]
- ao.adviceFunc = args[4];
- ao.aroundFunc = args[5];
- ao.aroundObj = dj_global;
- break;
- default:
- ao.srcObj = args[1];
- ao.srcFunc = args[2];
- ao.adviceObj = args[3]
- ao.adviceFunc = args[4];
- ao.aroundObj = args[5];
- ao.aroundFunc = args[6];
- ao.once = args[7];
- ao.delay = args[8];
- ao.rate = args[9];
- ao.adviceMsg = args[10];
- break;
- }
-
- if((typeof ao.srcFunc).toLowerCase() != "string"){
- ao.srcFunc = dojo.lang.getNameInObj(ao.srcObj, ao.srcFunc);
- }
-
- if((typeof ao.adviceFunc).toLowerCase() != "string"){
- ao.adviceFunc = dojo.lang.getNameInObj(ao.adviceObj, ao.adviceFunc);
- }
-
- if((ao.aroundObj)&&((typeof ao.aroundFunc).toLowerCase() != "string")){
- ao.aroundFunc = dojo.lang.getNameInObj(ao.aroundObj, ao.aroundFunc);
- }
-
- if(!ao.srcObj){
- dojo.raise("bad srcObj for srcFunc: "+ao.srcFunc);
- }
- if(!ao.adviceObj){
- dojo.raise("bad adviceObj for adviceFunc: "+ao.adviceFunc);
- }
- return ao;
- }
-
- this.connect = function(){
- var ao = interpolateArgs(arguments);
-
- // FIXME: just doing a "getForMethod()" seems to be enough to put this into infinite recursion!!
- var mjp = dojo.event.MethodJoinPoint.getForMethod(ao.srcObj, ao.srcFunc);
- if(ao.adviceFunc){
- var mjp2 = dojo.event.MethodJoinPoint.getForMethod(ao.adviceObj, ao.adviceFunc);
- }
-
- mjp.kwAddAdvice(ao);
-
- return mjp; // advanced users might want to fsck w/ the join point
- // manually
- }
-
- this.connectBefore = function() {
- var args = ["before"];
- for(var i = 0; i < arguments.length; i++) { args.push(arguments[i]); }
- return this.connect.apply(this, args);
- }
-
- this.connectAround = function() {
- var args = ["around"];
- for(var i = 0; i < arguments.length; i++) { args.push(arguments[i]); }
- return this.connect.apply(this, args);
- }
-
- this._kwConnectImpl = function(kwArgs, disconnect){
- var fn = (disconnect) ? "disconnect" : "connect";
- if(typeof kwArgs["srcFunc"] == "function"){
- kwArgs.srcObj = kwArgs["srcObj"]||dj_global;
- var tmpName = dojo.lang.nameAnonFunc(kwArgs.srcFunc, kwArgs.srcObj);
- kwArgs.srcFunc = tmpName;
- }
- if(typeof kwArgs["adviceFunc"] == "function"){
- kwArgs.adviceObj = kwArgs["adviceObj"]||dj_global;
- var tmpName = dojo.lang.nameAnonFunc(kwArgs.adviceFunc, kwArgs.adviceObj);
- kwArgs.adviceFunc = tmpName;
- }
- return dojo.event[fn]( (kwArgs["type"]||kwArgs["adviceType"]||"after"),
- kwArgs["srcObj"]||dj_global,
- kwArgs["srcFunc"],
- kwArgs["adviceObj"]||kwArgs["targetObj"]||dj_global,
- kwArgs["adviceFunc"]||kwArgs["targetFunc"],
- kwArgs["aroundObj"],
- kwArgs["aroundFunc"],
- kwArgs["once"],
- kwArgs["delay"],
- kwArgs["rate"],
- kwArgs["adviceMsg"]||false );
- }
-
- this.kwConnect = function(kwArgs){
- return this._kwConnectImpl(kwArgs, false);
-
- }
-
- this.disconnect = function(){
- var ao = interpolateArgs(arguments);
- if(!ao.adviceFunc){ return; } // nothing to disconnect
- var mjp = dojo.event.MethodJoinPoint.getForMethod(ao.srcObj, ao.srcFunc);
- return mjp.removeAdvice(ao.adviceObj, ao.adviceFunc, ao.adviceType, ao.once);
- }
-
- this.kwDisconnect = function(kwArgs){
- return this._kwConnectImpl(kwArgs, true);
- }
-}
-
-// exactly one of these is created whenever a method with a joint point is run,
-// if there is at least one 'around' advice.
-dojo.event.MethodInvocation = function(join_point, obj, args) {
- this.jp_ = join_point;
- this.object = obj;
- this.args = [];
- for(var x=0; x<args.length; x++){
- this.args[x] = args[x];
- }
- // the index of the 'around' that is currently being executed.
- this.around_index = -1;
-}
-
-dojo.event.MethodInvocation.prototype.proceed = function() {
- this.around_index++;
- if(this.around_index >= this.jp_.around.length){
- return this.jp_.object[this.jp_.methodname].apply(this.jp_.object, this.args);
- // return this.jp_.run_before_after(this.object, this.args);
- }else{
- var ti = this.jp_.around[this.around_index];
- var mobj = ti[0]||dj_global;
- var meth = ti[1];
- return mobj[meth].call(mobj, this);
- }
-}
-
-
-dojo.event.MethodJoinPoint = function(obj, methname){
- this.object = obj||dj_global;
- this.methodname = methname;
- this.methodfunc = this.object[methname];
- this.before = [];
- this.after = [];
- this.around = [];
-}
-
-dojo.event.MethodJoinPoint.getForMethod = function(obj, methname) {
- // if(!(methname in obj)){
- if(!obj){ obj = dj_global; }
- if(!obj[methname]){
- // supply a do-nothing method implementation
- obj[methname] = function(){};
- }else if((!dojo.lang.isFunction(obj[methname]))&&(!dojo.lang.isAlien(obj[methname]))){
- return null; // FIXME: should we throw an exception here instead?
- }
- // we hide our joinpoint instance in obj[methname + '$joinpoint']
- var jpname = methname + "$joinpoint";
- var jpfuncname = methname + "$joinpoint$method";
- var joinpoint = obj[jpname];
- if(!joinpoint){
- var isNode = false;
- if(dojo.event["browser"]){
- if( (obj["attachEvent"])||
- (obj["nodeType"])||
- (obj["addEventListener"]) ){
- isNode = true;
- dojo.event.browser.addClobberNodeAttrs(obj, [jpname, jpfuncname, methname]);
- }
- }
- obj[jpfuncname] = obj[methname];
- // joinpoint = obj[jpname] = new dojo.event.MethodJoinPoint(obj, methname);
- joinpoint = obj[jpname] = new dojo.event.MethodJoinPoint(obj, jpfuncname);
- obj[methname] = function(){
- var args = [];
-
- if((isNode)&&(!arguments.length)&&(window.event)){
- args.push(dojo.event.browser.fixEvent(window.event));
- }else{
- for(var x=0; x<arguments.length; x++){
- if((x==0)&&(isNode)&&(dojo.event.browser.isEvent(arguments[x]))){
- args.push(dojo.event.browser.fixEvent(arguments[x]));
- }else{
- args.push(arguments[x]);
- }
- }
- }
- // return joinpoint.run.apply(joinpoint, arguments);
- return joinpoint.run.apply(joinpoint, args);
- }
- }
- return joinpoint;
-}
-
-dojo.lang.extend(dojo.event.MethodJoinPoint, {
- unintercept: function() {
- this.object[this.methodname] = this.methodfunc;
- },
-
- run: function() {
- var obj = this.object||dj_global;
- var args = arguments;
-
- // optimization. We only compute once the array version of the arguments
- // pseudo-arr in order to prevent building it each time advice is unrolled.
- var aargs = [];
- for(var x=0; x<args.length; x++){
- aargs[x] = args[x];
- }
-
- var unrollAdvice = function(marr){
- if(!marr){
- dojo.debug("Null argument to unrollAdvice()");
- return;
- }
-
- var callObj = marr[0]||dj_global;
- var callFunc = marr[1];
-
- if(!callObj[callFunc]){
- dojo.raise("function \"" + callFunc + "\" does not exist on \"" + callObj + "\"");
- }
-
- var aroundObj = marr[2]||dj_global;
- var aroundFunc = marr[3];
- var msg = marr[6];
- var undef;
-
- var to = {
- args: [],
- jp_: this,
- object: obj,
- proceed: function(){
- return callObj[callFunc].apply(callObj, to.args);
- }
- };
- to.args = aargs;
-
- var delay = parseInt(marr[4]);
- var hasDelay = ((!isNaN(delay))&&(marr[4]!==null)&&(typeof marr[4] != "undefined"));
- if(marr[5]){
- var rate = parseInt(marr[5]);
- var cur = new Date();
- var timerSet = false;
- if((marr["last"])&&((cur-marr.last)<=rate)){
- if(dojo.event.canTimeout){
- if(marr["delayTimer"]){
- clearTimeout(marr.delayTimer);
- }
- var tod = parseInt(rate*2); // is rate*2 naive?
- var mcpy = dojo.lang.shallowCopy(marr);
- marr.delayTimer = setTimeout(function(){
- // FIXME: on IE at least, event objects from the
- // browser can go out of scope. How (or should?) we
- // deal with it?
- mcpy[5] = 0;
- unrollAdvice(mcpy);
- }, tod);
- }
- return;
- }else{
- marr.last = cur;
- }
- }
-
- // FIXME: need to enforce rates for a connection here!
-
- if(aroundFunc){
- // NOTE: around advice can't delay since we might otherwise depend
- // on execution order!
- aroundObj[aroundFunc].call(aroundObj, to);
- }else{
- // var tmjp = dojo.event.MethodJoinPoint.getForMethod(obj, methname);
- if((hasDelay)&&((dojo.render.html)||(dojo.render.svg))){ // FIXME: the render checks are grotty!
- dj_global["setTimeout"](function(){
- if(msg){
- callObj[callFunc].call(callObj, to);
- }else{
- callObj[callFunc].apply(callObj, args);
- }
- }, delay);
- }else{ // many environments can't support delay!
- if(msg){
- callObj[callFunc].call(callObj, to);
- }else{
- callObj[callFunc].apply(callObj, args);
- }
- }
- }
- }
-
- if(this.before.length>0){
- dojo.lang.forEach(this.before, unrollAdvice, true);
- }
-
- var result;
- if(this.around.length>0){
- var mi = new dojo.event.MethodInvocation(this, obj, args);
- result = mi.proceed();
- }else if(this.methodfunc){
- result = this.object[this.methodname].apply(this.object, args);
- }
-
- if(this.after.length>0){
- dojo.lang.forEach(this.after, unrollAdvice, true);
- }
-
- return (this.methodfunc) ? result : null;
- },
-
- getArr: function(kind){
- var arr = this.after;
- // FIXME: we should be able to do this through props or Array.in()
- if((typeof kind == "string")&&(kind.indexOf("before")!=-1)){
- arr = this.before;
- }else if(kind=="around"){
- arr = this.around;
- }
- return arr;
- },
-
- kwAddAdvice: function(args){
- this.addAdvice( args["adviceObj"], args["adviceFunc"],
- args["aroundObj"], args["aroundFunc"],
- args["adviceType"], args["precedence"],
- args["once"], args["delay"], args["rate"],
- args["adviceMsg"]);
- },
-
- addAdvice: function( thisAdviceObj, thisAdvice,
- thisAroundObj, thisAround,
- advice_kind, precedence,
- once, delay, rate, asMessage){
- var arr = this.getArr(advice_kind);
- if(!arr){
- dojo.raise("bad this: " + this);
- }
-
- var ao = [thisAdviceObj, thisAdvice, thisAroundObj, thisAround, delay, rate, asMessage];
-
- if(once){
- if(this.hasAdvice(thisAdviceObj, thisAdvice, advice_kind, arr) >= 0){
- return;
- }
- }
-
- if(precedence == "first"){
- arr.unshift(ao);
- }else{
- arr.push(ao);
- }
- },
-
- hasAdvice: function(thisAdviceObj, thisAdvice, advice_kind, arr){
- if(!arr){ arr = this.getArr(advice_kind); }
- var ind = -1;
- for(var x=0; x<arr.length; x++){
- if((arr[x][0] == thisAdviceObj)&&(arr[x][1] == thisAdvice)){
- ind = x;
- }
- }
- return ind;
- },
-
- removeAdvice: function(thisAdviceObj, thisAdvice, advice_kind, once){
- var arr = this.getArr(advice_kind);
- var ind = this.hasAdvice(thisAdviceObj, thisAdvice, advice_kind, arr);
- if(ind == -1){
- return false;
- }
- while(ind != -1){
- arr.splice(ind, 1);
- if(once){ break; }
- ind = this.hasAdvice(thisAdviceObj, thisAdvice, advice_kind, arr);
- }
- return true;
- }
-});
+dojo.require("dojo.event.*");
+dojo.deprecated("dojo.event", "replaced by dojo.event.*", "0.5");
Modified: struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/event/__package__.js
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/event/__package__.js?view=diff&rev=474551&r1=474550&r2=474551
==============================================================================
--- struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/event/__package__.js (original)
+++ struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/event/__package__.js Mon Nov 13 14:54:45 2006
@@ -1,5 +1,5 @@
/*
- Copyright (c) 2004-2005, The Dojo Foundation
+ Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
Licensed under the Academic Free License version 2.1 or above OR the
@@ -8,8 +8,9 @@
http://dojotoolkit.org/community/licensing.shtml
*/
-dojo.hostenv.conditionalLoadModule({
- common: ["dojo.event", "dojo.event.topic"],
- browser: ["dojo.event.browser"]
+dojo.kwCompoundRequire({
+ common: ["dojo.event.common", "dojo.event.topic"],
+ browser: ["dojo.event.browser"],
+ dashboard: ["dojo.event.browser"]
});
-dojo.hostenv.moduleLoaded("dojo.event.*");
+dojo.provide("dojo.event.*");
Modified: struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/event/browser.js
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/event/browser.js?view=diff&rev=474551&r1=474550&r2=474551
==============================================================================
--- struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/event/browser.js (original)
+++ struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/src/event/browser.js Mon Nov 13 14:54:45 2006
@@ -1,5 +1,5 @@
/*
- Copyright (c) 2004-2005, The Dojo Foundation
+ Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
Licensed under the Academic Free License version 2.1 or above OR the
@@ -9,9 +9,10 @@
*/
dojo.provide("dojo.event.browser");
-dojo.require("dojo.event");
+dojo.require("dojo.event.common");
-dojo_ie_clobber = new function(){
+// FIXME: any particular reason this is in the global scope?
+dojo._ie_clobber = new function(){
this.clobberNodes = [];
function nukeProp(node, prop){
@@ -26,7 +27,7 @@
var na;
var tna;
if(nodeRef){
- tna = nodeRef.getElementsByTagName("*");
+ tna = nodeRef.all || nodeRef.getElementsByTagName("*");
na = [nodeRef];
for(var x=0; x<tna.length; x++){
// if we're gonna be clobbering the thing, at least make sure
@@ -43,21 +44,23 @@
var basis = {};
for(var i = na.length-1; i>=0; i=i-1){
var el = na[i];
- if(el["__clobberAttrs__"]){
- for(var j=0; j<el.__clobberAttrs__.length; j++){
- nukeProp(el, el.__clobberAttrs__[j]);
+ try{
+ if(el && el["__clobberAttrs__"]){
+ for(var j=0; j<el.__clobberAttrs__.length; j++){
+ nukeProp(el, el.__clobberAttrs__[j]);
+ }
+ nukeProp(el, "__clobberAttrs__");
+ nukeProp(el, "__doClobber__");
}
- nukeProp(el, "__clobberAttrs__");
- nukeProp(el, "__doClobber__");
- }
+ }catch(e){ /* squelch! */};
}
na = null;
}
}
if(dojo.render.html.ie){
- window.onunload = function(){
- dojo_ie_clobber.clobber();
+ dojo.addOnUnload(function(){
+ dojo._ie_clobber.clobber();
try{
if((dojo["widget"])&&(dojo.widget["manager"])){
dojo.widget.manager.destroyAll();
@@ -65,25 +68,54 @@
}catch(e){}
try{ window.onload = null; }catch(e){}
try{ window.onunload = null; }catch(e){}
- dojo_ie_clobber.clobberNodes = [];
+ dojo._ie_clobber.clobberNodes = [];
// CollectGarbage();
- }
+ });
}
dojo.event.browser = new function(){
var clobberIdx = 0;
- this.clean = function(node){
+ this.normalizedEventName = function(/*String*/eventName){
+ switch(eventName){
+ case "CheckboxStateChange":
+ case "DOMAttrModified":
+ case "DOMMenuItemActive":
+ case "DOMMenuItemInactive":
+ case "DOMMouseScroll":
+ case "DOMNodeInserted":
+ case "DOMNodeRemoved":
+ case "RadioStateChange":
+ return eventName;
+ break;
+ default:
+ return eventName.toLowerCase();
+ break;
+ }
+ }
+
+ this.clean = function(/*DOMNode*/node){
+ // summary:
+ // removes native event handlers so that destruction of the node
+ // will not leak memory. On most browsers this is a no-op, but
+ // it's critical for manual node removal on IE.
+ // node:
+ // A DOM node. All of it's children will also be cleaned.
if(dojo.render.html.ie){
- dojo_ie_clobber.clobber(node);
+ dojo._ie_clobber.clobber(node);
}
}
- this.addClobberNode = function(node){
+ this.addClobberNode = function(/*DOMNode*/node){
+ // summary:
+ // register the passed node to support event stripping
+ // node:
+ // A DOM node
+ if(!dojo.render.html.ie){ return; }
if(!node["__doClobber__"]){
node.__doClobber__ = true;
- dojo_ie_clobber.clobberNodes.push(node);
+ dojo._ie_clobber.clobberNodes.push(node);
// this might not be the most efficient thing to do, but it's
// much less error prone than other approaches which were
// previously tried and failed
@@ -91,16 +123,42 @@
}
}
- this.addClobberNodeAttrs = function(node, props){
+ this.addClobberNodeAttrs = function(/*DOMNode*/node, /*Array*/props){
+ // summary:
+ // register the passed node to support event stripping
+ // node:
+ // A DOM node to stip properties from later
+ // props:
+ // A list of propeties to strip from the node
+ if(!dojo.render.html.ie){ return; }
this.addClobberNode(node);
for(var x=0; x<props.length; x++){
node.__clobberAttrs__.push(props[x]);
}
}
- this.removeListener = function(node, evtName, fp, capture){
+ this.removeListener = function( /*DOMNode*/ node,
+ /*String*/ evtName,
+ /*Function*/fp,
+ /*Boolean*/ capture){
+ // summary:
+ // clobbers the listener from the node
+ // evtName:
+ // the name of the handler to remove the function from
+ // node:
+ // DOM node to attach the event to
+ // fp:
+ // the function to register
+ // capture:
+ // Optional. should this listener prevent propigation?
if(!capture){ var capture = false; }
- evtName = evtName.toLowerCase();
+ evtName = dojo.event.browser.normalizedEventName(evtName);
+ if( (evtName == "onkey") || (evtName == "key") ){
+ if(dojo.render.html.ie){
+ this.removeListener(node, "onkeydown", fp, capture);
+ }
+ evtName = "onkeypress";
+ }
if(evtName.substr(0,2)=="on"){ evtName = evtName.substr(2); }
// FIXME: this is mostly a punt, we aren't actually doing anything on IE
if(node.removeEventListener){
@@ -108,10 +166,31 @@
}
}
- this.addListener = function(node, evtName, fp, capture, dontFix){
+ this.addListener = function(/*DOMNode*/node, /*String*/evtName, /*Function*/fp, /*Boolean*/capture, /*Boolean*/dontFix){
+ // summary:
+ // adds a listener to the node
+ // evtName:
+ // the name of the handler to add the listener to can be either of
+ // the form "onclick" or "click"
+ // node:
+ // DOM node to attach the event to
+ // fp:
+ // the function to register
+ // capture:
+ // Optional. Should this listener prevent propigation?
+ // dontFix:
+ // Optional. Should we avoid registering a new closure around the
+ // listener to enable fixEvent for dispatch of the registered
+ // function?
if(!node){ return; } // FIXME: log and/or bail?
if(!capture){ var capture = false; }
- evtName = evtName.toLowerCase();
+ evtName = dojo.event.browser.normalizedEventName(evtName);
+ if( (evtName == "onkey") || (evtName == "key") ){
+ if(dojo.render.html.ie){
+ this.addListener(node, "onkeydown", fp, capture, dontFix);
+ }
+ evtName = "onkeypress";
+ }
if(evtName.substr(0,2)!="on"){ evtName = "on"+evtName; }
if(!dontFix){
@@ -119,7 +198,7 @@
// around the resulting event
var newfp = function(evt){
if(!evt){ evt = window.event; }
- var ret = fp(dojo.event.browser.fixEvent(evt));
+ var ret = fp(dojo.event.browser.fixEvent(evt, this));
if(capture){
dojo.event.browser.stopEvent(evt);
}
@@ -149,17 +228,27 @@
}
}
- this.isEvent = function(obj){
+ this.isEvent = function(/*Object*/obj){
+ // summary:
+ // Tries to determine whether or not the object is a DOM event.
+
// FIXME: event detection hack ... could test for additional attributes
// if necessary
- return (typeof obj != "undefined")&&(typeof Event != "undefined")&&(obj.eventPhase);
+ return (typeof obj != "undefined")&&(typeof Event != "undefined")&&(obj.eventPhase); // Boolean
// Event does not support instanceof in Opera, otherwise:
//return (typeof Event != "undefined")&&(obj instanceof Event);
}
this.currentEvent = null;
- this.callListener = function(listener, curTarget){
+ this.callListener = function(/*Function*/listener, /*DOMNode*/curTarget){
+ // summary:
+ // calls the specified listener in the context of the passed node
+ // with the current DOM event object as the only parameter
+ // listener:
+ // the function to call
+ // curTarget:
+ // the Node to call the function in the scope of
if(typeof listener != 'function'){
dojo.raise("listener not a function: " + listener);
}
@@ -167,17 +256,18 @@
return listener.call(curTarget, dojo.event.browser.currentEvent);
}
- this.stopPropagation = function(){
- dojo.event.browser.currentEvent.cancelBubble = true;
+ this._stopPropagation = function(){
+ dojo.event.browser.currentEvent.cancelBubble = true;
}
- this.preventDefault = function(){
- dojo.event.browser.currentEvent.returnValue = false;
+ this._preventDefault = function(){
+ dojo.event.browser.currentEvent.returnValue = false;
}
this.keys = {
KEY_BACKSPACE: 8,
KEY_TAB: 9,
+ KEY_CLEAR: 12,
KEY_ENTER: 13,
KEY_SHIFT: 16,
KEY_CTRL: 17,
@@ -196,9 +286,26 @@
KEY_DOWN_ARROW: 40,
KEY_INSERT: 45,
KEY_DELETE: 46,
+ KEY_HELP: 47,
KEY_LEFT_WINDOW: 91,
KEY_RIGHT_WINDOW: 92,
KEY_SELECT: 93,
+ KEY_NUMPAD_0: 96,
+ KEY_NUMPAD_1: 97,
+ KEY_NUMPAD_2: 98,
+ KEY_NUMPAD_3: 99,
+ KEY_NUMPAD_4: 100,
+ KEY_NUMPAD_5: 101,
+ KEY_NUMPAD_6: 102,
+ KEY_NUMPAD_7: 103,
+ KEY_NUMPAD_8: 104,
+ KEY_NUMPAD_9: 105,
+ KEY_NUMPAD_MULTIPLY: 106,
+ KEY_NUMPAD_PLUS: 107,
+ KEY_NUMPAD_ENTER: 108,
+ KEY_NUMPAD_MINUS: 109,
+ KEY_NUMPAD_PERIOD: 110,
+ KEY_NUMPAD_DIVIDE: 111,
KEY_F1: 112,
KEY_F2: 113,
KEY_F3: 114,
@@ -211,6 +318,9 @@
KEY_F10: 121,
KEY_F11: 122,
KEY_F12: 123,
+ KEY_F13: 124,
+ KEY_F14: 125,
+ KEY_F15: 126,
KEY_NUM_LOCK: 144,
KEY_SCROLL_LOCK: 145
};
@@ -221,46 +331,184 @@
this.revKeys[this.keys[key]] = key;
}
- this.fixEvent = function(evt){
- if((!evt)&&(window["event"])){
- var evt = window.event;
+ this.fixEvent = function(/*Event*/evt, /*DOMNode*/sender){
+ // summary:
+ // normalizes properties on the event object including event
+ // bubbling methods, keystroke normalization, and x/y positions
+ // evt: the native event object
+ // sender: the node to treat as "currentTarget"
+ if(!evt){
+ if(window["event"]){
+ evt = window.event;
+ }
}
if((evt["type"])&&(evt["type"].indexOf("key") == 0)){ // key events
evt.keys = this.revKeys;
// FIXME: how can we eliminate this iteration?
- for(var key in this.keys) {
+ for(var key in this.keys){
evt[key] = this.keys[key];
}
- if((dojo.render.html.ie)&&(evt["type"] == "keypress")){
- evt.charCode = evt.keyCode;
+ if(evt["type"] == "keydown" && dojo.render.html.ie){
+ switch(evt.keyCode){
+ case evt.KEY_SHIFT:
+ case evt.KEY_CTRL:
+ case evt.KEY_ALT:
+ case evt.KEY_CAPS_LOCK:
+ case evt.KEY_LEFT_WINDOW:
+ case evt.KEY_RIGHT_WINDOW:
+ case evt.KEY_SELECT:
+ case evt.KEY_NUM_LOCK:
+ case evt.KEY_SCROLL_LOCK:
+ // I'll get these in keypress after the OS munges them based on numlock
+ case evt.KEY_NUMPAD_0:
+ case evt.KEY_NUMPAD_1:
+ case evt.KEY_NUMPAD_2:
+ case evt.KEY_NUMPAD_3:
+ case evt.KEY_NUMPAD_4:
+ case evt.KEY_NUMPAD_5:
+ case evt.KEY_NUMPAD_6:
+ case evt.KEY_NUMPAD_7:
+ case evt.KEY_NUMPAD_8:
+ case evt.KEY_NUMPAD_9:
+ case evt.KEY_NUMPAD_PERIOD:
+ break; // just ignore the keys that can morph
+ case evt.KEY_NUMPAD_MULTIPLY:
+ case evt.KEY_NUMPAD_PLUS:
+ case evt.KEY_NUMPAD_ENTER:
+ case evt.KEY_NUMPAD_MINUS:
+ case evt.KEY_NUMPAD_DIVIDE:
+ break; // I could handle these but just pick them up in keypress
+ case evt.KEY_PAUSE:
+ case evt.KEY_TAB:
+ case evt.KEY_BACKSPACE:
+ case evt.KEY_ENTER:
+ case evt.KEY_ESCAPE:
+ case evt.KEY_PAGE_UP:
+ case evt.KEY_PAGE_DOWN:
+ case evt.KEY_END:
+ case evt.KEY_HOME:
+ case evt.KEY_LEFT_ARROW:
+ case evt.KEY_UP_ARROW:
+ case evt.KEY_RIGHT_ARROW:
+ case evt.KEY_DOWN_ARROW:
+ case evt.KEY_INSERT:
+ case evt.KEY_DELETE:
+ case evt.KEY_F1:
+ case evt.KEY_F2:
+ case evt.KEY_F3:
+ case evt.KEY_F4:
+ case evt.KEY_F5:
+ case evt.KEY_F6:
+ case evt.KEY_F7:
+ case evt.KEY_F8:
+ case evt.KEY_F9:
+ case evt.KEY_F10:
+ case evt.KEY_F11:
+ case evt.KEY_F12:
+ case evt.KEY_F12:
+ case evt.KEY_F13:
+ case evt.KEY_F14:
+ case evt.KEY_F15:
+ case evt.KEY_CLEAR:
+ case evt.KEY_HELP:
+ evt.key = evt.keyCode;
+ break;
+ default:
+ if(evt.ctrlKey || evt.altKey){
+ var unifiedCharCode = evt.keyCode;
+ // if lower case but keycode is uppercase, convert it
+ if(unifiedCharCode >= 65 && unifiedCharCode <= 90 && evt.shiftKey == false){
+ unifiedCharCode += 32;
+ }
+ if(unifiedCharCode >= 1 && unifiedCharCode <= 26 && evt.ctrlKey){
+ unifiedCharCode += 96; // 001-032 = ctrl+[a-z]
+ }
+ evt.key = String.fromCharCode(unifiedCharCode);
+ }
+ }
+ } else if(evt["type"] == "keypress"){
+ if(dojo.render.html.opera){
+ if(evt.which == 0){
+ evt.key = evt.keyCode;
+ }else if(evt.which > 0){
+ switch(evt.which){
+ case evt.KEY_SHIFT:
+ case evt.KEY_CTRL:
+ case evt.KEY_ALT:
+ case evt.KEY_CAPS_LOCK:
+ case evt.KEY_NUM_LOCK:
+ case evt.KEY_SCROLL_LOCK:
+ break;
+ case evt.KEY_PAUSE:
+ case evt.KEY_TAB:
+ case evt.KEY_BACKSPACE:
+ case evt.KEY_ENTER:
+ case evt.KEY_ESCAPE:
+ evt.key = evt.which;
+ break;
+ default:
+ var unifiedCharCode = evt.which;
+ if((evt.ctrlKey || evt.altKey || evt.metaKey) && (evt.which >= 65 && evt.which <= 90 && evt.shiftKey == false)){
+ unifiedCharCode += 32;
+ }
+ evt.key = String.fromCharCode(unifiedCharCode);
+ }
+ }
+ }else if(dojo.render.html.ie){ // catch some IE keys that are hard to get in keyDown
+ // key combinations were handled in onKeyDown
+ if(!evt.ctrlKey && !evt.altKey && evt.keyCode >= evt.KEY_SPACE){
+ evt.key = String.fromCharCode(evt.keyCode);
+ }
+ }else if(dojo.render.html.safari){
+ switch(evt.keyCode){
+ case 63232: evt.key = evt.KEY_UP_ARROW; break;
+ case 63233: evt.key = evt.KEY_DOWN_ARROW; break;
+ case 63234: evt.key = evt.KEY_LEFT_ARROW; break;
+ case 63235: evt.key = evt.KEY_RIGHT_ARROW; break;
+ default:
+ evt.key = evt.charCode > 0 ? String.fromCharCode(evt.charCode) : evt.keyCode;
+ }
+ }else{
+ evt.key = evt.charCode > 0 ? String.fromCharCode(evt.charCode) : evt.keyCode;
+ }
}
}
-
if(dojo.render.html.ie){
if(!evt.target){ evt.target = evt.srcElement; }
- if(!evt.currentTarget){ evt.currentTarget = evt.srcElement; }
+ if(!evt.currentTarget){ evt.currentTarget = (sender ? sender : evt.srcElement); }
if(!evt.layerX){ evt.layerX = evt.offsetX; }
if(!evt.layerY){ evt.layerY = evt.offsetY; }
+ // FIXME: scroll position query is duped from dojo.html to avoid dependency on that entire module
+ // DONOT replace the following to use dojo.body(), in IE, document.documentElement should be used
+ // here rather than document.body
+ var doc = (evt.srcElement && evt.srcElement.ownerDocument) ? evt.srcElement.ownerDocument : document;
+ var docBody = ((dojo.render.html.ie55)||(doc["compatMode"] == "BackCompat")) ? doc.body : doc.documentElement;
+ if(!evt.pageX){ evt.pageX = evt.clientX + (docBody.scrollLeft || 0) }
+ if(!evt.pageY){ evt.pageY = evt.clientY + (docBody.scrollTop || 0) }
// mouseover
- if(evt.fromElement){ evt.relatedTarget = evt.fromElement; }
+ if(evt.type == "mouseover"){ evt.relatedTarget = evt.fromElement; }
// mouseout
- if(evt.toElement){ evt.relatedTarget = evt.toElement; }
+ if(evt.type == "mouseout"){ evt.relatedTarget = evt.toElement; }
this.currentEvent = evt;
evt.callListener = this.callListener;
- evt.stopPropagation = this.stopPropagation;
- evt.preventDefault = this.preventDefault;
+ evt.stopPropagation = this._stopPropagation;
+ evt.preventDefault = this._preventDefault;
}
- return evt;
+ return evt; // Event
}
- this.stopEvent = function(ev) {
+ this.stopEvent = function(/*Event*/evt){
+ // summary:
+ // prevents propigation and clobbers the default action of the
+ // passed event
+ // evt: Optional for IE. The native event object.
if(window.event){
- ev.returnValue = false;
- ev.cancelBubble = true;
+ evt.returnValue = false;
+ evt.cancelBubble = true;
}else{
- ev.preventDefault();
- ev.stopPropagation();
+ evt.preventDefault();
+ evt.stopPropagation();
}
}
}