Skip to content

Commit 219bece

Browse files
committed
Add the zero clipboard plugin to copy the word into the clipboard
1 parent fc29dc3 commit 219bece

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

app/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
<meta charset="UTF-8">
55
<title>Variables Library - Abstack Tech</title>
66
<link rel="stylesheet" href="styles/main.min.css">
7+
<script src="bower_components/zeroclipboard/dist/ZeroClipboard.min.js"></script>
78
<script src="bower_components/angularjs/angular.min.js"></script>
9+
<script src="bower_components/angular-zeroclipboard/src/angular-zeroclipboard.js"></script>
810
<script src="scripts/app.js"></script>
911
</head>
1012
<body ng-app="abstackVarLib" ng-controller="mainCtrl">
@@ -15,7 +17,7 @@
1517
<ul class="word-list ng-hide" ng-show="wordsList">
1618
<li ng-repeat="word in wordsList | keywords: keywords">
1719
<h3>
18-
<button class="btn-copy">COPY</button>
20+
<button class="btn-copy" ui-zeroclip zeroclip-model="word.word" zeroclip-copied="copiedWord(word)" ng-bind="word.copyTip || 'COPY'">COPY</button>
1921
<a target="_blank" ng-href="{{ word.url?word.url: 'http://www.dict.cn/' + word.word }}" ng-bind="word.word"></a>
2022
</h3>
2123
<span class="tag-box">

app/scripts/app.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
*
44
* Description: main
55
*/
6-
angular.module('abstackVarLib', [])
6+
angular.module('abstackVarLib', ['zeroclipboard'])
7+
.config(['uiZeroclipConfigProvider', function(uiZeroclipConfigProvider) {
8+
// config ZeroClipboard
9+
uiZeroclipConfigProvider.setZcConf({
10+
swfPath: '../bower_components/zeroclipboard/dist/ZeroClipboard.swf'
11+
});
12+
}])
713
.filter('keywords', function(){
814
return function(input, type){
915
if(!type)
@@ -18,7 +24,7 @@ angular.module('abstackVarLib', [])
1824
return temp;
1925
}
2026
})
21-
.controller('mainCtrl', ['$http', '$scope', function($http, $scope){
27+
.controller('mainCtrl', ['$timeout', '$http', '$scope', function($timeout, $http, $scope){
2228

2329
$http.get('/json/words.json')
2430
.success(function(data){
@@ -29,5 +35,10 @@ angular.module('abstackVarLib', [])
2935
$scope.keywords = tag;
3036
}
3137

32-
38+
$scope.copiedWord = function(word){
39+
word.copyTip = 'COPIED !';
40+
$timeout(function(){
41+
delete word.copyTip;
42+
}, 1500);
43+
}
3344
}]);

app/styles/main.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ only screen and (min-device-pixel-ratio: 2){
113113
border-left: 1px solid #49b3d9;
114114
cursor: pointer;
115115
outline: none;
116-
&:hover{
116+
&.zeroclipboard-is-hover{
117117
background-color: @main-color;
118118
}
119119
}

bower.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"tests"
2525
],
2626
"dependencies": {
27-
"angularjs": "1.2.27"
27+
"angularjs": "1.2.27",
28+
"angular-zeroclipboard": "~0.3.2"
2829
}
2930
}

0 commit comments

Comments
 (0)