2013-05-29 12:17:44 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								( function ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									var  num _users  =  document . getElementById ( 'number_of_users' ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										latest _user  =  document . getElementById ( 'latest_user' ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										active _users  =  document . getElementById ( 'active_users' ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										user _label  =  document . getElementById ( 'user_label' ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										active _record  =  document . getElementById ( 'active_record' ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										right _menu  =  document . getElementById ( 'right-menu' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									socket . emit ( 'user.count' ,  { } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									socket . on ( 'user.count' ,  function ( data )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										num _users . innerHTML  =  "We currently have <b>"  +  data . count  +  "</b> registered users." ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									socket . emit ( 'user.latest' ,  { } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									socket . on ( 'user.latest' ,  function ( data )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( data . username  ==  '' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-06-06 13:30:28 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											latest _user . innerHTML  =  '' ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-05-29 12:17:44 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
										}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											latest _user . innerHTML  =  "The most recent user to register is <b><a href='/users/" + data . username + "'>"  +  data . username  +  "</a></b>." ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									socket . emit ( 'api:user.active.get' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									socket . on ( 'api:user.active.get' ,  function ( data )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										var  plural _users  =  parseInt ( data . users )  !==  1 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											plural _anon  =  parseInt ( data . anon )  !==  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										active _users . innerHTML  =  'There '  +  ( plural _users  ?  'are'  :  'is' )  +  ' <strong>'  +  data . users  +  '</strong> user'  +  ( plural _users  ?  's'  :  '' )  +  ' and <strong>'  +  data . anon  +  '</strong> guest'  +  ( plural _anon  ?  's'  :  '' )  +  ' online' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									socket . emit ( 'api:user.active.get_record' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									socket . on ( 'api:user.active.get_record' ,  function ( data )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										active _record . innerHTML  =  "most users ever online was <strong>"  +  data . record  +  "</strong> on <strong>"  +  ( new  Date ( parseInt ( data . timestamp , 10 ) ) ) . toUTCString ( )  +  "</strong>" ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-06-24 14:33:53 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									socket . emit ( 'api:updateHeader' ,  {  fields :  [ 'username' ,  'picture' ,  'userslug' ]  } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-05-29 12:17:44 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									socket . on ( 'api:updateHeader' ,  function ( data )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-06-24 14:33:53 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-05-29 12:17:44 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
										var  rightMenu  =  $ ( '#right-menu' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( data . uid  >  0 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-06-20 11:55:56 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-06-19 09:35:44 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											var  userLabel  =  rightMenu . find ( '#user_label' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-06-20 11:55:56 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if ( userLabel . length )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-06-24 14:33:53 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												userLabel . attr ( 'href' , '/users/' + data [ 'userslug' ] ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-06-17 13:35:37 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											
							 
						 
					
						
							
								
									
										
										
										
											2013-06-20 11:55:56 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												userLabel . find ( 'img' ) . attr ( 'src' , data [ 'picture' ] + "?s=24&default=identicon" ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												userLabel . find ( 'span' ) . html ( data [ 'username' ] ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												var  userli  =  $ ( ' < li >  \ 
							 
						 
					
						
							
								
									
										
										
										
											2013-06-24 14:33:53 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																	< a  id = "user_label"  href = "/users/'+data['userslug']+'" >  \ 
							 
						 
					
						
							
								
									
										
										
										
											2013-06-20 11:55:56 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																		< img  src = "'+data['picture']+" ? s = 24 & default = identicon "+'" / >  \ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																		< span > '+data[' username ']+' < / s p a n >   \ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																	< / a >   \ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																< / l i > ' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												rightMenu . append ( userli ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												var  logoutli  =  $ ( '<li><a href="/logout">Log out</a></li>' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												rightMenu . append ( logoutli ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2013-05-29 12:17:44 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
										}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											rightMenu . html ( '' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											var  registerEl  =  document . createElement ( 'li' ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												loginEl  =  document . createElement ( 'li' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											registerEl . innerHTML  =  '<a href="/register">Register</a>' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											loginEl . innerHTML  =  '<a href="/login">Login</a>' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											right _menu . appendChild ( registerEl ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											right _menu . appendChild ( loginEl ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// Notifications dropdown
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									var  notifContainer  =  document . getElementsByClassName ( 'notifications' ) [ 0 ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										notifTrigger  =  notifContainer . querySelector ( 'a' ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										notifList  =  document . getElementById ( 'notif-list' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									notifTrigger . addEventListener ( 'click' ,  function ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( notifContainer . className . indexOf ( 'open' )  ===  - 1 )  socket . emit ( 'api:notifications.get' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									notifList . addEventListener ( 'click' ,  function ( e )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										var  target ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										switch ( e . target . nodeName )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											case  'SPAN' :  target  =  e . target . parentNode . parentNode ;  break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											case  'A' :  target  =  e . target . parentNode ;  break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											case  'li' :  target  =  e . target ;  break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( target )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											var  nid  =  parseInt ( target . getAttribute ( 'data-nid' ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( nid  >  0 )  socket . emit ( 'api:notifications.mark_read' ,  nid ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									socket . on ( 'api:notifications.get' ,  function ( data )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										var 	notifFrag  =  document . createDocumentFragment ( ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											notifEl  =  document . createElement ( 'li' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-06-24 16:35:50 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											notifIcon  =  document . querySelector ( '.notifications a i' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-05-29 12:17:44 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
											numRead  =  data . read . length , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											numUnread  =  data . unread . length , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											x ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										notifList . innerHTML  =  '' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( data . read . length  +  data . unread . length  >  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											for ( x = 0 ; x < numUnread ; x ++ )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												notifEl . setAttribute ( 'data-nid' ,  data . unread [ x ] . nid ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												notifEl . className  =  'unread' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												notifEl . innerHTML  =  '<a href="'  +  data . unread [ x ] . path  +  '"><span class="pull-right">'  +  utils . relativeTime ( data . unread [ x ] . datetime ,  true )  +  '</span>'  +  data . unread [ x ] . text  +  '</a>' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												notifFrag . appendChild ( notifEl . cloneNode ( true ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											for ( x = 0 ; x < numRead ; x ++ )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												notifEl . setAttribute ( 'data-nid' ,  data . read [ x ] . nid ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												notifEl . className  =  '' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												notifEl . innerHTML  =  '<a href="'  +  data . read [ x ] . path  +  '"><span class="pull-right">'  +  utils . relativeTime ( data . read [ x ] . datetime ,  true )  +  '</span>'  +  data . read [ x ] . text  +  '</a>' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												notifFrag . appendChild ( notifEl . cloneNode ( true ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											notifEl . innerHTML  =  '<a>You have no notifications</a>' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											notifFrag . appendChild ( notifEl ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										notifList . appendChild ( notifFrag ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-06-24 16:35:50 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										socket . emit ( 'api:notifications.removeFlag' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										notifIcon . className  =  'icon-circle-blank' ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-05-29 12:17:44 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-06-24 16:35:50 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									socket . on ( 'api:notifications.hasFlag' ,  function ( flag )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-05-29 12:17:44 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
										var  notifIcon  =  document . querySelector ( '.notifications a i' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if ( notifIcon )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-06-24 16:35:50 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( flag  >  0 )  notifIcon . className  =  'icon-circle active' ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-05-29 12:17:44 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
											else  notifIcon . className  =  'icon-circle-blank' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									socket . on ( 'event:new_notification' ,  function ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										document . querySelector ( '.notifications a i' ) . className  =  'icon-circle active' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-06-24 16:35:50 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									socket . emit ( 'api:notifications.hasFlag' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-06-05 16:01:26 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-06-26 12:32:30 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-06-05 16:01:26 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									require ( [ 'mobileMenu' ] ,  function ( mobileMenu )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										mobileMenu . init ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-05-29 12:17:44 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								} ( ) ) ;