From 6b5f10b1c402134a6d11e8616262ee284415bbf4 Mon Sep 17 00:00:00 2001 From: luchenqun Date: Sun, 11 Jun 2017 14:42:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E5=A4=8D=E5=88=B6=E6=96=87?= =?UTF-8?q?=E5=AD=97=E7=9A=84=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/bookmark-info-controller.js | 23 ++++++---------- .../controllers/bookmarks-controller.js | 23 ++++++---------- public/scripts/controllers/hot-controller.js | 23 ++++++---------- public/scripts/controllers/note-controller.js | 26 +++++++------------ .../scripts/controllers/search-controller.js | 23 ++++++---------- public/scripts/controllers/tags-controller.js | 25 +++++++----------- public/scripts/externe/clipboard.min.js | 16 +++++++----- public/views/bookmark-info.html | 2 +- public/views/bookmarks.html | 4 +-- public/views/hot.html | 2 +- public/views/note.html | 5 ++-- public/views/search.html | 2 +- public/views/tags.html | 2 +- 13 files changed, 68 insertions(+), 108 deletions(-) diff --git a/public/scripts/controllers/bookmark-info-controller.js b/public/scripts/controllers/bookmark-info-controller.js index 056eb3e..c7e9c93 100644 --- a/public/scripts/controllers/bookmark-info-controller.js +++ b/public/scripts/controllers/bookmark-info-controller.js @@ -48,22 +48,15 @@ app.controller('bookmarkInfoCtr', ['$scope', '$state', '$timeout', '$sce', '$win } } - $scope.copy = function(id, url) { - var clipboard = new Clipboard('#detailurl' + id, { - text: function() { - return url; + $scope.copy = function(url) { + clipboard.copy(url).then( + function() { + toastr.success(url + '
已复制到您的剪切板', "提示"); + }, + function(err) { + toastr.error(url + '
复制失败', "提示"); } - }); - - clipboard.on('success', function(e) { - toastr.success(url + '
已复制到您的剪切板', "提示"); - clipboard.destroy(); - }); - - clipboard.on('error', function(e) { - toastr.error(url + '
复制失败', "提示"); - clipboard.destroy(); - }); + ); } $document.bind("keydown", function(event) { diff --git a/public/scripts/controllers/bookmarks-controller.js b/public/scripts/controllers/bookmarks-controller.js index fe1faea..fb16732 100644 --- a/public/scripts/controllers/bookmarks-controller.js +++ b/public/scripts/controllers/bookmarks-controller.js @@ -128,22 +128,15 @@ app.controller('bookmarksCtr', ['$scope', '$state', '$stateParams', '$filter', ' }); } - $scope.copy = function(id, url) { - var clipboard = new Clipboard('#url' + id, { - text: function() { - return url; + $scope.copy = function(url) { + clipboard.copy(url).then( + function() { + toastr.success(url + '
已复制到您的剪切板', "提示"); + }, + function(err) { + toastr.error(url + '
复制失败', "提示"); } - }); - - clipboard.on('success', function(e) { - toastr.success(url + '
已复制到您的剪切板', "提示"); - clipboard.destroy(); - }); - - clipboard.on('error', function(e) { - toastr.error(url + '
复制失败', "提示"); - clipboard.destroy(); - }); + ); } $scope.jumpToTags = function(tagId) { diff --git a/public/scripts/controllers/hot-controller.js b/public/scripts/controllers/hot-controller.js index 3f9455f..c4e6f93 100644 --- a/public/scripts/controllers/hot-controller.js +++ b/public/scripts/controllers/hot-controller.js @@ -74,22 +74,15 @@ app.controller('hotCtr', ['$scope', '$state', '$stateParams', '$filter', '$windo } } - $scope.copy = function(id, url) { - var clipboard = new Clipboard('#hoturl' + id, { - text: function() { - return url; + $scope.copy = function(url) { + clipboard.copy(url).then( + function() { + toastr.success(url + '
已复制到您的剪切板', "提示"); + }, + function(err) { + toastr.error(url + '
复制失败', "提示"); } - }); - - clipboard.on('success', function(e) { - toastr.success(url + '
已复制到您的剪切板', "提示"); - clipboard.destroy(); - }); - - clipboard.on('error', function(e) { - toastr.error(url + '
复制失败', "提示"); - clipboard.destroy(); - }); + ); } $scope.detailBookmark = function(b) { diff --git a/public/scripts/controllers/note-controller.js b/public/scripts/controllers/note-controller.js index 7f79ccb..af3bbe9 100644 --- a/public/scripts/controllers/note-controller.js +++ b/public/scripts/controllers/note-controller.js @@ -86,7 +86,7 @@ app.controller('noteCtr', ['$scope', '$state', '$stateParams', '$filter', '$wind bookmarkService.addNote(note) .then((data) => { console.log(JSON.stringify(data)); - if(data.retCode == 0){ + if (data.retCode == 0) { note.id = data.insertId; note.created_at = $filter('date')(new Date(), "yyyy-MM-dd HH:mm:ss"); note.name = ''; @@ -105,24 +105,16 @@ app.controller('noteCtr', ['$scope', '$state', '$stateParams', '$filter', '$wind }); } - $scope.copy = function(id, content) { - console.log("copy note....."); + $scope.copy = function(content) { var showContent = content.length >= 180 ? content.substr(0, 180) + '...' : content; - var clipboard = new Clipboard("#noteid" + id, { - text: function() { - return content; + clipboard.copy(showContent).then( + function() { + toastr.success(showContent + '
已复制到您的剪切板', "提示"); + }, + function(err) { + toastr.error(showContent + '
复制失败', "提示"); } - }); - - clipboard.on('success', function(e) { - toastr.success(showContent + '
已复制到您的剪切板', "提示"); - clipboard.destroy(); - }); - - clipboard.on('error', function(e) { - toastr.error(showContent + '
复制失败', "提示"); - clipboard.destroy(); - }); + ); } $scope.delNote = function(id, content) { diff --git a/public/scripts/controllers/search-controller.js b/public/scripts/controllers/search-controller.js index 76081be..d06c227 100644 --- a/public/scripts/controllers/search-controller.js +++ b/public/scripts/controllers/search-controller.js @@ -142,22 +142,15 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi }); } - $scope.copy = function(id, url) { - var clipboard = new Clipboard('#searchurl' + id, { - text: function() { - return url; + $scope.copy = function(url) { + clipboard.copy(url).then( + function() { + toastr.success(url + '
已复制到您的剪切板', "提示"); + }, + function(err) { + toastr.error(url + '
复制失败', "提示"); } - }); - - clipboard.on('success', function(e) { - toastr.success(url + '
已复制到您的剪切板', "提示"); - clipboard.destroy(); - }); - - clipboard.on('error', function(e) { - toastr.error(url + '
复制失败', "提示"); - clipboard.destroy(); - }); + ); } $scope.search = function(page) { diff --git a/public/scripts/controllers/tags-controller.js b/public/scripts/controllers/tags-controller.js index 33d6107..6d01339 100644 --- a/public/scripts/controllers/tags-controller.js +++ b/public/scripts/controllers/tags-controller.js @@ -195,22 +195,15 @@ app.controller('tagsCtr', ['$scope', '$filter', '$window', '$stateParams', '$tim }); } - $scope.copy = function(id, url) { - var clipboard = new Clipboard('#tagurl' + id, { - text: function() { - return url; + $scope.copy = function(url) { + clipboard.copy(url).then( + function() { + toastr.success(url + '
已复制到您的剪切板', "提示"); + }, + function(err) { + toastr.error(url + '
复制失败', "提示"); } - }); - - clipboard.on('success', function(e) { - toastr.success(url + '
已复制到您的剪切板', "提示"); - clipboard.destroy(); - }); - - clipboard.on('error', function(e) { - toastr.error(url + '
复制失败', "提示"); - clipboard.destroy(); - }); + ); } $scope.toggleMode = function() { @@ -426,6 +419,8 @@ app.controller('tagsCtr', ['$scope', '$filter', '$window', '$stateParams', '$tim $scope.detailBookmark($scope.hoverBookmark) } else if (key == 'D') { $scope.delBookmark($scope.hoverBookmark) + } else if (key == 'C') { + $scope.copy($scope.hoverBookmark.url) } } }) diff --git a/public/scripts/externe/clipboard.min.js b/public/scripts/externe/clipboard.min.js index 1993676..23376c1 100644 --- a/public/scripts/externe/clipboard.min.js +++ b/public/scripts/externe/clipboard.min.js @@ -1,7 +1,9 @@ -/*! - * clipboard.js v1.6.1 - * https://zenorocha.github.io/clipboard.js - * - * Licensed MIT © Zeno Rocha - */ -!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.Clipboard=e()}}(function(){var e,t,n;return function e(t,n,o){function i(a,c){if(!n[a]){if(!t[a]){var l="function"==typeof require&&require;if(!c&&l)return l(a,!0);if(r)return r(a,!0);var u=new Error("Cannot find module '"+a+"'");throw u.code="MODULE_NOT_FOUND",u}var s=n[a]={exports:{}};t[a][0].call(s.exports,function(e){var n=t[a][1][e];return i(n?n:e)},s,s.exports,e,t,n,o)}return n[a].exports}for(var r="function"==typeof require&&require,a=0;a0&&void 0!==arguments[0]?arguments[0]:{};this.action=t.action,this.emitter=t.emitter,this.target=t.target,this.text=t.text,this.trigger=t.trigger,this.selectedText=""}},{key:"initSelection",value:function e(){this.text?this.selectFake():this.target&&this.selectTarget()}},{key:"selectFake",value:function e(){var t=this,n="rtl"==document.documentElement.getAttribute("dir");this.removeFake(),this.fakeHandlerCallback=function(){return t.removeFake()},this.fakeHandler=document.body.addEventListener("click",this.fakeHandlerCallback)||!0,this.fakeElem=document.createElement("textarea"),this.fakeElem.style.fontSize="12pt",this.fakeElem.style.border="0",this.fakeElem.style.padding="0",this.fakeElem.style.margin="0",this.fakeElem.style.position="absolute",this.fakeElem.style[n?"right":"left"]="-9999px";var o=window.pageYOffset||document.documentElement.scrollTop;this.fakeElem.style.top=o+"px",this.fakeElem.setAttribute("readonly",""),this.fakeElem.value=this.text,document.body.appendChild(this.fakeElem),this.selectedText=(0,i.default)(this.fakeElem),this.copyText()}},{key:"removeFake",value:function e(){this.fakeHandler&&(document.body.removeEventListener("click",this.fakeHandlerCallback),this.fakeHandler=null,this.fakeHandlerCallback=null),this.fakeElem&&(document.body.removeChild(this.fakeElem),this.fakeElem=null)}},{key:"selectTarget",value:function e(){this.selectedText=(0,i.default)(this.target),this.copyText()}},{key:"copyText",value:function e(){var t=void 0;try{t=document.execCommand(this.action)}catch(e){t=!1}this.handleResult(t)}},{key:"handleResult",value:function e(t){this.emitter.emit(t?"success":"error",{action:this.action,text:this.selectedText,trigger:this.trigger,clearSelection:this.clearSelection.bind(this)})}},{key:"clearSelection",value:function e(){this.target&&this.target.blur(),window.getSelection().removeAllRanges()}},{key:"destroy",value:function e(){this.removeFake()}},{key:"action",set:function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"copy";if(this._action=t,"copy"!==this._action&&"cut"!==this._action)throw new Error('Invalid "action" value, use either "copy" or "cut"')},get:function e(){return this._action}},{key:"target",set:function e(t){if(void 0!==t){if(!t||"object"!==("undefined"==typeof t?"undefined":r(t))||1!==t.nodeType)throw new Error('Invalid "target" value, use a valid Element');if("copy"===this.action&&t.hasAttribute("disabled"))throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute');if("cut"===this.action&&(t.hasAttribute("readonly")||t.hasAttribute("disabled")))throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes');this._target=t}},get:function e(){return this._target}}]),e}();e.exports=c})},{select:5}],8:[function(t,n,o){!function(i,r){if("function"==typeof e&&e.amd)e(["module","./clipboard-action","tiny-emitter","good-listener"],r);else if("undefined"!=typeof o)r(n,t("./clipboard-action"),t("tiny-emitter"),t("good-listener"));else{var a={exports:{}};r(a,i.clipboardAction,i.tinyEmitter,i.goodListener),i.clipboard=a.exports}}(this,function(e,t,n,o){"use strict";function i(e){return e&&e.__esModule?e:{default:e}}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function c(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function l(e,t){var n="data-clipboard-"+e;if(t.hasAttribute(n))return t.getAttribute(n)}var u=i(t),s=i(n),f=i(o),d=function(){function e(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{};this.action="function"==typeof t.action?t.action:this.defaultAction,this.target="function"==typeof t.target?t.target:this.defaultTarget,this.text="function"==typeof t.text?t.text:this.defaultText}},{key:"listenClick",value:function e(t){var n=this;this.listener=(0,f.default)(t,"click",function(e){return n.onClick(e)})}},{key:"onClick",value:function e(t){var n=t.delegateTarget||t.currentTarget;this.clipboardAction&&(this.clipboardAction=null),this.clipboardAction=new u.default({action:this.action(n),target:this.target(n),text:this.text(n),trigger:n,emitter:this})}},{key:"defaultAction",value:function e(t){return l("action",t)}},{key:"defaultTarget",value:function e(t){var n=l("target",t);if(n)return document.querySelector(n)}},{key:"defaultText",value:function e(t){return l("text",t)}},{key:"destroy",value:function e(){this.listener.destroy(),this.clipboardAction&&(this.clipboardAction.destroy(),this.clipboardAction=null)}}],[{key:"isSupported",value:function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:["copy","cut"],n="string"==typeof t?[t]:t,o=!!document.queryCommandSupported;return n.forEach(function(e){o=o&&!!document.queryCommandSupported(e)}),o}}]),t}(s.default);e.exports=h})},{"./clipboard-action":7,"good-listener":4,"tiny-emitter":6}]},{},[8])(8)}); \ No newline at end of file +(function(f,c){"undefined"!==typeof module?module.exports=c():"function"===typeof define&&"object"===typeof define.amd?define(c):this[f]=c()})("clipboard",function(){if("undefined"===typeof document||!document.addEventListener)return null;var f={};f.copy=function(){function c(){d=!1;b=null;e&&window.getSelection().removeAllRanges();e=!1}var d=!1,b=null,e=!1;document.addEventListener("copy",function(c){if(d){for(var e in b)c.clipboardData.setData(e,b[e]);c.preventDefault()}});return function(g){return new Promise(function(k, +f){d=!0;b="string"===typeof g?{"text/plain":g}:g instanceof Node?{"text/html":(new XMLSerializer).serializeToString(g)}:g;try{var n=document.getSelection();if(!document.queryCommandEnabled("copy")&&n.isCollapsed){var l=document.createRange();l.selectNodeContents(document.body);n.addRange(l);e=!0}if(document.execCommand("copy"))c(),k();else throw Error("Unable to copy. Perhaps it's not available in your browser?");}catch(p){c(),f(p)}})}}();f.paste=function(){var c=!1,d,b;document.addEventListener("paste", +function(e){if(c){c=!1;e.preventDefault();var g=d;d=null;g(e.clipboardData.getData(b))}});return function(e){return new Promise(function(g,f){c=!0;d=g;b=e||"text/plain";try{document.execCommand("paste")||(c=!1,f(Error("Unable to paste. Pasting only works in Internet Explorer at the moment.")))}catch(m){c=!1,f(Error(m))}})}}();"undefined"===typeof ClipboardEvent&&"undefined"!==typeof window.clipboardData&&"undefined"!==typeof window.clipboardData.setData&&(function(c){function d(a,b){return function(){a.apply(b, +arguments)}}function b(a){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof a)throw new TypeError("not a function");this._value=this._state=null;this._deferreds=[];l(a,d(f,this),d(k,this))}function e(a){var b=this;return null===this._state?void this._deferreds.push(a):void p(function(){var c=b._state?a.onFulfilled:a.onRejected;if(null===c)return void(b._state?a.resolve:a.reject)(b._value);var h;try{h=c(b._value)}catch(d){return void a.reject(d)}a.resolve(h)})} +function f(a){try{if(a===this)throw new TypeError("A promise cannot be resolved with itself.");if(a&&("object"==typeof a||"function"==typeof a)){var b=a.then;if("function"==typeof b)return void l(d(b,a),d(f,this),d(k,this))}this._state=!0;this._value=a;m.call(this)}catch(c){k.call(this,c)}}function k(a){this._state=!1;this._value=a;m.call(this)}function m(){for(var a=0,b=this._deferreds.length;b>a;a++)e.call(this,this._deferreds[a]);this._deferreds=null}function n(a,b,c,h){this.onFulfilled="function"== +typeof a?a:null;this.onRejected="function"==typeof b?b:null;this.resolve=c;this.reject=h}function l(a,b,c){var h=!1;try{a(function(a){h||(h=!0,b(a))},function(a){h||(h=!0,c(a))})}catch(d){h||(h=!0,c(d))}}var p=b.immediateFn||"function"==typeof setImmediate&&setImmediate||function(a){setTimeout(a,1)},q=Array.isArray||function(a){return"[object Array]"===Object.prototype.toString.call(a)};b.prototype["catch"]=function(a){return this.then(null,a)};b.prototype.then=function(a,c){var d=this;return new b(function(b, +f){e.call(d,new n(a,c,b,f))})};b.all=function(){var a=Array.prototype.slice.call(1===arguments.length&&q(arguments[0])?arguments[0]:arguments);return new b(function(b,c){function d(e,g){try{if(g&&("object"==typeof g||"function"==typeof g)){var k=g.then;if("function"==typeof k)return void k.call(g,function(a){d(e,a)},c)}a[e]=g;0===--f&&b(a)}catch(l){c(l)}}if(0===a.length)return b([]);for(var f=a.length,e=0;ed;d++)a[d].then(b,c)})};"undefined"!=typeof module&&module.exports?module.exports=b:c.Promise||(c.Promise=b)}(this),f.copy=function(c){return new Promise(function(d,b){if("string"!==typeof c&&!("text/plain"in c))throw Error("You must provide a text/plain type.");window.clipboardData.setData("Text","string"===typeof c?c:c["text/plain"])?d():b(Error("Copying was rejected."))})}, +f.paste=function(){return new Promise(function(c,d){var b=window.clipboardData.getData("Text");b?c(b):d(Error("Pasting was rejected."))})});return f}); diff --git a/public/views/bookmark-info.html b/public/views/bookmark-info.html index b05f18b..8874825 100644 --- a/public/views/bookmark-info.html +++ b/public/views/bookmark-info.html @@ -14,7 +14,7 @@
- 网页地址{{bookmark.url}} + 网页地址{{bookmark.url}}
diff --git a/public/views/bookmarks.html b/public/views/bookmarks.html index 59b187b..9aa9105 100644 --- a/public/views/bookmarks.html +++ b/public/views/bookmarks.html @@ -99,7 +99,7 @@ - {{ bookmark.url }} + {{ bookmark.url }} {{ bookmark.click_count }} @@ -156,7 +156,7 @@
- +
diff --git a/public/views/hot.html b/public/views/hot.html index 138a621..f6b5d6b 100644 --- a/public/views/hot.html +++ b/public/views/hot.html @@ -19,7 +19,7 @@
- +
diff --git a/public/views/note.html b/public/views/note.html index 7037cd0..8f671d8 100644 --- a/public/views/note.html +++ b/public/views/note.html @@ -1,4 +1,4 @@ -