Skip to content

Commit

Permalink
jqt.autotitles fixed; added hard coded title example to demo.
Browse files Browse the repository at this point in the history
  • Loading branch information
DataZombies committed Jan 22, 2011
1 parent 77e0782 commit f7db888
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
12 changes: 11 additions & 1 deletion demos/ext_autotitles/index.html
Expand Up @@ -28,17 +28,27 @@ <h1>Auto Titles</h1>
<li><a href="#page2">Oranges</a></li>
<li><a href="#page2">Bananas</a></li>
<li><a href="#page2">Apples</a></li>
<li><a href="#page3">Hard Coded Page Title</a></li>
</ul>
</div>
<div id="page2">
<div class="toolbar">
<a href="#" class="back">back</a>
<h1>[Fruit Name]</h1>
<h1></h1>
</div>
<div class="info">
The title for this page was automatically set from it&#8217;s referring link, no extra scripts required. Just include the extension and this happens.
</div>
</div>
<div id="page3">
<div class="toolbar">
<a href="#" class="back">back</a>
<h1>Kumquats</h1>
</div>
<div class="info">
The title for this page was hard coded and <i>not</i> replaced by the extension.
</div>
</div>
</div>
</body>
</html>
14 changes: 10 additions & 4 deletions extensions/jqt.autotitles.js
Expand Up @@ -23,14 +23,20 @@
if ($.jQTouch) {
$.jQTouch.addExtension(function AutoTitles(jQT) {
var titleSelector = '.toolbar h1';

$(function () {
$('#jqt').bind('pageAnimationStart', function (e, data) {
var $ref = $(e.target).data('referrer'),
$title = $(titleSelector, $(e.target));
if (data.direction === 'in') {
var $ref = $(e.target).data('referrer'),
$title = $(titleSelector, $(e.target));
if ($title.length && $ref && $title.data('title') !== $ref.text()) {
if ($title.html() === '' && $ref && $title.data('title') !== $ref.text()) {
$title.data('title', $title.html());
$title.html($ref.text());
$title.data('title', $ref.text());
}
} else {
if (typeof($title.data('title')) !== 'undefined' && $title.data('title') !== null) {
$title.html($title.data('title'));
$title.data('title', null);
}
}
});
Expand Down

0 comments on commit f7db888

Please sign in to comment.