From 74e7eef8a5ee8552d98766fd808d20475b1a8d7a Mon Sep 17 00:00:00 2001 From: Patrick Mowrer Date: Wed, 17 Dec 2014 12:49:00 -0500 Subject: [PATCH] Replace ng-clip.js symlink with actual file. The symlink doesn't come down with the bower download. It also appears to be more trouble than its worth in terms of versioning since dest/ng-clip.js would always point to the latest code. If a build/version-bump isn't performed for every single ng-clip.js commit, it would come out sync with ng-clip.min.js. --- dest/ng-clip.js | 85 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) mode change 120000 => 100644 dest/ng-clip.js diff --git a/dest/ng-clip.js b/dest/ng-clip.js deleted file mode 120000 index aac918d..0000000 --- a/dest/ng-clip.js +++ /dev/null @@ -1 +0,0 @@ -../src/ngClip.js \ No newline at end of file diff --git a/dest/ng-clip.js b/dest/ng-clip.js new file mode 100644 index 0000000..e92a426 --- /dev/null +++ b/dest/ng-clip.js @@ -0,0 +1,84 @@ +/*jslint node: true */ +/*global ZeroClipboard */ + +(function(window, angular, undefined) { + 'use strict'; + + angular.module('ngClipboard', []). + provider('ngClip', function() { + var self = this; + this.path = '//cdnjs.cloudflare.com/ajax/libs/zeroclipboard/2.1.6/ZeroClipboard.swf'; + return { + setPath: function(newPath) { + self.path = newPath; + }, + setConfig: function(config) { + self.config = config; + }, + $get: function() { + return { + path: self.path, + config: self.config + }; + } + }; + }). + run(['ngClip', function(ngClip) { + var config = { + swfPath: ngClip.path, + trustedDomains: ["*"], + allowScriptAccess: "always", + forceHandCursor: true, + }; + ZeroClipboard.config(angular.extend(config,ngClip.config || {})); + }]). + directive('clipCopy', ['ngClip', function (ngClip) { + return { + scope: { + clipCopy: '&', + clipClick: '&', + clipClickFallback: '&' + }, + restrict: 'A', + link: function (scope, element, attrs) { + // Bind a fallback function if flash is unavailable + if (ZeroClipboard.isFlashUnusable()) { + element.bind('click', function($event) { + // Execute the expression with local variables `$event` and `copy` + scope.$apply(scope.clipClickFallback({ + $event: $event, + copy: scope.$eval(scope.clipCopy) + })); + }); + + return; + } + + // Create the client object + var client = new ZeroClipboard(element); + if (attrs.clipCopy === "") { + scope.clipCopy = function(scope) { + return element[0].previousElementSibling.innerText; + }; + } + client.on( 'ready', function(readyEvent) { + + client.on('copy', function (event) { + var clipboard = event.clipboardData; + clipboard.setData(attrs.clipCopyMimeType || 'text/plain', scope.$eval(scope.clipCopy)); + }); + + client.on( 'aftercopy', function(event) { + if (angular.isDefined(attrs.clipClick)) { + scope.$apply(scope.clipClick); + } + }); + + scope.$on('$destroy', function() { + client.destroy(); + }); + }); + } + }; + }]); +})(window, window.angular);