Commits

Brantley Harris  committed fa972f0

More button action, yo.

  • Participants
  • Parent commits b9b6bf4

Comments (0)

Files changed (3)

File onpython3yet/media/css/base.css

 
 #footer a {
     color: #246;
+}
+
+.button {
+    display: block;
+    color: #444;
+    background-color: #FFF;
+    border: 1px solid #CCC;
+    text-align: center;
+    margin-left: auto;
+    margin-right: auto;
+    padding: 4px 0px;
+    width: 130px;
+    text-decoration: none !important;
+    -moz-border-radius: 4px;
+    border-radius: 4px;
+    text-shadow: #FFF 1px 1px 1px;
+}
+
+.button:hover {
+    background-color: #EEE;
+    -moz-box-shadow: 0px 0px 6px #CCC;
+    -webkit-box-shadow: 0px 0px 6px #CCC;
+    box-shadow: 0px 0px 6px #CCC;
 }

File onpython3yet/media/js/site.js

+site = {};
+site.onAjaxError = function(xhr, textStatus, errorThrown) {
+    if (console && jQuery.isFunction( console.error ))
+        console.error("Ajax error: " + textStatus + " " + errorThrown);
+};
+
+site.escapeHtml = function(s) {
+    s = s.replace(/&/g, "&");
+    s = s.replace(/</g, "&lt;");
+    s = s.replace(/>/g, "&gt;");
+    return s;
+};
+
+
+function PackageList(source) {
+    var self = this;
+    this.source = $(source);
+    this.url = this.source.attr('url');
+    this.offset = parseInt( this.source.attr('offset'), 10 );
+    this.more = $('<a class="more button" href="#">More</a>')
+                    .insertAfter(this.source)
+                    .click( function() {
+                        self.getMore();
+                        return false;
+                    });
+    
+    var hash = parseInt( window.location.hash.substring(1) );
+    console.log("Hash", hash);
+    if (hash) {
+        this.getMore( hash - this.offset );
+    }
+}
+
+PackageList.prototype.getMore = function(count) {
+    var self = this;
+    $.ajax({
+        url: this.url,
+        type: 'GET',
+        dataType: 'json',
+        data: {start: this.offset, offset: count || 40},
+        success: function(data, textStatus, xhr) {
+            $.each(data.packages, function(i, pkg) {
+                self.addPackage(pkg);
+            });
+            window.location.hash = self.offset;
+        },
+        error: site.onAjaxError
+    });
+}
+
+PackageList.prototype.addPackage = function(pkg) {
+    this.offset += 1;
+    var name = $('<div class="name">')
+        .append( site.escapeHtml( pkg.name ) );
+    var dependants = $('<div class="dependants">')
+        .append( pkg.required_count + " dependant" + (pkg.required_count == 1 ? "" : "s") );
+    var source = $('<a class="package"/>')
+        .attr('href', pkg.show_pkg_url)
+        .append(name)
+        .append(dependants)
+        .appendTo(this.source);
+}
+
+$(function(){
+    $('.package-list').each(function() {
+        new PackageList(this);
+    });
+});
+
+/*
 
 // Namespaces:
 var site = {},
 
 });
 
-site.escapeHtml = function(s) {
-    s = s.replace(/&/g, "&amp;");
-    s = s.replace(/</g, "&lt;");
-    s = s.replace(/>/g, "&gt;");
-    return s;
-};
-
 site.onAjaxError = function(xhr, textStatus, errorThrown) {
     console.error("Ajax error: " + textStatus + " " + errorThrown);
 };
 req.onResultFetch = function(pkg, data) {
     console.log('do something with data: ', data);
 };
+*/

File onpython3yet/templates/home/index.html

 {% block content %}	    
     <h2>2.x Packages Most Depended On</h2>
     <div class="info">{{ dependend_on_total }} packages out of {{ total }}</div>
-    <div id="package-list" offset="{{ offset }}" href="{% url packages.depended_on %}">
+    <div class="package-list" offset="{{ offset }}" url="{% url packages.depended_on %}">
     {% for pkg in most_depended_on %}
         {% include "pkg_link.html" %}
     {% endfor %}