This repository has been archived by the owner on May 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/com/mgreau/wwsmad/asciidoctor/IFrameAnchorPostProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.mgreau.wwsmad.asciidoctor; | ||
|
||
import org.asciidoctor.extension.Postprocessor; | ||
import org.asciidoctor.internal.DocumentRuby; | ||
import org.jsoup.Jsoup; | ||
import org.jsoup.nodes.Document; | ||
import org.jsoup.nodes.Element; | ||
|
||
/** | ||
* #12 : iframe : making linking between anchors work. | ||
* | ||
* @author greau.maxime@gmail.com | ||
* | ||
*/ | ||
public class IFrameAnchorPostProcessor extends Postprocessor { | ||
|
||
public IFrameAnchorPostProcessor(DocumentRuby documentRuby) { | ||
super(documentRuby); | ||
} | ||
|
||
@Override | ||
public String process(String output) { | ||
|
||
final Document document = Jsoup.parse(output); | ||
final String js = "js/iframe/iframe_anchors.js"; | ||
|
||
if (document.getElementsByAttributeValue("src", js).size() == 0){ | ||
Element head = document.getElementsByTag("head").first(); | ||
|
||
head.appendElement("script").attr("type", "text/javascript").attr("src", "http://code.jquery.com/jquery-1.7.2.min.js"); | ||
head.appendElement("script").attr("type", "text/javascript").attr("src", js); | ||
} | ||
|
||
return document.html(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
$(function () { | ||
//var iframeOffset = $("#html5-rendered", window.parent.document).offset(); | ||
$("a").each(function () { | ||
var link = $(this); | ||
var href = link.attr("href"); | ||
if (href && href[0] == "#") { | ||
var name = href.substring(1); | ||
$(this).click(function () { | ||
var nameElement = $("[name='" + name + "']"); | ||
var idElement = $("#" + name); | ||
var element = null; | ||
if (nameElement.length > 0) { | ||
element = nameElement; | ||
} else if (idElement.length > 0) { | ||
element = idElement; | ||
} | ||
|
||
if (element) { | ||
var offset = element.offset(); | ||
window.scrollTo(offset.left, offset.top); | ||
} | ||
|
||
return false; | ||
}); | ||
} | ||
}); | ||
}); |