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: 3 additions & 0 deletions starter-code/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ <h1>Title</h1>
<footer>
&copy; 2016 Code Fellows | Static Blog | Happy Ipsum!
</footer>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="scripts/blogArticles.js"></script>
<script src="scripts/article.js"></script>
<!-- // TODO: Intentionally vague: include all necessary script tags, in proper order! -->
</body>
</html>
34 changes: 23 additions & 11 deletions starter-code/scripts/article.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,40 @@
var articles = [];

function Article (options) {
/* TODO: This is our Model constructor. It will take in
our source data from blogArticles and instantiate a
new Object according to this new definition. options is
a placeholder for the object that will ultimately be
passed in. Use all of the properties in blogArticles
to populate the new Article data that we'll use. */
this.title = options.title;
function Article(options) {
/* TODO: done This is our Model constructor. It will take in
our source data from blogArticles and instantiate a
new Object according to this new definition. options is
a placeholder for the object that will ultimately be
passed in. Use all of the properties in blogArticles
to populate the new Article data that we'll use. */
this.title = options.title;
this.category = options.category;
this.author = options.author;
this.authorUrl = options.authorUrl;
this.publishedOn = options.publishedOn;
this.body = options.body;

};

Article.prototype.toHtml = function() {
var $newArticle = $('article.template').clone();
$newArticle.attr('data-category', this.category);
$newArticle.find('h1').text(this.title);
$newArticle.find('a').text(this.author).attr('href', this.authorUrl);
$newArticle.find('data-publishedOn', this.publishedOn);
$newArticle.find('.article-body').append(this.body);
/* TODO: We also need to fill in:
1. author name
2. author url
3. article title
4. article body
5. publication*/
$newArticle.find('time[pubdate]').attr('title', this.publishedOn);
$newArticle.find('time').text('about ' + parseInt((new Date() - new Date(this.publishedOn))/60/60/24/1000) + ' days ago');
/* TODO: This cloned article is no longer a template, as it now
has real data attached to it. Remove the class from this new article! */
$newArticle.find('time').text('about ' + parseInt((new Date() - new Date(this.publishedOn)) / 60 / 60 / 24 / 1000) + ' days ago');
$newArticle.removeClass('template');
/* TODO: done!
This cloned article is no longer a template, as it now
has real data attached to it. Remove the class from this new article! */
return $newArticle;
};

Expand Down