Skip to content

Commit 09b7618

Browse files
committedJan 17, 2016
Listing cell content copy feature
1 parent 1a0c488 commit 09b7618

File tree

3 files changed

+93
-13
lines changed

3 files changed

+93
-13
lines changed
 

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "LightPivotTable",
33
"author": "ZitRo",
4-
"version": "1.5.0",
4+
"version": "1.5.1",
55
"description": "A lightweight pivot table for MDX2JSON source for InterSystems Cache",
66
"main": "test/testServer.js",
77
"repository": {

‎source/css/LightPivot.css

+46-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@
6363
.lpt-icon-rows {
6464
position: relative;
6565
display: inline-block;
66-
width: 10px;
67-
height: 6px;
66+
width: 9px;
67+
height: 5px;
6868
border-top: 2px solid black;
6969
border-bottom: 2px solid black;
7070
vertical-align: middle;
@@ -81,6 +81,50 @@
8181
border-bottom: 2px solid black;
8282
}
8383

84+
.lpt-icon-copy {
85+
position: relative;
86+
display: inline-block;
87+
width: 9px;
88+
height: 13px;
89+
border: 1px solid black;
90+
border-radius: 2px;
91+
vertical-align: bottom;
92+
background: white;
93+
z-index: 1;
94+
cursor: pointer;
95+
}
96+
97+
.lpt-icon-copy:before {
98+
position: absolute;
99+
width: 9px;
100+
height: 13px;
101+
border: 1px solid black;
102+
border-radius: 2px;
103+
content: "";
104+
left: 2px;
105+
top: -3px;
106+
z-index: 0;
107+
background: white;
108+
}
109+
110+
.lpt-icon-copy:hover:before {
111+
background: #FFF7D7;
112+
}
113+
114+
.lpt-icon-copy:hover {
115+
background: #FFF7D7;
116+
}
117+
118+
.lpt-icon-copy:after {
119+
position: absolute;
120+
left: 4px;
121+
width: 7px;
122+
height: 2px;
123+
border-top: 1px solid black;
124+
border-bottom: 1px solid black;
125+
content: "";
126+
}
127+
84128
.lpt .lpt-tableBlock tr:hover td {
85129
box-shadow: inset 0 0 30px #fff5b9;
86130
}

‎source/js/PivotView.js

+46-10
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ PivotView.prototype._getSelectedText = function () {
433433
* @param {event} event
434434
* @param {function} [drillThroughHandler]
435435
*/
436-
PivotView.prototype._cellClickHandler = function (cell, x, y, event, drillThroughHandler, data) {
436+
PivotView.prototype._cellClickHandler = function (cell, x, y, event, drillThroughHandler) {
437437

438438
var data = this.controller.dataController.getData(),
439439
f = [], f1, f2, callbackRes = true, result,
@@ -492,16 +492,38 @@ PivotView.prototype._cellClickHandler = function (cell, x, y, event, drillThroug
492492

493493
};
494494

495+
PivotView.prototype.copyToClipboard = function (text) {
496+
497+
var $temp = document.createElement("input");
498+
document.body.appendChild($temp);
499+
500+
$temp.setAttribute("value", text);
501+
document.body.appendChild($temp);
502+
$temp.select();
503+
504+
var result = false;
505+
try {
506+
result = document.execCommand("copy");
507+
} catch (err) {
508+
console.log("Copy error: " + err);
509+
}
510+
511+
document.body.removeChild($temp);
512+
return result;
513+
514+
};
515+
495516
PivotView.prototype.listingClickHandler = function (params, data) {
496517

497518
if (data.info.leftHeaderColumnsNumber !== 0) {
498519
console.warn("Listing handler called not for a listing!");
499520
return;
500521
}
501522

502-
var self = this,
523+
var CLICK_EVENT = this.controller.CONFIG["triggerEvent"] || "click",
524+
self = this,
503525
el = function (e) { return document.createElement(e); },
504-
d1 = document.createElement("div"),
526+
d1 = el("div"),
505527
headers = data.rawData[0].map(function (v) {
506528
return v.value + (v.source && v.source.title ? "(" + v.source.title + ")" : "");
507529
}),
@@ -511,19 +533,35 @@ PivotView.prototype.listingClickHandler = function (params, data) {
511533
d1.style.fontSize = "12pt";
512534
d1.style.opacity = 0;
513535

514-
var h, val, hr;
536+
var h, val, hr, c, sp;
515537
for (var i = 0; i < headers.length; i++) {
516-
h = el("div"); val = el("div"); hr = el("hr");
517-
h.className = "lpt-messageHead";
518-
h.textContent = headers[i];
538+
h = el("div"); sp = el("span"); val = el("div"); hr = el("hr"); c = el("div");
539+
c.className = "lpt-icon-copy";
540+
c.title = "Copy";
541+
c.style.marginRight = "6px";
542+
sp.className = "lpt-messageHead";
543+
sp.textContent = headers[i];
519544
val.className = "lpt-messageBody";
545+
h.style.marginBottom = ".3em";
546+
520547
if (values[i] !== "")
521548
val.textContent = values[i];
522549
else
523550
val.innerHTML = "&nbsp;";
551+
552+
h.appendChild(c);
553+
h.appendChild(sp);
524554
d1.appendChild(h);
525555
d1.appendChild(val);
526556
d1.appendChild(hr);
557+
c.addEventListener(CLICK_EVENT, (function (value) { return function (e) {
558+
if (self.copyToClipboard(value) === false) {
559+
alert("Your browser does not support dynamic content copying.");
560+
}
561+
e.preventDefault();
562+
e.cancelBubble = true;
563+
e.preventBubble = true;
564+
}})(values[i]));
527565
}
528566

529567
this.elements.base.appendChild(d1);
@@ -1346,9 +1384,7 @@ PivotView.prototype.renderRawData = function (data) {
13461384
// add handlers
13471385
td.addEventListener(CLICK_EVENT, (function (x, y, cell) {
13481386
return function (event) {
1349-
_._cellClickHandler.call(
1350-
_, cell, x, y, event, info.drillThroughHandler, data
1351-
);
1387+
_._cellClickHandler.call(_, cell, x, y, event, info.drillThroughHandler);
13521388
};
13531389
})(x, y, rawData[y][x]));
13541390

0 commit comments

Comments
 (0)
Please sign in to comment.