angularjs - angular js zeroclipboard copy html -


i'm trying make copy button html link. user click on button , html loaded (as 'text/html') , when paste email or word document, rendered html link , not full text link.

i.e. want show mywebsite.com rather

<a href=http://www.mywebsite.com>mywebsite.com</a> 

when copied.

i'm using angular js , zeroclipboard (angular-zeroclipboard.js) here code: controller.js

var app = angular.module('myapp', ['zeroclipboard']);  app.config(['uizeroclipconfigprovider', function(uizeroclipconfigprovider) { // config zeroclipboard uizeroclipconfigprovider.setzcconf({   swfpath: 'assets/javascripts/vendor/zeroclipboard.swf' }); }]); 

my html file:

 <button ng-show="!copiedhtml" class="btn btn-swblue space hidden-xs" ui-zeroclip zeroclip-copied="copiedhtml=true" zeroclip-on-error="cliperror($event)" zeroclip-text="<a href='http://www.mywebsite.com/page_id=3'>http://www.mywebsite.com</a>"><span class="glyphicon glyphicon-duplicate"></span> copy html text</button>   <script src="javascripts/vendor/zeroclipboard.js"></script> <script src="javascripts/vendor/angular-zeroclipboard.js"></script> 

any idea how set mime type of copied text? lot!

ok, got using ng-clip. script use same directive copy plain text , html text. set mime-type in directive tag. these buttons turning green ok glyph (using bootstrap) 2 seconds , go normal afterwards. goes this:

add js html file:

<script src="javascripts/vendor/zeroclipboard.js"></script> <script src="javascripts/vendor/ng-clip.min.js"></script> 

adding directive js controller:

var app = angular.module('myapp', ['ngclipboard']);   [...]     app.directive('copybutton', function ($timeout) {     return {         restrict: "e",         scope: {                     content: '@',                     mimetype: '@',                     innertext: '@',                     class: '@'                 },         template: '<button type="button" class="btn btn-swblue space hidden-xs" clip-copy="content" clip-click="clipped()" data-clip-copy-mime-type="{{mimetype}}"><i class="glyphicon glyphicon-duplicate"></i> {{innertext}} </button>',         link: function ($scope, element, attrs) {             if(!$scope.mimetype){                 $scope.mimetype = "text/plain";                 $scope.innertext = "copy text "             }else {                 $scope.innertext = "copy html"             }              var togglebutton = function(element){                 angular.element(element.find('button')[0]).toggleclass("btn-swblue");                 angular.element(element.find('button')[0]).toggleclass("btn-success");                 angular.element(element.find('i')[0]).toggleclass("glyphicon-duplicate");                 angular.element(element.find('i')[0]).toggleclass("glyphicon-ok");             };              $scope.clipped = function(){                 togglebutton(element);                 $timeout(function(){ togglebutton(element); }, 2000);             };         }     }; }); 

and using in html:

<copy-button class="hidden-xxs" content="<a href=www.mywebsite.com?page=321>mywebsite.com</a>" mime-type="text/html"></copy-button> 

pretty cool, isn't it? :d


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -