-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from jico/use-strict-scope
Wrap module in a closure
- Loading branch information
Showing
3 changed files
with
62 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |