-
-
Save ToeJamson/5818360 to your computer and use it in GitHub Desktop.
Your Style Sheet in Realtime
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!-- DIV to be Updated --> | |
| <div id=update-this-with-css class=original-class> | |
| <p>This DIV will be updated via remote call.</p> | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div id=pubnub></div> | |
| <script src=http://cdn.pubnub.com/pubnub-3.1.min.js></script> | |
| <script>(function(){ | |
| // ----------------------------------------------------------------------- | |
| // Define the channel to broadcast your updates on. | |
| // In this case we are broadcasting updates to update a class-name | |
| // ----------------------------------------------------------------------- | |
| var channel = 'update-your-styles-sheet-in-real-time'; | |
| // ----------------------------------------------------------------------- | |
| // On Click/Touch, "Broadcast CSS Update" to everyone. | |
| // ----------------------------------------------------------------------- | |
| PUBNUB.bind( 'click', PUBNUB.$('send-css-update'), function() { | |
| PUBNUB.publish({ | |
| channel : channel, | |
| message : { | |
| 'element-id' : PUBNUB.$('element-id-to-update').value, | |
| 'css' : PUBNUB.$('inline-css').value | |
| } | |
| }) | |
| } ); | |
| // ----------------------------------------------------------------------- | |
| // On Receive Broadcast, Execute the CSS Updates. | |
| // This happens for everyone who is on this page. | |
| // ----------------------------------------------------------------------- | |
| PUBNUB.subscribe({ | |
| channel : channel, | |
| callback : function(message) { | |
| PUBNUB.attr( | |
| PUBNUB.$(message['element-id']), | |
| 'style', | |
| message['css'] | |
| ); | |
| } | |
| }); | |
| })();</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment