-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject_QuoteAPITwitterButton.html
More file actions
160 lines (116 loc) · 4.43 KB
/
Project_QuoteAPITwitterButton.html
File metadata and controls
160 lines (116 loc) · 4.43 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
<!doctype html>
<head>
<script src="https://code.jquery.com/jquery-2.2.0.min.js"></script>
<!--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">-->
<!--<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>-->
<script>
window.twttr = (function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0],
t = window.twttr || {};
if (d.getElementById(id)) return t;
js = d.createElement(s);
js.id = id;
js.src = "https://platform.twitter.com/widgets.js";
fjs.parentNode.insertBefore(js, fjs);
t._e = [];
t.ready = function(f) {
t._e.push(f);
};
return t;
}(document, "script", "twitter-wjs"));
</script>
<style>
html {
background: url(airBalloonBackground.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
#main {
/*position: absolute;*/
/*opacity: 0.3;*/
}
</style>
</head>
<body>
<div class="container-fluid" id="main">
<div class="row text-center">
<h2>Random Quote Generator</h2>
</div>
<div class="row text-center">
<div class="col-xs-12 well message">
The message will go here
</div>
</div>
<div class="row text-center">
<div class="col-xs-12">
<button id="getMessage" class="btn btn-primary">Get me a quote!</button>
</div>
</div>
</div>
<p></p>
<!--<script src="lib1.js"></script>
<script src="lib2.js"></script>
<script src="appWithIIFEModulizeGreet.js"></script>-->
<!--<script src="CaesarsCipher.js"></script>-->
<!--<script src="app.js"></script>-->
<script>
$(document).ready(function() {
var quote = 'defaultValue';
function getJoke() {
$.ajax({
url: "http://api.icndb.com/jokes/random",
// data: data,
success: function(json) {
$(".message").html(json.value.joke);
},
dataType: "json"
});
}
function htmlToString(string) {
var element = document.createElement("div");
element.setAttribute('id','temp');
element.innerHTML = string;
var formattedString = element.innerText;
return formattedString;
}
function getQuote() {
var quote;
$.ajax({
url: "https://crossorigin.me/http://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1&callback=",
dataType: "json",
success: function(json) {
$(".message").html(json[0].content + json[0].title);
quote = {quote:json[0].content, author:json[0].title};
//clean up quote string
// var n1 = quote.quote.search("<p>");
// var n2 = quote.quote.search("</p>");
// quote.quote = quote.quote.slice((n1 +3), n2);
quote.quote = htmlToString(quote.quote);
// Clear out previous button if it exists
var elem = document.getElementsByTagName('iframe')[1];
if (elem != null) {
elem.parentNode.removeChild(elem);
}
//create twitter button
var link = document.createElement('a');
link.setAttribute('href', 'https://twitter.com/share');
link.setAttribute('class', 'twitter-share-button');
link.setAttribute('style', 'margin-top:5px;');
link.setAttribute('id', 'twitterbutton');
link.setAttribute("data-text" , quote.quote + " -" + quote.author);
// link.setAttribute("data-via" ,"denvycom") ;
link.setAttribute("data-size" ,"large") ;
document.body.appendChild(link) ;
setTimeout(function(){twttr.widgets.load();}, 0000);
}
});
}
$.ajaxSetup({ cache: false });
getQuote();
$("#getMessage").on("click", function() { getQuote()});
});
</script>
</body>
</html>