some more cleanup

This commit is contained in:
Robin 2010-04-08 23:59:19 +02:00
parent 7657926a60
commit e830718757
5 changed files with 129 additions and 106 deletions

View file

@ -19,10 +19,5 @@
*
*/
var dir=''
var loc=document.location.toString();
if(loc.indexOf('#')!=-1){
dir=loc.substring(loc.indexOf('#')+1);
}
OC_onload.add(new function(){OC_FILES.browser.show(dir)});
OC_onload.add(OC_FILES.browser.showInitial);

View file

@ -21,8 +21,20 @@
OC_FILES.browser=new Object();
OC_FILES.browser.showInitial=function(){
var dir=''
var loc=document.location.toString();
if(loc.indexOf('#')!=-1){
dir=loc.substring(loc.indexOf('#')+1);
}
OC_FILES.dir=dir;
OC_FILES.getdirectorycontent(dir,OC_FILES.browser.show_callback);
}
OC_FILES.browser.show=function(dir){
dir=(dir)?dir:'';
if(!dir){
dir='';
}
OC_FILES.dir=dir;
OC_FILES.getdirectorycontent(dir,OC_FILES.browser.show_callback);
}
@ -71,14 +83,14 @@ OC_FILES.browser.show_callback=function(content){
a.addEvent('onclick',OC_FILES.browser.show);
a.appendChild(document.createTextNode('Home'));
var currentdir='';
for(index in dirs) {
for(var index=0;index<dirs.length;index++){
d=dirs[index];
currentdir=currentdir+'/'+d;
if(d!=''){
a=document.createElement('a');
td.appendChild(a);
a.setAttribute('href','#'+currentdir);
a.setAttribute('onclick','OC_FILES.browser.show("'+currentdir+'")');
a.addEvent('onclick',OC_FILES.browser.show,currentdir);
img=document.createElement('img');
a.appendChild(img);
img.src=WEBROOT+'/img/arrow.png';
@ -151,26 +163,28 @@ OC_FILES.browser.show_callback=function(content){
td.setAttribute('id',file['name']);
a=document.createElement('a');
td.appendChild(a);
a.appendChild(document.createTextNode(file['name']))
a.appendChild(document.createTextNode(file['name']));
var fileObject=OC_FILES.files[file['name']];
a.addEvent('onclick',new callBack(fileObject.actions['default'],fileObject));
if(file['type']=='dir'){
a.addEvent('onclick',OC_FILES.browser.show,[dir+'/'+file['name']]);
td.setAttribute('colspan',2);
a.setAttribute('href','#'+dir+'/'+file['name']);
}else{
a.setAttribute('href',WEBROOT+'/?dir=/'+dir+'&file='+file['name']);
a.setAttribute('href','#');
sizeTd=document.createElement('td');
tr.appendChild(sizeTd);
sizeTd.className='sizetext';
sizeTd.appendChild(document.createTextNode(sizeFormat(file['size'])));
}
a=document.createElement('a');
img=document.createElement('img');
var img=document.createElement('img');
td.appendChild(img);
img.className='file_actions';
img.alt=''
img.title='actions';
img.src=WEBROOT+'/img/arrow_down.png';
img.setAttribute('onclick','OC_FILES.browser.showactions(\''+file['name']+'\')')
var name=file['name'];
img.addEvent('onclick',OC_FILES.browser.showactions,name);
td=document.createElement('td');
tr.appendChild(td);
td.className='sizetext';
@ -284,9 +298,10 @@ OC_FILES.browser.showactions=function(file,hide){
div.appendChild(table);
tbody=document.createElement('tbody');
table.appendChild(tbody);
actions=OC_FILES.files[file].actions;
var file=OC_FILES.files[file]
var actions=file.actions;
for(name in actions){
if(actions[name].call){
if(actions[name].call && name!='default'){
tr=document.createElement('tr');
tbody.appendChild(tr);
td=document.createElement('td');
@ -294,7 +309,8 @@ OC_FILES.browser.showactions=function(file,hide){
a=document.createElement('a');
td.appendChild(a);
a.appendChild(document.createTextNode(name));
td.addEvent('onclick',new callBack(OC_FILES.files[file].actions[name],OC_FILES.files[file]));
var action=actions[name];
td.addEvent('onclick',new callBack(action,file));
}
}
node.appendChild(div);

View file

@ -42,25 +42,74 @@ callBack.prototype=function(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10){
callBack.prototype.func=false;
callBack.prototype.obj=false;
callBack.prototype.call=function(dummy,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10){
//the dummy is just to provide compatibility with the normal call function and isn't used
return this.func.call(this.obj,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10);
}
callBack.prototype.apply=function(dummy,arguments){
//the dummy is just to provide compatibility with the normal call function and isn't used
return this.apply(this.obj,arguments);
return this.func.apply(this.obj,arguments);
}
//provide a simple way to add things to the onload
OC_onload=new Object();
OC_onload.items=new Array();
OC_onload.add=function(callback){
OC_onload.items[OC_onload.items.length]=callback;
OC_onload.itemsPriority=new Array();
OC_onload.add=function(callback,priority){
if(priority){
OC_onload.itemsPriority[OC_onload.items.length]=callback;
}else{
OC_onload.items[OC_onload.items.length]=callback;
}
}
OC_onload.run=function(){
for(index in OC_onload.items){
if(OC_onload.items[index].call){
OC_onload.items[index].call();
}
}
for(index in OC_onload.itemsPriority){
if(OC_onload.itemsPriority[index].call){
OC_onload.itemsPriority[index].call();
}
}
for(index in OC_onload.items){
if(OC_onload.items[index].call){
OC_onload.items[index].call();
}
}
}
//implement Node.prototype under IE
if(typeof Node=='undefined'){
Node=new Object();
Node.prototype=new Object();
tmpObj=new Object();
tmpObj.prototype=document.createElement;
document.createElementNative=document.createElement;
tmpObj=null;
document.createElement=function(tagName){
// alert(tagName);
node=document.createElementNative(tagName);
for(name in Node.prototype){
node[name]=Node.prototype[name];
}
return node;
}
addNodePrototype=function(node){
if(!node){
node=document.getElementsByTagName('body');
node=node.item(0)
}
if(node.nodeType==1){
for(name in Node.prototype){
// node[name]=Node.prototype[name];
eval('node.'+name+'=Node.prototype.'+name+';');
}
if(node.hasChildNodes){
var childs=node.childNodes;
for(var i=0;i<childs.length;i++){
addNodePrototype(childs[i]);
}
}
}
}
OC_onload.add(new function(){addNodePrototype(document.documentElement);});
OC_onload.add(addNodePrototype,true);
}

View file

@ -12,90 +12,38 @@ usage: document.events.add(node,type,function,arguments);
or: node.addEvent(type,function,arguments);
*/
eventHandler=function(){
this.holders=Array();
}
document.events=new Object;
document.events.functions=Array();
document.events.args=Array();
eventHandler.prototype={
add:function(element,type,func,arguments){
var holder=this.getHolderByElement(element);
holder.addListner(type,func,arguments);
},
getHolderByElement:function(element){
var holder=false;
for (var i=0;i<this.holders.length;i++){
if (this.holders[i].getElement()==element){
var holder=this.holders[i];
document.events.add=function(element,type,func,args){
if(args){
if(typeof args!='object' && typeof args!='Object'){
args=[args];
}
}
if(!args){
args=Array();
}
if (type && element){
//wrap the function in a function, otherwise it won't work if func is actually a callBack
var funcId=document.events.functions.length;
document.events.functions[funcId]=func;
document.events.args[funcId]=args;
eval('callback=function(event){result=document.events.functions['+funcId+'].apply(this,document.events.args['+funcId+']);if(result===false){if(event.preventDefault){event.preventDefault();}}};');
if(element.addEventListener){
var eventType=type;
if(eventType.substr(0,2)=='on'){
eventType=eventType.substr(2);
}
element.addEventListener(eventType,callback,false);
}else{
element.attachEvent(type,callback);
}
if (!holder){
var holder=new eventHolder(element);
this.holders[this.holders.length]=holder;
}
return holder;
},
trigger:function(element,type,event){
var holder=eventHandler.getHolderByElement(element);
return holder.trigerEvent.call(holder,type,event);
}
}
eventHolder=function(element){
this.element=element;
this.listners=Array();
}
eventHolder.prototype={
addListner:function(type,func,arguments){
if (type && this.element){
if (!this.listners[type]){
this.listners[type]=Array();
eval("callback=function(event){return holder.trigerEvent.call(holder,'"+type+"',event)}");
if (this.element.tagName){//do we have a element (not an named event)
var holder=this;
//IE doesn't let you set the onload event the regulair way
if (type=="onload" && this.element.addEventListener && window.ActiveXObject){
this.element.addEventListener(type, callback, false);
}else if (type=="onload" && this.element.attachEvent && window.ActiveXObject){
this.element.attachEvent(type, callback);
}else{
eval("this.element."+type+"=function(event){return holder.trigerEvent.call(holder,'"+type+"',event)}");
}
}else{
eval("this.element."+type+"=function(event){return holder.trigerEvent.call(holder,'"+type+"',event)}");
}
}
var i=this.listners[type].length
this.listners[type][i]=func;
this.listners[type][i].applyArguments=arguments;
}else{
var i=this.listners.length
this.listners[i]=func;
this.listners[type][i].applyArguments=arguments;
}
},
trigerEvent:function(type,event){
if (type && this.element && this.listners[type]){
for (var i=0;i<this.listners[type].length;i++){
if(this.listners[type][i].applyArguments){
return this.listners[type][i].apply(this,this.listners[type][i].applyArguments)
}else{
return this.listners[type][i].call();
}
}
}else{
for (var i=0;i<this.listners.length;i++){
return this.listners[i](event);
}
}
},
getElement:function(){
return this.element;
}
}
document.events=new eventHandler();
Node.prototype.addEvent=function(type,func,arguments){
document.events.add(this,type,func,arguments);
}

View file

@ -58,7 +58,7 @@ OC_FILES.getdirectorycontent=function(dir,callback){
OC_FILES.dir='';
OC_FILES.upload=function(dir){
OC_FILES.uploadIFrame.setAttribute('onload',"OC_FILES.upload_callback.call(OC_FILES,'"+dir+"')");
OC_FILES.uploadIFrame.addEvent('onload',new callBack(OC_FILES.upload_callback,OC_FILES),dir);
var fileSelector=document.getElementById('fileSelector');
var max_upload=document.getElementById('max_upload').value;
if(fileSelector.files && fileSelector.files[0].fileSize){
@ -181,6 +181,13 @@ OC_FILES.file=function(dir,file,type){
this.actions[index]=OC_FILES.fileActions[this.extention][index];
}
}
if(OC_FILES.fileActions[this.type]){
for(index in OC_FILES.fileActions[this.type]){
if(OC_FILES.fileActions[this.type][index].call){
this.actions[index]=OC_FILES.fileActions[this.type][index];
}
}
}
}
OC_FILES.file.prototype.showactions=function(){
@ -204,6 +211,14 @@ OC_FILES.fileActions.all.rename=function(){
OC_FILES.fileActions.all.download=function(){
window.location=WEBROOT+'/files/get_file.php?dir='+this.dir+'&files='+this.file;
}
OC_FILES.fileActions.all['default']=OC_FILES.fileActions.all.download;
OC_FILES.fileActions.dir=new Object()
OC_FILES.fileActions.dir.open=function(){
OC_FILES.browser.show(this.dir+'/'+this.file);
}
OC_FILES.fileActions.dir['default']=OC_FILES.fileActions.dir.open;
OC_FILES.fileActions.jpg=new Object()