Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,6 @@ ratings:
- "**.module"
- "**.inc"
exclude_paths:
- js/**/*
- js/build/**/*
- js/tests/**/*
- lib/classes/**/*
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = function(grunt) {

// There are basically three phases of building the production theme:
// 0) Testing / linting
grunt.registerTask('test', ['jshint']);
grunt.registerTask('test', ['jshint', 'jasmine']);
// 1) Javascript preparation (concatenating and uglifying scripts)
grunt.registerTask('javascript', ['uglify']);
// 2) Stylesheet preparation (SASS, autoprefixing, and minification)
Expand Down
14 changes: 5 additions & 9 deletions js/scrollPosts.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,18 @@ $j(function(){

$j("#postContainer").load("/news/test/?offset="+offset);
$j("#another").click(function(){

offset = offset+10;

$j("#postContainer")
.slideUp()
.load("/news/test/?offset="+offset, function() {
$j("#mitContainer").css("display", "none");
$j(this).slideDown();
$j( "#postContainer" ).scrollTop( 300 );
$j(this).slideDown();
$j( "#postContainer" ).scrollTop( 300 );
});

return false;
});

});




59 changes: 2 additions & 57 deletions js/mitlibnews-more.js → js/src/mitlibnews-more.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* JSON objects into rendered HTML.
*
*/

var window, document, jQuery;

window.mitlibnews = window.mitlibnews || {};
Expand All @@ -17,38 +16,31 @@ window.mitlibnews.loader = {
* Properties
*/
container : '',
offset: 0,
page: 1,
postcontent: '',

/**
* Initialize
*/
initialize : function() {
console.log('MIT Libraries News Loader initializing...');
// Identify container that will receive post cards.
this.container = document.getElementById('mitlibnews-container');
// The type of query is identified by data attribute on the container.
this.setPostcontent();
console.log('Initialization complete.');
return true;
},

/**
* Simple Post Loader
*/
loadPosts : function(posts_per_page) {
console.log('Loading ' + posts_per_page + ' posts');
console.log('Query: ');
var query = this.buildQuery(posts_per_page);
console.log(query);
jQuery.ajax({
url: '/news/wp-json/posts',
data: query,
dataType: 'json',
type: 'GET',
success: function(data) {
console.log(posts_per_page + ' posts requested');
console.log(data.length + ' posts received');
if ( data.length < posts_per_page) {
window.mitlibnews.loader.hideMore();
}
Expand All @@ -58,34 +50,6 @@ window.mitlibnews.loader = {
jQuery(target).append( window.mitlibnews.loader.renderCard(value) );
});
window.mitlibnews.loader.setPage( window.mitlibnews.loader.getPage() + 1);
console.log('New page: ');
console.log(window.mitlibnews.loader.getPage());

},
error: function() {
console.log("Error");
}
});
console.log('');
},

/**
* Load More - Archive
*/
loadArchive : function() {
console.log('Loading Archive posts...');
jQuery.ajax({
url: '/news/wp-json/posts',
data: {
filter: {
'posts_per_page': 9,
'offset': 10,
}
},
dataType: 'json',
type: 'GET',
success: function(data) {
console.log(data);
},
error: function() {
console.log("Error");
Expand Down Expand Up @@ -317,14 +281,6 @@ window.mitlibnews.loader = {
return document.getElementById('mitlibnews-container');
},

/**
* Get Offset
*/
getOffset : function() {
console.log("Retrieving offset value of " + this.offset);
return this.offset;
},

/**
* Get Page
*/
Expand All @@ -339,32 +295,21 @@ window.mitlibnews.loader = {
return this.postcontent;
},

/**
* Set Offset
*/
setOffset : function(value) {
console.log("Replacing offset value of " + this.offset + " with " + value);
this.offset = value;
return this.getOffset();
},

/**
* Set Page
*/
setPage : function(value) {
console.log("Replacing page value of " + this.page + " with " + value);
this.page = value;
},

/**
* Set Post Content
*/
setPostcontent : function(value) {
setPostcontent : function() {
// The default value is 'all'.
this.postcontent = 'all';
// If everything is not set, just use the default.
if ( !this.container || !this.container.dataset || !this.container.dataset.postcontent ) {
console.log( 'Post content attribute not found! Using default value.' );
return true;
}
// If we're still here, use the real value.
Expand Down
38 changes: 38 additions & 0 deletions js/tests/mitlibnews-more.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
var window;

describe("Additional Posts suite", function() {
it("should initialize", function() {
var demo;
demo = window.mitlibnews.loader;
expect(demo.initialize()).toEqual(true);
// Default values
expect(demo.getPage()).toEqual(1);
expect(demo.getPostcontent()).toEqual('all');
});

it("should be able to get and set pagination", function() {
var demo;
demo = window.mitlibnews.loader;
demo.setPage(2);
expect(demo.getPage()).toEqual(2);
});

it("should be able to build a query", function() {
var demo, reference;
demo = window.mitlibnews.loader;
reference = {
page: 2,
filter: {
posts_per_page: 12
}
};
expect(demo.buildQuery(12)).toEqual(reference);
reference = {
page: 2,
filter: {
posts_per_page: 9
}
};
expect(demo.buildQuery(9)).toEqual(reference);
});
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"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",
Expand Down
6 changes: 6 additions & 0 deletions tasks/options/jasmine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
src: 'js/src/**/*.js',
options: {
specs: 'js/tests/**/*.js'
}
}
3 changes: 2 additions & 1 deletion tasks/options/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ module.exports = {
all: [
'Gruntfile.js',
'js/mitlibnews.js',
'js/mitlibnews-more.js'
'js/src/**/*.js',
'js/tests/**/*.js'
],
options: {
jshintrc: '.jshintrc'
Expand Down
2 changes: 1 addition & 1 deletion tasks/options/uglify.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
dest: 'js/build/mitlibnews.min.js'
},
loadMore: {
src: 'js/mitlibnews-more.js',
src: 'js/src/mitlibnews-more.js',
dest: 'js/build/mitlibnews-more.min.js'
},
lazyLoad: {
Expand Down