Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 4 commits
  • 5 files changed
  • 0 commit comments
  • 2 contributors
View
22 apps/search/templates/search/popular.html
@@ -0,0 +1,22 @@
+{#
+<div class="search-popular search-popular-col1">
+ <h2>Popular Searches</h2>
+ <ul>
+ <li><a href="?q=">Popular Search 1</a></li>
+ <li><a href="?q=">Popular Search 2</a></li>
+ <li><a href="?q=">Popular Search 3</a></li>
+ <li><a href="?q=">Popular Search 4</a></li>
+ <li><a href="?q=">Popular Search 5</a></li>
+ </ul>
+</div>
+<div class="search-popular">
+ <h2>Popular Topics</h2>
+ <ul>
+ <li><a href="?q=">Popular Topic 1</a></li>
+ <li><a href="?q=">Popular Topic 2</a></li>
+ <li><a href="?q=">Popular Topic 3</a></li>
+ <li><a href="?q=">Popular Topic 4</a></li>
+ <li><a href="?q=">Popular Topic 5</a></li>
+ </ul>
+</div>
+#}
View
71 apps/search/templates/search/results.html
@@ -5,7 +5,10 @@
{% macro doc_block(doc) -%}
<li class="doc-result">
- {{ doc.title }}
+ {% set url = '%s%s' % (settings.SITE_URL, url('wiki.document', doc.slug, locale=doc.locale)) %}
+ <h3><a href="{{ url }}">{{ doc.title }}</a></h3>
+ <div class="searchMeta"><a href="{{ url }}">{{ url }}</a></div>
+ <p><!-- match content here --></p>
</li>
{% endmacro %}
@@ -15,24 +18,58 @@
<div id="content-main" class="full">
<article id="search-results" class="main">
<div class="search-results">
+
+ <h1>Search</h1>
+ <div class="search-form">
+ <form action="" method="get">
+ <input name="q" id="search-q" type="search" value="{{ search_query }}" autofocus />
+ <button type="submit" id="search-submit">Search!</button>
+ </form>
+ </div>
+
+ {% if search_query: %}
+ {% if result_count: %}
+ <h2>Search Results For "{{ search_query }}"</h2>
+ <ul>
+ {% for doc in results %}
+ {{ doc_block(doc) }}
+ {% endfor %}
+ </ul>
- <ul>
- {% for doc in results %}
- {{ doc_block(doc) }}
- {% endfor %}
- </ul>
-{#
- {% for doc in results %}
- <div class="result {{ doc.type }}">
- <a class="title" href="{{ doc.url|urlparams(s=q,as='s') }}">{{ doc.title }}</a>
- <p>
- <a href="{{ doc.url|urlparams(s=q,as='s') }}">
- {{ doc.search_summary|safe }}
+ <div class="pager">
+ {% if next_page %}
+ <a class="button" href="{{ request.get_full_path()|urlparams(page=next_page) }}">
+ {{ _('Next Page') }}
</a>
- </p>
- </div>
- {% endfor %}
-#}
+ {% endif %}
+ {% if prev_page %}
+ <a class="button" href="{{ request.get_full_path()|urlparams(page=prev_page) }}">
+ {{ _('Previous Page') }}
+ </a>
+ {% endif %}
+ </div>
+ {% else %}
+ <h2>{{ _('Ooops!') }}</h2>
+ <p>{{ _('No documents relating to your search could be found.') }}</p>
+ {% include 'search/popular.html' %}
+ {% endif %}
+ {% else %}
+ {% include 'search/popular.html' %}
+ {% endif %}
+
+ <style type="text/css">
+ .doc-result { padding-bottom: 20px; }
+ .doc-result h3 { margin-bottom: 0; }
+ .doc-result .searchMeta { color: #999; font-size: 0.8em; padding: .2em 0; }
+ .doc-result p { padding-left: 0; margin-bottom: 0; font-size: 0.9em; }
+ .search-form { margin-bottom: 30px; }
+ #search-q { width: 80%; }
+ #search-submit { display: inline-block; }
+ .search-popular { width: 49%; float: left; margin-top: 20px; }
+ .search-popular ul { list-style-type: circle; padding-left: 30px; }
+ .search-popular ul li { padding-bottom: 10px; }
+ .search-popular-col1{ margin-right: 1%; }
+ </style>
</div>
View
26 apps/search/views.py
@@ -26,13 +26,27 @@ def search(request):
"""Performs search or displays the search form."""
search_query = request.GET.get('q', None)
- search = DocumentType.search()
- if search_query:
- search = search.query(or_={'title': search_query,
- 'content': search_query}
- )
+ page = int(request.GET.get('page', 1))
+
+ # Pagination
+ if page < 1:
+ page = 1
+ page_count = 10
+ start = page_count * (page - 1)
+ end = start + page_count
- return jingo.render(request, 'search/results.html', {'results': search})
+ results = DocumentType.search()
+ if search_query:
+ results = results.query(or_={'title': search_query,
+ 'content': search_query})
+ result_count = results.count()
+ results = results[start:end]
+
+ return jingo.render(request, 'search/results.html', {'results': results,
+ 'search_query': search_query,
+ 'result_count': result_count,
+ 'prev_page': page - 1 if start > 0 else None,
+ 'next_page': page + 1 if end < result_count else None})
@cache_page(60 * 15) # 15 minutes.
View
63 media/js/mdn/demos-devderby-landing.js
@@ -1,56 +1,63 @@
- function derbyTabs(targetblock) {
+(function() {
+
+ var targetRegex = /.*?#(.*)/g,
+ tabRegex = /.*?#tab-*/;
+
+ window.derbyTabs = function(targetblock) {
var currentblock;
- $("#current-challenge .block").addClass("block-hidden");
+ $('#current-challenge .block').addClass('block-hidden');
- if (targetblock) {
- currentblock = targetblock.replace( /.*?#(.*)/g, "$1" ); // determine which block to show by extracting the id from the href
+ if(targetblock) {
+ currentblock = targetblock.replace(targetRegex, '$1'); // determine which block to show by extracting the id from the href
tabSwitch(currentblock);
}
- else if ( !targetblock && (/.*?#tab-*/.test(window.location)) ) { // if no target is supplied, check the url for a fragment id prefixed with "tab-" (this means inbound links can point directly to a tab)
- currentblock = window.location.href.replace( /.*?#(.*)/g, "$1" );
- $("html,body").animate({scrollTop: $("#current-challenge").offset().top - 150}, 0); // HACK: compensate for overshooting the tabs when the page loads
+ else if(!targetblock && (tabRegex.test(window.location))) { // if no target is supplied, check the url for a fragment id prefixed with 'tab-' (this means inbound links can point directly to a tab)
+ currentblock = window.location.href.replace(targetRegex, '$1');
+ $('html,body').animate({scrollTop: $('#current-challenge').offset().top - 150}, 0); // HACK: compensate for overshooting the tabs when the page loads
tabSwitch(currentblock);
}
else {
- currentblock = $("#current-challenge .tabs li.current a").attr("href").replace( /.*?#(.*)/g, "$1" );
+ currentblock = $('#current-challenge .tabs li.current a').attr('href').replace(targetRegex, '$1');
tabSwitch(currentblock);
}
- $("#"+currentblock).removeClass("block-hidden"); // make the current block visible
- }
-
- function tabSwitch(targettab) {
- var tabs = $("#current-challenge .tabs li a");
+ $('#'+currentblock).removeClass('block-hidden'); // make the current block visible
+ };
+
+ window.tabSwitch = function(targettab) {
+ var tabs = $('#current-challenge .tabs li a');
if (targettab) {
for (var i = 0; i < tabs.length; i++) { // loop through the tabs
- var tab = $(tabs[i]).attr("href").replace( /.*?#(.*)/g, "$1" ); // strip down the href
+ var tab = $(tabs[i]).attr('href').replace(targetRegex, '$1'); // strip down the href
if ( targettab == tab ) { // if one of them matches our target
- $("#current-challenge .tabs li").removeClass("current"); // first clean the slate
- $("#current-challenge .tabs li a[href$=#"+targettab+"]").parents("li").addClass("current"); // then set that tab as current
+ $('#current-challenge .tabs li').removeClass('current'); // first clean the slate
+ $('#current-challenge .tabs li a[href$=#'+targettab+']').parents('li').addClass('current'); // then set that tab as current
}
}
}
};
-
- $("#current-challenge .tabs li a").click(function(){
- $("#current-challenge .tabs li").removeClass("current");
- $(this).parents("li").addClass("current");
- derbyTabs( $(this).attr("href").replace( /.*?#(.*)/g, "$1" ) ); // transmit target
+
+ $('#current-challenge .tabs li a').click(function(){
+ $('#current-challenge .tabs li').removeClass('current');
+ $(this).parents('li').addClass('current');
+ derbyTabs($(this).attr('href').replace(targetRegex, '$1')); // transmit target
return false;
- });
-
- $("#nav-derby a[rel=tab]").click(function(){
- derbyTabs( $(this).attr("href").replace( /.*?#(.*)/g, "$1" ) ); // transmit target
});
+ $('#nav-derby a[rel=tab]').click(function(){
+ derbyTabs($(this).attr('href').replace(targetRegex, '$1')); // transmit target
+ });
+
$(document).ready(function(){
derbyTabs();
- $("#upcoming li").hover(
+ $('#upcoming li').hover(
function(){
- $(this).children(".desc").fadeIn('fast');
+ $(this).children('.desc').fadeIn('fast');
},
function(){
- $(this).children(".desc").fadeOut('fast');
+ $(this).children('.desc').fadeOut('fast');
}
);
});
+
+})();
View
2 templates/base.html
@@ -140,7 +140,9 @@
<noscript><button type="submit">{{ _('Search') }}</button></noscript>
</p>
<input type="hidden" name="sitesearch" value="developer.mozilla.org">
+ {% if not waffle.flag('elasticsearch') %}
<div id="site-search-gg"></div>
+ {% endif %}
</form>
<a href="http://www.mozilla.org/" id="tabzilla">mozilla</a>

No commit comments for this range

Something went wrong with that request. Please try again.