diff options
author | Derrell Lipman <derrell@samba.org> | 2006-12-31 20:12:12 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:35:23 -0500 |
commit | d1e09e2e6f9db62bbab84abb53e23ee73764178a (patch) | |
tree | 18e57f756611c9d3e10fb41bf7c09eeb795028dd /swat/style/qooxdoo/widgets/core/QxBuilder.js | |
parent | 710dfce70ca9024d2f026518638bb193e914f4a0 (diff) | |
download | samba-d1e09e2e6f9db62bbab84abb53e23ee73764178a.tar.gz samba-d1e09e2e6f9db62bbab84abb53e23ee73764178a.tar.bz2 samba-d1e09e2e6f9db62bbab84abb53e23ee73764178a.zip |
r20446: rename swat directory to swat.obsolete; keeping it around since there is lots of useful info in it.
(This used to be commit 5f9f72a9cfab80561b23284001b67c4ea961757b)
Diffstat (limited to 'swat/style/qooxdoo/widgets/core/QxBuilder.js')
-rw-r--r-- | swat/style/qooxdoo/widgets/core/QxBuilder.js | 3 |
1 files changed, 0 insertions, 3 deletions
diff --git a/swat/style/qooxdoo/widgets/core/QxBuilder.js b/swat/style/qooxdoo/widgets/core/QxBuilder.js deleted file mode 100644 index c9b3277493..0000000000 --- a/swat/style/qooxdoo/widgets/core/QxBuilder.js +++ /dev/null @@ -1,3 +0,0 @@ -/* Copyright (c): 2002-2005 (Germany): United Internet, 1&1, GMX, Schlund+Partner, Alturo */ -function QxBuilder(flags){QxTarget.call(this);this._propertyEditors={};this._registerDefaultPropertyEditors();this._radioButtonManagers={};this._debugContext=[];this._flags=flags||{};if(this._flags.strict==null){this._flags.strict=true;};};QxBuilder.extend(QxTarget,"QxBuilder");proto.buildFromUrl=function(parent,url){var loader=new QxXmlHttpLoader();var self=this;loader.addEventListener("complete",function(e){self.build(parent,e.getValue());e.preventDefault();self.dispatchEvent(new QxEvent("done"),true);});loader.load(url);};proto.build=function(parent,node){if(parent instanceof QxApplication){parent=parent.getClientWindow().getDocument();};if(typeof node=="object"&&node.nodeName=='TEXTAREA'){node=node.value;};if(typeof node=="string"){if(new QxClient().isMshtml()){var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");xmlDoc.async=false;xmlDoc.loadXML(node);node=xmlDoc.documentElement;if(xmlDoc.parseError.errorCode!=0){throw new Error("error parsing xml "+xmlDoc.parseError+"\nLine:"+xmlDoc.parseError.line+':'+xmlDoc.parseError.srcText);};}else{var parser=new DOMParser();node=parser.parseFromString(node,"text/xml").documentElement;};};this._buildNodes(parent,node.childNodes);};proto._buildNodes=function(parent,nodes){var x=0;for(var i=0;i<nodes.length;i++){var n=nodes[i];if(n.nodeType==1){this._debugContext.push(n.nodeName+'['+(x++)+']');this._buildWidgetFromNode(parent,n);this._debugContext.pop();};};};proto._buildEventListener=function(widget,args,text){if(isInvalidString(args.type)){throw this._newBuildError('eventListener requires a string type attribute');};var self=this;if(isValidString(args.delegate)){var dc=this._formatDebugContext();if(args.delegate.indexOf('.')>-1){var p=args.delegate.split('.');var o=p[0];var m=p[1];widget.addEventListener(args.type,function(e){if(!window[o]){throw self._newError(dc,'delegate not found',{delegate:args.delegate});};if(!window[o][m]){throw self._newError(dc,'delegate not found',{delegate:args.delegate});};window[o][m].apply(window[o],[e]);});}else{widget.addEventListener(args.type,function(e){if(!window[args.delegate]){throw self._newError(dc,'delegate not found',{delegate:args.delegate});};window[args.delegate].apply(null,[e]);});};}else{if(!args.args){args.args="event";};var f=new Function(args.args,text);widget.addEventListener(args.type,f);};};proto._buildWidgetFromNode=function(parent,node){var className=this._extractClassName(node);if(!className){if(parent instanceof QxAtom){var text=this._serializeToString(node);parent.setText((parent.getText()||"")+text);return;};throw this._newBuildError("unrecognised node",{nodeName:node.nodeName});};if(className=="QxWidgets"){this._buildNodes(parent,node.childNodes);return;};if(className=="QxScript"){var e=document.createElement("script");var attribs=this._mapXmlAttribToObject(node);if(attribs.type){e.type=attribs.type;}else{e.type='text/javascript';};if((new QxClient).isMshtml()){e.innerHTML=eval(node.firstChild.nodeValue);}else {e.innerHTML=node.firstChild.nodeValue;};document.body.appendChild(e);return;};if(className=="QxEventListener"){var attribs=this._mapXmlAttribToObject(node);var text;if(node.firstChild){text=node.firstChild.nodeValue;};this._buildEventListener(parent,attribs,text);return;};var constructor=window[className];if(!constructor){throw this._newBuildError("constructor not found",{className:className});};var widget=new constructor();var attribs=this._mapXmlAttribToObject(node,widget);delete attribs['qxtype'];if(attribs.id){window[attribs.id]=widget;delete attribs.id;};for(var a in attribs){if(a.toLowerCase().indexOf('on')==0&&a.length>2){var type=a.substring(2);type=type.charAt(0)+type.substring(1);this._buildEventListener(widget,{type:type,args:'event'},attribs[a]);delete attribs[a];};};var layoutHint;if(typeof QxLayout!="undefined"&&parent instanceof QxLayout){if(attribs.layouthint){try{eval('layoutHint={'+attribs.layouthint+'}');}catch(e){throw this._newBuildError('invalid property value',{name:'layoutHint',value:attrib.layoutHint},e);};delete attribs.layouthint;};};for(var n in attribs){this._debugContext.push("@"+n);this._setWidgetProperty(widget,n,attribs[n]);this._debugContext.pop();};if(typeof QxMenu!="undefined"&&widget instanceof QxMenu){window.application.getClientWindow().getDocument().add(widget);parent.setMenu(widget);}else if(layoutHint&&typeof QxLayout!="undefined"&&parent instanceof QxLayout){parent.add(widget,layoutHint);}else{parent.add(widget);};this._buildNodes(widget,node.childNodes);};proto._setWidgetProperty=function(widget,name,value){var editor=this._findPropertyEditor(widget.classname,name);if(!editor){editor=this._coercePropertyEditor;};editor.set(widget,name,value);};proto._findPropertyEditor=function(className,propertyName){var m=this._propertyEditors[className];if(m&&m[propertyName]){return m[propertyName];};var w=window[className];if(w&&w.prototype.superclass&&w.prototype.superclass.prototype.classname){return this._findPropertyEditor(w.prototype.superclass.prototype.classname,propertyName);};return null;};proto.registerPropertyEditor=function(className,propertyName,editor){if(!this._propertyEditors[className])this._propertyEditors[className]={};this._propertyEditors[className][propertyName]=editor;};proto._registerDefaultPropertyEditors=function(){var self=this;var commaDelimitedPropertyEditor={};commaDelimitedPropertyEditor.set=function(widget,name,value){if(value==null||value==""){self._setProperty(widget,name,null);return;};var s=value.split(",");var v=[];for(var i=0;i<s.length;i++){v[i]=self._coerce(s[i]);};self._setProperties(widget,name,v);};var evalPropertyEditor={};evalPropertyEditor.set=function(widget,name,value){if(value==null||value==""){self._setProperty(widget,name,null);return;};self._setProperty(widget,name,eval(value));};var radioButtonManagerEditor={};radioButtonManagerEditor.set=function(widget,name,value){var manager=self._radioButtonManagers[value];if(!manager){manager=new QxRadioButtonManager(value);self._radioButtonManagers[value]=manager;};manager.add(widget);};this.registerPropertyEditor('QxWidget','location',commaDelimitedPropertyEditor);this.registerPropertyEditor('QxWidget','dimension',commaDelimitedPropertyEditor);this.registerPropertyEditor('QxWidget','styleproperty',commaDelimitedPropertyEditor);this.registerPropertyEditor('QxWidget','border',evalPropertyEditor);this.registerPropertyEditor('QxMenuRadioButton','group',radioButtonManagerEditor);this.registerPropertyEditor('QxRadioButton','group',radioButtonManagerEditor);this._coercePropertyEditor={};this._coercePropertyEditor.set=function(widget,name,value){self._setProperty(widget,name,self._coerce(value));};};proto._coerce=function(value){if(value==null)return value;if(typeof value=='object')return value;if(typeof value=='function')return value;if(typeof value=='number')return value;if(typeof value=='boolean')return value;if(typeof value=='date')return value;if(typeof value=='array')return value;var n=new Number(value);if(!isNaN(n))return n.valueOf();if(value=="true")return true;if(value=="false")return false;var d=Date.parse(value);if(d!=null&&!isNaN(d))return d;if(typeof value=='string'){if(value=="")return null;};return value;};proto._setProperty=function(widget,name,value){this._setProperties(widget,name,[value]);};proto._setProperties=function(widget,name,value){var n="set"+name;for(var a in widget){if(n==a.toLowerCase()){var setter=widget[a];break;};};if(!setter&&this._flags.strict)throw this._newBuildError('no setter defined on widget instance',{widget:widget,property:name});setter.apply(widget,value);};proto._extractClassName=function(node){var n;if(node.nodeName.toUpperCase()=="DIV"){if(!node.attributes['qxtype']){return null -};n=node.attributes['qxtype'].value;}else{n=node.nodeName;};var nameParts=n.split(":");if(nameParts.length!=2){return null;};return nameParts[0].toFirstUp()+nameParts[1].toFirstUp();};proto._serializeToString=function(node){var xmlSerializer=new XMLSerializer();return xmlSerializer.serializeToString(node);};proto._mapXmlAttribToObject=function(node){var r={};var c=node.attributes;for(var i=0;i<c.length;i++){r[c[i].name.toLowerCase()]=c[i].value;};return r;};proto._newBuildError=function(message,data,exception){return this._newError(this._formatDebugContext(),message,data,exception);};proto._newError=function(debugContext,message,data,exception){var m=message;var joiner="";var d="";if(data){for(var p in data){d+=joiner+p+"="+data[p]+'';joiner=" ";};m+=" "+d+" ";};m+=" context:"+debugContext+" ";if(exception){m+=" error:"+exception+" ";};return new Error(m);};proto._formatDebugContext=function(){var s="";for(var i=0;i<this._debugContext.length;i++){var v=this._debugContext[i];s+='/'+v;};return s;};
\ No newline at end of file |