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