1. Kenneth Love
  2. Redbeard

Commits

Kenneth Love  committed f30ce3f

added key list filtering

  • Participants
  • Parent commits 4eed33b
  • Branches default

Comments (0)

Files changed (3)

File static/js/redbeard.js

View file
  • Ignore whitespace
+jQuery.expr[':'].Contains = function(a, i, m) {
+    return (a.textContent || a.innerText || "").toUpperCase().indexOf(m[3].toUpperCase())>=0;
+}
+
+function listFilter(header, list) {
+    var form = $("<form>").attr({"class": "filterform", "action": "#"}),
+        input = $("<input>").attr({"class": "filterinput", "type": "search"});
+
+    $(form).append(input).appendTo(header);
+
+    $(input).change(function() {
+        var filter = $(this).val();
+        if (filter) {
+            $(list).find("a:not(:Contains(" + filter + "))").parent().slideUp();
+            $(list).find("a:Contains(" + filter + ")").parent().slideDown();
+        } else {
+            $(list).find("li").slideDown();
+        }
+    }).keyup(function() {
+        $(this).change();
+    });
+}

File templates/index.html

View file
  • Ignore whitespace
 	<input type="submit" value="Go">
 </form>
 
-<h2>Keys</h2>
-<ul>
+<h2 id="keyheader">Keys</h2>
+<ul id="keylist">
 	{% for key in keys %}
 	<li><a href="{{ url_for('key', key=key) }}">{{ key }}</a></li>
 	{% endfor %}
 {% block content %}
 <p>Hi! I'm some content!</p>
 {% endblock %}
+
+{% block extra_scripts %}
+	<script src="{{ url_for('static', filename='js/redbeard.js') }}"></script>
+	<script>
+		$(function() {
+			listFilter($("#keyheader"), $("#keylist"));
+		});
+	</script>
+{% endblock %}

File templates/layout.html

View file
  • Ignore whitespace
 	<link rel="stylesheet" href="{{ url_for('static', filename='css/reset.css') }}" type="text/css" media="screen" charset="utf-8">
 	<link rel="stylesheet" href="{{ url_for('static', filename='css/grid.css') }}" type="text/css" media="screen" charset="utf-8">
 	<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}" type="text/css" media="screen" charset="utf-8">
-	<script type="text/javascript" src="{{ url_for('static', filename='js/jquery-1.4.4.min.js') }}"></script>
 </head>
 <body>
 
 		{% endblock %}
 	</div>
 </div>
-
+	<script type="text/javascript" src="{{ url_for('static', filename='js/jquery-1.4.4.min.js') }}"></script>
+	{% block extra_scripts %}{% endblock %}
 </body>
 </html>