forked from I2P_Developers/i2p.i2p
Rearrange summary bar code to consolidate Ajax and IFrame, and /home and /console
Now, Ajax will be used first, and will fall back to IFrame if JS is disabled, and a separate page if on a text or mobile browser. Also, /home and /console (and everywhere) now all have the same summary bar content, which currently defaults to the original full listing.
This commit is contained in:
@ -18,12 +18,6 @@ public class NewsHelper extends ContentHelper {
|
||||
return super.getContent();
|
||||
}
|
||||
|
||||
/** @since 0.9.1 */
|
||||
public String getNewsHeadings() {
|
||||
SummaryBarRenderer renderer = new SummaryBarRenderer(_context, this);
|
||||
return renderer.renderNewsHeadingsHTML();
|
||||
}
|
||||
|
||||
/** @since 0.8.12 */
|
||||
public boolean shouldShowNews() {
|
||||
return NewsFetcher.getInstance(_context).shouldShowNews();
|
||||
|
@ -15,6 +15,7 @@ import net.i2p.router.RouterContext;
|
||||
*
|
||||
*/
|
||||
public class SummaryBarRenderer {
|
||||
// Commented out because broken. Replaced by if-elseif blob below.
|
||||
/*static final Map<String, java.lang.reflect.Method> ALL_SECTIONS;
|
||||
static {
|
||||
Map<String, java.lang.reflect.Method> aMap = new HashMap<String, java.lang.reflect.Method>();;
|
||||
@ -42,20 +43,10 @@ public class SummaryBarRenderer {
|
||||
|
||||
private final RouterContext _context;
|
||||
private final SummaryHelper _helper;
|
||||
private final NewsHelper _newshelper;
|
||||
|
||||
public SummaryBarRenderer(RouterContext context, SummaryHelper helper) {
|
||||
this(context, helper, null);
|
||||
}
|
||||
|
||||
public SummaryBarRenderer(RouterContext context, NewsHelper newshelper) {
|
||||
this(context, null, newshelper);
|
||||
}
|
||||
|
||||
public SummaryBarRenderer(RouterContext context, SummaryHelper helper, NewsHelper newshelper) {
|
||||
_context = context;
|
||||
_helper = helper;
|
||||
_newshelper = newshelper;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,25 +55,9 @@ public class SummaryBarRenderer {
|
||||
*/
|
||||
public void renderSummaryHTML(Writer out) throws IOException {
|
||||
StringBuilder buf = new StringBuilder(8*1024);
|
||||
String theme = _context.getProperty(CSSHelper.PROP_THEME_NAME, CSSHelper.DEFAULT_THEME);
|
||||
|
||||
// TODO - the bar would render more cleanly if we specified the img height and width here,
|
||||
// but unfortunately the images in the different themes are different sizes.
|
||||
// They range in height from 37 to 43 px. But there's a -2 bottom margin...
|
||||
// So put it in a div.
|
||||
buf.append("<div style=\"height: 36px;\"><a href=\"/\" target=\"_top\"><img src=\"")
|
||||
.append(CSSHelper.BASE_THEME_PATH)
|
||||
.append(theme)
|
||||
.append("/images/i2plogo.png\" alt=\"")
|
||||
.append(_("I2P Router Console"))
|
||||
.append("\" title=\"")
|
||||
.append(_("I2P Router Console"))
|
||||
.append("\"></a></div>\n");
|
||||
|
||||
out.write(buf.toString());
|
||||
|
||||
String[] sections = _helper.getSummaryBarSections();
|
||||
for (int i = 0; i < sections.length; i++) {
|
||||
// Commented out because broken. Replaced by if-elseif blob below.
|
||||
/*try {
|
||||
String section = (String)ALL_SECTIONS.get(sections[i]).invoke(this);
|
||||
if (section != null && section != "") {
|
||||
@ -546,7 +521,9 @@ public class SummaryBarRenderer {
|
||||
|
||||
/** @since 0.9.1 */
|
||||
public String renderNewsHeadingsHTML() {
|
||||
if (_newshelper == null || _newshelper.shouldShowNews()) return "";
|
||||
if (_helper == null) return "";
|
||||
NewsHelper newshelper = _helper.getNewsHelper();
|
||||
if (newshelper == null || newshelper.shouldShowNews()) return "";
|
||||
StringBuilder buf = new StringBuilder(512);
|
||||
String consoleNonce = System.getProperty("router.consoleNonce");
|
||||
if (consoleNonce != null) {
|
||||
@ -555,7 +532,7 @@ public class SummaryBarRenderer {
|
||||
.append(_("News & Updates"))
|
||||
.append("</a></h3><hr class=\"b\"><div class=\"newsheadings\">\n");
|
||||
// Get news content.
|
||||
String newsContent = _newshelper.getContent();
|
||||
String newsContent = newshelper.getContent();
|
||||
if (newsContent != "") {
|
||||
buf.append("<ul>\n");
|
||||
// Parse news content for headings.
|
||||
|
@ -739,6 +739,10 @@ public class SummaryHelper extends HelperBase {
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private NewsHelper _newshelper;
|
||||
public void storeNewsHelper(NewsHelper n) { _newshelper = n; }
|
||||
public NewsHelper getNewsHelper() { return _newshelper; }
|
||||
|
||||
public String[] getSummaryBarSections() {
|
||||
String config = _context.getProperty(PROP_SUMMARYBAR, PRESET_FULL);
|
||||
return config.split("" + S);
|
||||
|
Reference in New Issue
Block a user