Update of /cvsroot/dynapi/dynapi2x/src/dynapi/util
In directory usw-pr-cvs1:/tmp/cvs-serv15575/src/dynapi/util
Added Files:
cookie.js ioelement.js
Log Message:
Initial Import == 2.9
--- NEW FILE ---
/*
DynAPI Distribution
Cookie functions
The DynAPI Distribution is distributed under the terms of the GNU LGPL license.
*/
/* to-do: make a Cookie object that saves multiple values into one cookie that can be
parsed out later
example:
var c = new Cookie('mycookieset');
c.set('name','MyName');
c.set('array',[1,2,3]);
var c = dynapi.functions.getCookie('mycookieset');
var name = c.get('name');
var array = c.get('array');
array[array.length] = 4;
c.set('name',name+' MyLastName');
c.set('array',array);
*/
function Cookie() {
this.inherit('DynObject');
}
dynapi.setPrototype('Cookie','DynObject');
dynapi.functions.setCookie = function(name,value,days) {
if (days) {
var date=new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires="; expires="+date.toGMTString();
}
else expires = "";
dynapi.frame.document.cookie = name+"="+value+expires+"; path=/";
};
dynapi.functions.getCookie = function(name) {
var nameEQ = name+"=";
var ca = dynapi.frame.document.cookie.split(';');
for(var i=0;i<ca.length;i++) {
var c=ca[i];
while (c.charAt(0)==' ') c=c.substring(1,c.length);
if (c.indexOf(nameEQ)==0) return c.substring(nameEQ.length,c.length);
}
return null;
};
dynapi.functions.deleteCookie = function(name) {
dynapi.functions.setCookie(name,"",-1);
};
--- NEW FILE ---
/*
DynAPI Distribution
IOElement Class
The DynAPI Distribution is distributed under the terms of the GNU LGPL license.
requires: dynapi.api.DynLayer
*/
// DS: this code is now overly complicated for it's purpose, it will be simplified in
a later version
// I was originally using this code for script loading, but delegated all necessary
code to dynapi.library.js
function IOElement(hidden) {
this.inherit('DynLayer');
this.list = {};
this.loadList = [];
this.loadIndex = -1;
this.busy = true;
this.failTime = 15000;
this._hidden = (hidden!=null && hidden!=false);
if (this._hidden) {
this.setVisible(false);
var o = this;
if (!dynapi.loaded) {
dynapi.onLoad(function() {
dynapi.document.addChild(o);
});
}
else dynapi.document.addChild(o);
}
var r = Math.floor(Math.random()*10000000);
this.randID = 'IOElement'+r+'elm';
this.setID('IOElement'+r);
this.addEventListener(IOElement.events);
};
dynapi.setPrototype('IOElement','DynLayer');
IOElement.events = {
onprecreate : function(e) {
var o = e.getSource();
if (o._hidden) {
if (dynapi.ua.ns4) o.html = '<ilayer name="'+o.randID+'"
visibility="hide" width=0 height=0></ilayer>';
else if (dynapi.ua.ie) o.html = '<iframe name="'+o.randID+'"
style="width:0px; height:0px; visibility:hidden"></iframe>'; //style="display:none"
else o.html = '<iframe name="'+o.randID+'" style="width:0px;
height:0px; visibility:hidden"></iframe>';
}
else {
if (dynapi.ua.ns4) o.html = '<layer width='+o.w+'
height='+o.h+' name="'+o.randID+'" visibility="inherit"></ilayer>';
else o.html = '<iframe name="'+o.randID+'" width='+o.w+'
height='+o.h+' scrolling="no" frameborder="no" marginwidth=0 marginheight=0
style="overflow:hidden;"></iframe>';
}
},
oncreate : function(e) {
var o = e.getSource();
o.busy = false;
//if (!o._hidden && dynapi.ua.ie) {
// setTimeout(o+'.getScope().document.body.style.backgroundColor
= "'+o.bgColor+'"',1);
//}
//if (o.loadlist.length>0) o._loadNext();
}
};
IOElement.prototype.getScope = function() {
var scope;
if (dynapi.ua.ns4) scope = this.doc.layers[this.randID];
else scope = parent.frames[this.randID];
return scope;
};
IOElement.prototype.fail = function(id) {
//if (this.fn[id]) this.fn[id](false);
alert('failed')
this.busy = false;
};
IOElement.prototype.load = function(url, fn) {
if (typeof(url)=="string") this.loadList[this.loadList.length] = [url,fn];
else {
for (var i=0;i<url.length;i++) {
var src = url[i];
if (i==url.length-1) this.loadList[this.loadList.length] =
[src,fn];
else this.loadList[this.loadList.length] = [src];
}
}
this._loadNext();
};
IOElement.prototype._loadNext = function() {
if (this.busy) return; // dprint('IOElement Warning: busy');
else {
if (this.loadIndex<this.loadList.length-1) {
this.loadIndex++;
var l = this.loadList[this.loadIndex];
//alert('loadnext '+this.loadIndex+' '+l[0]);
this._load(l[0],l[1]);
}
}
};
IOElement.prototype._load = function(url, fn) {
if (url.indexOf('http')!=0) {
if (url.substr(0,1)=='/') url = 'http://'+document.domain+url;
else url = dynapi.documentPath+url;
}
var id = 'd'+Math.floor(Math.random()*1000000);
this.list[id] = fn;
this.busy = true;
//this.timer = setTimeout(this+'.fail('+id+')',this.failTime);
url += (url.indexOf('?')==-1)? '?' : '&';
url += 'ioLoadID='+id+'&ioElmID='+this.id;
var elm = this.getScope();
if (elm) {
if (dynapi.ua.ns4) elm.src = url;
else elm.document.location.href = url;
}
};
IOElement.prototype._notify = function(id,url) {
if (!this.busy) {
dprint('IOElement Error: '+id+' '+this.randID+' '+url);
return;
}
this.busy = false;
clearTimeout(this.timer);
var fn = this.list[id];
if (fn) {
if (typeof(fn)=="function") {
var e = new DynEvent("load",this);
e.success = true;
fn(e);
}
else if (typeof(fn)=="string") eval(fn);
}
this._loadNext();
};
IOElement.notify = function(elm, fn) {
if (elm) {
var url, id;
if (dynapi.ua.ns4) url = elm.src;
else url = elm.document.location.href;
if (url) {
elm.args = dynapi.functions.getURLArguments(url);
var id = elm.args["ioLoadID"];
var obj = parent.DynObject.all[elm.args["ioElmID"]];
if (obj!=null && id!=null) {
elm.onload = function() {
if (fn) fn();
obj._notify(id,url);
};
return obj;
}
else {
return false;
}
}
}
return null;
};
/* //pages loaded must include this code
<script>
if (parent.DynAPI) parent.IOElement.notify(this);
</script>
*/
_______________________________________________
Dynapi-CVS mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dynapi-cvs