@@ -433,7 +433,7 @@ PivotView.prototype._getSelectedText = function () {
433
433
* @param {event } event
434
434
* @param {function } [drillThroughHandler]
435
435
*/
436
- PivotView . prototype . _cellClickHandler = function ( cell , x , y , event , drillThroughHandler , data ) {
436
+ PivotView . prototype . _cellClickHandler = function ( cell , x , y , event , drillThroughHandler ) {
437
437
438
438
var data = this . controller . dataController . getData ( ) ,
439
439
f = [ ] , f1 , f2 , callbackRes = true , result ,
@@ -492,16 +492,38 @@ PivotView.prototype._cellClickHandler = function (cell, x, y, event, drillThroug
492
492
493
493
} ;
494
494
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
+
495
516
PivotView . prototype . listingClickHandler = function ( params , data ) {
496
517
497
518
if ( data . info . leftHeaderColumnsNumber !== 0 ) {
498
519
console . warn ( "Listing handler called not for a listing!" ) ;
499
520
return ;
500
521
}
501
522
502
- var self = this ,
523
+ var CLICK_EVENT = this . controller . CONFIG [ "triggerEvent" ] || "click" ,
524
+ self = this ,
503
525
el = function ( e ) { return document . createElement ( e ) ; } ,
504
- d1 = document . createElement ( "div" ) ,
526
+ d1 = el ( "div" ) ,
505
527
headers = data . rawData [ 0 ] . map ( function ( v ) {
506
528
return v . value + ( v . source && v . source . title ? "(" + v . source . title + ")" : "" ) ;
507
529
} ) ,
@@ -511,19 +533,35 @@ PivotView.prototype.listingClickHandler = function (params, data) {
511
533
d1 . style . fontSize = "12pt" ;
512
534
d1 . style . opacity = 0 ;
513
535
514
- var h , val , hr ;
536
+ var h , val , hr , c , sp ;
515
537
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 ] ;
519
544
val . className = "lpt-messageBody" ;
545
+ h . style . marginBottom = ".3em" ;
546
+
520
547
if ( values [ i ] !== "" )
521
548
val . textContent = values [ i ] ;
522
549
else
523
550
val . innerHTML = " " ;
551
+
552
+ h . appendChild ( c ) ;
553
+ h . appendChild ( sp ) ;
524
554
d1 . appendChild ( h ) ;
525
555
d1 . appendChild ( val ) ;
526
556
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 ] ) ) ;
527
565
}
528
566
529
567
this . elements . base . appendChild ( d1 ) ;
@@ -1346,9 +1384,7 @@ PivotView.prototype.renderRawData = function (data) {
1346
1384
// add handlers
1347
1385
td . addEventListener ( CLICK_EVENT , ( function ( x , y , cell ) {
1348
1386
return function ( event ) {
1349
- _ . _cellClickHandler . call (
1350
- _ , cell , x , y , event , info . drillThroughHandler , data
1351
- ) ;
1387
+ _ . _cellClickHandler . call ( _ , cell , x , y , event , info . drillThroughHandler ) ;
1352
1388
} ;
1353
1389
} ) ( x , y , rawData [ y ] [ x ] ) ) ;
1354
1390
0 commit comments