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
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,13 @@ public RssItems(String url, int max, int maxTitleLength, int maxExcerptLength, b
this.getElement().executeJs(IMAGE_METHOD.replaceAll("%%ATTRIBUTE_NAME%%", attributeName), this);
}

this.setUrl(url);
this.setAuto(true);
this.setMax(max);
this.setMaxExcerptLength(maxExcerptLength);
this.setMaxTitleLength(maxTitleLength);
addClassName("x-scope");
addClassName("rss-items-0");
refreshUrl();
addClassName("rss-items-0");
this.setUrl(url);
}

/**
Expand Down Expand Up @@ -155,7 +154,6 @@ public void setAuto(boolean auto) {
*/
public void setMaxTitleLength(int length) {
this.getElement().setProperty("maxTitleLength", length);
refreshUrl();
}

/**
Expand All @@ -164,7 +162,6 @@ public void setMaxTitleLength(int length) {
*/
public void setMaxExcerptLength(int length) {
this.getElement().setProperty("maxExcerptLength", length);
refreshUrl();
}

/**
Expand All @@ -173,21 +170,20 @@ public void setMaxExcerptLength(int length) {
*/
public void setMax(int max) {
this.getElement().setProperty("max", max);
refreshUrl();
}

public void setExtractImageFromDescription(boolean extractImageFromDescription) {
this.extractImageFromDescription = extractImageFromDescription;
refreshUrl();
}

/**
* Sets the url of the RSS
* Sets the url of the RSS and retrieves its items
* @param url
*/
public void setUrl(String url) {
this.getElement().setProperty("url", url);
this.url = url;
refreshUrl();
}

}
14 changes: 13 additions & 1 deletion src/main/resources/META-INF/frontend/rss-items.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ class RssItems extends PolymerElement {
* Max number of items to show. If it is undefined shows all items.
*/
max: {
type: Number
type: Number,
observer: '_maxChanged'
},
/**
* Max length for item excerpts. If the excerpt exceeds this length it will be trimed and will have an ellipsis appended.
Expand Down Expand Up @@ -278,6 +279,8 @@ class RssItems extends PolymerElement {
* @param {Object} xml XML element.
*/
xmlToItems(xml) {
// keep the xml, so that the items can be parsed again when max changes
this._xml = xml
var x2 = new X2JS()
var json = x2.xml2js(xml)
var items = json.rss ? json.rss.channel.item : json.channel.item
Expand All @@ -286,6 +289,15 @@ class RssItems extends PolymerElement {
this.items = this._parseItems(items)
}

/**
* Parse the last received xml again, since items are truncated when parsed.
*/
_maxChanged() {
if (this._xml !== undefined) {
this.xmlToItems(this._xml)
}
}

/**
* Parse items by getting excerpt and image source.
* @param {Array} items RSS items.
Expand Down
Loading