Skip to content

Commit

Permalink
Merge pull request #25418 from owncloud/use-clipboard-api
Browse files Browse the repository at this point in the history
[9.2] Add clipboard button to public share link
  • Loading branch information
Vincent Petry authored Jul 15, 2016
2 parents 43bf549 + cc67547 commit d4c0838
Show file tree
Hide file tree
Showing 11 changed files with 809 additions and 12 deletions.
9 changes: 6 additions & 3 deletions apps/files_sharing/css/sharetabview.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
top: 2px;
}

.shareTabView .shareWithRemoteInfo {
padding: 11px 20px;
.shareTabView .shareWithRemoteInfo,
.shareTabView .clipboardButton {
padding-left: 10px;
}

.shareTabView label {
Expand All @@ -28,7 +29,9 @@
width: 94%;
margin-left: 0;
}
.shareTabView input[type="text"].shareWithField {
.shareTabView input[type="text"].shareWithField,
.shareTabView input[type="text"].emailField,
.shareTabView input[type="text"].linkText {
width: 80%;
}

Expand Down
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"backbone": "~1.2.3",
"davclient.js": "https://github.com/evert/davclient.js.git",
"es6-promise": "https://github.com/jakearchibald/es6-promise.git#~2.3.0",
"base64": "~0.3.0"
"base64": "~0.3.0",
"clipboard": "^1.5.12"
}
}
8 changes: 8 additions & 0 deletions core/css/icons.css
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ img.icon-loading-small-dark, object.icon-loading-small-dark, video.icon-loading-
background-image: url('../img/actions/mail.svg');
}

.icon-mail-grey {
background-image: url('../img/actions/mail-grey.svg');
}

.icon-menu {
background-image: url('../img/actions/menu.svg');
}
Expand Down Expand Up @@ -368,3 +372,7 @@ img.icon-loading-small-dark, object.icon-loading-small-dark, video.icon-loading-
.icon-picture {
background-image: url('../img/places/picture.svg');
}

.icon-clippy {
background-image: url('../img/actions/clippy.svg');
}
3 changes: 3 additions & 0 deletions core/img/actions/clippy.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion core/js/core.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"bootstrap/js/tooltip.js",
"backbone/backbone.js",
"es6-promise/dist/es6-promise.js",
"davclient.js/lib/client.js"
"davclient.js/lib/client.js",
"clipboard/dist/clipboard.js"
],
"libraries": [
"jquery-showpassword.js",
Expand Down
35 changes: 35 additions & 0 deletions core/js/sharedialoglinkshareview.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
'<input type="checkbox" name="linkCheckbox" id="linkCheckbox-{{cid}}" class="checkbox linkCheckbox" value="1" {{#if isLinkShare}}checked="checked"{{/if}} />' +
'<label for="linkCheckbox-{{cid}}">{{linkShareLabel}}</label>' +
'<br />' +
'<div class="oneline">' +
'<label for="linkText-{{cid}}" class="hidden-visually">{{urlLabel}}</label>' +
'<input id="linkText-{{cid}}" class="linkText {{#unless isLinkShare}}hidden{{/unless}}" type="text" readonly="readonly" value="{{shareLinkURL}}" />' +
'<a class="{{#unless isLinkShare}}hidden-visually{{/unless}} clipboardButton icon icon-clippy" data-clipboard-target="#linkText-{{cid}}"></a>' +
'</div>' +
' {{#if publicUpload}}' +
'<div id="allowPublicUploadWrapper">' +
' <span class="icon-loading-small hidden"></span>' +
Expand Down Expand Up @@ -112,6 +115,38 @@
'onShowPasswordClick',
'onAllowPublicUploadChange'
);

var clipboard = new Clipboard('.clipboardButton');
clipboard.on('success', function(e) {
$input = $(e.trigger);
$input.tooltip({placement: 'bottom', trigger: 'manual', title: t('core', 'Copied!')});
$input.tooltip('show');
_.delay(function() {
$input.tooltip('hide');
}, 3000);
});
clipboard.on('error', function (e) {
$input = $(e.trigger);
var actionMsg = '';
if (/iPhone|iPad/i.test(navigator.userAgent)) {
actionMsg = t('core', 'Not supported!');
} else if (/Mac/i.test(navigator.userAgent)) {
actionMsg = t('core', 'Press ⌘-C to copy.');
} else {
actionMsg = t('core', 'Press Ctrl-C to copy.');
}

$input.tooltip({
placement: 'bottom',
trigger: 'manual',
title: actionMsg
});
$input.tooltip('show');
_.delay(function () {
$input.tooltip('hide');
}, 3000);
});

},

onLinkCheckBoxChange: function() {
Expand Down
8 changes: 4 additions & 4 deletions core/js/sharedialogmailview.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
var TEMPLATE =
'{{#if shareAllowed}}' +
' {{#if mailPublicNotificationEnabled}}' +
'<form id="emailPrivateLink" class="emailPrivateLinkForm">' +
'<form id="emailPrivateLink" class="emailPrivateLinkForm oneline">' +
' <input id="email" class="emailField" value="{{email}}" placeholder="{{mailPrivatePlaceholder}}" type="text" />' +
' <input id="emailButton" class="emailButton" type="submit" value="{{mailButtonText}}" />' +
' <a id="emailButton" class="icon icon-mail-grey" />' +
'</form>' +
' {{/if}}' +
'{{/if}}'
Expand Down Expand Up @@ -48,7 +48,7 @@
showLink: true,

events: {
'submit .emailPrivateLinkForm': '_onEmailPrivateLink'
'click #emailButton': '_onEmailPrivateLink'
},

initialize: function(options) {
Expand Down Expand Up @@ -173,4 +173,4 @@

OC.Share.ShareDialogMailView = ShareDialogMailView;

})();
})();
2 changes: 1 addition & 1 deletion core/js/sharedialogview.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
'<div class="loading hidden" style="height: 50px"></div>';

var TEMPLATE_REMOTE_SHARE_INFO =
'<a target="_blank" class="icon-info shareWithRemoteInfo hasTooltip" href="{{docLink}}" ' +
'<a target="_blank" class="icon icon-info shareWithRemoteInfo hasTooltip" href="{{docLink}}" ' +
'title="{{tooltip}}"></a>';

/**
Expand Down
4 changes: 2 additions & 2 deletions core/js/tests/specs/sharedialogviewSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ describe('OC.Share.ShareDialogView', function() {
dialog.render();

dialog.$el.find('.emailPrivateLinkForm .emailField').val('[email protected]');
dialog.$el.find('.emailPrivateLinkForm').trigger('submit');
dialog.$el.find('#emailButton').trigger('click');

expect(sendEmailPrivateLinkStub.callCount).toEqual(1);
expect(dialog.$el.find('.emailPrivateLinkForm .emailField').val()).toEqual('Sending ...');
Expand All @@ -463,7 +463,7 @@ describe('OC.Share.ShareDialogView', function() {
dialog.render();

dialog.$el.find('.emailPrivateLinkForm .emailField').val('[email protected]');
dialog.$el.find('.emailPrivateLinkForm').trigger('submit');
dialog.$el.find('#emailButton').trigger('click');

expect(sendEmailPrivateLinkStub.callCount).toEqual(1);
expect(dialog.$el.find('.emailPrivateLinkForm .emailField').val()).toEqual('Sending ...');
Expand Down
4 changes: 4 additions & 0 deletions core/vendor/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,7 @@ es6-promise/dist/*

# base64
base64/*min.js

# clipboard
clipboard/**
!clipboard/dist/clipboard.js
Loading

0 comments on commit d4c0838

Please sign in to comment.