let people embed the daily puzzle in their site!

pull/360/head
Thibault Duplessis 2015-03-17 21:22:58 +01:00
parent fd6a5ee3e4
commit 8ae8b90335
8 changed files with 93 additions and 4 deletions

View File

@ -48,8 +48,7 @@ object Main extends LilaController {
def embed = Action { req =>
Ok {
"""document.write("<iframe src='%s?embed=" + document.domain + "' class='lichess-iframe' allowtransparency='true' frameBorder='0' style='width: %dpx; height: %dpx;' title='Lichess free online chess'></iframe>");"""
.format(Env.api.Net.BaseUrl, getInt("w", req) | 820, getInt("h", req) | 650)
s"""document.write("<iframe src='${Env.api.Net.BaseUrl}?embed=" + document.domain + "' class='lichess-iframe' allowtransparency='true' frameBorder='0' style='width: ${getInt("w", req) | 820}px; height: ${getInt("h", req) | 650}px;' title='Lichess free online chess'></iframe>");"""
} as JAVASCRIPT withHeaders (CACHE_CONTROL -> "max-age=86400")
}

View File

@ -144,4 +144,22 @@ object Puzzle extends LilaController {
) map (_ as JSON)
}
}
def embed = Action { req =>
Ok {
val bg = get("bg", req) | "light"
val theme = get("theme", req) | "brown"
val url = s"""${req.domain + routes.Puzzle.frame}?bg=$bg&theme=$theme"""
s"""document.write("<iframe src='http://$url&embed=" + document.domain + "' class='lichess-training-iframe' allowtransparency='true' frameBorder='0' style='width: 224px; height: 264px;' title='Lichess free online chess'></iframe>");"""
} as JAVASCRIPT withHeaders (CACHE_CONTROL -> "max-age=86400")
}
def frame = Open { implicit ctx =>
OptionOk(env.daily()) { daily =>
html.puzzle.embed(
daily,
get("bg") | "light",
lila.pref.Theme(~get("theme")).cssClass)
}
}
}

View File

@ -0,0 +1,31 @@
@(daily: lila.puzzle.DailyPuzzle, bg: String, theme: String)(implicit ctx: Context)
<!doctype html>
<html>
<head>
<title>lichess.org training</title>
@if(bg == "dark") {
@cssTag("dark.css")
}
@cssTag(s"piece/merida.css")
@cssTag("common.css")
@cssTag("board.css")
<meta charset="utf-8">
</head>
<body
class="base highlight @bg"
style="width: 224px; height: 264px; overflow: hidden;">
<div id="daily_puzzle" class="is2d highlight @bg @theme merida" title="@trans.clickToSolve()">
@daily.html
<div class="vstext" style="text-align: center">
@trans.puzzleOfTheDay()<br />
@daily.color.fold(trans.whitePlays, trans.blackPlays)()
</div>
</div>
<script src="http://code.jquery.com/jquery-2.1.3.min.js"></script>
@jsTag("vendor/chessground.min.js")
@jsTagCompiled("puzzle.js")
@base.ga()
</body>
</html>

View File

@ -43,6 +43,35 @@
<br />
<br />
<div class="content_box small_box developers">
<h1 id="embed-puzzle" class="lichess_title">Embed the daily puzzle in your site</h1>
<div style="text-align: center;">
<script src="http://en.@netDomain/training/embed?theme=green&bg=light"></script>
</div>
<p>
Just add the following line to your site html:
</p>
<pre>&lt;script src="http://en.@netDomain/training/embed?theme=green&bg=light"&gt;&lt;/script&gt;</pre>
<p>
Parameters:
<ul>
<li>- <strong>theme</strong>: Controls the board theme. Available themes: @lila.pref.Theme.list.map(_.name).mkString(", ").</li>
<li>- <strong>bg</strong>: Controls the background color. Available backgrounds: light, dark.</li>
</ul>
</p>
<p>
The text is automatically translated to your visitor language.
</p>
</div>
<br />
<br />
<div class="content_box small_box developers">
<h1 id="use-api" class="lichess_title">Lichess HTTP API</h1>

View File

@ -13,7 +13,7 @@
<meta charset="utf-8">
</head>
<body
class="base"
class="base highlight @bg"
style="width: 224px; height: 264px; overflow: hidden;"
data-stream-url="@routes.Tv.streamOut">
<div id="featured_game" class="is2d highlight @bg @theme merida" title="lichess.org TV">

View File

@ -89,6 +89,8 @@ POST /training/difficulty controllers.Puzzle.difficulty
GET /training/new controllers.Puzzle.newPuzzle
GET /training/history controllers.Puzzle.history
GET /training/daily controllers.Puzzle.daily
GET /training/embed controllers.Puzzle.embed
GET /training/frame controllers.Puzzle.frame
GET /training/:id controllers.Puzzle.show(id: Int)
GET /training/:id/load controllers.Puzzle.load(id: Int)
POST /training/:id/attempt controllers.Puzzle.attempt(id: Int)

View File

@ -0,0 +1,11 @@
var elem = document.querySelector('#daily_puzzle .mini_board');
elem.target = '_blank';
var lm = elem.getAttribute('data-lastmove');
Chessground(elem, {
coordinates: false,
viewOnly: true,
minimalDom: true,
fen: elem.getAttribute('data-fen'),
lastMove: lm ? [lm[0] + lm[1], lm[2] + lm[3]] : null,
orientation: elem.getAttribute('data-color')
});

View File

@ -5,7 +5,6 @@ function parseFen($elem) {
$elem.each(function() {
var $this = $(this).removeClass('parse_fen');
var lm = $this.data('lastmove');
var lastMove = lm ? [lm[0] + lm[1], lm[2] + lm[3]] : [];
var color = $this.data('color');
var ground = $this.data('chessground');
var playable = $this.data('playable');