-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread.html
More file actions
164 lines (162 loc) · 8.46 KB
/
Copy pathread.html
File metadata and controls
164 lines (162 loc) · 8.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<!DOCTYPE html>
<html>
<head>
<meta charset="utf8">
<script src="vue.js"></script>
<script src="jquery-3.3.1.min.js"></script>
<script src="https://trello.com/1/client.js?key=ce77e6af1371cfb41f4a8e8840d76f4c"></script>
<script src="date.format.js"></script>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script><!--引入MarkDown渲染引擎-->
<script src="common.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="page" class="page">
<div class="article" v-if="memberCreatorFullName">
<div style="display: flex; justify-content: space-between; align-items: center">
<p class="page-title">{{name}}</p>
<!--登录信息-->
<div class="user-info" v-if="authorized"><img :src="user_info.avatarUrl+'/50.png'"/><a class="article-info" style="padding-left:10px">{{user_info.fullName}}</a></div>
<button v-else v-on:click="authorize()">用Trello账户登录</button>
</div>
<div class="article-info">
<img class="avatar" v-bind:src="memberCreatorAvatar"/>
<a style="margin:10px">{{memberCreatorFullName}}</a>
<a class="shallow_text">{{created_date}}</a>
</div>
<div v-html="compiledMarkdown"></div>
<div class="comments">
<p class="comments-title">评论 共{{comments.length}}条</p>
<div>
<textarea id="comment-textarea" placeholder="支持用markdown写评论" v-on:input="onTextareaInput"></textarea>
<button v-on:click="onPostComment">{{authorized ? "发布评论" : "登录并发布评论"}}</button>
</div>
<!--a :href="link" style="display: block;margin-bottom: 10px">在Trello上发表评论</a-->
<div class="comment" v-for="c in comments">
<div class="article-info">
<img class="avatar" v-bind:src="c.memberCreator.avatarUrl+'/30.png'"/>
<a style="margin:10px">{{c.memberCreator.fullName}}</a>
<a class="shallow_text">{{new Date(c.date).format("Y年m月d日 H:i")}}</a>
</div>
<div v-html="c.compiledMarkdown"></div>
</div>
</div>
</div>
</div>
<script>
var app = new Vue({
el: "#page",
data: {
card_id: "",
memberCreatorFullName: "",
memberCreatorAvatar: "",
created_date: "",
comments: new Array(), // 评论
name: "",
desc: "",
link: "", // 对应卡片的link
isMobile: false,
authorized: false,
user_info: {},
document: document, // document对象
textarea: null
},
computed: {
compiledMarkdown: function(){
return marked(this.desc, {});
},
},
created: function(){
if(localStorage["trello_token"]!=undefined) // 曾经主动登录过,尝试自动登录
{
this.authorize();
}
var addr = new URL(window.location.href);
var id = addr.searchParams.get("card_id");
//if(navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|wOSBrowser|BrowserNG|WebOS)/i)) this.isMobile = true;
if(id == undefined) window.location = "index.html";
console.log(id);
this.card_id = id;
this.textarea = document.getElementById("comment-textarea");
this.refresh();
},
methods: {
refresh() { // 页面内全部刷新,但是不是浏览器意义上的刷新
var that = this;
original = window.Trello.get("boards/zqJHbNrr/cards/"+this.card_id+"?actions=createCard,commentCard");
original.fail(function(data){window.location = "index.html"}); // 失败的处理机制
original.done(
function(data){
console.log(data);
that.comments = new Array();
that.link = data.url;
var ex = "[在Trello上阅读此文章]("+that.link+")\n\n";
that.desc = ex+data.desc;
that.name = data.name;
that.memberCreatorFullName = data.actions[data.actions.length-1].memberCreator.fullName;
that.memberCreatorAvatar = data.actions[data.actions.length-1].memberCreator.avatarUrl+"/30.png";
that.created_date = new Date(1000*parseInt(that.card_id.substring(0,8),16)).format("Y年m月d日 H:i");
for(var i=0;i<=data.actions.length-2;++i) { // 从最晚到最早的评论排序
data.actions[i].compiledMarkdown = marked(data.actions[i].data.text);
that.comments.push(data.actions[i]); // 其他actions都是comments
}
}
)
},
authorize(suc=null) {
var that = this;
Trello.authorize({
expiration: "never",
type: "popup",
name: "KenCloud",
scope: { read: true, write: true},
success() {
console.log(Trello.token(),Trello.authorized())
console.log(localStorage);
that.authorized = true;
Trello.get("tokens/"+Trello.token()+"/member", function(dat){
console.log("info of token:",dat)
that.user_info = dat;
if(suc!=null) suc(); // 回调成功函数
})
}
})
},
onTextareaInput(e) { // 设置自动伸缩高度
$('textarea').each(function () {
this.setAttribute('style', 'height:' + (this.scrollHeight) + 'px;overflow-y:hidden;');
}).on('input', function () {
this.style.height = 'auto';
this.style.height = (this.scrollHeight) + 'px';
});
}
,
postComment(suc=null) {
var value = document.getElementById("comment-textarea").value;
const link = "cards/"+this.card_id+"/actions/comments";
console.log("valueis:",value, "linkis:",link);
if(!value) return;
var that = this;
var t = Trello.post(link, {text: value}, function(){
that.refresh();
this.textarea.value = "";
if(suc!=null) suc(); // 回调成功函数
})
console.log(t);
},
onPostComment() {
var that = this;
if(this.authorized) {
this.postComment(function(){console.log("comment successful")})
}
else {
this.authorize(function(){
that.postComment(function(){console.log("comment successful")})
})
}
}
}
})
</script>
</body>
</html>