-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlike_iframe.html
More file actions
executable file
·209 lines (179 loc) · 8.51 KB
/
like_iframe.html
File metadata and controls
executable file
·209 lines (179 loc) · 8.51 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<!DOCTYPE html>
<!-- saved from url=(0155)https://assets.tumblr.com/assets/html/like_iframe.html?_v=c301660e229be2b44e2e912486577f3c#name=meteroi&post_id=72088597300&rk=4np852c2&root_id=72088597300 -->
<html><script id="tinyhippos-injected">if (window.top.ripple) { window.top.ripple("bootstrap").inject(window, document); }</script><!--<![endif]--><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Tumblr</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
html, body {
width: 100%;
height: 100%;
}
#like_wrapper {
height: 100%;
width: 100%;
}
#like {
display: block;
width: 100%;
height: 100%;
cursor: default;
}
#like svg {
fill: #ccc;
}
.white #like svg {
fill: #fff;
}
.black #like svg {
fill: #000;
}
#like.liked svg {
fill: #d75f45;
}
#like.show {
opacity: 1;
}
.no_svg #like {
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/iframe_like_big_default.png', sizingMethod='scale');
}
.no_svg .white #like {
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/iframe_like_big_white.png', sizingMethod='scale');
}
.no_svg .black #like {
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/iframe_like_big_black.png', sizingMethod='scale');
}
.no_svg #like.liked {
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/iframe_like_big_red.png', sizingMethod='scale');
}
</style>
</head>
<body>
<div id="like_wrapper">
<a href="https://www.tumblr.com/register?redirect_to=http%3A%2F%2Fmeteroi.com%2F" id="like" target="_top" onclick="return false;" class="show" style="cursor: pointer;">
<svg width="100%" height="100%" viewBox="0 0 19 16" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" fill="#000000"><path d="M14.0425097,0.000920262799 C16.1435097,-0.0400797372 18.8835097,1.28192026 18.9635097,5.36992026 C19.0525097,9.95492026 15.1985097,13.3079203 9.48350967,16.2089203 C3.76650967,13.3079203 -0.0874903349,9.95492026 0.00150966509,5.36992026 C0.0815096651,1.28192026 2.82150967,-0.0400797372 4.92250967,0.000920262799 C7.02450967,0.0419202628 8.87050967,2.26592026 9.46950967,2.92792026 C10.0945097,2.26592026 11.9405097,0.0419202628 14.0425097,0.000920262799 Z"></path></svg>
</a>
</div>
<script type="text/javascript">
var state = '';
var form_key = '';
var post_id = '';
var reblog_key = '';
var root_id = '';
var like = document.getElementById('like');
function is_logged_in() {
return (document.cookie.indexOf('logged_in=1') != -1);
}
function setup_listener(callback){
callback = callback || function(){};
// http://davidwalsh.name/window-iframe
// Create IE + others compatible event handler
var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
var eventer = window[eventMethod];
var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message";
// Listen to message from child window
eventer(messageEvent,function(e) {
var message = e.data.split(';');
callback(message, e.origin);
},false);
}
function getVars() {
var get_vars = {};
window.location.hash.replace(
/[#?&]+([^=&]+)(=[^&]*)?/gi,
function(m, key, value){
get_vars[key] = (value === undefined) ? true : value.substring(1);
}
);
return get_vars;
}
function setup_variables() {
var vars = getVars();
if (vars['post_id']) post_id = vars['post_id'];
if (vars['rk']) reblog_key = vars['rk'];
if (vars['root_id']) root_id = vars['root_id'];
if (vars['color']) {
if (vars['color'] == 'white') {
document.getElementById('like_wrapper').className = 'white';
} else if (vars['color'] == 'black') {
document.getElementById('like_wrapper').className = 'black';
}
}
}
// Transition unload -- Supresses iframe white flash
window.onbeforeunload = function(){
if (window !== parent) parent.postMessage('location_change' + ';' + document.location.protocol + '//' + document.location.host,
document.referrer);
};
function like_post() {
var action = (state === 'liked') ? 'unlike' : 'like';
var data = action + ';' + JSON.stringify({post_id: post_id, reblog_key: reblog_key, root_id: root_id});
var iframe_count = window.parent.frames.length;
for (var i = 0; i<iframe_count; i++) {
try {
if (window.parent.frames[i] !== window) window.parent.frames[i].postMessage(data, '*');
} catch (e) {
// do nothing
}
}
}
function update_status() {
like.className = (state === 'liked') ? 'show liked' : 'show';
var msg = "tumblelog_like;" + post_id + ";" + state;
window.parent.postMessage(msg, document.referrer);
}
function setup_state() {
like.style.cursor = "pointer";
like.onclick = function(e) {
like_post();
return false;
}
update_status();
}
function recieve_data(message, origin) {
if (message[0] === "state_update") {
var data = JSON.parse(message[1]);
if (typeof(data) === "object") {
if (data.length) {
data.forEach(function(d) {
// Doing a non-strict check on ids, this is on
// purpose because sometimes it appears to return
// a string and not a number.
if (d.post_id == post_id) {
state = (d.state) ? 'liked' : 'unliked';
setup_state();
}
});
} else {
// Non-strict check.
if (data.post_id == post_id) {
state = (data.state) ? 'liked' : 'unliked';
setup_state();
}
}
}
}
}
window.onload = function() {
if (post_id) {
var data = 'like_iframe_load;' + JSON.stringify({post_id: post_id});
window.parent.postMessage(data, '*');
}
}
// Set up variables -- logged out user should still pick up color settings.
setup_variables();
// don't setup the click events if they are not logged in
if (is_logged_in()) {
setup_listener(recieve_data);
} else {
// logged out and doesn't care about state
var path = (document.cookie.indexOf('logged_in') != -1) ? '/login?' : '/register?';
like.href = "https://www.tumblr.com" + path + 'redirect_to=' + encodeURIComponent(document.referrer);
like.onclick = function() { return true; };
like.style.cursor = "pointer";
like.className = 'show';
}
</script>
</body></html>