Skip to content

Commit

Permalink
removed unnecessary function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
fb55 committed Aug 26, 2011
1 parent 3a3f47d commit 6f05da3
Showing 1 changed file with 32 additions and 30 deletions.
62 changes: 32 additions & 30 deletions lib/nodepie.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -188,39 +188,41 @@ NodePie.prototype._checkEncoding = function(xml){
* entry arrays etc. * entry arrays etc.
**/ **/
NodePie.prototype._checkType = function(){ 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++){ for(var i=0, len = root_keys.length; i<len; i++){


key = root_keys[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; continue;
}


if(key.trim().toLowerCase() == "rdf" || key.trim().substr(-4).toLowerCase() == ":rdf"){ type = key.trim().toLowerCase();
this.feedType = "rdf";
this.rootElement = this.feed[root_keys[i]]; this.rootElement = elem;
this.channelElement = this.rootElement.channel || {};
this.itemsElement = this.rootElement.item || [];
break;
}


if(key.trim().toLowerCase() == "feed"){ if(type === "feed"){
this.feedType = "atom"; this.feedType = "atom";
this.rootElement = this.feed[root_keys[i]]; this.channelElement = elem || {};
this.channelElement = this.rootElement || {}; this.itemsElement = elem.entry || [];
this.itemsElement = this.rootElement.entry || [];
break; break;
} }

else if(type === "rss"){
if(key.trim().toLowerCase() == "rss"){
this.feedType = "rss"; this.feedType = "rss";
this.rootElement = this.feed[root_keys[i]]; this.channelElement = elem.channel || {};
this.channelElement = this.rootElement.channel || {};
this.itemsElement = this.channelElement.item || []; this.itemsElement = this.channelElement.item || [];
break; 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){ if(!this.rootElement){
Expand Down Expand Up @@ -443,7 +445,7 @@ NodePie.prototype.getDate = function(){
var dcns = this.namespaces[NodePie.NS.DC], date; var dcns = this.namespaces[NodePie.NS.DC], date;


date = this.channelElement.lastBuildDate || this.channelElement.updated || date = this.channelElement.lastBuildDate || this.channelElement.updated ||
(dcns && this.channelElement[dcns+":date"]) || false; (dcns && this.channelElement[dcns+":date"]);


if(!date){ if(!date){
return false; return false;
Expand Down Expand Up @@ -481,12 +483,11 @@ NodePie.prototype.getItemQuantity = function(max){


this._item_count = 0; this._item_count = 0;


if(!this.itemsElement){ if(this.itemsElement){
this._item_count = 0; if(Array.isArray(this.itemsElement))
}else if(Array.isArray(this.itemsElement)){ this._item_count = this.itemsElement.length;
this._item_count = this.itemsElement.length; else if(typeof this.itemsElement == "object")
}else if(typeof this.itemsElement == "object"){ this._item_count = 1;
this._item_count = 1;
} }


return max && max<this._item_count ? max : this._item_count; return max && max<this._item_count ? max : this._item_count;
Expand All @@ -501,17 +502,18 @@ NodePie.prototype.getItemQuantity = function(max){
**/ **/
NodePie.prototype.getItems = function(start, length){ NodePie.prototype.getItems = function(start, length){
start = start || 0; start = start || 0;
length = length || this.getItemQuantity(); var quantity = this.getItemQuantity();
length = length || quantity;


if(start >= this.getItemQuantity()){ if(start >= quantity){
start = this.getItemQuantity()-1; start = quantity-1;
if(start<0){ if(start<0){
start = 0; start = 0;
} }
} }


if(length > this.getItemQuantity() - start){ if(length > quantity - start){
length = this.getItemQuantity() - start; length = quantity - start;
} }


var items = []; var items = [];
Expand Down

0 comments on commit 6f05da3

Please sign in to comment.