Skip to content

Commit de40f84

Browse files
committedSep 17, 2013
jquery improvements; issue #20
1 parent a1bc909 commit de40f84

File tree

6 files changed

+84
-76
lines changed

6 files changed

+84
-76
lines changed
 

‎public_html/index.html

+5-11
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,13 @@
4747
<script src='src/js/MoleculeGeometryBuilder.js'></script>
4848

4949
<script>
50-
$(document).ready(function( ) {
50+
$(function( ) {
5151
/* Mouse Events */
52-
$('#container').mousedown( function( event ) {
53-
MouseManager.onMouseDown( event );
54-
});
52+
$('#container')
53+
.mousedown( MouseManager.onMouseDown )
54+
.mouseup( MouseManager.onMouseUp )
55+
.mousemove( MouseManager.onMouseMove );
5556

56-
$('#container').mouseup( function( event ) {
57-
MouseManager.onMouseUp( event );
58-
});
59-
60-
$('#container').mousemove( function( event ) {
61-
MouseManager.onMouseMove( event );
62-
});
6357
/* Anti-Bot-Spam Measure */
6458
$('#contact').text('saschlac' + '@udel' + '.edu');
6559
/* Initialize */

‎public_html/src/js/GameScreen.js

+14-11
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@
6767
$('#gameButtons').html(this.defaultHTML);
6868
$('#gameCompletedUI').removeClass('in active');
6969
$('#rightPanel').removeClass('in');
70-
$('#questionPanel').removeClass('in active');
71-
$('#questionPanel').empty();
70+
$('#questionPanel')
71+
.removeClass('in active')
72+
.empty();
7273
$('#time')
7374
.css('color', '#F8F8FE')
7475
.text('2:00');
@@ -187,11 +188,13 @@
187188

188189
function setQuestionText(questionText) {
189190
if(questionText) {
190-
$('#questionPanel').text(questionText);
191-
$('#questionPanel').addClass('in');
191+
$('#questionPanel')
192+
.text(questionText)
193+
.addClass('in');
192194
} else {
193-
$('#questionPanel').empty();
194-
$('#questionPanel').removeClass('in');
195+
$('#questionPanel')
196+
.empty()
197+
.removeClass('in');
195198
}
196199
}
197200

@@ -287,7 +290,7 @@
287290
};
288291

289292
function enableButtons(gameScreen) {
290-
$('#gameUI .button[data-logic=\'return\']').on('click', function() {
293+
$('#gameUI').find('.button[data-logic=\'return\']').on('click', function() {
291294
$(this).trigger(new ScreenChangeEvent('menu'));
292295
});
293296

@@ -299,8 +302,8 @@
299302
}
300303
});
301304

302-
$('#loadingUI .button[data-logic=\'begin\']').on('click', function() {
303-
$('#loadingUI .button').off('click');
305+
$('#loadingUI').find('.button[data-logic=\'begin\']').on('click', function() {
306+
$('#loadingUI').find('.button').off('click');
304307
gameScreen.startGame( );
305308
});
306309

@@ -311,11 +314,11 @@
311314

312315
function disableButtons( ) {
313316
$('#gameButtons').off('click');
314-
$('#loadingUI .button').off('click');
317+
$('#loadingUI').find('.button').off('click');
315318
}
316319

317320
function disableReturnButton( ) {
318-
$('#gameUI .button').off('click');
321+
$('#gameUI').find('.button').off('click');
319322
}
320323

321324
window.GameScreen = GameScreen;

‎public_html/src/js/HighScoreScreen.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232
};
3333

3434
function enableButtons(menuScreen) {
35-
$('#highScoreUI .button[data-logic=\'menu\']').on('click', function() {
35+
$('#highScoreUI').find('.button[data-logic=\'menu\']').on('click', function() {
3636
$(this).trigger(new ScreenChangeEvent('menu'));
3737
});
3838
}
3939

4040
function disableButtons( ) {
41-
$('#highScoreUI .button').off('click');
41+
$('#highScoreUI').find('.button').off('click');
4242
}
4343

4444
window.HighScoreScreen = HighScoreScreen;

‎public_html/src/js/LoginScreen.js

+38-30
Original file line numberDiff line numberDiff line change
@@ -82,45 +82,53 @@
8282
};
8383

8484
function enableButtons(loginScreen) {
85-
$('#loginUI .button[data-logic=\'login\']').on('click', function() {
86-
$('#loginButton').addClass('hide');
87-
FCCommunicationManager.login($('#emailLogin')
88-
.val(), $('#passLogin').val(),
89-
loginScreen.loginComplete.bind(loginScreen));
90-
});
91-
92-
$('#loginUI [data-logic=\'showCreate\']')
93-
.on('click', loginScreen.createDivShow);
94-
95-
$('#loginUI [data-logic=\'showLogin\']')
96-
.on('click', loginScreen.loginDivShow);
97-
98-
$('#loginUI .button[data-logic=\'register\']')
99-
.on('click', function() {
100-
$('#registerMismatch').addClass('hide');
101-
$('#registerFail').addClass('hide');
102-
103-
if($('#passRegister').val() == $('#passRepRegister').val()) {
104-
$('#registerButton').addClass('hide');
105-
FCCommunicationManager.register($('#emailRegister').val(),
85+
$('#loginUI')
86+
.find('.button[data-logic=\'login\']')
87+
.on('click', function() {
88+
$('#loginButton').addClass('hide');
89+
FCCommunicationManager.login(
90+
$('#emailLogin').val(),
91+
$('#passLogin').val(),
92+
loginScreen.loginComplete.bind(loginScreen)
93+
);
94+
})
95+
.end()
96+
97+
.find('[data-logic=\'showCreate\']')
98+
.on('click', loginScreen.createDivShow)
99+
.end()
100+
101+
.find('[data-logic=\'showLogin\']')
102+
.on('click', loginScreen.loginDivShow)
103+
.end()
104+
105+
.find('.button[data-logic=\'register\']')
106+
.on('click', function() {
107+
$('#registerMismatch, #registerFail').addClass('hide');
108+
109+
if($('#passRegister').val() == $('#passRepRegister').val()) {
110+
$('#registerButton').addClass('hide');
111+
FCCommunicationManager.register(
112+
$('#emailRegister').val(),
106113
$('#passRegister').val(),
107114
$('#usernameRegister').val(),
108-
loginScreen.registerComplete.bind(loginScreen));
109-
} else {
110-
$('#registerMismatch').removeClass('hide');
111-
}
112-
});
115+
loginScreen.registerComplete.bind(loginScreen)
116+
);
117+
} else {
118+
$('#registerMismatch').removeClass('hide');
119+
}
120+
});
113121

114122
/* TODO - Move these somewhere else? Both are buttons that can be pushed at any time. */
115-
$('#pageHeader [data-logic=\'logout\']').on('click', function() {
123+
$('#pageHeader').find('[data-logic=\'logout\']').on('click', function() {
116124
if(confirm('Logout from Molecule Flashcards?')) {
117125
CookieManager.deleteCookie('username', '/');
118126
CookieManager.deleteCookie('authenticator', '/');
119127
window.location.href = '';
120128
}
121129
});
122130

123-
$('#errorMessage [data-logic=\'retry\']').on('click', function() {
131+
$('#errorMessage').find('[data-logic=\'retry\']').on('click', function() {
124132
CommunicationManager.retry();
125133
$('#errorMessage').removeClass('in activeTop');
126134
});
@@ -137,10 +145,10 @@
137145
}
138146
});
139147

140-
};
148+
}
141149

142150
function disableButtons( ) {
143-
$('#loginUI .button').off('click');
151+
$('#loginUI').find('.button').off('click');
144152
}
145153

146154
window.LoginScreen = LoginScreen;

‎public_html/src/js/MenuScreen.js

+23-20
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
};
5353

5454
MenuScreen.prototype.showAvailableTopics = function(response) {
55-
$('#topicList').empty();
55+
var $topicList = $('#topicList').empty();
5656
this.topics = response.available_games;
5757
UserData.gameID = this.topics[0].id;
5858
UserData.gameTimeLimit = this.topics[0].time_limit;
@@ -72,8 +72,8 @@
7272
this.insertInfo(keys, values, TOPIC_HTML, '#topicList');
7373
this.topics[i].dataID = i;
7474
}
75-
$('#topicList').scrollTop(0);
76-
this.$currentTopic = $($('#topicList').children()[0]);
75+
$topicList.scrollTop(0);
76+
this.$currentTopic = $topicList.children(':first');
7777
this.$currentTopic.addClass("selected");
7878
this.updateRightPanel(this.topics[0]);
7979
};
@@ -117,26 +117,30 @@
117117
};
118118

119119
function enableButtons(menuScreen) {
120-
$('#mainMenuUI .button[data-logic=\'tutorial\']')
121-
.on('click', function() {
122-
$(this).trigger(new ScreenChangeEvent('tutorial'));
123-
});
124120

125-
$('#tutorialUI .button[data-logic=\'endTutorial\']')
121+
$('#mainMenuUI')
122+
.find('.button[data-logic=\'tutorial\']')
123+
.on('click', function() {
124+
$(this).trigger(new ScreenChangeEvent('tutorial'));
125+
})
126+
.end()
127+
128+
.find('.button[data-logic=\'scores\']')
129+
.on('click', function() {
130+
$(this).trigger(new ScreenChangeEvent('score'));
131+
})
132+
.end()
133+
134+
.find('.button[data-logic=\'start\']')
135+
.on('click', function() {
136+
$(this).trigger(new ScreenChangeEvent('game'));
137+
});
138+
139+
$('#tutorialUI').find('.button[data-logic=\'endTutorial\']')
126140
.on('click', function() {
127141
menuScreen.endTutorial( );
128142
});
129143

130-
$('#mainMenuUI .button[data-logic=\'scores\']')
131-
.on('click', function() {
132-
$(this).trigger(new ScreenChangeEvent('score'));
133-
});
134-
135-
$('#mainMenuUI .button[data-logic=\'start\']')
136-
.on('click', function() {
137-
$(this).trigger(new ScreenChangeEvent('game'));
138-
});
139-
140144
$('#topicList').on('click', '.topic[data-id]', function(e) {
141145
menuScreen.updateRightPanel(menuScreen.topics[$(this).data('id')]);
142146
$('#topicList').children().removeClass("selected");
@@ -146,8 +150,7 @@
146150
}
147151

148152
function disableButtons( ) {
149-
$('#mainMenuUI .button').off('click');
150-
$('#tutorialUI .button').off('click');
153+
$('#mainMenuUI, #tutorialUI').find('.button').off('click');
151154
$('#topicList').off('click');
152155
}
153156

‎public_html/src/js/TutorialScreen.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@
3131
};
3232

3333
function enableButtons(tutorialScreen) {
34-
$('#tutorialUI .button[data-logic=\'endTutorial\']')
34+
$('#tutorialUI').find('.button[data-logic=\'endTutorial\']')
3535
.on('click', function() {
3636
$(this).trigger(new ScreenChangeEvent('menu'));
3737
});
3838
}
3939

4040
function disableButtons( ) {
41-
$('#tutorialUI .button').off('click');
41+
$('#tutorialUI').find('.button').off('click');
4242
}
4343

4444
window.TutorialScreen = TutorialScreen;

0 commit comments

Comments
 (0)
Please sign in to comment.