File: highlight.rb

package info (click to toggle)
tdiary 2.0.2%2B20060303-5
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 8,172 kB
  • ctags: 1,957
  • sloc: ruby: 23,926; lisp: 514; makefile: 87; sh: 71; sql: 32
file content (70 lines) | stat: -rw-r--r-- 1,638 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# highlight.rb $Revision: 1.2.2.3 $
#
# Highlighting the element jumped from other pages.
#
# Copyright (C) 2003 by Ryuji SAKAI
# Copyright (C) 2003 by Kazuhiro NISHIYAMA
# You can redistribute it and/or modify it under GPL2.
#
if @mode == 'day' then
	add_footer_proc do
		<<-SCRIPT
			<script type="text/javascript"><!--
			var highlightElem = null;
			var saveClass = null;
	
			function highlightElement(name) {
				if (highlightElem) {
					highlightElem.className = saveClass;
					highlightElem = null;
				}
	
				highlightElem = getHighlightElement(name);
				if (!highlightElem) return;
			
				saveClass = highlightElem.className;
				highlightElem.className = "highlight";
			}
					
			function getHighlightElement(name) {
				for (var i=0; i<document.anchors.length; ++i) {
					var anchor = document.anchors[i];
					if (anchor.name == name) {
						var elem;
						if (anchor.parentElement) {
							elem = anchor.parentElement;
						} else if (anchor.parentNode) {
							elem = anchor.parentNode;
						}
						return elem;
					}
				}
				return null;
			}
			
			if (document.location.hash) {
				highlightElement(document.location.hash.substr(1));
			}
			
			hereURL = document.location.href.split(/\#/)[0];
			for (var i=0; i<document.links.length; ++i) {
				if (hereURL == document.links[i].href.split(/\#/)[0]) {
					document.links[i].onclick = handleLinkClick;
				}
			}
			
			function handleLinkClick() {
				highlightElement(this.hash.substr(1));
			}
			// --></script>
		SCRIPT
	end
end

# Local Variables:
# mode: ruby
# indent-tabs-mode: t
# tab-width: 3
# ruby-indent-level: 3
# End:
# vi: ts=3 sw=3