Skip to content

Commit

Permalink
use api module
Browse files Browse the repository at this point in the history
  • Loading branch information
geraldb committed Jul 4, 2013
1 parent b18ab37 commit 1d4abaf
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 105 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
##############################
# komodo project files

*.kpf

39 changes: 39 additions & 0 deletions js/jquery.football.api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

////////////////////////////////////
// football.db api wrapper

var sportdb_api_new = function( opts )
{
var _defaults = {
apiPathPrefix: 'http://footballdb.herokuapp.com/api/v1'
};
var _settings;

function _debug( msg ) {
if( window.console && window.console.log ) {
window.console.log( '[debug] '+msg );
}
}

function _init( opts )
{
_settings = _.extend( {}, _defaults, opts );

_debug( 'apiPathPrefix: ' + _settings.apiPathPrefix );
}

function _fetch_round( event_key, round_pos, onsuccess )
{
var api_url = _settings.apiPathPrefix + '/event/' + event_key + '/round/' + round_pos + '?callback=?';
$.getJSON( api_url, onsuccess );
}

// call "c'tor/constructor"
_init( opts );

// return/export public api
return {
fetch_round: _fetch_round
}
} // fn sportdb_api_new

41 changes: 0 additions & 41 deletions js/jquery.football.js → js/jquery.football.widget.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,5 @@


////////////////////////////////////
// football.dp api wrapper

var sportdb_api_new = function( opts )
{
var _defaults = {
apiPathPrefix: 'http://footballdb.herokuapp.com/api/v1',
};
var _settings;

function _debug( msg ) {
if( window.console && window.console.log ) {
window.console.log( '[debug] '+msg );
}
}

function _init( opts )
{
_settings = _.extend( {}, _defaults, opts );

_debug( 'apiPathPrefix: ' + _settings.apiPathPrefix );
}

function _fetch_round( event_key, round_pos, onsuccess )
{
var api_url = _settings.apiPathPrefix + '/event/' + event_key + '/round/' + round_pos + '?callback=?';
$.getJSON( api_url, onsuccess );
}

// call "c'tor/constructor"
_init( opts );

// return/export public api
return {
fetch_round: _fetch_round
}
} // fn sportdb_api_new




var sportdb_widget_new = function( id, opts ) {

var _$el;
Expand Down
File renamed without changes.
File renamed without changes.
68 changes: 4 additions & 64 deletions matchday.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
<meta charset='UTF-8'>
<title>Matchday Example / sport.db JSON(P) API</title>

<script src='js/3rd/jquery-2.0.2.min.js'></script>
<script src='js/3rd/underscore-1.4.4.min.js'></script>
<script src='js/libs/jquery-2.0.2.min.js'></script>
<script src='js/libs/underscore-1.4.4.min.js'></script>

<script src='js/jquery.football.js'></script>
<script src='js/jquery.football.api.js'></script>
<script src='js/jquery.football.widget.js'></script>

<style>

Expand All @@ -24,34 +25,16 @@
</style>

<script>

function debug( msg ) {
if( window.console && window.console.log ) {
window.console.log( '[debug] '+msg );
}
}

var sportdb_widget;
var sportdb_widget2;

$(document).ready( function() {

debug( 'enter document.ready' );

// NB: sportdb_widget make it global var (that is, we do NOT use var sportdb_widget)

// fix: fetch_rounds!!! via service!!!! no need to specifiy!!

sportdb_widget = sportdb_widget_new( '#widget',
{ event: 'euro.2012',
rounds: ['1', '2', '3', '4', '5', '6' ]} );


sportdb_widget2 = sportdb_widget_new( '#widget2',
{ event: 'de.2012_13',
rounds: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12' ],
tplId: '#widgetTpl'} );

$( '#widgetjq' ).football( { event: 'euro.2012',
rounds: ['1', '2', '3', '4', '5', '6' ]} );
});
Expand All @@ -60,56 +43,13 @@
</head>
<body>

<script type='text/template' id='widgetTpl'>
<h3>
<%= data.event.title %>
-
<%= data.round.title %>
</h3>

<table>
<% _.each( data.games, function( game, index ) { %>
<tr>
<td>
<%= game.play_at %>
</td>
<td style='text-align: right;'>
<%= game.team1_title %> (<%= game.team1_code %>)
</td>

<td>
<% if( game.score1 != null && game.score2 != null ) { %>
<% if( game.score1ot != null && game.score2ot != null ) { %>
<% if ( game.score1p != null && game.score2p != null ) { %>
<%= game.score1p %> - <%= game.score2p %> iE /
<% } %>
<%= game.score1ot %> - <%= game.score2ot %> nV /
<% } %>
<%= game.score1 %> - <%= game.score2 %>
<% } else { %>
-
<% } %>
</td>
<td>
<%= game.team2_title %> (<%= game.team2_code %>)
</td>
</tr>
<% }); %>
</table>
</script>



<h1>Matchday Example / sport.db JSON(P) API</h1>

<div id='widget'></div>

<!-- try another widget -->

<div id='widget2'></div>

<!-- try another widget -->

<div id='widgetjq'></div>

</body>
Expand Down
96 changes: 96 additions & 0 deletions matchday2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
<title>Matchday Example / sport.db JSON(P) API</title>

<script src='js/libs/jquery-2.0.2.min.js'></script>
<script src='js/libs/underscore-1.4.4.min.js'></script>

<script src='js/jquery.football.api.js'></script>
<script src='js/jquery.football.widget.js'></script>

<style>

a {
color: black;
text-decoration: none;
}

#widget, #widget2 {
/* background-color: lime; */
border: 1px solid green;
padding: 4px;
}
</style>

<script>

function debug( msg ) {
if( window.console && window.console.log ) {
window.console.log( '[debug] '+msg );
}
}

var sportdb_widget;

$(document).ready( function() {

debug( 'enter document.ready' );

sportdb_widget = sportdb_widget_new( '#widget',
{ event: 'de.2012_13',
rounds: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12' ],
tplId: '#widgetTpl'} );
});
</script>

</head>
<body>

<script type='text/template' id='widgetTpl'>
<h3>
<%= data.event.title %>
-
<%= data.round.title %>
</h3>

<table>
<% _.each( data.games, function( game, index ) { %>
<tr>
<td>
<%= game.play_at %>
</td>
<td style='text-align: right;'>
<%= game.team1_title %> (<%= game.team1_code %>)
</td>

<td>
<% if( game.score1 != null && game.score2 != null ) { %>
<% if( game.score1ot != null && game.score2ot != null ) { %>
<% if ( game.score1p != null && game.score2p != null ) { %>
<%= game.score1p %> - <%= game.score2p %> iE /
<% } %>
<%= game.score1ot %> - <%= game.score2ot %> nV /
<% } %>
<%= game.score1 %> - <%= game.score2 %>
<% } else { %>
-
<% } %>
</td>
<td>
<%= game.team2_title %> (<%= game.team2_code %>)
</td>
</tr>
<% }); %>
</table>
</script>



<h1>Matchday Example / sport.db JSON(P) API</h1>

<div id='widget'></div>

</body>
</html>

0 comments on commit 1d4abaf

Please sign in to comment.