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 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
for(var child of gridNode.children) if(child.id == id) return child;
return null;
@ -498,6 +523,14 @@ core.GridNodes.deleteNode = function(gridNode, id, callback){ // Delete a GridNo
core.GridNodes.refreshNode = function(gridNode, callback){ // Refresh content of a GridNode
if(gridNode.__isLoading == true) return;
gridNode.__isLoading = true;
switch(gridNode.type){
case core.GridNodes.GridNodeType.folder:
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.fromFrame(gridNode.url, function(infos){
if(infos){
gridNode.title = infos.title;
@ -509,10 +542,31 @@ core.GridNodes.refreshNode = function(gridNode, callback){ // Refresh content of
core.GridNodes.saveNode(gridNode);
if(callback) callback(infos);
});
break;
}
}
core.GridNodes.capturePage = function(gridNode, callback){
if(gridNode.__isLoading == true) return;
gridNode.__isLoading = true;
switch(gridNode.type){
case core.GridNodes.GridNodeType.folder:
var nodes = core.GridNodes.getNodeWithParent(gridNode.id);
if(nodes){
var path = '';
for(var i=1; i<nodes.length; i++) path = path + '/' + nodes[i].title;
core.SiteInfos.fromNewTab('/dial?path=' + path, function(infos){
if(infos){
gridNode.image = infos.screenshot;
} 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;
@ -524,4 +578,6 @@ core.GridNodes.capturePage = function(gridNode, callback){
core.GridNodes.saveNode(gridNode);
if(callback) callback(infos);
});
break;
}
}

View File

@ -324,7 +324,8 @@ dial.populateGrid = function(){
populateFolder = function(link, node){
link.Node = node;
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;
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);