Skip to content

Instantly share code, notes, and snippets.

@neochief
Created April 14, 2015 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neochief/eb674f47f21c8cc0b729 to your computer and use it in GitHub Desktop.
Save neochief/eb674f47f21c8cc0b729 to your computer and use it in GitHub Desktop.
User-echo: Work-around for multiple widgets on one page
$(function(){
// This is standard userecho widget object.
var default_code = {
host: 'yoursite.userecho.com',
forum: '111111',
lang: 'en',
tab_corner_radius: 5,
tab_font_size: 20,
tab_image_hash: 'ZmVlZGJhY2s%3D',
tab_chat_hash: 'Y2hhdA%3D%3D',
tab_alignment: 'right',
tab_text_color: '#FFFFFF',
tab_text_shadow_color: '#00000055',
tab_bg_color: '#57A957',
tab_hover_color: '#F45C5C'
};
// Grab this from widget object (see 'forum' attribute).
var public_forum_id = '11111';
// Then, in userecho admin, set widget to Helpdesk forum and take a new value from 'forum' attribute.
var private_forum_id = '222222';
var create_user_echo = function(token, forum_id){
forum_id = forum_id || public_forum_id;
_ues = $.extend({}, default_code, {forum: forum_id});
$('#ue-overlay').remove();
$('#ue-dlg').remove();
delete UE;
if (token) {
_ues.params = {sso_token: token}
}
(function () {
var _ue = document.createElement('script');
_ue.type = 'text/javascript';
_ue.async = true;
_ue.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'cdn.userecho.com/js/widget-1.4.gz.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(_ue, s);
})();
};
if (typeof(Storage) !== "undefined" && localStorage.user_echo_token) {
create_user_echo(localStorage.user_echo_token);
}
else {
jQuery.ajax({
type: "GET",
url: "/user_echo_token"
}).done(function (token) {
if (!token) {
token = '';
}
if (typeof(Storage) !== "undefined") {
localStorage.user_echo_token = token;
}
create_user_echo(token);
});
}
var forum_loaded = 'public';
$('.contact-us-link').click(function(e){
e.preventDefault();
if (forum_loaded == 'contact') {
return UE.Popin.show();
}
create_user_echo(localStorage.user_echo_token, private_forum_id);
setTimeout(function(){
forum_loaded = 'private';
UE.Popin.show();
var interval = setInterval(function() {
if (!$('#ue-dlg-content iframe').length) {
UE.Popin.show();
}
else {
clearInterval(interval);
}
}, 3000);
}, 300);
});
$('.forum-link').click(function(e){
e.preventDefault();
if (forum_loaded == 'public') {
return UE.Popin.show();
}
create_user_echo(localStorage.user_echo_token, public_forum_id);
setTimeout(function(){
forum_loaded = 'public';
UE.Popin.show();
var interval = setInterval(function() {
if (!$('#ue-dlg-content iframe').length) {
UE.Popin.show();
}
else {
clearInterval(interval);
}
}, 3000);
}, 300);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment