Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
Revert "Merge pull request elastic#1876 from w33ble/clipboard"
Browse files Browse the repository at this point in the history
This reverts commit 67f3fe9, reversing
changes made to 1b3a385.
  • Loading branch information
Spencer Alger committed Nov 11, 2014
1 parent 34466c6 commit ff1f3da
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 120 deletions.
4 changes: 1 addition & 3 deletions src/kibana/components/clipboard/clipboard.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<span>
<a
ng-if="!disabled"
tooltip="{{shownText}}"
<a tooltip="{{shownText}}"
tooltip-placement="{{tipPlacement}}"
tooltip-animation="false"
tooltip-popup-delay="0"
Expand Down
72 changes: 32 additions & 40 deletions src/kibana/components/clipboard/clipboard.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,41 @@
define(function (require) {
// ng-clip expects ZeroClipboard to be global, but it's AMD, so it never is
var ZeroClipboard = window.ZeroClipboard = require('zeroclipboard');
require('ng-clip');

var $ = require('jquery');
var html = require('text!components/clipboard/clipboard.html');
var module = require('modules').get('kibana');

module.directive('kbnClipboard', function ($compile, $timeout) {
return {
restrict: 'E',
template: html,
replace: true,
scope: {
copyText: '=copy'
},
transclude: true,
link: function ($scope, $el, attr) {
if (ZeroClipboard.isFlashUnusable()) {
$scope.disabled = true;
return;
}

$scope.tipPlacement = attr.tipPlacement || 'top';
$scope.tipText = attr.tipText || 'Copy to clipboard';
$scope.tipConfirm = attr.tipConfirm = 'Copied!';
$scope.icon = attr.icon || 'fa-clipboard';
require('modules')
.get('kibana')
.directive('kbnClipboard', function ($compile, $timeout) {
return {
restrict: 'E',
template: html,
replace: true,
scope: {
copyText: '=copy'
},
transclude: true,
link: function ($scope, $el, attr) {
$scope.tipPlacement = attr.tipPlacement || 'top';
$scope.tipText = attr.tipText || 'Copy to clipboard';
$scope.tipConfirm = attr.tipConfirm = 'Copied!';
$scope.icon = attr.icon || 'fa-clipboard';

$scope.shownText = $scope.tipText;
$scope.shownText = $scope.tipText;

$el.on('click', function () {
$scope.shownText = $scope.tipConfirm;
// Reposition tooltip to account for text length change
$('a', $el).mouseenter();
});
$el.on('click', function () {
$scope.shownText = $scope.tipConfirm;
// Reposition tooltip to account for text length change
$('a', $el).mouseenter();
});

$el.on('mouseleave', function () {
$scope.shownText = $scope.tipText;
});
$el.on('mouseleave', function () {
$scope.shownText = $scope.tipText;
});

$scope.$on('$destroy', function () {
$el.off('click');
$el.off('mouseleave');
});
}
};
});
$scope.$on('$destroy', function () {
$el.off('click');
$el.off('mouseleave');
});
}
};
});
});
4 changes: 4 additions & 0 deletions src/kibana/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ define(function (require) {
require('angular-route');
require('angular-bindonce');

// Seems bad?
window.ZeroClipboard = require('zeroclipboard');
require('ng-clip');

var configFile = JSON.parse(require('text!config'));

var kibana = modules.get('kibana', [
Expand Down
13 changes: 3 additions & 10 deletions src/kibana/plugins/dashboard/partials/share.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,15 @@

<p>
<div class="input-group">
<label>
Embed this dashboard.
<kbn-clipboard copy="opts.shareData().embed"></kbn-clipboard>
<small>Add to your html source. Note all clients must still be able to access kibana</small>
</label>
<label>Embed this dashboard. <kbn-clipboard copy="opts.shareData().embed"></kbn-clipboard> <small>Add to your html source. Note all clients must still be able to access kibana</small></label>
<div class="form-control" disabled>{{opts.shareData().embed}}</div>
</div>
</p>

<p>
<div class="input-group">
<label>
Share a link
<kbn-clipboard copy="opts.shareData().link"></kbn-clipboard>
</label>
<div class="form-control" disabled>{{opts.shareData().link}}</div>
<label>Share a link <kbn-clipboard copy="opts.shareData().link"></kbn-clipboard></i></a></label>
<div class="form-control" disabled>{{opts.shareData().link}}</div>
</div>
</p>
</form>
9 changes: 3 additions & 6 deletions src/kibana/plugins/visualize/editor/panels/share.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

<p>
<div class="form-group">
<label>
Embed this visualization.
<label>Embed this visualization.
<kbn-clipboard copy="conf.shareData().embed"></kbn-clipboard>

<small>Add to your html source. Note all clients must still be able to access kibana</small>
</label>
<div class="form-control" disabled>{{conf.shareData().embed}}</div>
Expand All @@ -13,10 +13,7 @@

<p>
<div class="form-group">
<label>
Share a link
<kbn-clipboard copy="conf.shareData().link"></kbn-clipboard>
</label>
<label>Share a link <kbn-clipboard copy="conf.shareData().link"></kbn-clipboard></label>
<div class="form-control" disabled>{{conf.shareData().link}}</div>
</div>
</p>
Expand Down
1 change: 1 addition & 0 deletions src/kibana/require.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ require.config({
leaflet: {
deps: ['css!bower_components/leaflet/dist/leaflet.css']
}

},
waitSeconds: 60
});
94 changes: 33 additions & 61 deletions test/unit/specs/components/clipboard.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
define(function (require) {
var angular = require('angular');
var _ = require('lodash');
var sinon = require('test_utils/auto_release_sinon');
var sinon = require('sinon/sinon');
var $ = require('jquery');

require('components/clipboard/clipboard');

describe('Clipboard directive', function () {
var $scope;
var $rootScope;
var $compile;
var $interpolate;
var el;
var tips;

function init() {

var $scope, $rootScope, $compile, $interpolate, el, tips;

beforeEach(function (done) {
// load the application
module('kibana');

Expand All @@ -28,72 +24,48 @@ define(function (require) {

$scope = el.scope();
$scope.$digest();
});
}

describe('With flash disabled', function () {
beforeEach(function () {
sinon.stub(window.ZeroClipboard, 'isFlashUnusable', _.constant(true));
init();
});

it('should be an empty element', function () {
expect(el.children()).to.have.length(0);
done();
});

it('should not show the tooltip', function () {
var clip = el.find('[tooltip]');
expect(clip).to.have.length(0);
});

it('should not show the clipboard button', function () {
var clip = el.find('[clip-copy]');
expect(clip).to.have.length(0);
});
});

describe('With flash enabled', function () {
beforeEach(function () {
sinon.stub(window.ZeroClipboard, 'isFlashUnusable', _.constant(false));
init();
});

it('should contain an element with clip-copy', function () {
var clip = el.find('[clip-copy]');
expect(clip).to.have.length(1);
});
it('should contain an element with clip-copy', function () {
var clip = el.find('[clip-copy]');
expect(clip).to.have.length(1);
});

it('should have a tooltip', function () {
var clip = el.find('[tooltip]');
expect(clip).to.have.length(1);
it('should have a tooltip', function () {
var clip = el.find('[tooltip]');
expect(clip).to.have.length(1);

var clipText = $interpolate($(clip).attr('tooltip'))();
expect(clipText).to.be('Copy to clipboard');
var clipText = $interpolate($(clip).attr('tooltip'))();
expect(clipText).to.be('Copy to clipboard');

});
});

it('should change the tooltip text when clicked, back when mouse leaves', function () {
el.mouseenter();
el.click();
$scope.$digest();
it('should change the tooltip text when clicked, back when mouse leaves', function () {
el.mouseenter();
el.click();
$scope.$digest();

var clipText = $interpolate($('[tooltip]', el).attr('tooltip'))();
expect(clipText).to.be('Copied!');
var clipText = $interpolate($('[tooltip]', el).attr('tooltip'))();
expect(clipText).to.be('Copied!');

el.mouseleave();
$scope.$digest();
el.mouseleave();
$scope.$digest();

clipText = $interpolate($('[tooltip]', el).attr('tooltip'))();
expect(clipText).to.be('Copy to clipboard');
});
clipText = $interpolate($('[tooltip]', el).attr('tooltip'))();
expect(clipText).to.be('Copy to clipboard');
});

it('should unbind all handlers on destroy', function () {
var handlers = $._data(el.get(0), 'events');
expect(Object.keys(handlers)).to.have.length(2);
it('should unbind all handlers on destroy', function () {
var handlers = $._data(el.get(0), 'events');
expect(Object.keys(handlers)).to.have.length(2);

$scope.$destroy();
expect(Object.keys(handlers)).to.have.length(0);
});
$scope.$destroy();
expect(Object.keys(handlers)).to.have.length(0);
});

});
});

0 comments on commit ff1f3da

Please sign in to comment.