修复复制文本失败问题

This commit is contained in:
luchenqun 2018-03-28 16:48:14 +08:00
parent ed4697256c
commit ea7cd1447f
9 changed files with 35 additions and 59 deletions

View File

@ -26,6 +26,20 @@
<link href="/css/externe/ngDialog-theme-plain.css" rel="stylesheet"> <link href="/css/externe/ngDialog-theme-plain.css" rel="stylesheet">
<link href="/css/externe/medium-editor.css" rel="stylesheet"> <link href="/css/externe/medium-editor.css" rel="stylesheet">
<base href="/"> <base href="/">
<script type="text/javascript">
window.onload = function() {
var clipboard = new ClipboardJS(document.getElementById('clipboard'));
clipboard.on('success', function(e) {
var text = e.text.length >= 180 ? e.text.substr(0, 180) + '...' : e.text;
toastr.success(text + '<br/>已复制到您的剪切板', "提示");
e.clearSelection();
});
clipboard.on('error', function(e) {
var text = e.text.length >= 180 ? e.text.substr(0, 180) + '...' : e.text;
toastr.error(text + '<br/>复制失败', "提示");
});
}
</script>
</head> </head>
<body ng-app="bookmarkApp"> <body ng-app="bookmarkApp">
<div class="ui container"> <div class="ui container">
@ -39,7 +53,10 @@
<div class="foot" style="margin-bottom:10px;"> <div class="foot" style="margin-bottom:10px;">
<div class="ui segment container"> <div class="ui segment container">
我爱佳佳与这个世界&nbsp;&nbsp;|&nbsp;&nbsp;Copyleft ©All Rights Reserved LCQ&nbsp;&nbsp;|&nbsp;&nbsp;联系我(QQ:530485521)&nbsp;&nbsp;|&nbsp;&nbsp;<a href="https://github.com/luchenqun/my-bookmark" target="_blank">网站源码</a>&nbsp;&nbsp;|&nbsp;&nbsp;V1.5.0&nbsp;&nbsp;|&nbsp;&nbsp;<span>由于使用国外服务器如果加载失败请按F5你懂的(●'◡'●)</span><br/> 我爱佳佳与这个世界&nbsp;&nbsp;|&nbsp;&nbsp;Copyleft ©All Rights Reserved LCQ&nbsp;&nbsp;|&nbsp;&nbsp;联系我(QQ:530485521)&nbsp;&nbsp;|&nbsp;&nbsp;<a href="https://github.com/luchenqun/my-bookmark" target="_blank">网站源码</a>&nbsp;&nbsp;|&nbsp;&nbsp;V1.5.0&nbsp;&nbsp;|&nbsp;&nbsp;<span>由于使用国外服务器如果加载失败请按F5你懂的(●'◡'●)</span><br/>
由于<a href="https://github.com/shadowsocks/shadowsocks/issues" target="_blank">众所周知</a>的原因,最近网站访问不稳定。请大家在设置里面备份一下书签,以防无法访问的时候可以用浏览器书签代替使用。 </div>
<!-- 主要用来配合clipboard.min.js复制文本的 -->
<div id="clipboard" data-clipboard-text="i love this world and jiajia!" style="opacity:0;cursor:default">
<span>Copy</span>
</div> </div>
</div> </div>
<!-- directive书签编辑 --> <!-- directive书签编辑 -->

View File

@ -49,14 +49,7 @@ app.controller('bookmarkInfoCtr', ['$scope', '$state', '$timeout', '$sce', '$win
} }
$scope.copy = function(url) { $scope.copy = function(url) {
clipboard.copy(url).then( dataService.clipboard(url);
function() {
toastr.success(url + '<br/>已复制到您的剪切板', "提示");
},
function(err) {
toastr.error(url + '<br/>复制失败', "提示");
}
);
} }
$document.bind("keydown", function(event) { $document.bind("keydown", function(event) {

View File

@ -124,14 +124,7 @@ app.controller('bookmarksCtr', ['$scope', '$state', '$stateParams', '$filter', '
} }
$scope.copy = function(url) { $scope.copy = function(url) {
clipboard.copy(url).then( dataService.clipboard(url);
function() {
toastr.success(url + '<br/>已复制到您的剪切板', "提示");
},
function(err) {
toastr.error(url + '<br/>复制失败', "提示");
}
);
} }
$scope.jumpToTags = function(tagId) { $scope.jumpToTags = function(tagId) {

View File

@ -77,14 +77,7 @@ app.controller('hotCtr', ['$scope', '$state', '$stateParams', '$filter', '$windo
} }
$scope.copy = function(url) { $scope.copy = function(url) {
clipboard.copy(url).then( dataService.clipboard(url);
function() {
toastr.success(url + '<br/>已复制到您的剪切板', "提示");
},
function(err) {
toastr.error(url + '<br/>复制失败', "提示");
}
);
} }
$scope.detailBookmark = function(b) { $scope.detailBookmark = function(b) {

View File

@ -134,15 +134,7 @@ app.controller('noteCtr', ['$scope', '$state', '$stateParams', '$filter', '$wind
} }
$scope.copy = function(content) { $scope.copy = function(content) {
var showContent = content.length >= 180 ? content.substr(0, 180) + '...' : content; dataService.clipboard(content);
clipboard.copy(content).then(
function() {
toastr.success(showContent + '<br/>已复制到您的剪切板', "提示");
},
function(err) {
toastr.error(showContent + '<br/>复制失败', "提示");
}
);
} }
$scope.delNote = function(id, content) { $scope.delNote = function(id, content) {

View File

@ -144,14 +144,7 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
} }
$scope.copy = function(url) { $scope.copy = function(url) {
clipboard.copy(url).then( dataService.clipboard(url);
function() {
toastr.success(url + '<br/>已复制到您的剪切板', "提示");
},
function(err) {
toastr.error(url + '<br/>复制失败', "提示");
}
);
} }
$scope.search = function(page) { $scope.search = function(page) {

View File

@ -236,14 +236,7 @@ app.controller('tagsCtr', ['$scope', '$filter', '$window', '$stateParams', '$tim
} }
$scope.copy = function(url) { $scope.copy = function(url) {
clipboard.copy(url).then( dataService.clipboard(url);
function() {
toastr.success(url + '<br/>已复制到您的剪切板', "提示");
},
function(err) {
toastr.error(url + '<br/>复制失败', "提示");
}
);
} }
$scope.toggleMode = function() { $scope.toggleMode = function() {

File diff suppressed because one or more lines are too long

View File

@ -125,6 +125,10 @@ app.factory('dataService', [function() {
} }
return ret; return ret;
},
clipboard: function(text) {
$("#clipboard").attr("data-clipboard-text", text);
document.getElementById("clipboard").click();
} }
}; };