瀏覽代碼

Use same JS function to valid 404 search form and main navigation search form

Talha Mansoor 11 年之前
父節點
當前提交
34a225343a
共有 2 個文件被更改,包括 3 次插入16 次删除
  1. 1 13
      templates/404.html
  2. 2 3
      templates/base.html

+ 1 - 13
templates/404.html

@@ -20,7 +20,7 @@ Page does not exist at {{ SITENAME|striptags }} blog.
         <p>Sorry, but the page you are looking for cannot be found. It seems that the page you were trying to reach doesn't exist, or may be it has just moved, or it no longer exists.</p>
         <p>The best thing to do is to use the search form or start again from the <a href="{{ SITEURL }}">home page</a>.</p>
         <div class="input-append">
-            <form action="{{ SITEURL }}/search.html" onsubmit="return validateForm404()">
+            <form action="{{ SITEURL }}/search.html" onsubmit="return validateForm(this.elements['q'].value)">
                 <input type="text" class="span12" placeholder="Search" name="q" id="tipue_search_input_404">
                 <button class="btn" type="button">Search</button>
             </form>
@@ -28,15 +28,3 @@ Page does not exist at {{ SITENAME|striptags }} blog.
     </div>
 </div>
 {% endblock content %}
-
-{% block script %}
-{{ super() }}
-        <script>
-            function validateForm404()
-            {
-                var query_404 = document.getElementById('tipue_search_input_404');
-                return (typeof(query_404) != 'undefined' && query_404 != null && query_404.value.length > 0);
-            }
-        </script>
-
-{% endblock script %}

+ 2 - 3
templates/base.html

@@ -57,7 +57,7 @@
                             <li {% if page_name == "categories" %} class="active"{% endif %}><a href="{{ SITEURL }}/categories.html">Categories</a></li>
                             <li {% if page_name == "tags" %} class="active"{% endif %}><a href="{{ SITEURL }}/tags.html">Tags</a></li>
                             <li {% if page_name == "archives" %} class="active"{% endif %}><a href="{{ SITEURL }}/archives.html">Archives</a></li>
-                            <li><form class="navbar-search" action="{{ SITEURL }}/search.html" onsubmit="return validateForm()"> <input type="text" class="search-query" placeholder="Search" name="q" id="tipue_search_input"></form></li>
+                            <li><form class="navbar-search" action="{{ SITEURL }}/search.html" onsubmit="return validateForm(this.elements['q'].value);"> <input type="text" class="search-query" placeholder="Search" name="q" id="tipue_search_input"></form></li>
                         </ul>
                     </div>
                 </div>
@@ -79,9 +79,8 @@
         <script src="http://code.jquery.com/jquery.min.js"></script>
         <script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min.js"></script>
         <script>
-            function validateForm()
+            function validateForm(query)
             {
-                var query = document.getElementById('tipue_search_input').value;
                 return (query.length > 0);
             }
         </script>