counts.js 580 B

1234567891011121314151617181920212223242526
  1. /* vim: set ts=2: */
  2. var loc = document.location;
  3. var port = loc.port == '' ? ( loc.protocol == 'https:' ? 443 : 80 ) : loc.port;
  4. var url = loc.protocol + '//' + loc.hostname + ':' + port;
  5. counts = io.connect( url + '/counts' );
  6. counts.on( 'connect', function() {
  7. if( typeof noteID !== 'undefined' ) {
  8. counts.emit( 'join', noteID );
  9. }
  10. counts.emit( 'watch', lectureID );
  11. });
  12. counts.on( 'counts', function( c ) {
  13. for( id in c ) {
  14. var selector = 'span[note-id="' + id + '"].count';
  15. var target = $( selector );
  16. if( target ) {
  17. target.text( c[ id ] );
  18. }
  19. }
  20. });