From bc2aa6314a8d82854a799fe1e750c05dcef1b492 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Mon, 23 May 2011 06:31:39 +0000 Subject: Some Javascript cleanup, now working across all browsers including IE9. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1126329 13f79535-47bb-0310-9956-ffa450edef68 --- sca-cpp/trunk/modules/js/htdocs/all-min.js | 78 +++++++++--------------------- sca-cpp/trunk/modules/js/htdocs/ui.js | 10 ---- sca-cpp/trunk/modules/js/htdocs/util.js | 18 +++++-- sca-cpp/trunk/modules/js/htdocs/xmlutil.js | 30 +++++------- 4 files changed, 51 insertions(+), 85 deletions(-) (limited to 'sca-cpp') diff --git a/sca-cpp/trunk/modules/js/htdocs/all-min.js b/sca-cpp/trunk/modules/js/htdocs/all-min.js index bb79a5bb2d..b73c9ad5ea 100644 --- a/sca-cpp/trunk/modules/js/htdocs/all-min.js +++ b/sca-cpp/trunk/modules/js/htdocs/all-min.js @@ -1,21 +1,3 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ function cons(car,cdr){var a=new Array();a.push(car);return a.concat(cdr);} function car(l){return l[0];} function first(l){return car(l);} @@ -62,7 +44,8 @@ try{console.log(s);}catch(e){}}catch(e){} return true;} function debug(o){try{for(f in o){try{log('debug '+f+'='+o[f]);}catch(e){}}}catch(e){} return true;} -var config;if(isNil(config)) +function isIE(){if(typeof isIE.detected!='undefined') +return isIE.detected;isIE.detected=navigator.appName=='Microsoft Internet Explorer';return isIE.detected;};var config;if(isNil(config)) config={} function AssertException(){} AssertException.prototype.toString=function(){return'AssertException';};function assert(exp){if(!exp) @@ -77,8 +60,8 @@ return'';return' '+writeValue(car(l))+writeList(cdr(l));} if(!isList(v)) return writePrimitive(v);if(isNil(v)) return'()';return'('+writeValue(car(v))+writeList(cdr(v))+')';} -function memo(obj,key,f){if(!obj[memo]) -obj.memo={};if(obj.memo[key]) +function memo(obj,key,f){if(!('memo'in obj)){obj.memo={};return obj.memo[key]=f();} +if(key in obj.memo) return obj.memo[key];return obj.memo[key]=f();} function unmemo(obj){obj.memo={};return true;} function properties(o){var a=new Array();for(p in o) @@ -171,9 +154,7 @@ function readElements(l,childf){if(isNil(l)) return l;return cons(readElement(car(l),childf),readElements(cdr(l),childf));} function isXML(l){if(isNil(l)) return false;return car(l).substring(0,5)=='\n'+writeXMLDocument(doc)+'\n');} var atom={};atom.entryElementValues=function(e){var lt=filter(selector(mklist(element,"'title")),e);var t=isNil(lt)?'':elementValue(car(lt));var li=filter(selector(mklist(element,"'id")),e);var i=isNil(li)?'':elementValue(car(li));var lc=filter(selector(mklist(element,"'content")),e);return append(mklist(element,"'entry",mklist(element,"'title",t),mklist(element,"'id",i)),isNil(lc)?mklist():mklist(mklist(element,"'content",elementValue(car(lc)))))};atom.entriesElementValues=function(e){if(isNil(e)) @@ -204,7 +187,7 @@ return e;return cons(atom.entryElementValues(car(e)),atom.entriesElementValues(c return false;return car(l).match(''+html+'';return''+html+'';};ui.menu=function(name,href,target){function Menu(n,h,t){this.name=n;this.href=h;this.target=isNil(t)?'_parent':t;this.content=function(){function complete(uri){var q=uri.indexOf('?');if(q!=-1) return complete(uri.substr(0,q));if(uri.match('.*\.html$')) return uri;if(uri.match('.*/$')) return uri+'index.html';return uri+'/index.html';} if(complete(this.href)!=complete(window.top.location.pathname)) return ui.ahref(this.href,this.target,''+this.name+'');return ui.ahref(this.href,this.target,''+this.name+'');};} -return new Menu(name,href,target);};ui.menubar=function(left,right){var bar=''+ -'';} +items+='
';for(i in left) +return new Menu(name,href,target);};ui.menubar=function(left,right){var bar='
'+''+ -''+'
';for(i in left) bar=bar+'' -bar=bar+'
'+left[i].content()+'
';for(i in right) +bar=bar+'
';for(i in right) bar=bar+'' bar=bar+'
'+right[i].content()+'
';return bar;};ui.selectSuggestion=function(node,value){for(;;){node=node.parentNode;if(node.tagName.toLowerCase()=='div') break;} @@ -283,9 +262,7 @@ input.hideSuggestDiv=function(){if(this.suggestDiv!=null){this.suggestDiv.style. input.showSuggestDiv=function(){if(this.suggestDiv==null){this.suggestDiv=document.createElement('div');this.suggestDiv.input=this;this.suggestDiv.className='suggest';input.parentNode.insertBefore(this.suggestDiv,input);this.suggestDiv.style.visibility='hidden';this.suggestDiv.style.zIndex='99';this.suggestDiv.selectSuggestion=function(value){this.input.selectSuggestion(value);}} var values=this.suggest();var items='';for(var i=0;i'+values[i]+'
';items+='';} if(items.length!=0) items+='
'+values[i]+'
';this.suggestDiv.innerHTML=items;if(items.length!=0){var node=input;var left=0;var top=0;for(;;){left+=node.offsetLeft;top+=node.offsetTop;node=node.offsetParent;if(node.tagName.toLowerCase()=='body') break;} @@ -309,20 +286,14 @@ return'';return'  '+indent(i-1);} function rows(l,i){if(isNil(l)) return'';var e=car(l);if(!isList(e)) return rows(expandElementValues("'value",l),i);if(isList(car(e))) -return rows(expandElementValues("'value",l),i);if(elementHasValue(e)){var v=elementValue(e);if(!isList(v)){return''+indent(i)+elementName(e).slice(1)+''+ -''+(v!=null?v:'')+''+ -rows(cdr(l),i);} +return rows(expandElementValues("'value",l),i);if(elementHasValue(e)){var v=elementValue(e);if(!isList(v)){return''+indent(i)+elementName(e).slice(1)+''+''+(v!=null?v:'')+''+rows(cdr(l),i);} return rows(expandElementValues(elementName(e),v),i)+rows(cdr(l),i);} -return''+indent(i)+elementName(e).slice(1)+''+ -''+''+ -rows(elementChildren(e),i+1)+ -rows(cdr(l),i);} +return''+indent(i)+elementName(e).slice(1)+''+''+''+rows(elementChildren(e),i+1)+rows(cdr(l),i);} return''+rows(l,0)+'
';} ui.datalist=function(l){function rows(l,i){if(isNil(l)) return'';var e=car(l);if(!isList(e)) return rows(expandElementValues("'value",l),i);if(isList(car(e))) -return rows(expandElementValues("'value",l),i);if(elementHasValue(e)){var v=elementValue(e);if(!isList(v)){return''+(v!=null?v:'')+''+ -rows(cdr(l),i);} +return rows(expandElementValues("'value",l),i);if(elementHasValue(e)){var v=elementValue(e);if(!isList(v)){return''+(v!=null?v:'')+''+rows(cdr(l),i);} return rows(expandElementValues(elementName(e),v),i)+rows(cdr(l),i);} return rows(elementChildren(e),i+1)+rows(cdr(l),i);} return''+rows(l,0)+'
';} @@ -336,8 +307,7 @@ return o.toString();if(o.constructor==Date) return'{javaClass: "java.util.Date", time: '+o.valueOf()+'}';if(o.constructor==Array){var v=[];for(var i=0;i tag. */ diff --git a/sca-cpp/trunk/modules/js/htdocs/util.js b/sca-cpp/trunk/modules/js/htdocs/util.js index 69359fa167..b74eedc6ed 100644 --- a/sca-cpp/trunk/modules/js/htdocs/util.js +++ b/sca-cpp/trunk/modules/js/htdocs/util.js @@ -207,6 +207,16 @@ function debug(o) { return true; } +/** + * Return true if the current browser is Internet Explorer. + */ +function isIE() { + if (typeof isIE.detected != 'undefined') + return isIE.detected; + isIE.detected = navigator.appName == 'Microsoft Internet Explorer'; + return isIE.detected; +}; + /** * External build configuration. */ @@ -267,15 +277,17 @@ function writeValue(v) { * Apply a function and memoize its result. */ function memo(obj, key, f) { - if (!obj[memo]) + if (!('memo' in obj)) { obj.memo = {}; - if (obj.memo[key]) + return obj.memo[key] = f(); + } + if (key in obj.memo) return obj.memo[key]; return obj.memo[key] = f(); } /** - * Un-memoize store results. + * Un-memoize stored results. */ function unmemo(obj) { obj.memo = {}; diff --git a/sca-cpp/trunk/modules/js/htdocs/xmlutil.js b/sca-cpp/trunk/modules/js/htdocs/xmlutil.js index 3965596599..4d943cce75 100644 --- a/sca-cpp/trunk/modules/js/htdocs/xmlutil.js +++ b/sca-cpp/trunk/modules/js/htdocs/xmlutil.js @@ -111,19 +111,8 @@ function isXML(l) { */ function parseXML(l) { var s = writeStrings(l); - if (window.DOMParser) { - var p = new DOMParser(); - return p.parseFromString(s, "text/xml"); - } - var doc; - try { - doc = new ActiveXObject("MSXML2.DOMDocument"); - } catch (e) { - doc = new ActiveXObject("Microsoft.XMLDOM"); - } - doc.async = 'false'; - doc.loadXML(s); - return doc; + var p = new DOMParser(); + return p.parseFromString(s, "text/xml"); } /** @@ -196,7 +185,12 @@ function writeList(l, node, doc) { var token = car(l); if (isTaggedList(token, attribute)) { - node.setAttribute(attributeName(token).substring(1), '' + attributeValue(token)); + if (isIE()) { + var aname = attributeName(token).substring(1); + if (aname != 'xmlns') + node.setAttribute(aname, '' + attributeValue(token)); + } else + node.setAttribute(attributeName(token).substring(1), '' + attributeValue(token)); } else if (isTaggedList(token, element)) { @@ -213,7 +207,9 @@ function writeList(l, node, doc) { } var ns = xmlns(elementChildren(tok)); - if (ns == null || !doc.createElementNS) + if (isIE()) + return doc.createElementNS(ns != null? ns : node.namespaceURI, elementName(tok).substring(1)); + if (ns == null) return doc.createElement(elementName(tok).substring(1)); return doc.createElementNS(ns, elementName(tok).substring(1)); } @@ -244,9 +240,7 @@ function writeList(l, node, doc) { * Make a new XML document. */ function mkXMLDocument() { - if (document.implementation && document.implementation.createDocument) - return document.implementation.createDocument('', '', null); - return new ActiveXObject("MSXML2.DOMDocument"); + return document.implementation.createDocument('', '', null); } /** -- cgit v1.2.3