Skip to content

Commit

Permalink
version 9. no more token input. need to use hash tags to tag foods.
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Reyes committed Nov 9, 2011
1 parent 7263f94 commit 0e33c4b
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 19 deletions.
2 changes: 1 addition & 1 deletion app.yaml
@@ -1,5 +1,5 @@
application: cmufreenoms
version: 8
version: 9
runtime: python
api_version: 1

Expand Down
67 changes: 51 additions & 16 deletions scripts/base.js
@@ -1,24 +1,58 @@
// Handler for .ready() called.
$(function(){
highlight_current_tab();

var descriptions = $('#reports .description');
descriptions.each(function(index, description){
description = $(description);
var description_words = description.text().split(" ");

/*
$("input#foods").tokenInput("/foods.json", {
preventDuplicates : true,
onAdd : function(){
setHiddenValues();
},
onRemove: function(){
setHiddenValues();
for(var i=0 ; i < description_words.length; i++){
var hash_word = description_words[i];

if(hash_word.match(/#.*/)){
var word = hash_word.substring(1,hash_word.length);
var tag_link = $('<a class="tagged_food"></a>');
tag_link.attr("href", "/find/" + word);
tag_link.text(hash_word);
description_words[i] = tag_link[0].outerHTML;

}
}
description.html(description_words.join(" "));
$('#reports .description .tagged_food').click(function(e){
searchKeyPressed(e, $(this).attr('href').match(/find\/(.*)/)[1]);
setSearchText();
return false;
});
});

$('#reports .location').click(function(e){
searchKeyPressed(e, $(this).attr('href').match(/find\/(.*)/)[1]);
setSearchText();
return false;
});
*/

$('#find_search_box').bind("keydown", function(e){
element = this;
setTimeout(function(){ searchKeyPressed(e,element); }, 1);
setTimeout(function(){ searchKeyPressed(e,$(element).val()); }, 1);
});

setSearchText();
displayNoticeIfNone();
});

function displayNoticeIfNone(){
var visible = $('#reports li.visible');
var no_results = $('#no_results');
if(visible.length == 0){
no_results.removeClass("hidden");
} else {
no_results.addClass("hidden");
}
}

function setSearchText(){
var path = window.location.pathname;
var path = decodeURIComponent(path);
var matchData = path.match(/\/find\/(.*)/);
Expand All @@ -31,11 +65,9 @@ $(function(){
window.history.pushState(null,null,"/find");
}
}
});
}

function searchKeyPressed(element){
var search_val = $(element).val();

function searchKeyPressed(e, search_val){
if(search_val != ""){
document.title = 'FREE NOMS! - Find "' + search_val + '"';
} else {
Expand All @@ -44,6 +76,7 @@ function searchKeyPressed(element){

updateSearchURL(search_val);
filterReports(search_val);
displayNoticeIfNone();
}

function updateSearchURL(val){
Expand All @@ -57,9 +90,11 @@ function filterReports(searchVal){
$.each(reports, function(index, value){
var val = $(value);
if(value.textContent.toLowerCase().match(searchRegExp)){
val.show();
val.removeClass("hidden");
val.addClass("visible")
} else {
val.hide();
val.addClass("hidden");
val.removeClass("visible")
}
});
}
Expand Down
13 changes: 13 additions & 0 deletions stylesheets/style.css
Expand Up @@ -131,6 +131,15 @@ span.separator {
text-decoration: none;
}

.hidden {
display: none;
}

#no_results{
text-align: center;
margin: 60px;
}

div.report label {
width: 90px;
display: inline-block;
Expand Down Expand Up @@ -251,4 +260,8 @@ div.login p{
img.sorry {
display: block;
margin: 50px auto 70px;
}

.tagged_food {
color: green;
}
7 changes: 5 additions & 2 deletions views/find.html
Expand Up @@ -15,14 +15,17 @@ <h2>Noms</h2>
<a class="location" href="/find/{{ report.location }}">{{ report.location }}</a>
<span class="time">{{ report.date|date:"f A" }}</span>
<span class="date">{{ report.date|date:"M j"}}</span>
{# <p>{{ report.description }}</p> #}
<p class="description">{{ report.description }}</p>
<!--
<p>
{% for spotted in report.foods %}
<span>{{ spotted.food.name }} </span>
{% endfor %}
</p>
-->
</li>
{% endfor %}
<ul>
</ul>
<p id="no_results" class="hidden">Sorry, there are no reports which meet the search constraints. :' (</p>
</div>
{% endblock %}

0 comments on commit 0e33c4b

Please sign in to comment.