Skip to content

Commit

Permalink
day 19
Browse files Browse the repository at this point in the history
  • Loading branch information
typester committed Dec 21, 2009
1 parent 088bea2 commit 5b29703
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/Jobeet/Controller/Search.pm
Expand Up @@ -10,6 +10,10 @@ sub index :Path {
or $c->detach('/default');

$c->stash->{jobs} = models('Schema::Job')->search_fulltext($query);

if ($c->req->header('X-Requested-With') =~ /XMLHttpRequest/i) {
$c->view('MT')->template('search/ajax');
}
}

1;
Expand Down
6 changes: 5 additions & 1 deletion root/common/base.mt
Expand Up @@ -6,7 +6,10 @@
<link rel="shortcut icon" href="/favicon.ico" />
<link rel="alternate" type="application/atom+xml" title="Latest Jobs"
href="<?= $c->uri_for('/job/atom') ?>" />
<? block javascripts => '' ?>
? block javascripts => sub {
<script type="text/javascript" src="<?= $c->uri_for('/js/jquery-1.3.2.min.js') ?>"></script>
<script type="text/javascript" src="<?= $c->uri_for('/js/search.js') ?>"></script>
? } # endblock javascripts
<? block stylesheets => '' ?>
</head>
<body>
Expand All @@ -31,6 +34,7 @@
<input type="text" name="q"
id="search_keywords" />
<input type="submit" value="search" />
<img id="loader" src="<?= $c->uri_for('/images/loader.gif') ?>" style="vertical-align: middle; display: none" />
<div class="help">
Enter some keywords (city, country, position, ...)
</div>
Expand Down
19 changes: 19 additions & 0 deletions root/js/jquery-1.3.2.min.js

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions root/js/search.js
@@ -0,0 +1,18 @@
$(document).ready(function()
{
$('.search input[type="submit"]').hide();

$('#search_keywords').keyup(function(key)
{
if (this.value.length >= 3 || this.value == '')
{
$('#loader').show();
$('#jobs').load(
$(this).parents('form').attr('action'),
{ q: this.value + '*' },
function() { $('#loader').hide(); }
);
}
});
});

8 changes: 8 additions & 0 deletions root/search/ajax.mt
@@ -0,0 +1,8 @@
? my @jobs = $c->stash->{jobs}->all;

? if (@jobs) {
?= include('job/partial_jobs', @jobs );
? } else {
No results.
? }

0 comments on commit 5b29703

Please sign in to comment.