Permalink
Browse files

-Code Cleanup

  • Loading branch information...
1 parent c0975b7 commit 8b102c02f7c8c8444424dc6e91f5c3d1a7f4ee30 @codenothing committed Sep 8, 2010
Showing with 82 additions and 85 deletions.
  1. +1 −1 master/index.html
  2. +50 −72 master/js.js
  3. +10 −8 node/{node.js → server.js}
  4. +11 −0 revar.sh
  5. +2 −1 server.sh
  6. +1 −1 slideshow/Config.js
  7. +5 −1 slideshow/js.js
  8. +1 −1 slideshow/styles.css
  9. +1 −0 starttime.sh
View
@@ -1,10 +1,10 @@
+<!DOCTYPE html>
<html>
<head>
<title>Master Controller</title>
<script type='text/javascript' src='jquery-1.4.2.js'></script>
<script type='text/javascript' src='js.js'></script>
<link rel="stylesheet" href="styles.css" />
- </style>
</head>
<body>
<!--
View
@@ -5,53 +5,58 @@
*/
jQuery(function(){
// Cheap mobile check
- var mobile = ( 'Touch' in window ), time = jQuery('#time'), slides, selected, timeLeft, timeWarning, timeid;
+ var mobile = ( 'Touch' in window ), time = jQuery('#time'), slideWrapper = jQuery('#slides'), slides, timeLeft, timeWarning, timeid;
- function change( op ) {
- jQuery.get('/', { op: op, _CacheKiller: Date.now() }, function( response ) {
- jQuery.getJSON('/', { op: 'config', _Cache: Date.now() }, function( data ) {
- selected = data.slide;
- slides.removeClass('chosen').eq( selected ).addClass('chosen');
- // Countdown timer
- timeLeft = parseInt( data.timeLeft / 1000, 10 );
- timeWarning = parseInt( data.timeWarning / 1000, 10 );
- timer();
- if ( data.timeEnabled ) {
- if ( timeid ) {
- timeid = clearInterval( timeid );
- }
- timeid = setInterval(function(){
- timeLeft--;
- timer();
- }, 1000);
- }
- });
- });
- }
+ // Configuration update
+ function config( data ) {
+ var max = parseInt( data.max, 10 ) + 1, i = 0, list = '';
- function next(){
- change('next-slide');
- return false;
- }
+ for ( ; ++i < max; ) {
+ list += "<div>" + i + "</div>";
+ }
- function prev(){
- change('prev-slide');
- return false;
+ slides = slideWrapper.html( list ).children('div');
+ slides.removeClass('chosen').eq( data.slide ).addClass('chosen');
+
+
+ // Countdown timer
+ timeLeft = parseInt( data.timeLeft / 1000, 10 );
+ timeWarning = parseInt( data.timeWarning / 1000, 10 );
+ timer();
+ if ( data.timeEnabled ) {
+ if ( timeid ) {
+ timeid = clearInterval( timeid );
+ }
+ timeid = setInterval(function(){
+ timeLeft--;
+ timer();
+ }, 1000);
+ }
}
+
+ // Countdown Display
function timer(){
var min = parseInt( timeLeft / 60, 10 ), sec = timeLeft % 60;
+
+ // Zero-fill
if ( min < 10 ) {
min = '0' + min;
}
+
+ // Zero-fill
if ( sec < 10 ) {
sec = '0' + sec;
}
+
+ // Don't go into negatives
if ( timeLeft < 1 ) {
min = '00';
sec = '00';
}
+
+ // Color coding
time[ 0 ].className = '';
time.html( min + ':' + sec ).addClass(
timeLeft < 1 ? 'end' :
@@ -61,57 +66,30 @@ jQuery(function(){
}
- // Action handlers
- jQuery('#next').bind( mobile ? 'touchstart' : 'click', next);
- jQuery('#prev').bind( mobile ? 'touchstart' : 'click', prev);
+ // Slide Selection
+ slideWrapper.bind( mobile ? 'touchstart' : 'click', function( event ) {
+ var target = jQuery( event.target );
+ if ( target.is('div') ) {
+ slides.removeClass('chosen');
+ target.addClass('chosen');
+ jQuery.getJSON('/', { op: 'slide', slide: parseInt( target.text(), 10 ) - 1, _CacheKiller: Date.now() }, config );
+ }
+ });
- // Hover Effects
+
+ // Action Effects
jQuery('#next,#prev').bind( mobile ? 'touchstart' : 'mousedown', function(){
jQuery( this ).addClass('chosen');
+ jQuery.getJSON( '/', { op: this.id + '-slide', _CacheKiller: Date.now() }, config );
+ return false;
})
.bind( mobile ? 'touchend' : 'mouseup', function(){
jQuery( this ).removeClass('chosen');
+ return false;
});
- // Listing slides
- jQuery.getJSON('/', { op: 'config', _Cache: Date.now() }, function( data ) {
- var max = parseInt( data.max, 10 ) + 1, i = 0, list = '';
- console.warn( data );
-
- for ( ; ++i < max; ) {
- list += "<div>" + i + "</div>";
- }
-
- jQuery('#slides').html( list ).bind( mobile ? 'touchstart' : 'click', function( event ) {
- var target = jQuery( event.target );
-
- if ( target.is('div') ) {
- selected = parseInt( target.text(), 10 ) - 1;
- jQuery.get('/', { op: 'slide', slide: selected, _CacheKiller: Date.now() }, function( response ) {
- console.log( response );
- slides.removeClass('chosen').eq( selected ).addClass('chosen');
- });
- }
- });
-
- slides = jQuery('#slides').children('div');
- slides.removeClass('chosen').eq( selected = data.slide ).addClass('chosen');
-
-
- // Countdown timer
- timeLeft = parseInt( data.timeLeft / 1000, 10 );
- timeWarning = parseInt( data.timeWarning / 1000, 10 );
- timer();
- if ( data.timeEnabled ) {
- if ( timeid ) {
- timeid = clearInterval( timeid );
- }
- timeid = setInterval(function(){
- timeLeft--;
- timer();
- }, 1000);
- }
- });
+ // Build the page
+ jQuery.getJSON( '/', { op: 'config', _CacheKiller: Date.now() }, config );
});
@@ -16,8 +16,8 @@ var sys = require('sys'),
timeEnd: 0,
timeEnabled: false,
slide: 0,
- max: 0,
- }
+ max: 0
+ },
stack = {},
rdir = /\/$/, rstart = /^[^\/]/;
@@ -27,16 +27,16 @@ var sys = require('sys'),
Socket
*/
server.addListener("connection", function( conn ) {
+ sys.puts( 'Connection Created [id:' + conn.id + '] [time:' + Date.now() + ']' );
conn.write(
JSON.stringify({
slide: Info.slide
})
);
stack[ conn.id ] = conn;
- sys.puts( 'Connection Created - ' + Date.now() );
});
server.addListener("close", function( conn ) {
- sys.puts('Closing Connection');
+ sys.puts( 'Closing Connection [id:' + conn.id + '] [time:' + Date.now() + ']' );
if ( stack.hasOwnProperty( conn.id ) ) {
delete stack[ conn.id ];
}
@@ -66,6 +66,7 @@ http.createServer(function( request, response ) {
file = '/' + file;
}
+
// Operations check
if ( query.op == 'config' ) {
Info.timeLeft = Info.timeEnd - Date.now();
@@ -75,8 +76,8 @@ http.createServer(function( request, response ) {
}
else if ( query.op == 'start-time' ) {
Info.timeEnabled = true;
- Info.timeEnd = Date.now() + Config.timed
- Info.timeLeft = Info.timeEnd
+ Info.timeEnd = Date.now() + Config.timed;
+ Info.timeLeft = Info.timeEnd;
response.writeHead( 200 );
response.end( JSON.stringify( Info ) );
return;
@@ -91,6 +92,7 @@ http.createServer(function( request, response ) {
ret.slide = query.slide;
}
+
// Do slide transition if requested
if ( ret.slide !== undefined ) {
Info.slide = ret.slide;
@@ -102,11 +104,11 @@ http.createServer(function( request, response ) {
}
}
response.writeHead( 200 );
- response.end("ok");
+ response.end( JSON.stringify( Info ) );
}
else if ( query.op ) {
response.writeHead( 200 );
- response.end("ok");
+ response.end( JSON.stringify( Info ) );
}
else {
fs.readFile( __dirname + '/../master' + file, function( e, data ) {
View
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+# Version/Date
+version=1.0
+today=`date "+%B %d, %Y"`
+
+# Date Changer
+grep -ilr --exclude-dir=.git --exclude=revar.sh --exclude=README.md "[DATE]" * | xargs -i@ sed -i "s/\[DATE\]/${today}/g" @
+
+# Version Changer
+grep -ilr --exclude-dir=.git --exclude=revar.sh --exclude=README.md "[VERSION]" * | xargs -i@ sed -i "s/\[VERSION\]/${version}/g" @
View
@@ -1,6 +1,7 @@
+#!/bin/bash
#
# Node Slide [VERSION]
# [DATE]
# Corey Hart @ http://www.codenothing.com
#
-node node/node.js
+node node/server.js
View
@@ -8,7 +8,7 @@ this.Config = {
enableSocket: true && ( 'WebSocket' in this ),
// Websocket connection
- host: '10.0.1.2',
+ host: 'localhost',
port: 8124,
// Time takes to transition between slides
View
@@ -7,12 +7,13 @@ jQuery(function(){
var deck = jQuery('#deck'), slides = deck.children('section'), win = jQuery( window ), slide = 0, width, height;
+ // Slide Transition
function change(){
deck.stop().animate( { marginLeft: ( slide * width ) * -1 }, Config.transitions );
}
- // Enable page resizing
+ // Handle page resizing
win.resize(function(){
// Dimensions
width = win.width();
@@ -21,6 +22,7 @@ jQuery(function(){
slides.width( width - 60 ).height( height - 30 );
deck.width( width * slides.length + 100 );
})
+ // Allow custom slide views
.keyup(function( event ) {
// left
if ( event.keyCode == 37 ) {
@@ -37,9 +39,11 @@ jQuery(function(){
}
}
})
+ // Make adjustments
.resize();
+ // Only create the connection if allowed
if ( Config.enableSocket ) {
var connection = new WebSocket( 'ws://' + Config.host + ':' + Config.port + '/' );
connection.onmessage = function( event ) {
View
@@ -40,7 +40,7 @@ a:hover { color: #3c5dc9; text-decoration:none; }
/* Slider App Styles */
#deck { overflow: hidden; }
-section { padding: 0 30px 30px; float: left; }
+section { padding: 0 30px 30px; float: left; overflow: auto; }
h1 { font-family: 'ChunkFiveRegular', Arial; font-size:50px; text-shadow: 0px 1px 0px rgba(255, 255, 255, 0.8); }
h2 { font-family: 'ChunkFiveRegular', Arial; font-size: 30px; text-shadow: 0px 1px 0px rgba(255, 255, 255, 0.8); }
p, li { font-family: Arial; font-size:20px; text-shadow: 0px 1px 0px rgba(255, 255, 255, 0.8); }
View
@@ -1,3 +1,4 @@
+#!/bin/bash
#
# Node Slide [VERSION]
# [DATE]

0 comments on commit 8b102c0

Please sign in to comment.