diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..aa73e00 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,24 @@ +{ + "curly" : true, + "eqeqeq" : true, + "immed" : true, + "latedef" : true, + "newcap" : true, + "noarg" : true, + "sub" : true, + "undef" : true, + "boss" : true, + "eqnull" : true, + "node" : true, + "es5" : false, + "globals" : { + "it" : false, + "xit" : false, + "describe" : false, + "xdescribe" : false, + "beforeEach" : false, + "afterEach" : false, + "expect" : false, + "spyOn" : false + } +} diff --git a/.travis.yml b/.travis.yml index 95d75ab..206d836 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,8 +10,12 @@ language: php # Declare versions of PHP to use. Use one decimal max. php: + # aliased to a recent 7.0.x version + - "7.0" + # aliased to a recent 5.6.x version + - "5.6" # aliased to a recent 5.5.x version - # "5.5" + - "5.5" # aliased to a recent 5.4.x version - "5.4" # aliased to a recent 5.3.x version @@ -26,6 +30,10 @@ env: # @link https://github.com/WordPress/WordPress # WP_VERSION=master WP_MULTISITE=0 # WP_VERSION=master WP_MULTISITE=1 + # WordPress 4.6 + # @link https://github.com/WordPress/WordPress/tree/4.6-branch + # WP_VERSION=4.6 WP_MULTISITE=0 + - WP_VERSION=4.6 WP_MULTISITE=1 # WordPress 4.5 # @link https://github.com/WordPress/WordPress/tree/4.5-branch # WP_VERSION=4.5 WP_MULTISITE=0 @@ -41,7 +49,11 @@ env: matrix: allow_failures: - php: "5.4" - - env: WP_VERSION=4.5 WP_MULTISITE=1 + - php: "5.5" + - php: "5.6" + - php: "7.0" + - env: "WP_VERSION=4.5 WP_MULTISITE=1" + - env: "WP_VERSION=4.6 WP_MULTISITE=1" fast_finish: true # Use this to prepare the system to install prerequisites or dependencies. diff --git a/Gruntfile.js b/Gruntfile.js index 32d98cd..af8eb31 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -32,13 +32,15 @@ module.exports = function(grunt) { require('load-grunt-tasks')(grunt); // There are basically three phases of building the production theme: + // 0) Testing / linting + grunt.registerTask('test', ['jshint', 'jasmine']); // 1) Javascript preparation (concatenating and uglifying scripts) - // (coming soon) + grunt.registerTask('javascript', ['uglify']); // 2) Stylesheet preparation (SASS, autoprefixing, and minification) // (coming soon) // 3) Appending the most recent git commit to the theme version grunt.registerTask('release', ['gitinfo', 'replace']); // The default task performs all three phases. - grunt.registerTask('default', ['release']); + grunt.registerTask('default', ['test', 'javascript', 'release']); }; diff --git a/additionalPosts-biblio.php b/additionalPosts-biblio.php index de5feb2..aedbd75 100644 --- a/additionalPosts-biblio.php +++ b/additionalPosts-biblio.php @@ -62,7 +62,7 @@ - + diff --git a/additionalPosts-cat.php b/additionalPosts-cat.php index bffe643..ae96224 100644 --- a/additionalPosts-cat.php +++ b/additionalPosts-cat.php @@ -68,9 +68,7 @@ - + have_posts() ) : ?> @@ -86,7 +84,7 @@ - + diff --git a/additionalPosts-search.php b/additionalPosts-search.php index 884bb97..f6fc065 100644 --- a/additionalPosts-search.php +++ b/additionalPosts-search.php @@ -55,7 +55,7 @@ function set_search( $q ) { if ( 'search' == $query_split[0] ) { $search_args['s'] = urldecode( $query_split[1] ); } -} // foreach +} $the_query = new WP_Query( $search_args ); // The set_search() function is defined above. diff --git a/archive.php b/archive.php index 813809b..140ce50 100644 --- a/archive.php +++ b/archive.php @@ -20,15 +20,12 @@ get_header(); $date = DateTime::createFromFormat( 'Ymd', get_field( 'event_date' ) ); +get_template_part( 'inc/sub-header' ); +if ( (get_post_type( get_the_ID() ) === 'bibliotech') || (cat_is_ancestor_of( 73, $cat ) or is_category( 73 )) ) { + get_template_part( 'inc/bib-header' ); +} ?> - - - - - -
@@ -36,7 +33,7 @@
-
+
-
+
diff --git a/category.php b/category.php index 1a5b3c7..d24fdbe 100644 --- a/category.php +++ b/category.php @@ -8,8 +8,6 @@ get_header(); - - $date = DateTime::createFromFormat( 'Ymd', get_field( 'event_date' ) ); ?> @@ -18,7 +16,7 @@
-
+
' . 'Category: ' . '' . single_cat_title( '', false ) . '' . '' ); @@ -33,7 +31,7 @@ - + diff --git a/codesniffer.ruleset.xml b/codesniffer.ruleset.xml index b05691f..83ab96f 100644 --- a/codesniffer.ruleset.xml +++ b/codesniffer.ruleset.xml @@ -13,6 +13,8 @@ + + diff --git a/css/style.css b/css/style.css index 1329af0..9f92146 100644 --- a/css/style.css +++ b/css/style.css @@ -4,7 +4,7 @@ Description: A Wordpress child theme that descends from mitlibraries-parent Author: Design by Moth Design, development by MIT Libraries Template: libraries - Version: 1.5.0-@@branch-@@commit; + Version: 2.0.0-@@branch-@@commit; */ @import url("../libraries/style.css"); diff --git a/functions.php b/functions.php index 464b1bb..abef27d 100644 --- a/functions.php +++ b/functions.php @@ -32,11 +32,12 @@ function add_styles() { add_action( 'wp_enqueue_scripts', 'add_styles' ); /** - * Add LazyLoad and MyScripts for all users + * Add LazyLoad, loader, and main javascript for all users */ function add_scripts() { - wp_enqueue_script( 'lazyload', get_stylesheet_directory_uri() . '/js/lazyload.js', array( 'jquery' ), '', true ); - wp_enqueue_script( 'myScripts', get_stylesheet_directory_uri() . '/js/myScripts.js', array( 'lazyload' ), '', true ); + wp_enqueue_script( 'lazyload', get_stylesheet_directory_uri() . '/js/build/jquery.lazyload.min.js', array( 'jquery' ), '', true ); + wp_enqueue_script( 'loader', get_stylesheet_directory_uri() . '/js/build/mitlibnews.loader.min.js', '', '', true ); + wp_enqueue_script( 'mitlibnews', get_stylesheet_directory_uri() . '/js/build/mitlibnews.min.js', array( 'lazyload', 'loader' ), '', true ); } add_action( 'wp_enqueue_scripts', 'add_scripts' ); @@ -112,6 +113,7 @@ function mitlibnews_register_news_posts() { 'labels' => $labelsFeatures, 'public' => true, 'menu_position' => 5, + 'show_in_rest' => true, 'supports' => array( 'title' ), 'taxonomies' => array( 'category' ), @@ -156,6 +158,7 @@ function theme_apto_object_taxonomies( $object_taxonomies, $post_type ) { 'labels' => $labelsFeatures, 'public' => true, 'menu_position' => 5, + 'show_in_rest' => true, 'supports' => $supports_default, 'taxonomies' => array( 'category' ), ); @@ -356,6 +359,7 @@ function biblio_taxonomy() { 'show_ui' => true, 'show_admin_column' => true, 'show_in_nav_menus' => true, + 'show_in_rest' => true, 'show_tagcloud' => true, ); register_taxonomy( 'bibliotech_issues', array( 'bibliotech' ), $args ); @@ -365,7 +369,7 @@ function biblio_taxonomy() { // Hook into the 'init' action. add_action( 'init', 'biblio_taxonomy', 0 ); -} +} // End bibliotechs custom taxonomy. /** * Registers news sidebar @@ -397,3 +401,187 @@ function SearchFilter( $query ) { return $query; } add_filter( 'pre_get_posts','SearchFilter' ); + + +/** + * Custom API endpoints + * + * @param WP_REST_Request $request Full data about the request. + */ +function mitlibnews_cards( WP_REST_Request $request ) { + + $args = array(); + $response = array(); + + // Get passed parameters for building the right query. + $params = $request->get_params(); + + // Build query type. + $categories = $params['categories']; + + // Posts per page needs to be an integer. + $args['posts_per_page'] = mitlibnews_cardargs_postsperpage( $params['filter']['posts_per_page'] ); + + // Only certain post types are recognized. + $args['post_type'] = mitlibnews_cardargs_posttype( $params['type'] ); + + // If requested, filter by author. + $args['author'] = mitlibnews_cardargs_author( $params['filter'] ); + + // If requested, filter by a single category. + if ( array_key_exists( 'categories', $params ) && is_array( $categories ) && is_int( (int) $params['categories'][0] ) ) { + $args['cat'] = (int) $params['categories'][0]; + } + + // If requested, filter by a single tag. + if ( array_key_exists( 'issue', $params ) ) { + $args['bibliotech_issues'] = (string) $params['issue']; + } + + // If requested, filter by a single tag. + if ( array_key_exists( 's', $params ) ) { + $args['s'] = (string) $params['s']; + } + + // If requested, change sort order. + $args['orderby'] = mitlibnews_cardargs_orderby( $params['filter'] ); + + // If requested, filter by custom field. + if ( array_key_exists( 'meta_query', $params['filter'] ) ) { + $args['meta_query'] = mitlibnews_cardargs_metaquery( $params['filter']['meta_query'] ); + } + + // Build the query. + $args['order'] = 'DESC'; + + // Execute the query. + $posts = new WP_Query( $args ); + + // Assemble the response. + $controller = new WP_REST_Posts_Controller( 'post' ); + if ( $posts->have_posts() ) { + while ( $posts->have_posts() ) { + $posts->the_post(); + $post = $posts->post; + $data = $controller->prepare_item_for_response( $post, $request ); + $response[] = $controller->prepare_response_for_collection( $data ); + } + wp_reset_postdata(); + } + + // Return the response. + return new WP_REST_Response( $response, 200 ); + +} +add_action( 'rest_api_init', function() { + register_rest_route( 'mitlibnews/v1', '/cards', array( + 'methods' => 'GET', + 'callback' => 'mitlibnews_cards', + )); +}); + +/** + * Assemble API query: author + * + * @param array $input Contents of $params['filter']. + */ +function mitlibnews_cardargs_author( $input ) { + if ( array_key_exists( 'author', $input ) && is_int( (int) $input['author'] ) ) { + return (int) $input['author']; + } + return ''; +} + +/** + * Assemble API query: orderby + * + * @param array $input Contents of $params['filter']. + */ +function mitlibnews_cardargs_orderby( $input ) { + $orderby = 'post_date'; + if ( array_key_exists( 'orderby', $input ) ) { + $orderby = (string) $input['orderby']; + } + return $orderby; +} + + +/** + * Assemble API query: posts_per_page + * + * @param int $input Contents of $params['filter']['posts_per_page']. + */ +function mitlibnews_cardargs_postsperpage( $input ) { + $posts_per_page = 9; + if ( is_int( (int) $input ) ) { + $posts_per_page = (int) $input; + } + return $posts_per_page; +} + +/** + * Assemble API query: post_type + * + * Only three values are accepted for post_type queries + * + * @param int $input Contents of $params['type']. + */ +function mitlibnews_cardargs_posttype( $input ) { + $post_type = array(); + if ( is_array( $input ) ) { + if ( in_array( 'bibliotech', $input, true ) ) { + $post_type[] = 'bibliotech'; + } + if ( in_array( 'post', $input, true ) ) { + $post_type[] = 'post'; + } + if ( in_array( 'spotlights', $input, true ) ) { + $post_type[] = 'spotlights'; + } + } + return $post_type; +} + +/** + * Assemble API query: meta_query array + * + * @param int $input Contents of $params['filter']. + */ +function mitlibnews_cardargs_metaquery( $input ) { + $meta_query = array(); + if ( 'is_event' === $input[0]['key'] ) { + // We currently only support meta_queries based on the is_event custom field. + if ( 'false' === $input[0]['value'] ) { + // The query is for items which aren't events. + $meta_query[] = mitlibnews_cardargs_metaquery_item( 'is_event', '!=', '1', 'NUMERIC' ); + } elseif ( 'true' === $input[0]['value'] ) { + // The query is for events, but past or future? + $meta_query[] = mitlibnews_cardargs_metaquery_item( 'is_event', '=', '1', 'NUMERIC' ); + if ( 'future' === $input[0]['type'] ) { + // Query for future events. + $meta_query[] = mitlibnews_cardargs_metaquery_item( 'event_date', '>=', date( 'Y-m-d' ), 'DATE' ); + } elseif ( 'past' === $input[0]['type'] ) { + // Query for past events. + $meta_query[] = mitlibnews_cardargs_metaquery_item( 'event_date', '<', date( 'Y-m-d' ), 'DATE' ); + } + } + } + return $meta_query; +} + +/** + * Assemble API query: meta_query item + * + * @param string $key The variable being tested. + * @param string $compare The comparision being performed. + * @param string $value The value being tested for. + * @param string $type The type of comparison being performed. + */ +function mitlibnews_cardargs_metaquery_item( $key, $compare, $value, $type ) { + return array( + 'key' => $key, + 'value' => $value, + 'compare' => $compare, + 'type' => $type, + ); +} diff --git a/inc/events.php b/inc/events.php index 1e3bb75..c76f902 100644 --- a/inc/events.php +++ b/inc/events.php @@ -48,5 +48,5 @@
- + diff --git a/index.php b/index.php index 535a6b0..3eaa9e5 100644 --- a/index.php +++ b/index.php @@ -89,7 +89,7 @@
-
+
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 @@
-
+
posts; ?> -

Upcoming classes & events

+
0 ) { $i = -1; @@ -123,7 +123,7 @@

Past classes & events

-
+
0 ) { $i = -1; @@ -146,9 +146,8 @@ - diff --git a/page-news.php b/page-news.php index 4ef8412..b69a313 100644 --- a/page-news.php +++ b/page-news.php @@ -22,7 +22,7 @@
-
+

News

diff --git a/search.php b/search.php index ed4ea60..6c2aa59 100644 --- a/search.php +++ b/search.php @@ -15,9 +15,9 @@
-
+ +
- diff --git a/single.php b/single.php index 2c41d9c..bb472a1 100644 --- a/single.php +++ b/single.php @@ -109,7 +109,7 @@
- + @@ -171,20 +171,21 @@ $currentPost = get_the_ID(); -$myCatId = $category[ $r ]->cat_ID; + $category_id = $category[ $r ]->cat_ID; $args = array( 'post_type' => array( 'post', 'bibliotech', 'spotlights' ), - 'cat' => $myCatId, + 'cat' => $category_id, 'posts_per_page' => '3', 'order' => 'DESC', 'orderby' => 'date', 'post__not_in' => array( $currentPost ), ); - ?> + +?> -
+