diff --git a/app/elements/pages/page-element.html b/app/elements/pages/page-element.html index 3de070d..03c872a 100644 --- a/app/elements/pages/page-element.html +++ b/app/elements/pages/page-element.html @@ -1,6 +1,8 @@ + + @@ -60,7 +62,9 @@

[[element]]

Bower Command
- + Copy + +

Bundled Elements

@@ -224,7 +228,48 @@

Bundled Behaviors

_isCartIconHidden: function(view) { return view.indexOf('demo:') === 0; }, + // Copy bower command to the clipboard + _copyCommand: function() { + var textArea = document.createElement("textarea"); + // Place in top-left corner of screen regardless of scroll position. + textArea.style.position = 'fixed'; + textArea.style.top = 0; + textArea.style.left = 0; + + // Ensure it has a small width and height. Setting to 1px / 1em + // doesn't work as this gives a negative w/h on some browsers. + textArea.style.width = '2em'; + textArea.style.height = '2em'; + + // We don't need padding, reducing the size if it does flash render. + textArea.style.padding = 0; + + // Clean up any borders. + textArea.style.border = 'none'; + textArea.style.outline = 'none'; + textArea.style.boxShadow = 'none'; + + // Avoid flash of white box if rendered for any reason. + textArea.style.background = 'transparent'; + + + textArea.value = this._bowerCommand(this.metadata.source); + + document.body.appendChild(textArea); + + textArea.select(); + + try { + var successful = document.execCommand('copy'); + var msg = successful ? 'Copied' : 'Oops, unable to copy'; + this.copyResultToast.show(msg); + } catch (err) { + this.copyResultToast.show('Oops, unable to copy'); + } + document.body.removeChild(textArea); + }, + _handleError: function() { this.router.go('/404'); },