Bookdetail is handled with ajax. Template is not complete though. re #73

Fixes some small bugs with the other template.
This commit is contained in:
Sébastien Lucas 2013-06-15 16:09:37 +02:00
parent b7ab8bd9d9
commit a0cb911ce9
7 changed files with 101 additions and 16 deletions

View file

@ -343,6 +343,7 @@ class Page
public $query; public $query;
public $favicon; public $favicon;
public $n; public $n;
public $book;
public $totalNumber = -1; public $totalNumber = -1;
public $entryArray = array(); public $entryArray = array();
@ -678,8 +679,8 @@ class PageBookDetail extends Page
{ {
public function InitializeContent () public function InitializeContent ()
{ {
$book = Book::getBookById ($this->idGet); $this->book = Book::getBookById ($this->idGet);
$this->title = $book->title; $this->title = $this->book->title;
} }
} }

View file

@ -115,7 +115,16 @@ class Book extends Base {
} }
} }
$serie = $this->getSerie (); $serie = $this->getSerie ();
if (is_null ($serie)) $serie = ""; if (is_null ($serie)) {
$sn = "";
$scn = "";
$su = "";
} else {
$sn = $serie->name;
$scn = str_format (localize ("content.series.data"), $this->seriesIndex, $serie->name);
$link = new LinkNavigation ($serie->getUri ());
$su = $link->hrefXhtml ();
}
return array ("hasCover" => $this->hasCover, return array ("hasCover" => $this->hasCover,
"preferedData" => $preferedData, "preferedData" => $preferedData,
@ -124,7 +133,33 @@ class Book extends Base {
"pubDate" => $this->getPubDate (), "pubDate" => $this->getPubDate (),
"authorsName" => $this->getAuthorsName (), "authorsName" => $this->getAuthorsName (),
"tagsName" => $this->getTagsName (), "tagsName" => $this->getTagsName (),
"seriesName" => $serie); "seriesName" => $sn,
"seriesCompleteName" => $scn,
"seriesurl" => $su);
}
public function getFullContentArray () {
$out = $this->getContentArray ();
$out ["detailurl"] = $this->getDetailUrl (true);
$out ["coverurl"] = Data::getLink ($this, "jpg", "image/jpeg", Link::OPDS_IMAGE_TYPE, "cover.jpg", NULL)->hrefXhtml ();
$out ["thumbnailurl"] = Data::getLink ($this, "jpg", "image/jpeg", Link::OPDS_THUMBNAIL_TYPE, "cover.jpg", NULL, NULL, 150)->hrefXhtml ();
$out ["datas"] = array ();
foreach ($this->getDatas() as $data) {
array_push ($out ["datas"], array ("format" => $data->format, "url" => $data->getHtmlLink ()));
}
$out ["authors"] = array ();
foreach ($this->getAuthors () as $author) {
$link = new LinkNavigation ($author->getUri ());
array_push ($out ["authors"], array ("name" => $author->name, "url" => $link->hrefXhtml ()));
}
$out ["tags"] = array ();
foreach ($this->getTags () as $tag) {
$link = new LinkNavigation ($tag->getUri ());
array_push ($out ["tags"], array ("name" => $tag->name, "url" => $link->hrefXhtml ()));
}
;
return $out;
} }
public function getDetailUrl ($permalink = false) { public function getDetailUrl ($permalink = false) {

View file

@ -31,6 +31,9 @@
foreach ($currentPage->entryArray as $entry) { foreach ($currentPage->entryArray as $entry) {
array_push ($entries, $entry->getContentArray ()); array_push ($entries, $entry->getContentArray ());
} }
if (!is_null ($currentPage->book)) {
$out ["book"] = $currentPage->book->getFullContentArray ();
}
$out ["databaseId"] = GetUrlParam (DB, ""); $out ["databaseId"] = GetUrlParam (DB, "");
$out ["databaseName"] = Base::getDbName (); $out ["databaseName"] = Base::getDbName ();
$out ["page"] = $page; $out ["page"] = $page;
@ -60,7 +63,8 @@
"previousAlt" => localize ("paging.previous.alternate"), "previousAlt" => localize ("paging.previous.alternate"),
"nextAlt" => localize ("paging.next.alternate"), "nextAlt" => localize ("paging.next.alternate"),
"searchAlt" => localize ("search.alternate"), "searchAlt" => localize ("search.alternate"),
"homeAlt" => localize ("home.alternate")); "homeAlt" => localize ("home.alternate"),
"permalinkAlt" => localize ("permalink.alternate"));
$out ["containsBook"] = 0; $out ["containsBook"] = 0;
if ($currentPage->containsBook ()) { if ($currentPage->containsBook ()) {

View file

@ -95,13 +95,6 @@
nextEffect : 'none' nextEffect : 'none'
<?php if ($isEink) echo ", openEffect : 'none', closeEffect : 'none', helpers : {overlay : null}"; ?> <?php if ($isEink) echo ", openEffect : 'none', closeEffect : 'none', helpers : {overlay : null}"; ?>
}); });
$(".fancydetail").fancybox({
'type' : 'ajax',
prevEffect : 'none',
nextEffect : 'none'
<?php if ($isEink) echo ", openEffect : 'none', closeEffect : 'none', helpers : {overlay : null}"; ?>
});
<?php } ?> <?php } ?>
$(".headright").click(function(){ $(".headright").click(function(){
@ -114,6 +107,10 @@
} }
}); });
$.get('templates/default/bookdetail.html', function(data){
templateBookDetail = doT.template (data);
});
$.get('templates/default/frontpage.html', function(data){ $.get('templates/default/frontpage.html', function(data){
template = doT.template(data); template = doT.template(data);
$.getJSON('<?php echo "getJSON.php?" . str_replace ("&", "&amp;", $_SERVER["QUERY_STRING"]); ?>', function(data) { $.getJSON('<?php echo "getJSON.php?" . str_replace ("&", "&amp;", $_SERVER["QUERY_STRING"]); ?>', function(data) {

View file

@ -0,0 +1,34 @@
<article class="bookpopup">
<span class="cover">
{{? it.book.hasCover == 1}}
<a href="{{=it.book.coverurl}}">
<img src="{{=it.book.thumbnailurl}}" alt="{{=it.i18n.coverAlt}}" />
</a>
{{?}}
</span>
<h2 class="download">
{{~it.book.datas:data:i}}
<a href="{{=data.url}}">{{=data.format}}</a><br />
{{~}}
</h2>
<h1><a rel="bookmark" href="{{=it.book.detailurl}}"><img src="images/Link.png?v={{=it.version}}" alt="{{=it.i18n.permalinkAlt}}" /></a>{{=htmlEscape (it.title)}}</h1>
<p class="popupless">
<h3>{{=it.i18n.authorsTitle}}: </h3>
{{~it.book.authors:author:j}}
{{? j > 0}}, {{?}}<a href="{{=author.url}}">{{=htmlEscape (author.name)}}</a>
{{~}}
</p>
{{? it.book.tagsName != ""}}
<p class="popupless">
<h3>{{=it.i18n.tagsTitle}}: </h3>
{{~it.book.tags:tag:k}}
{{? k > 0}}, {{?}}<a href="{{=tag.url}}">{{=htmlEscape (tag.name)}}</a>
{{~}}
</p>
{{?}}
{{? it.book.seriesName != ""}}
<p class="popupless">
<h3><a href="{{=it.book.seriesurl}}">{{=it.i18n.seriesTitle}}</a> : </h3>{{=htmlEscape (it.book.seriesCompleteName)}}
</p>
{{?}}
</article>

View file

@ -55,7 +55,7 @@
</h2> </h2>
<h4>{{=it.i18n.authorsTitle}} : </h4><span class="sa">{{=htmlEscape (entry.book.authorsName)}}</span><br /> <h4>{{=it.i18n.authorsTitle}} : </h4><span class="sa">{{=htmlEscape (entry.book.authorsName)}}</span><br />
{{? entry.book.tagsName != ""}}<h4>{{=it.i18n.tagsTitle}} : </h4>{{=htmlEscape (entry.book.tagsName)}}<br />{{?}} {{? entry.book.tagsName != ""}}<h4>{{=it.i18n.tagsTitle}} : </h4>{{=htmlEscape (entry.book.tagsName)}}<br />{{?}}
{{? entry.book.seriesName != ""}}<h4>{{=it.i18n.seriesTitle}} : </h4>{{=htmlEscape (entry.book.SeriesName)}}<br />{{?}} {{? entry.book.seriesName != ""}}<h4>{{=it.i18n.seriesTitle}} : </h4>{{=htmlEscape (entry.book.seriesName)}}<br />{{?}}
</div></a> </div></a>
</article> </article>
{{?}} {{?}}

18
util.js
View file

@ -1,4 +1,4 @@
var template, result; var template, templateBookDetail, result;
function htmlEscape(str) { function htmlEscape(str) {
return String(str) return String(str)
@ -10,7 +10,7 @@ function htmlEscape(str) {
} }
function navigateTo (url) { function navigateTo (url) {
jsonurl = url.replace ("index", "getJSON"); var jsonurl = url.replace ("index", "getJSON");
$.getJSON(jsonurl, function(data) { $.getJSON(jsonurl, function(data) {
history.pushState(data, "", url); history.pushState(data, "", url);
updatePage (data); updatePage (data);
@ -23,6 +23,20 @@ function updatePage (data) {
$(".container").html (result); $(".container").html (result);
ajaxifyLinks (); ajaxifyLinks ();
$(".fancydetail").click(function(event){
event.preventDefault();
var url = $(this).attr("href");
var jsonurl = url.replace ("bookdetail", "getJSON");
$.getJSON(jsonurl, function(data) {
var detail = templateBookDetail (data);
$.fancybox( {
content: detail,
autoSize: true
});
});
});
} }
function ajaxifyLinks () { function ajaxifyLinks () {