Skip to content

Commit

Permalink
Merge pull request #31 from jico/use-strict-scope
Browse files Browse the repository at this point in the history
Wrap module in a closure
  • Loading branch information
asafdav committed Jul 22, 2014
2 parents 3a284a9 + 1f6dfbf commit cde01e9
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 59 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ng-clip",
"version": "0.2.1",
"version": "0.2.2",
"main": "dest/ng-clip.min.js",
"dependencies": {
"angular": ">=1.0.4",
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngClip",
"version": "0.1.4",
"version": "0.2.2",
"dependencies": {},
"devDependencies": {
"grunt": "~0.4.1",
Expand All @@ -26,11 +26,11 @@
"connect-livereload": "~0.2.0",
"grunt-google-cdn": "~0.2.0",
"grunt-ngmin": "~0.0.2",
"karma": "~0.9",
"karma-jasmine": "~0.0.3",
"karma-chrome-launcher": "~0.0.2"
"karma": "~0.12.0",
"karma-jasmine": "~0.1.5",
"karma-chrome-launcher": "~0.1.4"
},
"engines": {
"node": ">=0.8.0"
}
}
}
109 changes: 56 additions & 53 deletions src/ngClip.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,65 @@
/*jslint node: true */
/*global ZeroClipboard */
'use strict';

angular.module('ngClipboard', []).
provider('ngClip', function() {
var self = this;
this.path = '//cdnjs.cloudflare.com/ajax/libs/zeroclipboard/2.1.1/ZeroClipboard.swf';
return {
setPath: function(newPath) {
self.path = newPath;
},
$get: function() {
return {
path: self.path
};
}
};
}).
run(['ngClip', function(ngClip) {
ZeroClipboard.config({
swfPath: ngClip.path,
trustedDomains: ["*"],
allowScriptAccess: "always",
forceHandCursor: true
});
}]).
directive('clipCopy', ['ngClip', function (ngClip) {
return {
scope: {
clipCopy: '&',
clipClick: '&'
},
restrict: 'A',
link: function (scope, element, attrs) {
// Create the client object
var client = new ZeroClipboard(element);
if (attrs.clipCopy === "") {
scope.clipCopy = function(scope) {
return element[0].previousElementSibling.innerText;
(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.1/ZeroClipboard.swf';
return {
setPath: function(newPath) {
self.path = newPath;
},
$get: function() {
return {
path: self.path
};
}
client.on( 'ready', function(readyEvent) {
};
}).
run(['ngClip', function(ngClip) {
ZeroClipboard.config({
swfPath: ngClip.path,
trustedDomains: ["*"],
allowScriptAccess: "always",
forceHandCursor: true
});
}]).
directive('clipCopy', ['ngClip', function (ngClip) {
return {
scope: {
clipCopy: '&',
clipClick: '&'
},
restrict: 'A',
link: function (scope, element, attrs) {
// 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('text/plain', scope.$eval(scope.clipCopy));
});
client.on('copy', function (event) {
var clipboard = event.clipboardData;
clipboard.setData('text/plain', scope.$eval(scope.clipCopy));
});

client.on( 'aftercopy', function(event) {
if (angular.isDefined(attrs.clipClick)) {
scope.$apply(scope.clipClick);
}
});
client.on( 'aftercopy', function(event) {
if (angular.isDefined(attrs.clipClick)) {
scope.$apply(scope.clipClick);
}
});

scope.$on('$destroy', function() {
client.destroy();
scope.$on('$destroy', function() {
client.destroy();
});
});
});
}
};
}]);
}
};
}]);
})(window, window.angular);

0 comments on commit cde01e9

Please sign in to comment.