Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add copy link button to examples' files #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ $(document).ready(function() {
let node = {
name: currentNode.name,
example: currentNode.example,
is_file_name: currentNode.is_file_name,
path: currentNode.path,
expanded: true,
children: traverseTreeData([], paths.slice(1))
};
Expand All @@ -170,19 +172,21 @@ $(document).ready(function() {

$('.source_table.highlighted li.covered').live('click', function() {
const exampleRefs = $(this).children('.reverse_coverage')[0].dataset.exampleRefs.split(",");
if(!$(this).children('.reverse_coverage').is(':visible')){
if(!$(this).children('.reverse_coverage').is(':visible')) {
let treeData = [];
const self = this;
exampleRefs.forEach(function(ref) {
const example = window.examples[ref]
const treeNodes = []
example["file_path"].split('/').slice(1).forEach(function(node_path){
treeNodes.push({ name: node_path })
const example = window.examples[ref];
const treeNodes = [];
const parts = example['file_path'].split('/').slice(1);
parts.forEach(function(node_path, i) {
var node = { name: node_path, is_file_name: (parts.length - 1 == i) };
if(node.is_file_name) node.path = example['file_path'];
treeNodes.push(node);
});
treeNodes.push({ example: example, name: example['full_description'] });

treeData = traverseTreeData(treeData, treeNodes)
})
treeData = traverseTreeData(treeData, treeNodes);
});

const domElement = self.querySelector('.reverse_coverage');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,18 @@
var expando = document.createElement('div');

leaf.setAttribute('class', 'tree-leaf');
content.setAttribute('class', 'tree-leaf-content');
content.setAttribute('class', 'tree-leaf-content' + (item.is_file_name ? ' file_name' : ''));
content.setAttribute('data-item', JSON.stringify(item));
text.setAttribute('class', 'tree-leaf-text');
text.textContent = item.name;
expando.setAttribute('class', 'tree-expando ' + (item.expanded ? 'expanded' : ''));
if(item.is_file_name) {
var copyURL = document.createElement('a');
copyURL.setAttribute('href', 'Javascript:void(0)');
copyURL.setAttribute('class', 'copy-example-path');
copyURL.setAttribute('data-path', item.path);
text.appendChild(copyURL);
}
expando.setAttribute('class', 'tree-expando' + (item.expanded ? ' expanded' : ''));
expando.textContent = item.expanded ? '-' : '+';
content.appendChild(expando);
content.appendChild(text);
Expand Down Expand Up @@ -140,6 +147,13 @@
forEach(container.querySelectorAll('.tree-expando'), function (node) {
node.onclick = click;
});
forEach(container.querySelectorAll('.copy-example-path'), function (node) {
node.onclick = function(e) {
var el = (e.target || e.currentTarget);
e.stopPropagation();
navigator.clipboard.writeText(el.getAttribute('data-path'));
};
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,10 @@ td

&:before
content: '↳ '

a.copy-example-path
background: url('./clipboard.gif') no-repeat
display: inline-block
width: 11px
height: 13px
margin-left: 6px
7 changes: 7 additions & 0 deletions lib/reverse_coverage/formatters/html/public/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,13 @@ td {
.tree-expando.hidden + .tree-leaf-text:before {
content: "↳ "; }

a.copy-example-path {
background: url("./clipboard.gif") no-repeat;
display: inline-block;
width: 11px;
height: 13px;
margin-left: 6px; }




38 changes: 28 additions & 10 deletions lib/reverse_coverage/formatters/html/public/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -1663,11 +1663,18 @@ jQuery.url = function()
var expando = document.createElement('div');

leaf.setAttribute('class', 'tree-leaf');
content.setAttribute('class', 'tree-leaf-content');
content.setAttribute('class', 'tree-leaf-content' + (item.is_file_name ? ' file_name' : ''));
content.setAttribute('data-item', JSON.stringify(item));
text.setAttribute('class', 'tree-leaf-text');
text.textContent = item.name;
expando.setAttribute('class', 'tree-expando ' + (item.expanded ? 'expanded' : ''));
if(item.is_file_name) {
var copyURL = document.createElement('a');
copyURL.setAttribute('href', 'Javascript:void(0)');
copyURL.setAttribute('class', 'copy-example-path');
copyURL.setAttribute('data-path', item.path);
text.appendChild(copyURL);
}
expando.setAttribute('class', 'tree-expando' + (item.expanded ? ' expanded' : ''));
expando.textContent = item.expanded ? '-' : '+';
content.appendChild(expando);
content.appendChild(text);
Expand Down Expand Up @@ -1720,6 +1727,13 @@ jQuery.url = function()
forEach(container.querySelectorAll('.tree-expando'), function (node) {
node.onclick = click;
});
forEach(container.querySelectorAll('.copy-example-path'), function (node) {
node.onclick = function(e) {
var el = (e.target || e.currentTarget);
e.stopPropagation();
navigator.clipboard.writeText(el.getAttribute('data-path'));
};
});
}

/**
Expand Down Expand Up @@ -1994,6 +2008,8 @@ $(document).ready(function() {
let node = {
name: currentNode.name,
example: currentNode.example,
is_file_name: currentNode.is_file_name,
path: currentNode.path,
expanded: true,
children: traverseTreeData([], paths.slice(1))
};
Expand All @@ -2011,19 +2027,21 @@ $(document).ready(function() {

$('.source_table.highlighted li.covered').live('click', function() {
const exampleRefs = $(this).children('.reverse_coverage')[0].dataset.exampleRefs.split(",");
if(!$(this).children('.reverse_coverage').is(':visible')){
if(!$(this).children('.reverse_coverage').is(':visible')) {
let treeData = [];
const self = this;
exampleRefs.forEach(function(ref) {
const example = window.examples[ref]
const treeNodes = []
example["file_path"].split('/').slice(1).forEach(function(node_path){
treeNodes.push({ name: node_path })
const example = window.examples[ref];
const treeNodes = [];
const parts = example['file_path'].split('/').slice(1);
parts.forEach(function(node_path, i) {
var node = { name: node_path, is_file_name: (parts.length - 1 == i) };
if(node.is_file_name) node.path = example['file_path'];
treeNodes.push(node);
});
treeNodes.push({ example: example, name: example['full_description'] });

treeData = traverseTreeData(treeData, treeNodes)
})
treeData = traverseTreeData(treeData, treeNodes);
});

const domElement = self.querySelector('.reverse_coverage');

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.