-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dashboard): Add copy to clipboard button
Add button to copy id values to clipboard closes #288
- Loading branch information
Showing
5 changed files
with
84 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
(function () { | ||
'use strict'; | ||
|
||
angular.module('openSenseMapApp').directive('osemClipboard', OsemClipboard); | ||
|
||
OsemClipboard.$inject = ['$window']; | ||
function OsemClipboard ($window) { | ||
// Usage: | ||
// | ||
// Creates: | ||
// | ||
var directive = { | ||
link: link, | ||
restrict: 'A', | ||
scope: { | ||
text: '=' | ||
} | ||
}; | ||
|
||
return directive; | ||
|
||
function link (scope, element) { | ||
element.on('click', function (event) { | ||
// event.stopPropagation(); | ||
// event.preventDefault(); | ||
|
||
var textField = $window.document.createElement('textarea'); | ||
// Place in top-left corner of screen regardless of scroll position. | ||
textField.style.position = 'fixed'; | ||
textField.style.top = '0'; | ||
textField.style.left = '0'; | ||
textField.style.width = '2em'; | ||
textField.style.height = '2em'; | ||
textField.style.padding = '0'; | ||
textField.style.border = 'none'; | ||
textField.style.outline = 'none'; | ||
textField.style.boxShadow = 'none'; | ||
textField.style.background = 'transparent'; | ||
textField.innerText = scope.text; | ||
$window.document.body.appendChild(textField); | ||
|
||
var range, selection; | ||
range = $window.document.createRange(); | ||
range.selectNodeContents(textField); | ||
selection = $window.getSelection(); | ||
selection.removeAllRanges(); | ||
selection.addRange(range); | ||
textField.setSelectionRange(0, 999999); | ||
|
||
$window.document.execCommand('copy'); | ||
$window.document.body.removeChild(textField); | ||
}); | ||
} | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters