refactor OC.Breadcrumbs, allow injection of container to allow rendering crumbs into full screen editor

This commit is contained in:
Jörn Friedrich Dreyer 2013-08-16 17:20:49 +02:00
parent 64d09452f5
commit 5b8d30c6b6
1 changed files with 29 additions and 20 deletions

View File

@ -431,9 +431,16 @@ OC.Notification={
OC.Breadcrumb={ OC.Breadcrumb={
container:null, container:null,
crumbs:[],
show:function(dir, leafname, leaflink){ show:function(dir, leafname, leaflink){
OC.Breadcrumb.clear(); if(!this.container){//default
this.container=$('#controls');
}
this._show(this.container, dir, leafname, leaflink);
},
_show:function(container, dir, leafname, leaflink){
var self = this;
this._clear(container);
// show home + path in subdirectories // show home + path in subdirectories
if (dir && dir !== '/') { if (dir && dir !== '/') {
@ -450,8 +457,7 @@ OC.Breadcrumb={
crumbImg.attr('src',OC.imagePath('core','places/home')); crumbImg.attr('src',OC.imagePath('core','places/home'));
crumbLink.append(crumbImg); crumbLink.append(crumbImg);
crumb.append(crumbLink); crumb.append(crumbLink);
OC.Breadcrumb.container.prepend(crumb); container.prepend(crumb);
OC.Breadcrumb.crumbs.push(crumb);
//add path parts //add path parts
var segments = dir.split('/'); var segments = dir.split('/');
@ -460,20 +466,23 @@ OC.Breadcrumb={
if (name !== '') { if (name !== '') {
pathurl = pathurl+'/'+name; pathurl = pathurl+'/'+name;
var link = OC.linkTo('files','index.php')+'?dir='+encodeURIComponent(pathurl); var link = OC.linkTo('files','index.php')+'?dir='+encodeURIComponent(pathurl);
OC.Breadcrumb.push(name, link); self._push(container, name, link);
} }
}); });
} }
//add leafname //add leafname
if (leafname && leaflink) { if (leafname && leaflink) {
OC.Breadcrumb.push(leafname, leaflink); this._push(container, leafname, leaflink);
} }
}, },
push:function(name, link){ push:function(name, link){
if(!OC.Breadcrumb.container){//default if(!this.container){//default
OC.Breadcrumb.container=$('#controls'); this.container=$('#controls');
} }
return this._push(OC.Breadcrumb.container, name, link);
},
_push:function(container, name, link){
var crumb=$('<div/>'); var crumb=$('<div/>');
crumb.addClass('crumb').addClass('last'); crumb.addClass('crumb').addClass('last');
@ -482,30 +491,30 @@ OC.Breadcrumb={
crumbLink.text(name); crumbLink.text(name);
crumb.append(crumbLink); crumb.append(crumbLink);
var existing=OC.Breadcrumb.container.find('div.crumb'); var existing=container.find('div.crumb');
if(existing.length){ if(existing.length){
existing.removeClass('last'); existing.removeClass('last');
existing.last().after(crumb); existing.last().after(crumb);
}else{ }else{
OC.Breadcrumb.container.prepend(crumb); container.prepend(crumb);
} }
OC.Breadcrumb.crumbs.push(crumb);
return crumb; return crumb;
}, },
pop:function(){ pop:function(){
if(!OC.Breadcrumb.container){//default if(!this.container){//default
OC.Breadcrumb.container=$('#controls'); this.container=$('#controls');
} }
OC.Breadcrumb.container.find('div.crumb').last().remove(); this.container.find('div.crumb').last().remove();
OC.Breadcrumb.container.find('div.crumb').last().addClass('last'); this.container.find('div.crumb').last().addClass('last');
OC.Breadcrumb.crumbs.pop();
}, },
clear:function(){ clear:function(){
if(!OC.Breadcrumb.container){//default if(!this.container){//default
OC.Breadcrumb.container=$('#controls'); this.container=$('#controls');
} }
OC.Breadcrumb.container.find('div.crumb').remove(); this._clear(this.container);
OC.Breadcrumb.crumbs=[]; },
_clear:function(container) {
container.find('div.crumb').remove();
} }
}; };