-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathviral.html
More file actions
139 lines (125 loc) · 4.57 KB
/
viral.html
File metadata and controls
139 lines (125 loc) · 4.57 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
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>Viral OK widgets</title>
<style>
#WidgetOKHolder {
display: none;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
padding: 0;
margin: 0;
background-color: rgba(0, 0, 0, 0.25);
}
#WidgetOKHolder iframe {
display: block;
width: 90%;
height: 90%;
padding: 0;
margin: 0 auto;
margin-top: 5%;
border: 2px solid #a0a0a0;
}
</style>
</head>
<body>
<script type="text/javascript" src="//api.odnoklassniki.ru/js/fapi5.js" defer="defer"></script>
<script src="https://odnoklassniki.github.io/ok-js-sdk/oksdk.js"></script>
<script type="text/javascript">
WidgetOK = {
rParams: {},
hParams: {},
/* --- BEGIN your config --- */
appId: '1139348224',
returnUrl: '//apiok.github.io/js_sample_widgets/viral-cb.html',
/* --- END your config --- */
/** @public */
openInvite: function () {
WidgetOK.open('WidgetInvite');
},
/** @public */
openSuggest: function () {
WidgetOK.open('WidgetSuggest');
},
/** @public */
openMediatopicPost: function () {
WidgetOK.open('WidgetMediatopicPost', {
feed: '{"media": [{"type": "text", "text": "hello world!"}]}'
});
},
/** @private */
open: function (widget, args) {
var p = WidgetOK.rParams;
var p1 = WidgetOK.hParams;
var sessSecKey = p['session_secret_key'] || p1['session_secret_key'];
args = args || {};
var proto = window.location.protocol == 'file:' ? 'http:' : window.location.protocol;
var sigSource = '';
if (args.feed != null) {
sigSource += 'st.attachment=' + args.feed;
}
sigSource += 'st.return=' + proto + WidgetOK.returnUrl + sessSecKey;
var query = proto + '//connect.ok.ru/dk?st.cmd=' + widget + '&st.app=' + WidgetOK.appId;
if (args.feed != null) {
query += '&st.attachment=' + encodeURIComponent(args.feed);
}
query += '&st.signature=' + OKSDK.Util.md5(sigSource);
query += '&st.return=' + encodeURIComponent(proto + WidgetOK.returnUrl);
if (p1['access_token']) {
query += '&st.access_token=' + p1['access_token'];
}
if (p['session_key']) {
query += '&st.session_key=' + p['session_key'];
}
var holder = document.getElementById('WidgetOKHolder');
var html = [];
html.push('<a style="float:right;display:block;" onclick="document.getElementById(',
"'WidgetOKHolder').style.display = 'none';", '">[close]</a>');
html.push('<iframe src="', query, '"></iframe>');
holder.innerHTML = html.join('');
holder.style.display = 'block';
}
};
</script>
<div id="WidgetOKHolder"></div>
<p>
<input type="button" onclick="WidgetOK.openMediatopicPost();" value="Post a new feed"/><br/>
Posts a simple "hello world!" mediatopic
</p>
<p>
<input type="button" onclick="WidgetOK.openInvite();" value="Invite (not-playing) friends to app"/><br/>
Selects friends for invitation
</p>
<p>
<input type="button" onclick="WidgetOK.openSuggest();" value="Suggest app to friends (both playing and not)"/><br/>
Selects friends for suggestion
</p>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function () {
WidgetOK.rParams = FAPI.Util.getRequestParameters();
WidgetOK.hParams = FAPI.Util.getRequestParameters(window.location.hash);
FAPI.init({'app_id': 1139348224, 'app_key': 'CBAEBKOEEBABABABA'},
function () {
// alert('SUCCESS');
},
function (err) {
alert('ERROR:' + err);
}
);
window.addEventListener('message', function (event) {
if (event.data == 'hideWidgetIframe') {
var holder = document.getElementById('WidgetOKHolder');
holder.innerHTML = '';
holder.style.display = 'none';
}
}, false);
}, false);
</script>
</body>
</html>