website navbar search fix

This commit is contained in:
Anand Doshi 2015-03-18 17:24:19 +05:30
parent c10e3ec75e
commit 889efae87b
4 changed files with 12 additions and 18 deletions

View file

@ -37,5 +37,8 @@
});
</script>
</div>
{% include "templates/includes/blog/blog_common.html" %}
<script>
frappe.set_search_path("/blog");
</script>
{% endblock %}

View file

@ -15,7 +15,6 @@
{% include "templates/includes/list/list.html" %}
</div>
</div>
{% include "templates/includes/blog/blog_common.html" %}
{% endblock %}
{% block script %}{% include "templates/includes/list/list.js" %}{% endblock %}

View file

@ -1,14 +0,0 @@
<script>
frappe.ready(function() {
frappe.get_navbar_search().on("keypress", function(e) {
if(e.which===13) {
var txt = $(this).val();
if(txt) {
$(this).val("");
frappe.load_via_ajax("/blog?txt=" + encodeURIComponent(txt));
}
return false;
}
});
});
</script>

View file

@ -2,6 +2,7 @@
// MIT License. See license.txt
frappe.provide("website");
frappe.provide("frappe.search_path");
$.extend(frappe, {
_assets_loaded: [],
@ -266,7 +267,7 @@ $.extend(frappe, {
},
load_via_ajax: function(href) {
// console.log("calling ajax");
// console.log("calling ajax", href);
window.previous_href = href;
history.pushState(null, null, href);
@ -438,11 +439,16 @@ $.extend(frappe, {
$(".navbar .search").on("keypress", function(e) {
var val = $(this).val();
if(e.which===13 && val) {
frappe.load_via_ajax(location.pathname + "?txt=" + encodeURIComponent(val));
$(this).val("").blur();
var path = (frappe.search_path && frappe.search_path[location.pathname] || location.pathname);
frappe.load_via_ajax(path + "?txt=" + encodeURIComponent(val));
return false;
}
});
},
set_search_path: function(path) {
frappe.search_path[location.pathname] = path;
},
make_navbar_active: function() {
var pathname = window.location.pathname;
$(".navbar-nav a.active").removeClass("active");