Skip to content

Instantly share code, notes, and snippets.

@mberman84
Created April 2, 2014 03:03
Show Gist options
  • Save mberman84/9927293 to your computer and use it in GitHub Desktop.
Save mberman84/9927293 to your computer and use it in GitHub Desktop.
:javascript
var readyFunc;
readyFunc = function() {
if(typeof(pubnub) == "undefined"){
var pubnub = PUBNUB.init({
subscribe_key : "#{CONFIG['pubnub_subscribe_key']}"
})
}
pubnub.subscribe({
channel : "#{@customer.channel}",
message : function(message){
if(message.customer_id == #{@customer.id}){
debugger;
$('#message').append($('<li>').text("#{@customer.first_name}" + ': (' + "#{Time.now.utc.to_s(:time)}" + ') '+ message.text));
}
}
});
console.log("ready func is a " + typeof(readyFunc) );
$(document).ready(function(){
console.log("running readyfunc from document.ready event handler");
readyFunc();
$(document).unbind('page:load');
$(document).on('page:load', function(){
console.log("running readyfunc from page:load event handler");
readyFunc();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment