mirror of
https://github.com/smogon/pokemon-showdown-client.git
synced 2026-03-21 17:50:29 -05:00
Embed news into HTML for faster loading
This commit is contained in:
parent
3abcba151c
commit
daaa6f3bfd
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,5 +1,5 @@
|
|||
/sprites/
|
||||
/audio/
|
||||
/js/config.js
|
||||
/index.html
|
||||
/index.php
|
||||
.DS_Store
|
||||
|
|
|
|||
|
|
@ -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'))))
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -67,9 +67,34 @@
|
|||
<div id="header" class="header">
|
||||
<img class="logo" src="//play.pokemonshowdown.com/pokemonshowdownbeta.png" alt="Pokémon Showdown! (beta)" /><div class="maintabbarbottom"></div>
|
||||
</div>
|
||||
<div id="main">
|
||||
<div id="loading-message" class="mainmessage">Initializing... <noscript>FAILED<br /><br />Poké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é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>
|
||||
|
|
@ -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') {
|
||||
|
|
@ -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é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></div>';
|
||||
|
||||
buf += '</div>';
|
||||
this.$el.html(buf);
|
||||
// (created during page load)
|
||||
|
||||
this.$activityMenu = this.$('.activitymenu');
|
||||
this.$pmBox = this.$activityMenu.find('.pmbox');
|
||||
|
|
@ -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
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -209,7 +209,6 @@
|
|||
focused: true,
|
||||
initialize: function() {
|
||||
window.app = this;
|
||||
$('#main').html('');
|
||||
this.initializeRooms();
|
||||
this.initializePopups();
|
||||
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
User-agent: Mediapartners-Google
|
||||
Disallow:
|
||||
|
||||
User-agent: *
|
||||
Disallow: /
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user