Skip to content
Browse files

further work on stream visualization couchapp

  • Loading branch information...
1 parent 4757dbe commit 8024cbb5cc2f154e5e52a36cb1f5a35855e3811a @maxogden committed
View
1 couchapp/_attachments/pages/index.html
@@ -85,7 +85,6 @@ <h1 id="title">Couchpubtato Feed Viewer</h1>
<a class='author hover_profile' rel='#profile_{{nickname}}_{{randomToken}}' title="{{nickname}}'s info" href='#'>
{{nickname}}
</a>
- <p></p>
{{message}}
</div>
<div class="info">
View
3 couchapp/_attachments/script/couchpubtato_viewer.js
@@ -64,7 +64,7 @@ var monocles = {
var html = $.mustache( $( "#" + template + "Template" ).text(), data ),
targetDom = $( "#" + target );
if( append ) {
- targetDom.append( html );
+ targetDom.html( html );
} else {
targetDom.html( html );
}
@@ -90,6 +90,7 @@ var monocles = {
},
getPosts: function( opts ) {
+ console.log(monocles.oldestDoc)
$.getJSON( monocles.config.baseURL + 'api', function( dbInfo ) {
if( monocles.config.vhost ) dbInfo.db_name = 'api';
monocles.render( 'db', 'stats', dbInfo );
View
115 couchapp/_attachments/script/jquery.stream.js
@@ -0,0 +1,115 @@
+(function($) {
+ $.stream = $.stream || {};
+
+ $.fn.stream = function(options) {
+ options = $.extend(true, {}, $.fn.stream.defaults, options || {});
+ }
+
+ $.fn.stream.defaults = { // set up default options
+ templateSelector: function(selector) { return "#" + selector + "Template" },
+ infiniteScrollBuffer: 400,
+ infiniteScrollContainer: $( document ),
+ loaderDom: $( '.loader' ),
+ }
+
+ $.extend($.stream, {
+
+ /** Uses mustache to render a template out to a target DOM
+ * template: camelcase ID (minus the word Template) of the DOM object containg your mustache template
+ * target: ID of the DOM node you wish to render the template into
+ * data: data object to pass into the mustache template when rendering
+ * append: whether or not to append to or replace the contents of the target
+ **/
+ render: function( template, target, data, append ) {
+ if ( ! data ) data = {};
+ var html = $.mustache( $( $.stream.templateSelector(template) ).text(), data ),
+ targetDom = $( "#" + target );
+ if( append ) {
+ targetDom.append( html );
+ } else {
+ targetDom.html( html );
+ }
+ },
+
+ bindInfiniteScroll: function() {
+ var stream = this;
+
+ $( window ).scroll( function( e ) {
+ if ( stream.loaderShowing() ) {
+ return;
+ }
+
+ var containerScrollTop = stream.infiniteScrollContainer.scrollTop();
+ if ( ! containerScrollTop ) {
+ var ownerDoc = stream.infiniteScrollContainer.get().ownerDocument;
+ if( ownerDoc ) {
+ containerScrollTop = $( ownerDoc.body ).scrollTop();
+ }
+ }
+ var distanceToBottom = $( document ).height() - ( containerScrollTop + $( window ).height() );
+
+ if ( distanceToBottom < stream.infiniteScrollBuffer ) {
+ stream.getPosts( { offsetDoc: stream.oldestDoc } );
+ }
+ });
+ },
+
+ showLoader: function() {
+ this.loaderDom.removeClass( 'hidden' );
+ },
+
+ hideLoader: function() {
+ this.loaderDom.addClass( 'hidden' );
+ },
+
+ loaderShowing: function() {
+ var showing = false;
+ if( this.loaderDom.css( 'display' ) !== "none" ) showing = true;
+ return showing;
+ },
+ });
+
+ function ajax(obj, options, errorMessage, ajaxOptions) {
+ options = $.extend({successStatus: 200}, options);
+ ajaxOptions = $.extend({contentType: "application/json"}, ajaxOptions);
+ errorMessage = errorMessage || "Unknown error";
+ $.ajax($.extend($.extend({
+ type: "GET", dataType: "json", cache : !$.browser.msie,
+ beforeSend: function(xhr){
+ if(ajaxOptions && ajaxOptions.headers){
+ for (var header in ajaxOptions.headers){
+ xhr.setRequestHeader(header, ajaxOptions.headers[header]);
+ }
+ }
+ },
+ complete: function(req) {
+ try {
+ var resp = $.httpData(req, "json");
+ } catch(e) {
+ if (options.error) {
+ options.error(req.status, req, e);
+ } else {
+ alert(errorMessage + ": " + e);
+ }
+ return;
+ }
+ if (options.ajaxStart) {
+ options.ajaxStart(resp);
+ }
+ if (req.status == options.successStatus) {
+ if (options.beforeSuccess) options.beforeSuccess(req, resp);
+ if (options.success) options.success(resp);
+ } else if (options.error) {
+ options.error(req.status, resp && resp.error || errorMessage, resp && resp.reason || "no response");
+ } else {
+ alert(errorMessage + ": " + resp.reason);
+ }
+ }
+ }, obj), ajaxOptions));
+ }
+
+ function toJSON(obj) {
+ return obj !== null ? JSON.stringify(obj) : null;
+ }
+
+})(jQuery);
View
8 couchapp/_attachments/style/monocles.css
@@ -355,6 +355,14 @@ h1.big_text {
border-top: 1px solid #999999;
border-bottom: 2px solid #eeeeee; }
+.loader {
+ width: 128px;
+ margin: 30px auto 0px auto;
+}
+
+.hidden {
+ display: none; }
+
.show_post_comments ul.comment_set {
width: 100%; }

0 comments on commit 8024cbb

Please sign in to comment.
Something went wrong with that request. Please try again.