Skip to content

Commit

Permalink
Embed news into HTML for faster loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Zarel committed Sep 20, 2013
1 parent 3abcba1 commit daaa6f3
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/sprites/
/audio/
/js/config.js
/index.html
/index.php
.DS_Store
16 changes: 12 additions & 4 deletions githooks/update-version-query-strings
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,23 @@
* post-commit, post-checkout, post-merge, post-rewrite
*/

date_default_timezone_set('America/Los_Angeles');

include __DIR__.'/../../pokemonshowdown.com/news/include.php';

function replaceMatch($m) {
$filename = str_replace('/play.pokemonshowdown.com/', '', $m[2]);
$hash = substr(md5_file($filename), 0, 8);
return "${m[1]}=\"/${m[2]}?${hash}\"";
}

file_put_contents('index.html',
preg_replace_callback('/(src|href)="\/(.*?)\?[a-z0-9]*?"/',
'replaceMatch',
file_get_contents('index.template.html'))
file_put_contents('index.php',
str_replace('<!-- newsid -->',
getNewsId(),
str_replace('<!-- news -->',
''.renderNews().'',
preg_replace_callback('/(src|href)="\/(.*?)\?[a-z0-9]*?"/',
'replaceMatch',
file_get_contents('index.template.php'))))
);

31 changes: 28 additions & 3 deletions index.template.html → index.template.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,34 @@
<div id="header" class="header">
<img class="logo" src="//play.pokemonshowdown.com/pokemonshowdownbeta.png" alt="Pok&eacute;mon Showdown! (beta)" /><div class="maintabbarbottom"></div>
</div>
<div id="main">
<div id="loading-message" class="mainmessage">Initializing... <noscript>FAILED<br /><br />Pok&eacute;mon Showdown requires JavaScript.</noscript></div>
</div>
<div class="ps-room scrollable" id="mainmenu"><div class="mainmenuwrapper">
<div class="leftmenu">
<div class="activitymenu">
<div class="pmbox">
<?php
if ($_COOKIE['showdown_readnews'] !== '<!-- newsid -->') {
?>
<div class="pm-window news-embed" data-newsid="<!-- newsid -->">
<h3><button class="closebutton" tabindex="-1"><i class="icon-remove-sign"></i></button>Latest News</h3>
<div class="pm-log">
<div style="font-size:9pt;padding:1px 10px"><!-- news --></div>
</div>
</div>
<?php
}
?>
</div>
</div>
<div class="mainmenu">
<div id="loading-message" class="mainmessage">Initializing... <noscript>FAILED<br /><br />Pok&eacute;mon Showdown requires JavaScript.</noscript></div>
</div>
</div>
<div class="rightmenu">
</div>
<div class="mainmenufooter">
<small><a href="//pokemonshowdown.com/" target="_blank"><strong>Pokémon Showdown</strong></a> | <a href="http://smogon.com/" target="_blank"><strong>Smogon</strong></a><br><a href="//pokemonshowdown.com/dex/" target="_blank">Pokédex</a> | <a href="//pokemonshowdown.com/replay/" target="_blank">Replays</a> | <a href="//pokemonshowdown.com/rules" target="_blank">Rules</a></small> | <small><a href="//pokemonshowdown.com/forums/" target="_blank">Forum</a></small>
</div>
</div></div>
<script>
document.getElementById('loading-message').innerHTML += ' DONE<br />Loading libraries...';
</script>
Expand Down
23 changes: 9 additions & 14 deletions js/client-mainmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@
initialize: function() {
this.$el.addClass('scrollable');

var buf = '<div class="mainmenuwrapper">';

// left menu 2 (high-res: right, low-res: top)
buf += '<div class="leftmenu"><div class="activitymenu"><div class="pmbox"></div></div>';
// (created during page load)

// left menu 1 (high-res: left, low-res: bottom)
buf += '<div class="mainmenu">';
var buf = '';
if (app.down) {
buf += '<div class="menugroup">';
if (app.down === 'ddos') {
Expand All @@ -49,18 +47,16 @@
} else {
buf += '<p><button class="button" name="joinRoom" value="ladder">Ladder</button></p>';
}
buf += '<p><button class="button" name="credits">Credits</button></p></div></div></div>';
buf += '<p><button class="button" name="credits">Credits</button></p></div></div>';
this.$('.mainmenu').html(buf);

// right menu
if (!app.down) {
buf += '<div class="rightmenu"><div class="menugroup"><p><button class="button" name="joinRoom" value="lobby">Join lobby chat</button></p></div></div>';
this.$('.rightmenu').html('<div class="menugroup"><p><button class="button" name="joinRoom" value="lobby">Join lobby chat</button></p></div>');
}

// footer
buf += '<div class="mainmenufooter"><small><a href="//pokemonshowdown.com/" target="_blank"><strong>Pok&eacute;mon Showdown</strong></a> | <a href="http://smogon.com/" target="_blank"><strong>Smogon</strong></a><br /><a href="//pokemonshowdown.com/dex/" target="_blank">Pok&eacute;dex</a> | <a href="//pokemonshowdown.com/replay/" target="_blank">Replays</a> | <a href="//pokemonshowdown.com/rules" target="_blank">Rules</a></small> | <small><a href="//pokemonshowdown.com/forums/" target="_blank">Forum</a></div>';

buf += '</div>';
this.$el.html(buf);
// (created during page load)

this.$activityMenu = this.$('.activitymenu');
this.$pmBox = this.$activityMenu.find('.pmbox');
Expand All @@ -69,9 +65,6 @@
this.updateFormats();

app.user.on('saveteams', this.updateTeams, this);

app.on('init:loadprefs', this.addNews, this);
if (app.prefsLoaded) this.addNews();
},

// news
Expand Down Expand Up @@ -188,7 +181,9 @@
// not a true PM; just close the window
$pmWindow = $(e.currentTarget).closest('.pm-window');
var newsId = $pmWindow.data('newsid');
if (newsId) Tools.prefs('readnews', ''+newsId);
if (newsId) {
$.cookie('showdown_readnews', ''+newsId, {expires: 365});
}
$pmWindow.remove();
return;
}
Expand Down
8 changes: 6 additions & 2 deletions js/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@
focused: true,
initialize: function() {
window.app = this;
$('#main').html('');
this.initializeRooms();
this.initializePopups();

Expand Down Expand Up @@ -1098,7 +1097,12 @@
}
}

var el = $('<div class="ps-room" style="display:none"></div>').appendTo('body');
var el;
if (!id) {
el = $('#mainmenu');
} else {
el = $('<div class="ps-room" style="display:none"></div>').appendTo('body');
}
var typeName = '';
if (typeof type === 'string') {
typeName = type;
Expand Down
3 changes: 3 additions & 0 deletions robots.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
User-agent: Mediapartners-Google
Disallow:

User-agent: *
Disallow: /

Expand Down

0 comments on commit daaa6f3

Please sign in to comment.