Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails with ng-repeat #7

Closed
bebraw opened this issue Jan 9, 2014 · 8 comments
Closed

Fails with ng-repeat #7

bebraw opened this issue Jan 9, 2014 · 8 comments

Comments

@bebraw
Copy link

bebraw commented Jan 9, 2014

For some reason ng-clip fails with ng-repeat. Maybe it's related to directive binding somehow? It keeps on pointing at the first item. Fiddle.

@asafdav
Copy link
Owner

asafdav commented Jan 9, 2014

Hi,
Thanks for your report.

Duplicate of #2
Apparently, ZeroClipboard has a bug and you can't create more than one instance.

I plan to refactor the directive and try using one ZeroClipboard instance for multiple instances of ng-clip.

@asafdav asafdav closed this as completed Jan 9, 2014
@bebraw
Copy link
Author

bebraw commented Jan 10, 2014

I plan to refactor the directive and try using one ZeroClipboard instance for multiple instances of ng-clip.

Ok. I tried that. I moved ZeroClipboard into Service and then triggered the behavior using Angular click handler. Here's the basic idea:

'use strict';

angular.module('ngClipboard', []).
  value('ZeroClipboardConfig', {
    path: '//cdnjs.cloudflare.com/ajax/libs/zeroclipboard/1.2.3/ZeroClipboard.swf'
  }).
  factory('clipService', ['ZeroClipboardConfig', function (ZeroClipboardConfig) {
    var clip = new ZeroClipboard(null, {
      moviePath: ZeroClipboardConfig.path,
      trustedDomains: ['*'],
      allowScriptAccess: 'always'
    });

    return {
      clip: function(text) {
        clip.flashBridge.setText(text); // doesn't copy... tried clip.setText too
      }
    };
  }]).
  directive('clipCopy', ['clipService', function (clipService) {
    return {
      scope: {
        clipCopy: '&',
        clipClick: '&'
      },
      restrict: 'A',
      link: function (scope, element, attrs) {
        element.on('click', function() {
          clipService.clip(scope.$eval(scope.clipCopy));

          if(angular.isDefined(attrs.clipClick)) {
            scope.$apply(scope.clipClick);
          }
        });
      }
    };
  }]);

For some reason I couldn't get it to work, though... I might be missing something simple.

Alternatively we could just wait till they resolve zeroclipboard/zeroclipboard#90 . Looks like they are testing a fix at the moment.

Or you could swap zeroclipboard to some other alternative. For me it seems like a very bloated library considering what it is doing. In this case we don't need event handling etc. for instance. Just a copy hook (Flash bridge) is enough.

@markalanevans
Copy link

Any luck w/ this?

@bebraw
Copy link
Author

bebraw commented Jan 15, 2014

@markalanevans Yes. If you use ZeroClipboard version ~1.3.0-beta.1 it actually works! You will get a bunch of deprecation warnings like new ZeroClipboard(elements, options) is deprecated. See docs for more info: https://github.com/zeroclipboard/zeroclipboard/blob/master/docs/instructions.md#deprecations` but it works! It would be easy to get rid of that deprecation warning simply by tweaking ng-clip a bit. Just waiting for @asafdav to do that.

@asafdav
Copy link
Owner

asafdav commented Jan 15, 2014

Working on it right now,
Hope I'll have a version soon.

Thanks !

@asafdav
Copy link
Owner

asafdav commented Jan 15, 2014

Hi,
I made some changes and added a new example to the repository.
Can you please confirm that it solved your problem and there are no unwanted warnings in the console ?

As soon as you confirm, I'll create a new version and update README.md accordingly.

@bebraw
Copy link
Author

bebraw commented Jan 15, 2014

@asafdav Seems to work! Thanks a lot. :)

@asafdav
Copy link
Owner

asafdav commented Jan 15, 2014

Awesome! Thanks for the follow up!

On Wed, Jan 15, 2014 at 2:46 PM, Juho Vepsäläinen
notifications@github.comwrote:

@asafdav https://github.com/asafdav Seems to work! Thanks a lot. :)


Reply to this email directly or view it on GitHubhttps://github.com//issues/7#issuecomment-32358313
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants