Skip to content

Instantly share code, notes, and snippets.

@MichelleGlauser
Created May 7, 2013 00:38
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 MichelleGlauser/5529449 to your computer and use it in GitHub Desktop.
Save MichelleGlauser/5529449 to your computer and use it in GitHub Desktop.
There's a Get Satisfaction community that asked for pop-up notifications of new activity, just as you would see on Facebook (instead of just sending emails to those following the topic). They wanted to be notified of new replies while on a topic page, and new topics while on the main community page. This would be useful for users and administrat…
// Head Tag:
<style>
#reply_notification,
#topic_notification {
background-color: #7dba00;
position: fixed;
bottom: 0;
z-index: 9999;
padding: 35px 30px;
right: 0;
color:white;
box-shadow: 0px 0px 10px rgba(0,0,0,0.3);
border: 1px solid rgb(101, 146, 7);
display:none;
}
#reply_notification p,
#topic_notification p {
color: #fff;
font-size: 16px;
text-shadow: 1px 1px 0px rgba(0,0,0,0.3);
font-weight: bold;
}
#reply_notification .button a,
#topic_notification .button a {
background: none;
}
</style>
// Header HTML:
<div id="reply_notification">
<p>There is a new reply to this conversation.</p>
<div class="button"><a href="#">Refresh to view.</a></div>
</div>
<div id="topic_notification">
<p>A new topic has been added.</p>
<div class="button"><a href="#">Refresh to view.</a></div>
</div>
// Footer HTML:
<script language="javascript">
jQuery(document).ready(function () {
// Check for new replies:
this_url = location.protocol + "//" + location.host + location.pathname;
if (jQuery('#about_topic_sidebar').size() > 0 ) {
md = /^\/([^\/]+)\/.*?([^\/]+)$/.exec(document.location.pathname);
if( md ) {
companyName = md[1];
slug = md[2];
} else {
companyName='', slug='';
}
api_url = 'https://api.getsatisfaction.com/topics/' + slug + '.json';
} else {
md = /^\/([^\/]+)\/.*?([^\/]+)$/.exec(document.location.pathname);
if( md ) {
companyName = md[1];
slug = md[2];
} else {
companyName='', slug='';
}
api_url = 'https://api.getsatisfaction.com/companies/' + companyName + '/topics.json';
}
jQuery.ajax({
type: 'GET',
url: api_url,
dataType: 'jsonp',
success: function(results) {
if ( results.active_replies ) {
current_replies = results.active_replies;
} else {
current_topics = results.total;
}
},
data: {},
async: false,
error: function(e, s, m){}
});
window.setInterval(function(){
jQuery.ajax({
type: 'GET',
url: api_url,
dataType: 'jsonp',
success: function(results) {
replies = results.active_replies;
if ( results.active_replies ) {
replies = results.active_replies;
if (replies > current_replies) {
jQuery('#reply_notification').show();
jQuery('#topic_notification').hide();
}
} else {
topics = results.total;
if (topics > current_topics) {
jQuery('#topic_notification').show();
jQuery('#reply_notification').hide();
}
}
},
data: {},
async: false,
error: function(e, s, m){}
});
},5000 /*5s*/);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment