diff options
author | Soreine <nicolas@gitbook.com> | 2016-05-11 17:54:26 +0200 |
---|---|---|
committer | Soreine <nicolas@gitbook.com> | 2016-05-12 13:35:29 +0200 |
commit | 7892259fe64a39a3a2cc3caedeb7ca8c3396dd56 (patch) | |
tree | 7fb792d66608e8f20f5c0dbcb563f16a0c5af09b | |
parent | b97d1c7796659336f68c988f02d0f0376d1e9e82 (diff) | |
download | gitbook-7892259fe64a39a3a2cc3caedeb7ca8c3396dd56.zip gitbook-7892259fe64a39a3a2cc3caedeb7ca8c3396dd56.tar.gz gitbook-7892259fe64a39a3a2cc3caedeb7ca8c3396dd56.tar.bz2 |
Extend Book.getLanguageBook
-rw-r--r-- | lib/models/book.js | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/models/book.js b/lib/models/book.js index 2a97f78..0a4a41a 100644 --- a/lib/models/book.js +++ b/lib/models/book.js @@ -176,14 +176,18 @@ Book.prototype.isLanguageBook = function() { }; /** - Return a languages book + Returns the book for a language. + Returns itself if matches the language itself. - @param {String} language - @return {Book} + @param {String} lang Language ID + @return {Book | Null} Null if no such language */ -Book.prototype.getLanguageBook = function(language) { - var books = this.getBooks(); - return books.get(language); +Book.prototype.getLanguageBook = function(lang) { + if (this.getLanguage() === lang) { + return this; + } else { + return this.getBooks().get(lang) || null; + } }; /** |