Permalink
Browse files

removed unnecessary function calls

  • Loading branch information...
1 parent 3a3f47d commit 6f05da3501092f758076da4bcace0d53966ee652 @fb55 fb55 committed Aug 26, 2011
Showing with 32 additions and 30 deletions.
  1. +32 −30 lib/nodepie.js
View
62 lib/nodepie.js
@@ -188,39 +188,41 @@ NodePie.prototype._checkEncoding = function(xml){
* entry arrays etc.
**/
NodePie.prototype._checkType = function(){
- var root_keys = Object.keys(this.feed), key;
+ var root_keys = Object.keys(this.feed), key, type, elem;
for(var i=0, len = root_keys.length; i<len; i++){
key = root_keys[i];
+ elem = this.feed[key];
- if(typeof this.feed[key] != "object" || Array.isArray(this.feed[key])){
+ if(typeof elem !== "object" || Array.isArray(elem))
continue;
- }
- if(key.trim().toLowerCase() == "rdf" || key.trim().substr(-4).toLowerCase() == ":rdf"){
- this.feedType = "rdf";
- this.rootElement = this.feed[root_keys[i]];
- this.channelElement = this.rootElement.channel || {};
- this.itemsElement = this.rootElement.item || [];
- break;
- }
+ type = key.trim().toLowerCase();
+
+ this.rootElement = elem;
- if(key.trim().toLowerCase() == "feed"){
+ if(type === "feed"){
this.feedType = "atom";
- this.rootElement = this.feed[root_keys[i]];
- this.channelElement = this.rootElement || {};
- this.itemsElement = this.rootElement.entry || [];
+ this.channelElement = elem || {};
+ this.itemsElement = elem.entry || [];
break;
}
-
- if(key.trim().toLowerCase() == "rss"){
+ else if(type === "rss"){
this.feedType = "rss";
- this.rootElement = this.feed[root_keys[i]];
- this.channelElement = this.rootElement.channel || {};
+ this.channelElement = elem.channel || {};
this.itemsElement = this.channelElement.item || [];
break;
}
+ else if(type === "rdf" || type.substr(-4) === ":rdf"){
+ this.feedType = "rdf";
+ this.channelElement = elem.channel || {};
+ this.itemsElement = elem.item || [];
+ break;
+ }
+ else{
+ this.rootElement = null;
+ }
}
if(!this.rootElement){
@@ -443,7 +445,7 @@ NodePie.prototype.getDate = function(){
var dcns = this.namespaces[NodePie.NS.DC], date;
date = this.channelElement.lastBuildDate || this.channelElement.updated ||
- (dcns && this.channelElement[dcns+":date"]) || false;
+ (dcns && this.channelElement[dcns+":date"]);
if(!date){
return false;
@@ -481,12 +483,11 @@ NodePie.prototype.getItemQuantity = function(max){
this._item_count = 0;
- if(!this.itemsElement){
- this._item_count = 0;
- }else if(Array.isArray(this.itemsElement)){
- this._item_count = this.itemsElement.length;
- }else if(typeof this.itemsElement == "object"){
- this._item_count = 1;
+ if(this.itemsElement){
+ if(Array.isArray(this.itemsElement))
+ this._item_count = this.itemsElement.length;
+ else if(typeof this.itemsElement == "object")
+ this._item_count = 1;
}
return max && max<this._item_count ? max : this._item_count;
@@ -501,17 +502,18 @@ NodePie.prototype.getItemQuantity = function(max){
**/
NodePie.prototype.getItems = function(start, length){
start = start || 0;
- length = length || this.getItemQuantity();
+ var quantity = this.getItemQuantity();
+ length = length || quantity;
- if(start >= this.getItemQuantity()){
- start = this.getItemQuantity()-1;
+ if(start >= quantity){
+ start = quantity-1;
if(start<0){
start = 0;
}
}
- if(length > this.getItemQuantity() - start){
- length = this.getItemQuantity() - start;
+ if(length > quantity - start){
+ length = quantity - start;
}
var items = [];

0 comments on commit 6f05da3

Please sign in to comment.