+
6 ) {
get_template_part( 'inc/more-posts' );
-} //$i > 6
+}
?>
diff --git a/js/lazyload.js b/js/lazyload.js
deleted file mode 100644
index 3e4a5f4..0000000
--- a/js/lazyload.js
+++ /dev/null
@@ -1,15 +0,0 @@
-(function($,window,document,undefined){var $window=$(window);$.fn.lazyload=function(options){var elements=this;var $container;var settings={threshold:0,failure_limit:0,event:"scroll",effect:"show",container:window,data_attribute:"original",skip_invisible:true,appear:null,load:null,placeholder:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC"};function update(){var counter=0;elements.each(function(){var $this=$(this);if(settings.skip_invisible&&!$this.is(":visible")){return;}
-if($.abovethetop(this,settings)||$.leftofbegin(this,settings)){}else if(!$.belowthefold(this,settings)&&!$.rightoffold(this,settings)){$this.trigger("appear");counter=0;}else{if(++counter>settings.failure_limit){return false;}}});}
-if(options){if(undefined!==options.failurelimit){options.failure_limit=options.failurelimit;delete options.failurelimit;}
-if(undefined!==options.effectspeed){options.effect_speed=options.effectspeed;delete options.effectspeed;}
-$.extend(settings,options);}
-$container=(settings.container===undefined||settings.container===window)?$window:$(settings.container);if(0===settings.event.indexOf("scroll")){$container.bind(settings.event,function(){return update();});}
-this.each(function(){var self=this;var $self=$(self);self.loaded=false;if($self.attr("src")===undefined||$self.attr("src")===false){if($self.is("img")){$self.attr("src",settings.placeholder);}}
-$self.one("appear",function(){if(!this.loaded){if(settings.appear){var elements_left=elements.length;settings.appear.call(self,elements_left,settings);}
-$("
![]()
").bind("load",function(){var original=$self.attr("data-"+settings.data_attribute);$self.hide();if($self.is("img")){$self.attr("src",original);}else{$self.css("background-image","url('"+original+"')");}
-$self[settings.effect](settings.effect_speed);self.loaded=true;var temp=$.grep(elements,function(element){return!element.loaded;});elements=$(temp);if(settings.load){var elements_left=elements.length;settings.load.call(self,elements_left,settings);}}).attr("src",$self.attr("data-"+settings.data_attribute));}});if(0!==settings.event.indexOf("scroll")){$self.bind(settings.event,function(){if(!self.loaded){$self.trigger("appear");}});}});$window.bind("resize",function(){update();});if((/(?:iphone|ipod|ipad).*os 5/gi).test(navigator.appVersion)){$window.bind("pageshow",function(event){if(event.originalEvent&&event.originalEvent.persisted){elements.each(function(){$(this).trigger("appear");});}});}
-$(document).ready(function(){update();});return this;};$.belowthefold=function(element,settings){var fold;if(settings.container===undefined||settings.container===window){fold=(window.innerHeight?window.innerHeight:$window.height())+$window.scrollTop();}else{fold=$(settings.container).offset().top+$(settings.container).height();}
-return fold<=$(element).offset().top-settings.threshold;};$.rightoffold=function(element,settings){var fold;if(settings.container===undefined||settings.container===window){fold=$window.width()+$window.scrollLeft();}else{fold=$(settings.container).offset().left+$(settings.container).width();}
-return fold<=$(element).offset().left-settings.threshold;};$.abovethetop=function(element,settings){var fold;if(settings.container===undefined||settings.container===window){fold=$window.scrollTop();}else{fold=$(settings.container).offset().top;}
-return fold>=$(element).offset().top+settings.threshold+$(element).height();};$.leftofbegin=function(element,settings){var fold;if(settings.container===undefined||settings.container===window){fold=$window.scrollLeft();}else{fold=$(settings.container).offset().left;}
-return fold>=$(element).offset().left+settings.threshold+$(element).width();};$.inviewport=function(element,settings){return!$.rightoffold(element,settings)&&!$.leftofbegin(element,settings)&&!$.belowthefold(element,settings)&&!$.abovethetop(element,settings);};$.extend($.expr[":"],{"below-the-fold":function(a){return $.belowthefold(a,{threshold:0});},"above-the-top":function(a){return!$.belowthefold(a,{threshold:0});},"right-of-screen":function(a){return $.rightoffold(a,{threshold:0});},"left-of-screen":function(a){return!$.rightoffold(a,{threshold:0});},"in-viewport":function(a){return $.inviewport(a,{threshold:0});},"above-the-fold":function(a){return!$.belowthefold(a,{threshold:0});},"right-of-fold":function(a){return $.rightoffold(a,{threshold:0});},"left-of-fold":function(a){return!$.rightoffold(a,{threshold:0});}});})(jQuery,window,document);
\ No newline at end of file
diff --git a/js/mitlibnews.js b/js/mitlibnews.js
new file mode 100644
index 0000000..1318404
--- /dev/null
+++ b/js/mitlibnews.js
@@ -0,0 +1,17 @@
+var jQuery, NewsLoader, Loader;
+
+(function($) {
+
+ //lazy loading
+ $("img.img-responsive").lazyload({
+ effect : "fadeIn",
+ effectspeed: 450,
+ failure_limit: 999999
+ });
+
+ //category force selection of all news
+ $('input:checkbox[id=in-category-43]').attr('checked',true);
+
+ NewsLoader = new Loader();
+
+})(jQuery);
diff --git a/js/myScripts.js b/js/myScripts.js
deleted file mode 100644
index 7d5ed16..0000000
--- a/js/myScripts.js
+++ /dev/null
@@ -1,35 +0,0 @@
-
-
-(function($) {
-
- //lazy loading
- $("img.img-responsive").lazyload({
- effect : "fadeIn",
- effectspeed: 450 ,
- failure_limit: 999999
- });
-
- //category force selection of all news
- $('input:checkbox[id=in-category-43]').attr('checked',true);
-
-})(jQuery);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/js/src/mitlibnews.loader.js b/js/src/mitlibnews.loader.js
new file mode 100644
index 0000000..c55c8af
--- /dev/null
+++ b/js/src/mitlibnews.loader.js
@@ -0,0 +1,214 @@
+var document, jQuery;
+
+function Loader(params) {
+ "use strict";
+
+ // Default parameters
+ // Container is the HTML element to which everything is added.
+ this.container = 'mitlibnews-container';
+ // Postcontainer is DOM element corresponding to Container.
+ this.postcontainer = '';
+ // Page is the counter used for pagination.
+ this.page = 1;
+ // Pagesize sets how many articles are loaded in a page
+ this.pagesize = 9;
+ // Postcontent determines what type of content is loaded from the API
+ this.postcontent = 'all';
+
+ // Read param object, if passed, and set new values
+ if ( params ) {
+ if ( '' !== params.container ) {
+ this.setContainer( params.container );
+ }
+ if ( '' !== params.page ) {
+ this.setPage( params.page );
+ }
+ if ( '' !== params.pagesize ) {
+ this.setPagesize( params.pagesize );
+ }
+ if ( '' !== params.postcontent ) {
+ this.setPostcontent( params.postcontent );
+ }
+ }
+
+ // Connect to markup, read data attributes
+ this.initialize();
+
+}
+
+Loader.prototype = {
+ constructor: Loader,
+
+ // Initialization
+ initialize : function() {
+ // Look up specified post container in DOM
+ console.log('Looking for ' + this.getContainer() );
+ this.postcontainer = document.getElementById( this.getContainer() );
+
+ // If no post container is found, then we quit and do nothing further.
+ if( !this.postcontainer ) {
+ console.log('Post container not found...');
+ return false;
+ } else {
+ console.log('Post container found. Continuing...');
+ }
+
+ // Read data attributes
+ this.loadAttributes();
+
+ // Load posts
+ this.loadPosts();
+ },
+
+ /**
+ * Build query
+ *
+ * This builds a JSON object that will be fed to the API in order to return posts
+ */
+ buildQuery : function() {
+ var query = {
+ 'page': this.getPage(),
+ };
+ var filter = {
+ 'posts_per_page': this.getPagesize(),
+ };
+ var type = ['post', 'bibliotech', 'spotlights'];
+ // Context-specific values
+ if ( this.getPostcontent() === 'author' ) {
+ filter.author = this.postcontainer.dataset.postauthor;
+ // Author indexes don't show Spotlights
+ type = ['post', 'bibliotech'];
+ } else if ( this.getPostcontent() === 'bibliotech' ) {
+ // Only return bibliotech content
+ type = ['bibliotech'];
+ } else if ( this.getPostcontent() === 'category' ) {
+ query.categories = [this.postcontainer.dataset.postcategory];
+ } else if ( this.getPostcontent() === 'futureevents' ) {
+ // Only return post content
+ type = ['post'];
+ filter.meta_query = [{
+ 'key': 'is_event',
+ 'value': true,
+ 'type': 'future',
+ }];
+ } else if ( this.getPostcontent() === 'issue' ) {
+ query.issue = this.postcontainer.dataset.postissue;
+ type = ['bibliotech'];
+ } else if ( this.getPostcontent() === 'news' ) {
+ // Only return post content
+ type = ['post'];
+ filter.meta_query = [{
+ 'key': 'is_event',
+ 'value': false,
+ }];
+ } else if ( this.getPostcontent() === 'pastevents' ) {
+ // Only return post content
+ type = ['post'];
+ filter.meta_query = [{
+ 'key': 'is_event',
+ 'value': true,
+ 'type': 'past',
+ }];
+ } else if ( this.getPostcontent() === 'related' ) {
+ // Related queries are sorted randomly
+ filter.orderby = 'rand';
+ query.categories = [this.postcontainer.dataset.postcategory];
+ } else if ( this.getPostcontent() === 'search' ) {
+ query.search = this.postcontainer.dataset.search;
+ }
+ // Assemble pieces into query object
+ query.filter = filter;
+ query.type = type;
+ return query;
+ },
+
+ // Load attributes
+ loadAttributes : function() {
+ // If the post container doesn't have data attributes, then leave the defaults
+ if ( !this.postcontainer || !this.postcontainer.dataset ) {
+ return true;
+ }
+
+ if ( this.postcontainer.dataset.pagesize ) {
+ this.setPagesize( this.postcontainer.dataset.pagesize );
+ }
+
+ if ( this.postcontainer.dataset.postcontent ) {
+ this.setPostcontent( this.postcontainer.dataset.postcontent );
+ }
+
+ // At this point, the status of values like this.postcontent are set.
+
+ return true;
+ },
+
+ // Load posts
+ loadPosts : function() {
+
+ // Assemble query object
+ var query = this.buildQuery();
+
+ console.log('Query object:');
+ console.log(query);
+
+ // Query the API
+ jQuery.ajax({
+ url: '/news/wp-json/mitlibnews/v1/cards',
+ data: query,
+ dataType: 'json',
+ type: 'GET',
+ success: function(data) {
+ jQuery.each(data, function( index, value ) {
+ console.log('\n' + value.type + '\n' + value.title.rendered );
+ console.log(value);
+ });
+ },
+ error: function() {
+ console.log('Error');
+ }
+ });
+ },
+
+ // Render a JSON object into HTML
+ renderCard: function(index, post) {
+ console.log(index);
+ console.log(post);
+ jQuery( this.postContainer ).append( post );
+ },
+
+ // Container getter and setter
+ getContainer : function() {
+ return this.container;
+ },
+
+ setContainer : function(value) {
+ this.container = value;
+ },
+
+ // Page getter and setter
+ getPage : function() {
+ return +this.page;
+ },
+
+ setPage : function(value) {
+ this.page = +value;
+ },
+
+ // Pagesize getter and setter
+ getPagesize : function() {
+ return +this.pagesize;
+ },
+
+ setPagesize : function(value) {
+ this.pagesize = +value;
+ },
+
+ // Postcontent getter and setter
+ getPostcontent : function() {
+ return this.postcontent;
+ },
+
+ setPostcontent : function(value) {
+ this.postcontent = value;
+ }
+};
\ No newline at end of file
diff --git a/js/tests/mitlibnews.loader.spec.js b/js/tests/mitlibnews.loader.spec.js
new file mode 100644
index 0000000..6fb5bee
--- /dev/null
+++ b/js/tests/mitlibnews.loader.spec.js
@@ -0,0 +1,57 @@
+describe("Loader test suite", function() {
+ it("expects tautologies", function() {
+ expect(true).toBe(true);
+ });
+
+ it("should have expected defaults", function() {
+ var test = new Loader();
+ expect( test.container ).toEqual('mitlibnews-container');
+ expect( test.page ).toEqual(1);
+ expect( test.pagesize ).toEqual(9);
+ expect( test.postcontent ).toEqual('all');
+ });
+
+ it("should allow objects passed in definition", function() {
+ var test = new Loader({container: 'foo', page: 3, pagesize: 5, postcontent: 'bar'});
+ expect( test.container ).toEqual('foo');
+ expect( test.page ).toEqual(3);
+ expect( test.pagesize ).toEqual(5);
+ expect( test.postcontent ).toEqual('bar');
+ });
+
+ it("should have container getter and setter methods", function() {
+ var test = new Loader();
+ expect( test.getContainer() ).toEqual('mitlibnews-container');
+ expect( test.getContainer( test.setContainer('bar') ) ).toEqual('bar');
+ });
+
+ it("should have page getter and setter methods", function() {
+ var test = new Loader();
+ expect( test.getPage() ).toEqual(1);
+ expect( test.getPage( test.setPage(2) ) ).toEqual(2);
+ });
+
+ it("should have pagesize getter and setter methods", function() {
+ var test = new Loader();
+ expect( test.getPagesize() ).toEqual(9);
+ expect( test.getPagesize( test.setPagesize(12) ) ).toEqual(12);
+ });
+
+ it("should have postcontent getter and setter methods", function() {
+ var test = new Loader();
+ expect( test.getPostcontent() ).toEqual('all');
+ expect( test.getPostcontent( test.setPostcontent('baz') ) ).toEqual('baz');
+ });
+
+ it("should build a query object", function() {
+ var test = new Loader();
+ defaultQuery = {
+ page: 1,
+ filter: {
+ posts_per_page: 9,
+ },
+ type: ['post', 'bibliotech', 'spotlights']
+ }
+ expect( test.buildQuery() ).toEqual(defaultQuery);
+ });
+});
\ No newline at end of file
diff --git a/package.json b/package.json
index f86127d..43f77c4 100644
--- a/package.json
+++ b/package.json
@@ -1,8 +1,8 @@
{
"name": "mitlibraries-news",
- "version": "1.3.0",
+ "version": "2.0.0",
"description": "A Wordpress child theme that descends from mitlibraries-parent",
- "main": "index.js",
+ "main": "mitlibnews.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
@@ -22,10 +22,14 @@
"devDependencies": {
"glob": "^7.0.5",
"grunt": "^1.0.1",
+ "grunt-contrib-jasmine": "^1.0.3",
+ "grunt-contrib-jshint": "^1.0.0",
+ "grunt-contrib-uglify": "^2.0.0",
"grunt-gitinfo": "^0.1.8",
"grunt-replace": "^1.0.1"
},
"dependencies": {
+ "jquery-lazyload": "^1.9.7",
"load-grunt-tasks": "^3.5.0"
}
}
diff --git a/page-biblio-archive.php b/page-biblio-archive.php
index 7223c4e..9c8f6ea 100644
--- a/page-biblio-archive.php
+++ b/page-biblio-archive.php
@@ -59,7 +59,7 @@
?>
diff --git a/page-bibliotech.php b/page-bibliotech.php
index a0b44ab..f428b2d 100644
--- a/page-bibliotech.php
+++ b/page-bibliotech.php
@@ -50,7 +50,7 @@
-
+
@@ -58,7 +58,7 @@