1
0
mirror of https://github.com/MatMoul/quickdial-webext.git synced 2024-12-23 15:36:12 +00:00

Feature: Add Capture in a new Tab support for folder

This commit is contained in:
MatMoul 2017-10-14 20:51:38 +02:00
parent 30b432d1b8
commit 20ca231945
2 changed files with 80 additions and 23 deletions

View File

@ -404,6 +404,31 @@ core.GridNodes.getNode = function(gridNode, path){ // Return GridNode from RootG
return core.GridNodes.getNode(child, path.substr(child.title.length + 1)); return core.GridNodes.getNode(child, path.substr(child.title.length + 1));
return null; return null;
} }
core.GridNodes.getNodeWithParent = function(id){
var parents = [];
function findNode(gridNode){
if(gridNode.id == id){
parents.unshift(gridNode);
return gridNode;
}
if(gridNode.children){
for(var i=0; i<gridNode.children.length; i++){
var result = findNode(gridNode.children[i]);
if(result){
parents.unshift(gridNode);
return result;
}
}
}
return null;
}
findNode(core.node, id);
if(parents.length>0) return parents;
return null;
}
core.GridNodes.getChildNode = function(gridNode, id){ // Return child node by ID core.GridNodes.getChildNode = function(gridNode, id){ // Return child node by ID
for(var child of gridNode.children) if(child.id == id) return child; for(var child of gridNode.children) if(child.id == id) return child;
return null; return null;
@ -498,30 +523,61 @@ core.GridNodes.deleteNode = function(gridNode, id, callback){ // Delete a GridNo
core.GridNodes.refreshNode = function(gridNode, callback){ // Refresh content of a GridNode core.GridNodes.refreshNode = function(gridNode, callback){ // Refresh content of a GridNode
if(gridNode.__isLoading == true) return; if(gridNode.__isLoading == true) return;
gridNode.__isLoading = true; gridNode.__isLoading = true;
core.SiteInfos.fromFrame(gridNode.url, function(infos){ switch(gridNode.type){
if(infos){ case core.GridNodes.GridNodeType.folder:
gridNode.title = infos.title; delete gridNode.image;
gridNode.image = infos.screenshot; delete gridNode.__isLoading;
} else { core.GridNodes.saveNode(gridNode);
gridNode.image = '0'; if(callback) callback({ title: gridNode.title, screenshot: gridNode.image });
} break;
delete gridNode.__isLoading; case core.GridNodes.GridNodeType.bookmark:
core.GridNodes.saveNode(gridNode); core.SiteInfos.fromFrame(gridNode.url, function(infos){
if(callback) callback(infos); if(infos){
}); gridNode.title = infos.title;
gridNode.image = infos.screenshot;
} else {
gridNode.image = '0';
}
delete gridNode.__isLoading;
core.GridNodes.saveNode(gridNode);
if(callback) callback(infos);
});
break;
}
} }
core.GridNodes.capturePage = function(gridNode, callback){ core.GridNodes.capturePage = function(gridNode, callback){
if(gridNode.__isLoading == true) return; if(gridNode.__isLoading == true) return;
gridNode.__isLoading = true; gridNode.__isLoading = true;
core.SiteInfos.fromNewTab(gridNode.url, function(infos){ switch(gridNode.type){
if(infos){ case core.GridNodes.GridNodeType.folder:
gridNode.title = infos.title; var nodes = core.GridNodes.getNodeWithParent(gridNode.id);
gridNode.image = infos.screenshot; if(nodes){
} else { var path = '';
gridNode.image = '0'; for(var i=1; i<nodes.length; i++) path = path + '/' + nodes[i].title;
} core.SiteInfos.fromNewTab('/dial?path=' + path, function(infos){
delete gridNode.__isLoading; if(infos){
core.GridNodes.saveNode(gridNode); gridNode.image = infos.screenshot;
if(callback) callback(infos); } else {
}); delete gridNode.image;
}
delete gridNode.__isLoading;
core.GridNodes.saveNode(gridNode);
if(callback) callback({ title: gridNode.title, screenshot: gridNode.image });
});
}
break;
case core.GridNodes.GridNodeType.bookmark:
core.SiteInfos.fromNewTab(gridNode.url, function(infos){
if(infos){
gridNode.title = infos.title;
gridNode.image = infos.screenshot;
} else {
gridNode.image = '0';
}
delete gridNode.__isLoading;
core.GridNodes.saveNode(gridNode);
if(callback) callback(infos);
});
break;
}
} }

View File

@ -324,7 +324,8 @@ dial.populateGrid = function(){
populateFolder = function(link, node){ populateFolder = function(link, node){
link.Node = node; link.Node = node;
link.className = 'Folder'; link.className = 'Folder';
link.childNodes[0].style.backgroundImage = ''; if(node.image) link.childNodes[0].style.backgroundImage = 'url(' + node.image + ')';
else link.childNodes[0].style.backgroundImage = '';
link.childNodes[1].innerText = node.title; link.childNodes[1].innerText = node.title;
if(dial.path) link.href = '?' + 'bg=' + encodeURIComponent(app.settings.backgroundColor) + '&path=' + encodeURIComponent(dial.path + node.title); if(dial.path) link.href = '?' + 'bg=' + encodeURIComponent(app.settings.backgroundColor) + '&path=' + encodeURIComponent(dial.path + node.title);
else link.href = '?' + 'bg=' + encodeURIComponent(app.settings.backgroundColor) + '&path=' + encodeURIComponent(node.title); else link.href = '?' + 'bg=' + encodeURIComponent(app.settings.backgroundColor) + '&path=' + encodeURIComponent(node.title);