Skip to content

Commit 38b0904

Browse files
committed
feature: add config
1 parent ee120cd commit 38b0904

File tree

3 files changed

+80
-9
lines changed

3 files changed

+80
-9
lines changed

README.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,56 @@ bower install angular-zeroclipboard
1010

1111
or, you can download 'angular-zeroclipboard.js' form 'src' manualy
1212

13+
## Setup
1314

15+
#### sample
16+
17+
```
18+
angular.module('demo', ['angular.zeroclipboard']).
19+
config(['uiZeroclipConfigProvider', function(uiZeroclipConfigProvider) {
20+
21+
// config ZeroClipboard
22+
uiZeroclipConfigProvider.setZcConf({
23+
moviePath: '../bower_components/zeroclipboard/ZeroClipboard.swf'
24+
});
25+
26+
// set directive options
27+
uiZeroclipConfigProvider.setOptions({
28+
buttonText: 'Copy Me!'
29+
});
30+
31+
}]);
32+
```
33+
34+
35+
## Config
36+
37+
* `uiZeroclipConfigProvider.setZcConf({})` Config the ZeroClipboard
38+
39+
The params is an object. and just same as [ZeroClipboard official config](https://github.com/zeroclipboard/zeroclipboard/blob/1.x-master/docs/instructions.md)
40+
41+
* `uiZeroclipConfigProvider.setOptions()` Config this directive Config
42+
43+
```
44+
{
45+
// set the button class
46+
buttonClass: '',
47+
48+
// set button's Text
49+
buttonText: 'Copy',
50+
51+
// set the callback function of the events which ZeroClipboard dispataches
52+
load: null,
53+
mouseover: null,
54+
mouseout: null,
55+
mousedown: null,
56+
mouseup: null,
57+
complete: null,
58+
noflash: null,
59+
wrongflash: null,
60+
dataRequested: null
61+
}
62+
```
1463

1564
## LICENSE
1665

@@ -20,4 +69,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
2069

2170
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
2271

23-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
72+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

demo/demo.html

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,23 @@
44
<meta charset="UTF-8">
55
<title>Angular ZeroClipBoard</title>
66
<script src="../bower_components/angular/angular.js"></script>
7-
<script src="../bower_components/zeroclipboard/ZeroClipboard.js"></script>
7+
<script src="../bower_components/zeroclipboard/ZeroClipboard.min.js"></script>
88
<script src="../src/angular-zeroclipboard.js"></script>
99
<script>
1010
angular.module('demo', ['angular.zeroclipboard']).
11-
config(['uiZeroclipConfigProvider', function(uiZeroclip) {
11+
config(['uiZeroclipConfigProvider', function(uiZeroclipConfigProvider) {
1212

13-
}])
13+
// config ZeroClipboard
14+
uiZeroclipConfigProvider.setZcConf({
15+
moviePath: '../bower_components/zeroclipboard/ZeroClipboard.swf'
16+
});
17+
18+
// set directive options
19+
uiZeroclipConfigProvider.setOptions({
20+
buttonText: 'Copy Me!'
21+
});
22+
23+
}]);
1424
</script>
1525
</head>
1626
<body>

src/angular-zeroclipboard.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
angular.module('angular.zeroclipboard', []).provider('uiZeroclipConfig', function() {
2-
this.zeroclipConfig = {
2+
3+
// default configs
4+
var _zeroclipConfig = {
35
buttonClass: '',
4-
moviePath: "../bower_components/zeroclipboard/ZeroClipboard.swf",
6+
moviePath: "ZeroClipboard.swf",
57
trustedDomains: [window.location.host],
68
cacheBust: true,
79
forceHandCursor: false,
@@ -13,7 +15,7 @@ angular.module('angular.zeroclipboard', []).provider('uiZeroclipConfig', functio
1315
hoverClass: "zeroclipboard-is-hover",
1416
activeClass: "zeroclipboard-is-active"
1517
};
16-
this.options = {
18+
var _options = {
1719
buttonClass: '',
1820
buttonText: 'Copy',
1921
load: null,
@@ -26,11 +28,20 @@ angular.module('angular.zeroclipboard', []).provider('uiZeroclipConfig', functio
2628
wrongflash: null,
2729
dataRequested: null
2830
};
31+
32+
this.setZcConf = function(zcConf) {
33+
angular.extend(_zeroclipConfig, zcConf);
34+
};
35+
36+
this.setOptions = function(options) {
37+
angular.extend(_options, options);
38+
};
39+
2940
this.$get = ['$rootScope',
3041
function($rootScope) {
3142
return {
32-
zeroclipConfig: this.zeroclipConfig,
33-
options: this.options
43+
zeroclipConfig: _zeroclipConfig,
44+
options: _options
3445
}
3546
}
3647
];
@@ -56,6 +67,7 @@ directive('uiZeroclip', ['$document', '$window', 'uiZeroclipConfig',
5667
var btn = document.createElement('button');
5768
btn.appendChild(document.createTextNode(options.buttonText));
5869
btn.setAttribute('data-clipboard-target', 'uiZeroclip' + _id);
70+
btn.setAttribute('class', options.buttonClass);
5971
_id++;
6072
insertAfter(btn, elm[0]);
6173
copyBtns.push(btn);

0 commit comments

Comments
 (0)