Commit 1b1767ca authored by Liang Ding's avatar Liang Ding

Fix #11976

parent e729c4d8
......@@ -20,7 +20,7 @@ package org.b3log.solo.event;
* Event types.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.7, Oct 17, 2012
* @version 1.1.0.7, May 30, 2014
* @since 0.3.1
*/
public final class EventTypes {
......@@ -39,6 +39,11 @@ public final class EventTypes {
* Indicates a remove article event.
*/
public static final String REMOVE_ARTICLE = "Remove Article";
/**
* Indicates a before render article event.
*/
public static final String BEFORE_RENDER_ARTICLE = "Before Render Article";
/**
* Indicates an add comment to article event.
......
/*
* Copyright (c) 2009, 2010, 2011, 2012, 2013, B3log Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.b3log.solo.plugin.list;
import org.b3log.latke.Latkes;
import org.b3log.latke.event.AbstractEventListener;
import org.b3log.latke.event.Event;
import org.b3log.latke.event.EventException;
import org.b3log.latke.logging.Logger;
import org.b3log.solo.event.EventTypes;
import org.b3log.solo.model.Article;
import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
/**
* List (table of contents of an article) handler.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.0, May 30, 2014
* @since 0.6.7
*/
public class ListHandler extends AbstractEventListener<JSONObject> {
/**
* Logger.
*/
private static final Logger LOGGER = Logger.getLogger(ListHandler.class.getName());
/**
* Instance.
*/
private static final ListHandler INSTANCE = new ListHandler();
@Override
public String getEventType() {
return EventTypes.BEFORE_RENDER_ARTICLE;
}
/**
* Gets the instance.
*
* @return instance
*/
public static ListHandler getInstance() {
return INSTANCE;
}
@Override
public void action(final Event<JSONObject> event) throws EventException {
final JSONObject data = event.getData();
final JSONObject article = data.optJSONObject(Article.ARTICLE);
String content = article.optString(Article.ARTICLE_CONTENT);
final Document doc = Jsoup.parse(content);
final StringBuilder listBuilder = new StringBuilder();
listBuilder.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + Latkes.getStaticPath() + "/plugins/list/style.css\" />");
final Elements hs = doc.select("h1, h2, h3, h4, h5");
listBuilder.append("<ul class='b3-solo-list'>");
for (int i = 0; i < hs.size(); i++) {
final Element element = hs.get(i);
final String tagName = element.tagName().toLowerCase();
final String text = element.text();
final String id = "b3_solo_" + tagName + "_" + i;
element.before("<span id='" + id + "'></span>");
listBuilder.append("<li class='b3-solo-list-").append(tagName).append("'><a href='#").append(id).append("'>").append(text).append(
"</a></li>");
}
listBuilder.append("</ul>");
final Element body = doc.getElementsByTag("body").get(0);
content = listBuilder.toString() + body.html();
article.put(Article.ARTICLE_CONTENT, content);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!--
Description: B3log Solo parent POM.
Version: 2.0.4.10, Apr 28, 2014
Version: 2.0.4.11, May 31, 2014
Author: Liang Ding
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
......@@ -29,7 +29,7 @@
<properties>
<servlet.version>2.5</servlet.version>
<slf4j.version>1.7.5</slf4j.version>
<org.b3log.latke.version>1.0.11</org.b3log.latke.version>
<org.b3log.latke.version>1.0.12</org.b3log.latke.version>
<maven-gae-plugin.version>0.9.0</maven-gae-plugin.version>
<gae.version>1.8.1.1</gae.version>
......
......@@ -31,4 +31,3 @@ log4j.logger.org.b3log.solo=WARN
log4j.logger.org.b3log.latke=ERROR
log4j.logger.org.b3log.latke.util.freemarker.Templates=ERROR
#
# Copyright (c) 2009, 2010, 2011, B3log Team
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# Description: Table of contents generator.
# Version: 1.0.0.0, May 30, 2014
# Author: Liang Ding
#
rendererId=footer.ftl
author=<a href="http://88250.b3log.org">88250</a>
name=Table of Contents Generator
version=0.0.1
types=PUBLIC
classesDirPath=/WEB-INF/classes/
pluginClass=
eventListenerClasses=org.b3log.solo.plugin.list.ListHandler
\ No newline at end of file
/*
* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014 B3log Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* 403, 404, 500, article-pwd, init, login and kill-browser page style.
*
* @author <a href="mailto:LLY219@gmail.com">Liyuan Li</a>
* @version 1.0.0.0, May 31, 2014
*/
.b3-solo-list {
margin: 20px 30px;
list-style: none;
}
.b3-solo-list-h1 {
}
.b3-solo-list-h2 {
margin-left: 16px;
}
.b3-solo-list-h3 {
margin-left: 32px;
}
.b3-solo-list-h4 {
margin-left: 48px;
}
.b3-solo-list-h5 {
margin-left: 62px;
}
\ No newline at end of file
......@@ -237,20 +237,7 @@ var ease = {
scrollEvent: function () {
var _it = this;
$(window).scroll(function () {
var y = $(window).scrollTop(),
topH = 0;
if ($("#top").css("display") === "block") {
topH = $("#top").height();
}
// header event
if (y >= _it.headerH + topH) {
_it.$nav.css("position", "fixed");
_it.$body.css("marginTop", "55px");
} else {
_it.$nav.css("position" ,"inherit");
_it.$body.css("marginTop", "0");
}
var y = $(window).scrollTop();
// go top icon show or hide
if (y > _it.headerH) {
......@@ -293,15 +280,6 @@ var ease = {
$(".article-body").each(function () {
this.innerHTML = Util.replaceEmString($(this).html());
});
},
/**
* @description 纠正评论滚动位置偏差
*/
scrollToCmt: function () {
if ($(window.location.hash).length == 1) {
$(window).scrollTop($(window.location.hash).offset().top - 60);
}
}
};
......
......@@ -158,7 +158,6 @@
$(document).ready(function() {
page.load();
ease.scrollToCmt();
// emotions
page.replaceCommentsEm("#comments .article-body");
<#nested>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment