Skip to content

Commit e59ee92

Browse files
committed
update
1 parent 5b3f90f commit e59ee92

File tree

2 files changed

+194
-0
lines changed

2 files changed

+194
-0
lines changed

themes/learn4/js/jquery.cookie.js

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*!
2+
* jQuery Cookie Plugin v1.4.1
3+
* https://github.com/carhartl/jquery-cookie
4+
*
5+
* Copyright 2006, 2014 Klaus Hartl
6+
* Released under the MIT license
7+
*/
8+
(function (factory) {
9+
if (typeof define === 'function' && define.amd) {
10+
// AMD (Register as an anonymous module)
11+
define(['jquery'], factory);
12+
} else if (typeof exports === 'object') {
13+
// Node/CommonJS
14+
module.exports = factory(require('jquery'));
15+
} else {
16+
// Browser globals
17+
factory(jQuery);
18+
}
19+
}(function ($) {
20+
21+
var pluses = /\+/g;
22+
23+
function encode(s) {
24+
return config.raw ? s : encodeURIComponent(s);
25+
}
26+
27+
function decode(s) {
28+
return config.raw ? s : decodeURIComponent(s);
29+
}
30+
31+
function stringifyCookieValue(value) {
32+
return encode(config.json ? JSON.stringify(value) : String(value));
33+
}
34+
35+
function parseCookieValue(s) {
36+
if (s.indexOf('"') === 0) {
37+
// This is a quoted cookie as according to RFC2068, unescape...
38+
s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
39+
}
40+
41+
try {
42+
// Replace server-side written pluses with spaces.
43+
// If we can't decode the cookie, ignore it, it's unusable.
44+
// If we can't parse the cookie, ignore it, it's unusable.
45+
s = decodeURIComponent(s.replace(pluses, ' '));
46+
return config.json ? JSON.parse(s) : s;
47+
} catch(e) {}
48+
}
49+
50+
function read(s, converter) {
51+
var value = config.raw ? s : parseCookieValue(s);
52+
return $.isFunction(converter) ? converter(value) : value;
53+
}
54+
55+
var config = $.cookie = function (key, value, options) {
56+
57+
// Write
58+
59+
if (arguments.length > 1 && !$.isFunction(value)) {
60+
options = $.extend({}, config.defaults, options);
61+
62+
if (typeof options.expires === 'number') {
63+
var days = options.expires, t = options.expires = new Date();
64+
t.setMilliseconds(t.getMilliseconds() + days * 864e+5);
65+
}
66+
67+
return (document.cookie = [
68+
encode(key), '=', stringifyCookieValue(value),
69+
options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
70+
options.path ? '; path=' + options.path : '',
71+
options.domain ? '; domain=' + options.domain : '',
72+
options.secure ? '; secure' : ''
73+
].join(''));
74+
}
75+
76+
// Read
77+
78+
var result = key ? undefined : {},
79+
// To prevent the for loop in the first place assign an empty array
80+
// in case there are no cookies at all. Also prevents odd result when
81+
// calling $.cookie().
82+
cookies = document.cookie ? document.cookie.split('; ') : [],
83+
i = 0,
84+
l = cookies.length;
85+
86+
for (; i < l; i++) {
87+
var parts = cookies[i].split('='),
88+
name = decode(parts.shift()),
89+
cookie = parts.join('=');
90+
91+
if (key === name) {
92+
// If second argument (value) is a function it's a converter...
93+
result = read(cookie, value);
94+
break;
95+
}
96+
97+
// Prevent storing a cookie that we couldn't decode.
98+
if (!key && (cookie = read(cookie)) !== undefined) {
99+
result[name] = cookie;
100+
}
101+
}
102+
103+
return result;
104+
};
105+
106+
config.defaults = {};
107+
108+
$.removeCookie = function (key, options) {
109+
// Must not alter options, thus extending a fresh object...
110+
$.cookie(key, '', $.extend({}, options, { expires: -1 }));
111+
return !$.cookie(key);
112+
};
113+
114+
}));

themes/learn4/templates/partials/base.html.twig

+80
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
{% do assets.addJs('theme://js/clipboard.min.js') %}
3535
{% do assets.addJs('theme://js/learn.js') %}
3636
{% do assets.addJs('theme://js/addTargetToAnchors.js') %}
37+
{% do assets.addJs('theme://js/jquery.cookie.js') %}
3738
{{ assets.js() }}
3839
{% endblock %}
3940

@@ -95,5 +96,84 @@
9596
{% include 'partials/analytics.html.twig' %}
9697
{% endif %}
9798
{% endblock %}
99+
100+
101+
<script>
102+
(function(i, s, o, g, r, a, m) {
103+
i['DaoVoiceObject'] = r;
104+
i[r] = i[r] || function() {
105+
(i[r].q = i[r].q || []).push(arguments)
106+
}, i[r].l = 1 * new Date();
107+
a = s.createElement(o), m = s.getElementsByTagName(o)[0];
108+
a.async = 1;
109+
a.src = g;
110+
m.parentNode.insertBefore(a, m)
111+
})(window, document, 'script', '//widget.daovoice.io/widget/91af7bf3.js', 'daovoice');
112+
if (typeof $.cookie('token') != 'undefined') {
113+
$.ajax({
114+
url: "https://api.daocloud.io/get-token-info",
115+
data: {},
116+
type: 'GET',
117+
beforeSend: function(xhr) {
118+
xhr.setRequestHeader('Authorization', $.cookie("token"));
119+
},
120+
success: function(res) {
121+
if (res.user.tenant) {
122+
var create_at_time = new Date(res.user.created_at).getTime() / 1000 - 28800;
123+
var user_name = res.user.tenant.tenant_name;
124+
var user_id = res.user.user_id;
125+
126+
$.ajax({
127+
url: "https://api.daocloud.io/users/connections",
128+
type: 'GET',
129+
beforeSend: function(xhr) {
130+
xhr.setRequestHeader('Authorization', $.cookie("token"));
131+
},
132+
success: function(res) {
133+
var email = null;
134+
for (i = 0; i < res.user.connections.length; i++) {
135+
if (res.user.connections[i]['connect_type'] == 'email')
136+
email = res.user.connections[i]['connect_value'];
137+
}
138+
139+
daovoice('init', {
140+
app_id: "91af7bf3",
141+
user_id: user_id,
142+
email: email,
143+
name: user_name,
144+
signed_up: create_at_time
145+
});
146+
daovoice('update');
147+
},
148+
error: function(res) {
149+
daovoice('init', {
150+
app_id: "91af7bf3"
151+
});
152+
daovoice('update');
153+
}
154+
});
155+
156+
157+
}
158+
},
159+
error: function(XMLHttpRequest, textStatus, errorThrown) {
160+
var status = XMLHttpRequest.status;
161+
if (status == 401 || status == 404) {
162+
daovoice('init', {
163+
app_id: "91af7bf3"
164+
});
165+
daovoice('update');
166+
}
167+
}
168+
});
169+
} else {
170+
daovoice('init', {
171+
app_id: "91af7bf3"
172+
});
173+
daovoice('update');
174+
}
175+
</script>
176+
177+
98178
</body>
99179
</html>

0 commit comments

Comments
 (0)