-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
122 lines (117 loc) · 3.58 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>quote</title>
<link rel="stylesheet" href="libs/font-awesome.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="quote-box">
<div class="quote-text">
<i class="fa fa-quote-left"></i>
<span id="text">
<!-- -->
</span>
</div>
<div class="quote-author">
- <span id="author">
<!-- -->
</span>
</div>
<div class="buttons">
<a href="" class="button" id="tweet-quote" title="Tweet this quote!" target="_blank">
<i class="fa fa-twitter"></i>
</a>
<a href="" class="button" id="tumblr-quote" title="Post this quote on tumblr!" target="_blank">
<i class="fa fa-tumblr"></i>
</a>
<button class="button" id="new-quote">New quote</button>
</div>
</div>
<div class="footer"> by <a href="#">allen</a></div>
<!-- js -->
<!-- <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script> -->
<script type="text/javascript" src="libs/jquery.js"></script>
<script type="text/javascript" src="libs/jquery-ui.js"></script>
<script type="text/javascript">
// 当前窗口是否在iframe内部
function inIframe() {
try {
return window.self !== window.top;
} catch (e) {
return true;
}
}
// color Array
var colors = ['#16a085', '#27ae60', '#2c3e50', '#f39c12', '#e74c3c', '#9b59b6', '#FB6964', '#342224', "#472E32", "#BDBB99", "#77B1A9", "#73A857"];
//
var currentQuote = '',
currentAuthor = '';
//
function openURL(url) {
window.open(url, 'Share', 'width=550, height=400, toolbar=0, scrollbars=1 ,location=0 ,statusbar=0,menubar=0, resizable=0');
}
//
function getQuote() {
$.ajax({
headers: {
"X-Mashape-Key": "OivH71yd3tmshl9YKzFH7BTzBVRQp1RaKLajsnafgL2aPsfP9V",
Accept: "application/json",
"Content-Type": "application/x-www-form-urlencoded"
},
url: 'https://andruxnet-random-famous-quotes.p.mashape.com/cat=',
success: function (data) {
console.log(data);
if (typeof data === "string") {
data = JSON.parse(data);
}
currentQuote = data.quote;
currentAuthor = data.author;
/*if (inIframe()) {
}*/
//
$(".quote-text").animate({
opacity: 0
}, 500, function () {
$(this).animate({
opacity: 1
}, 500);
$("#text").text(currentQuote);
})
$(".quote-author").animate({
opacity: 0
}, 500, function () {
$(this).animate({
opacity: 1
}, 500);
$("#author").text(currentAuthor);
})
// 通过animate实现颜色渐变 需要jquery ui支持
var color = Math.floor(Math.random() * colors.length);
$("body").animate({
backgroundColor: colors[color],
color: colors[color]
}, 1000);
$(".button").animate({
backgroundColor: colors[color]
}, 1000);
}
})
}
$(function () {
getQuote();
$("#new-quote").click(function () {
getQuote();
});
$("#tweet-quote").click(function () {
openURL('https://twitter.com/intent/tweet?hashtags=quotes&related=freecodecamp&text=' + currentQuote + ' ' + currentAuthor);
});
$("#tumblr-quote").click(function () {
openURL('https://www.tumblr.com/widgets/share/tool?posttype=quote&tags=quotes,freecodecamp&caption=' + encodeURIComponent(currentAuthor) + '&content=' + encodeURIComponent(currentQuote) + '&canonicalUrl=https%3A%2F%2Fwww.tumblr.com%2Fbuttons&shareSource=tumblr_share_button');
})
})
</script>
</body>
</html>