From: Robert R. <rai...@us...> - 2002-01-11 20:51:58
|
Update of /cvsroot/dynapi/dynapi2x/src In directory usw-pr-cvs1:/tmp/cvs-serv15575/src Added Files: dynapi-2.5mode.js dynapi.js Log Message: Initial Import == 2.9 --- NEW FILE --- /* DynAPI 2.5x Compatibility Mode ------------------------------------- These commands make v2.9 largely backward compatible with 2.5. However, some changes make it impossible to be fully compatible. All syntax that has been changed can be considered deprecated. This compatibility mode is merely a starting point and it is recommended that you read "docs/changelog.html" for a complete description of the new features and to move your code over to 2.9 syntax. A short list of non-compatibility: - DynAPI.onload = function(){} can no longer be used, replace with dynapi.onLoad(function() {}); - EventListener is no longer available, it is now an empty object, and thus the e.getTarget() is now removed. Instead of retreiving an object from DynEvent using e.getTarget(), you must change to e.getSource(), and retrieve the widget object in another fashion. Include this file *AFTER* event.js,dyndocument.js,dynlayer.js,mouseevent.js */ // these have not been tested, nor is a complete list // syntax changes DynAPI = dynapi; Methods = dynapi.functions; EventListener = dynapi.functions.Null; DynMouseEvent = MouseEvent; dynapi.librarypath = dynapi.libraryPath = dynapi.library.path; // v2.5x package/include system; DynAPIObject.prototype.getLibraryPath = function() {return dynapi.library.path}; DynAPIObject.prototype.setLibraryPath = function(path) { dynapi.library.setPath(path); }; DynAPIObject.prototype.addPackage = function(pckg) { if (!this.packages) this.packages = []; if (this.packages[pckg]) return; this.packages[pckg] = { libs: [] }; }; DynAPIObject.prototype.addLibrary = function(path,files) { var pckg = path.substring(0,path.indexOf('.')); if (!pckg) { alert("DynAPI Error: Incorrect DynAPI.addLibrary usage"); return; } var name = path.substring(path.indexOf('.')+1); if (!this.packages[pckg]) this.addPackage(pckg); if (this.packages[pckg].libs[name]) { alert("DynAPI Error: Library "+name+" already exists"); return; } this.packages[pckg].libs[name] = files; }; DynAPIObject.prototype.include = function(src,pth) { src=src.split('.'); if (src[src.length-1] == 'js') src.length -= 1; var path=pth||this.libraryPath||''; if (path.substr(path.length-1) != "/") path += "/"; var pckg=src[0]; var grp=src[1]; var file=src[2]; if (file=='*') { if (this.packages[pckg]) group=this.packages[pckg].libs[grp]; if (group) for (var i=0;i<group.length;i++) document.write('<script language="Javascript1.2" src="'+path+pckg+'/'+grp+'/'+group[i]+'.js"><\/script>'); else alert('include()\n\nThe following package could not be loaded:\n'+src+'\n\nmake sure you specified the correct path.'); } else document.write('<script language="Javascript1.2" src="'+path+src.join('/')+'.js"><\/script>'); }; DynAPIObject.prototype.addLoadFunction = function(f) { this.onLoad(f); }; DynAPIObject.prototype.addUnLoadFunction = function(f) { this.onUnload(f); }; DynAPIObject.prototype.addResizeFunction = function(f) { l = {onresize : f}; dynapi.document.addEventListener(l); }; DynAPI.addPackage('dynapi'); DynAPI.addLibrary('dynapi.api' ,["browser","dynlayer","dyndocument"]); DynAPI.addLibrary('dynapi.event',["listeners","mouse","dragevent","keyboard"]); DynAPI.addLibrary('dynapi.ext' ,["inline","layer","dragdrop","functions"]); DynAPI.addLibrary('dynapi.gui' ,["viewport","dynimage","button","buttonimage","label","list","loadpanel","pushpanel","scrollbar","scrollpane","sprite"]); DynAPI.addLibrary('dynapi.util' ,["circleanim","cookies","debug","thread","hoveranim","imganim","pathanim","console"]); // DynLayer DynLayer.prototype.moveTo = DynLayer.prototype.setLocation; DynLayer.prototype.moveBy = function(x,y) { this.setLocation(this.x+x,this.y+y); } DynLayer.prototype.isDynLayer = true; DynDocument.prototype.isDynDocument = true; // resize events if (dynapi.ua.ns4) { DynLayer.prototype.setSize = function(w,h,noevt) { var cw = (w!=null && w!=this.w); var ch = (h!=null && h!=this.h); if (cw) this.w = w<0? 0 : w; if (ch) this.h = h<0? 0 : h; if (cw||ch) { if (this._childAnchors) this._updateAnchors(); if (this._layout) this._layout._fixLayout(); if (this.css) { if (cw) this.css.clip.width = this.w; if (ch) this.css.clip.height = this.h; } if (noevt!=false) this.invokeEvent('resize'); } return (cw||ch); }; } else { DynLayer.prototype.setSize = function(w,h,noevt) { var cw = (w!=null && w!=this.w); var ch = (h!=null && h!=this.h); if (cw) this.w = w<0? 0 : w; if (ch) this.h = h<0? 0 : h; if (cw||ch) { if (this._childAnchors) this._updateAnchors(); if (this._layout) this._layout._fixLayout(); if (this.css) { if (cw) this.css.width = this.w||0; if (ch) this.css.height = this.h||0; if (cw || ch) this.css.clip = 'rect(0px '+(this.w||0)+'px '+(this.h||0)+'px 0px)'; } if (noevt!=false) this.invokeEvent('resize'); } return (cw||ch); }; } DynLayer.prototype.setWidth=function(w,noevt) {this.setSize(w,null,noevt)}; DynLayer.prototype.setHeight=function(h,noevt) {this.setSize(null,h,noevt)}; DynElement._flagEvent = function(obj,type) { if (type=="create") { obj._created = true; obj.created = true; // added } var l=obj.children.length; for (var i=0; i<l; i++) { DynElement._flagEvent(obj.children[i],type); } obj.invokeEvent(type); // called after children }; --- NEW FILE --- /* DynAPI Distribution DynObject, DynAPI Object, UserAgent, Library, Functions The DynAPI Distribution is distributed under the terms of the GNU LGPL license. */ function DynObject() { this.setID("DynObject"+DynObject._c++); }; var p = DynObject.prototype; p.inherit = function(n) { var b = 0; if (n) { var a = arguments; var p = dynapi.frame[n]; if (!p && dynapi.ua.ns4 && dynapi.library) p = dynapi.library.elm[n]; if (p) { this[n] = p; this[n](a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9]); b = 1; } } if (!b) alert('Inherit Error: '+n); }; p.getClassName = function() {return this._className}; p.getClass = function() {return dynapi.frame[this._className]}; p.isClass = function(n) {return DynObject.isClass(this._className,n)}; p.addMethod = function(n,fn) {this[n] = fn}; p.removeMethod = function(n) {this[n] = null}; p.setID = function(id) { if (this.id) delete DynObject.all[this.id]; this.id = id; DynObject.all[this.id] = this; }; p.toString = function() {return "DynObject.all."+this.id}; DynObject.all = []; DynObject._c = -1; DynObject.isClass = function(cn,n) { if (cn == n) return true; else { var c = dynapi.frame[cn]; var p = c.prototype._pClassName; if (p) return DynObject.isClass(p,n) else return false; } }; function _UserAgent() { var b = navigator.appName; var v = this.version = navigator.appVersion; this.v = parseInt(v); this.ns = (b=="Netscape"); this.ie = (b=="Microsoft Internet Explorer"); this.opera = navigator.userAgent.indexOf("Opera")>0; this.supported = true; if (this.ns) { this.v = parseInt(v); this.ns4 = (this.v==4); this.ns6 = (this.v>=5); } else if (this.ie) { this.ie4 = this.ie5 = this.ie55 = this.ie6 = false; if (v.indexOf('MSIE 4')>0) {this.ie4 = true; this.v = 4;} else if (v.indexOf('MSIE 5')>0) {this.ie5 = true; this.v = 5;} else if (v.indexOf('MSIE 5.5')>0) {this.ie55 = true; this.v = 5.5;} else if (v.indexOf('MSIE 6')>0) {this.ie6 = true; this.v = 6;} } else if (this.opera) { this.v = parseInt(v); } else { this.supported = false; return; } this.dom = (document.createElement && document.appendChild && document.getElementsByTagName)? true : false; this.def = (this.ie||this.dom); var ua = navigator.userAgent.toLowerCase(); this.win32 = ua.indexOf("win")>-1; this.mac = ua.indexOf("mac")>-1; this.other = (!this.win32 && !this.mac); } function DynAPIObject() { this.DynObject = DynObject; this.DynObject(); this.version = 2.9; this.loaded = false; this.ua = new _UserAgent(); this._loadfn = []; this._unloadfn = []; var f = this.frame = self; var url = f.document.location.href; url = url.substring(0,url.lastIndexOf('/')+1); this.documentPath = url; var o = this; this.library = {}; this.library.setPath = function(p) {o.library.path = p}; f.onload = function() { o.loaded = true; if (o.library._create) o.library._create(); // calls dynapi._onLoad() after loading necessary files else setTimeout(o+'._onLoad()',1); }; f.onunload = function() { for (var i=0;i<o._unloadfn.length;i++) { var f = o._unloadfn[i]; if (typeof(f)=="string") eval(f); if (typeof(f)=="function") f(); } if (o.document) { o.document._destroy(); o.document = null; } }; }; p = DynAPIObject.prototype = new DynObject; p.onLoad = function(f) { if (f!=null) this._loadfn[this._loadfn.length] = f; }; p._onLoad = function(f) { for (var i=0;i<this._loadfn.length;i++) { var f = this._loadfn[i]; if (typeof(f)=="string") eval(f); if (typeof(f)=="function") f(); } } p.onUnload = function(f) { if (f!=null) this._unloadfn[this._unloadfn.length] = f; }; p.setPrototype = function(sC,sP) { var c = this.frame[sC]; var p = this.frame[sP]; if ((!c || !p) && this.ua.ns4 && this.library && this.library.elm) { if (!c) c = this.library.elm[sC]; if (!p) p = this.library.elm[sP]; } if (!c || !p) return alert('Prototype Error'); c.prototype = new p(); c.prototype._className = sC; c.prototype._pClassName = sP; c.toString = function() {return '['+sC+']'}; return c.prototype; }; var dynapi = new DynAPIObject(); dynapi.functions = { removeFromArray : function(array, index, id) { // need it? var which=(typeof(index)=="object")?index:array[index]; if (id) delete array[which.id]; else for (var i=0; i<array.length; i++) if (array[i] == which) { if(array.splice) array.splice(i,1); else { for(var x=i; x<array.length-1; x++) array[x]=array[x+1]; array.length -= 1; } break; } return array; }, getContainerLayerOf : function(element) { // need it? if(!element) return null; if(dynapi.ua.def&&!dynapi.ua.ie) while (!element.lyrobj && element.parentNode && element.parentNode!=element) element=element.parentNode; else if(dynapi.ua.ie) while (!element.lyrobj && element.parentElement && element.parentElement!=element) element=element.parentElement; return element.lyrobj }, True : function() {return true}, False : function() {return false}, Null : function() {}, getImage : function(src,w,h) { var img = (w!=null&&h!=null)? new Image(w,h) : new Image(); img.src = src; return img; }, getURLArguments : function(o) { // pass a string or frame/layer object var url; if (typeof(o)=="string") url = o; else if (dynapi.ua.ns4 && o.src) url = o.src; else if (o.document) url = o.document.location.href; else return {}; var list = {}; var s = url.substring(url.indexOf('?')+1); var a = s.split('&'); var b; for (var i=0;i<a.length;i++) { var b = a[i].split('='); list[b[0]] = b[1]; } return list; } }; dynapi.documentArgs = dynapi.functions.getURLArguments(dynapi.frame); dynapi.debug = {}; dynapi.debug.print = function(s) { if (!dynapi._debugBuffer) dynapi._debugBuffer = s; else dynapi._debugBuffer += '\n'+s; }; // The DynAPI library system is optional, this can be removed if you want to include other scripts manually function DynAPILibrary() { this.inherit('DynObject'); // list of js files: this.scripts['../src/lib/dynapi/api/dynlayer.js'] = {dep, objects, pkg, fn}; this.scripts = {}; // list of package names: this.packages['dynapi.api'] = dynapi.api = {_objects,_path} this.packages = {}; // list of object names: this.objects['DynLayer'] = this.scripts['../src/lib/dynapi/api/dynlayer.js'] this.objects = {}; this._c = 0; this.loadList = []; this.loadIndex = -1; this.path = null; this.busy = true; } p = dynapi.setPrototype('DynAPILibrary','DynObject'); // can return a path specific to a package, eg. dynapi.library.getPath('dynapi.api') returns '/src/lib/dynapi/api/' p.getPath = function(pkg) { if (!pkg) pkg = 'dynapi'; if (this.packages[pkg]) return this.packages[pkg]._path; return null; }; // set dynapi path p.setPath = function(p) { this.path = p; // to-do: rearrange so add()'s can be done before setPath // full paths will then be determined when queued // need an extra argument on addPackage to specify whether the path is relative to this.path or not // OR: add functionality so that these package definitions can be loaded/included on the fly this.addPackage('dynapi',p); this.add('dynapi.debug','debug.js'); this.add('dynapi.library','library.js'); this.add('dynapi.functions','functions.js'); this.addPackage('dynapi.api',p+'api/'); this.add(['dynapi.api.DynEvent','dynapi.api.EventObject','dynapi.api.DynElement'],'event.js'); this.add('dynapi.api.DynDocument','dyndocument.js','DynEvent'); this.add('dynapi.api.DynLayer','dynlayer.js','DynDocument'); this.add('dynapi.api.MouseEvent','mouse.js','DynLayer'); this.addPackage('dynapi.api.ext',p+'api/ext/'); this.add('dynapi.api.ext.DragEvent','dragevent.js','DynDocument'); this.add('dynapi.api.ext.DynKeyEvent','dynkeyevent.js','DynLayer'); this.addPackage('dynapi.fx',p+'fx/'); this.add('dynapi.fx.Thread','thread.js','DynLayer'); this.add('dynapi.fx.PathAnimation','pathanim.js','Thread'); this.add('dynapi.fx.GlideAnimation','pathanim_glide.js','PathAnimation'); this.add('dynapi.fx.SlideAnimation','pathanim_slide.js','PathAnimation'); this.add('dynapi.fx.ImageAnimation','imganim.js','Thread'); this.addPackage('dynapi.gui',p+'gui/'); this.add('dynapi.gui.DynImage','dynimage.js','DynLayer'); this.add('dynapi.gui.Graphics','graphics.js','DynLayer'); this.add('dynapi.gui.LoadPanel','loadpanel.js','DynLayer'); this.addPackage('dynapi.util',p+'util/'); this.add('dynapi.util.Cookie','cookie.js'); this.add('dynapi.util.IOElement','ioelement.js','DynLayer'); }; // adds package(s) to the library p.addPackage = function(pkg, path) { var ps; if (pkg.indexOf('.')) ps = pkg.split('.'); else ps = [pkg]; var p = dynapi.frame; for (var i=0;i<ps.length;i++) { // returns the package object (eg. dynapi.api), or creates it if non-existant if (!p[ps[i]]) p[ps[i]] = {}; p = p[ps[i]]; } this.packages[pkg] = p; p._objects = []; p._path = path; return p; }; // add object(s) to the library p.add = function(name, src, dep, relSource) { var objects = typeof(name)=="string"? [name] : name; var dep = !dep? [] : typeof(dep)=="string"? [dep] : dep; var s,p,pkg; if (objects[0].indexOf('.')) { pkg = objects[0].substring(0,objects[0].lastIndexOf('.')); if (pkg && this.packages[pkg]) { p = this.packages[pkg]; if (relSource!=false) src = p._path + src; } } if (!this.scripts[src]) s = this.scripts[src] = {}; else s = this.scripts[src]; s.objects = []; s.dep = dep; s.src = src; s.pkg = pkg; s.loaded = false; s.fn = null; var n; for (var i=0;i<objects.length;i++) { n = objects[i]; if (pkg) n = n.substring(n.lastIndexOf('.')+1); this.objects[n] = s; s.objects[s.objects.length] = n; if (p) p._objects[p._objects.length] = n; } return s; }; // returns a list of js source filenames to load p._queue = function(n, list, force) { var na=[], names=[],o; if (list==null) list = []; if (typeof(n)=="string") na = [n]; else na = n; for (var i=0;i<na.length;i++) { o = na[i]; if (typeof(o)=="string") { if (this.packages[o]) for (var j in this.packages[o]._objects) names[names.length] = this.packages[o]._objects[j]; else names[names.length] = o; } else if (typeof(o)=="object" && o.length) { list = this._queue(o, list, force); } } var s; for (var j=0;j<names.length;j++) { s = this._queueObject(names[j], force); if (s) { if (s.dep) for (var i=0;i<s.dep.length;i++) list = this._queue(s.dep[i], list, force); list[list.length] = s.src; } } return list; }; // determines whether to add the script this object is in to the queue p._queueObject = function(n, f) { if (n.indexOf('.')) { var pkg = n.substring(0,n.lastIndexOf('.')); if (this.packages[pkg]) n = n.substring(n.lastIndexOf('.')+1); } var s = this.objects[n]; if (s) { if (!s.queued) { if (f!=true && s.loaded) dynapi.debug.print('Library Warning: '+n+' is already loaded'); else { s.queued = true; s.loaded = false; return s; } } } else dynapi.debug.print('Library Error: no library map for '+n); return false; }; // writes the <script> tag for the object p.include = function(n) { var a = arguments; if (dynapi.loaded) this.load(a); else { var list = this._queue(a); var src; for (var i=0;i<list.length;i++) { src = list[i]; this.scripts[src].loaded = true; dynapi.frame.document.write('<script language="JavaScript" src="'+src+'"><\/script>'); } } }; p.load = p.reload = p.loadScript = function(n) { dynapi.debug.print('Warning: dynapi.library load extensions not included'); }; dynapi.library = new DynAPILibrary(); // deprecated var DynAPI = dynapi; |