mizuho 0.9.8 → 0.9.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,116 @@
1
+ #topbar {
2
+ position: fixed;
3
+ left: 0;
4
+ top: 0;
5
+ right: 0;
6
+ height: 2.5em;
7
+ padding-left: 10%;
8
+ padding-right: 10%;
9
+ z-index: 1;
10
+ background: #880000;
11
+ overflow: hidden;
12
+ white-space: nowrap;
13
+ box-shadow: 0px 3px 6px #555555;
14
+ -moz-box-shadow: 0px 3px 6px #555555;
15
+ -webkit-box-shadow: 0px 3px 6px #555555;
16
+ -o-box-shadow: 0px 3px 6px #555555;
17
+ }
18
+
19
+ #topbar .title {
20
+ display: inline-block;
21
+ margin: 0.6em 1em 0 0;
22
+ vertical-align: top;
23
+ }
24
+
25
+ #topbar .title img {
26
+ display: none;
27
+ margin-right: 6px;
28
+ vertical-align: middle;
29
+ }
30
+
31
+ #topbar .title a {
32
+ color: #fffafa;
33
+ border: 0;
34
+ }
35
+
36
+ #topbar .title:hover img,
37
+ .mobile #topbar .title img {
38
+ display: inline-block;
39
+ margin-left: -17px;
40
+ }
41
+
42
+ #topbar .title:hover a,
43
+ .mobile #topbar .title a {
44
+ color: #ffffdd;
45
+ }
46
+
47
+ #floattoc {
48
+ position: fixed;
49
+ z-index: 1;
50
+ top: 2em;
51
+ bottom: 20%;
52
+ width: 50%;
53
+ background: #f0f0f0;
54
+ color: black;
55
+ box-shadow: 0px 6px 6px #555555;
56
+ -moz-box-shadow: 0px 6px 6px #555555;
57
+ -webkit-box-shadow: 0px 6px 6px #555555;
58
+ -o-box-shadow: 0px 6px 6px #555555;
59
+ overflow: auto;
60
+ padding: 1em;
61
+ border-radius: 6px;
62
+ -webkit-border-radius: 8px;
63
+ -webkit-border-top-left-radius: 0;
64
+ -webkit-border-top-right-radius: 0;
65
+ -moz-border-radius: 8px;
66
+ -moz-border-radius-topleft: 0;
67
+ -moz-border-top-right-radius: 0;
68
+ -o-border-radius: 8px;
69
+ -o-border-radius-topleft: 0;
70
+ -o-border-top-right-radius: 0;
71
+ border-radius: 8px;
72
+ border-top-left-radius: 0;
73
+ border-top-right-radius: 0;
74
+ }
75
+
76
+ #floattoc a.current {
77
+ font-weight: bold;
78
+ color: black;
79
+ }
80
+
81
+ #current_section {
82
+ display: inline-block;
83
+ margin: 0.5em 0 0 0;
84
+ padding: 0.2em 0.5em 0.2em 0.5em;
85
+ background: #550000;
86
+ font-size: 90%;
87
+ vertical-align: top;
88
+ color: white;
89
+ border: none;
90
+ -webkit-border-radius: 8px;
91
+ -moz-border-radius: 8px;
92
+ -o-border-radius: 8px;
93
+ border-radius: 8px;
94
+ }
95
+
96
+ #current_section:hover {
97
+ text-decoration: none;
98
+ border: none;
99
+ }
100
+
101
+ #current_section.pressed {
102
+ background: #f0f0f0;
103
+ color: black;
104
+ -webkit-border-top-left-radius: 8px;
105
+ -webkit-border-top-right-radius: 8px;
106
+ -webkit-border-bottom-left-radius: 0;
107
+ -webkit-border-bottom-right-radius: 0;
108
+ -moz-border-radius-topleft: 8px;
109
+ -moz-border-radius-topright: 8px;
110
+ -moz-border-bottom-left-radius: 0;
111
+ -moz-border-bottom-right-radius: 0;
112
+ border-top-left-radius: 8px;
113
+ border-top-right-radius: 8px;
114
+ border-bottom-left-radius: 0;
115
+ border-bottom-right-radius: 0;
116
+ }
@@ -0,0 +1,7 @@
1
+ <div id="topbar" style="display: none">
2
+ <div class="title">
3
+ <img src="{INLINE_IMAGE:arrow-up.png}" width="11" height="10" alt="">
4
+ <a href="javascript:void(Mizuho.smoothlyScrollToToc())">{TITLE}</a>
5
+ </div>
6
+ <a href="javascript:void(0)" id="current_section"></a>
7
+ </div>
@@ -0,0 +1,175 @@
1
+ Mizuho.initializeTopBar = $.proxy(function() {
2
+ var $window = this.$window;
3
+ var $document = this.$document;
4
+ var self = this;
5
+ var $topbar = $('#topbar');
6
+ var $title = $('#header h1');
7
+ var $currentSection = $('#current_section');
8
+ var isMobileDevice = this.isMobileDevice();
9
+ var timerId;
10
+
11
+ var $floattoc = $('<div id="floattoc"></div>').html($('#toc').html());
12
+ $floattoc.find('#toctitle').remove();
13
+ $floattoc.find('.comments').remove();
14
+ $floattoc.css('visibility', 'hidden');
15
+ $floattoc.insertAfter($topbar);
16
+ var $floattoclinks = $floattoc.find('a');
17
+ $floattoclinks.each(function() {
18
+ // Firefox changes '#!' to '#%21' so change that back.
19
+ var $this = $(this);
20
+ var href = $this.attr('href');
21
+ if (href.match(/^#%21/)) {
22
+ $this.attr('href', href.replace(/^#%21/, '#!'));
23
+ }
24
+ });
25
+ $floattoclinks.click(function(event) {
26
+ self.internalLinkClicked(this, event);
27
+ });
28
+
29
+ function showFloatingToc() {
30
+ var scrollUpdateTimerId;
31
+
32
+ function reposition() {
33
+ if (isMobileDevice) {
34
+ $floattoc.css({
35
+ top: $currentSection.offset().top +
36
+ $currentSection.innerHeight() +
37
+ 'px',
38
+ height: $window.height() * 0.7 + 'px'
39
+ });
40
+ }
41
+ }
42
+
43
+ function highlightCurrentTocEntry() {
44
+ var currentSubsection = self.currentSubsection();
45
+ $floattoclinks.removeClass('current');
46
+ if (currentSubsection) {
47
+ var currentSubsectionTitle = $(currentSubsection).text();
48
+ var $link;
49
+
50
+ $floattoclinks.each(function() {
51
+ if ($(this).text() == currentSubsectionTitle) {
52
+ $link = $(this);
53
+ return false;
54
+ }
55
+ });
56
+ if ($link) {
57
+ $link.addClass('current');
58
+ self.setScrollTop(
59
+ $floattoc.scrollTop() +
60
+ $link.position().top -
61
+ $floattoc.height() * 0.45,
62
+ $floattoc);
63
+ return false;
64
+ }
65
+ }
66
+ }
67
+
68
+ function hideFloatingToc() {
69
+ $currentSection.removeClass('pressed');
70
+ $floattoc.css('visibility', 'hidden');
71
+ $floattoclinks.unbind('click', hideFloatingToc);
72
+ $document.unbind('mousedown', onMouseDown);
73
+ $document.unbind('touchdown', onMouseDown);
74
+ $document.unbind('mizuho:hideTopBar', hideFloatingToc);
75
+ $window.unbind('scroll', onScroll);
76
+ if (scrollUpdateTimerId !== undefined) {
77
+ clearTimeout(scrollUpdateTimerId);
78
+ scrollUpdateTimerId = undefined;
79
+ }
80
+ }
81
+
82
+ function onMouseDown(event) {
83
+ if (event.target != $floattoc[0]
84
+ && $(event.target).closest('#floattoc').length == 0) {
85
+ hideFloatingToc();
86
+ }
87
+ }
88
+
89
+ function onScroll(event) {
90
+ if (scrollUpdateTimerId === undefined) {
91
+ scrollUpdateTimerId = setTimeout(function() {
92
+ scrollUpdateTimerId = undefined;
93
+ reposition();
94
+ highlightCurrentTocEntry();
95
+ }, 100);
96
+ }
97
+ }
98
+
99
+ // Layout and display floating TOC.
100
+ highlightCurrentTocEntry();
101
+ var origScrollTop = $document.scrollTop();
102
+ var windowWidth = $window.width();
103
+ var maxRight = windowWidth - Math.floor(windowWidth * 0.1);
104
+
105
+ if ($currentSection.offset().left + $floattoc.outerWidth() > maxRight) {
106
+ $floattoc.css('left', maxRight - $floattoc.outerWidth());
107
+ } else {
108
+ $floattoc.css('left', $currentSection.offset().left + 'px');
109
+ }
110
+ reposition();
111
+ $floattoc.css('visibility', 'visible');
112
+ $currentSection.addClass('pressed');
113
+
114
+ $floattoclinks.bind('click', hideFloatingToc);
115
+ $document.bind('mousedown', onMouseDown)
116
+ $document.bind('touchdown', onMouseDown);
117
+ $document.bind('mizuho:hideTopBar', hideFloatingToc);
118
+ $window.bind('scroll', onScroll);
119
+ }
120
+
121
+ function update() {
122
+ if ($title.offset().top + $title.height() < $document.scrollTop()) {
123
+ if (!$topbar.is(':visible')) {
124
+ $topbar.slideDown(250);
125
+ $document.trigger('mizuho:showTopBar');
126
+ }
127
+ } else {
128
+ if ($topbar.is(':visible')) {
129
+ $topbar.slideUp();
130
+ $document.trigger('mizuho:hideTopBar');
131
+ }
132
+ }
133
+
134
+ if (isMobileDevice) {
135
+ $topbar.css({
136
+ top: $document.scrollTop() + 'px',
137
+ width: $window.width() -
138
+ parseInt($topbar.css('padding-left')) -
139
+ parseInt($topbar.css('padding-right')) +
140
+ 'px'
141
+ });
142
+ }
143
+
144
+ var header = self.currentSubsection();
145
+ var name;
146
+ if (header) {
147
+ name = $(header).text();
148
+ } else {
149
+ name = 'Preamble';
150
+ }
151
+ $currentSection.text(name);
152
+ }
153
+
154
+ function scheduleUpdate() {
155
+ if (timerId !== undefined) {
156
+ return;
157
+ }
158
+ timerId = setTimeout(function() {
159
+ timerId = undefined;
160
+ update();
161
+ }, 100);
162
+ }
163
+
164
+ if (isMobileDevice) {
165
+ // Mobile devices don't support position fixed.
166
+ $topbar.css('position', 'absolute');
167
+ $floattoc.css('position', 'absolute');
168
+ }
169
+
170
+ $currentSection.click(showFloatingToc);
171
+ $window.scroll(scheduleUpdate);
172
+ $document.bind('mizuho:updateTopBar', update);
173
+ }, Mizuho);
174
+
175
+ $(document).ready(Mizuho.initializeTopBar);
@@ -0,0 +1,188 @@
1
+ # Copyright (c) 2012 Hongli Lai
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
22
+ require 'stringio'
23
+ require 'mizuho/id_map'
24
+
25
+ describe Mizuho::IdMap do
26
+ before :each do
27
+ @id_map = Mizuho::IdMap.new
28
+ end
29
+
30
+ describe "#associate" do
31
+ describe "if the given title is not in the map" do
32
+ describe "if no similar titles exist in the map" do
33
+ before :each do
34
+ @id1 = @id_map.associate "Installation"
35
+ @id2 = @id_map.associate "Installation on Linux"
36
+ @id3 = @id_map.associate "Configuration"
37
+ end
38
+
39
+ it "returns a new unique ID" do
40
+ @id1.should_not == @id2
41
+ @id1.should_not == @id3
42
+ end
43
+
44
+ it "marks the entry as associated" do
45
+ @id_map["Installation"].should be_associated
46
+ @id_map["Installation on Linux"].should be_associated
47
+ @id_map["Configuration"].should be_associated
48
+ end
49
+
50
+ it "doesn't mark the corresponding entry as fuzzy" do
51
+ @id_map["Installation"].should_not be_fuzzy
52
+ @id_map["Installation on Linux"].should_not be_fuzzy
53
+ @id_map["Configuration"].should_not be_fuzzy
54
+ end
55
+ end
56
+
57
+ describe "if one or more similar titles exist in the map" do
58
+ before :each do
59
+ @entry1 = @id_map.add("Installation using a tarball", nil, false, false)
60
+ @entry2 = @id_map.add("Installation using a Linux tarball", nil, false, false)
61
+ end
62
+
63
+ it "associates with the most similar title and returns its ID" do
64
+ @id3 = @id_map.associate "Installation using tarball"
65
+ @id3.should == @entry1.id
66
+ @entry1.title.should == "Installation using tarball"
67
+ end
68
+
69
+ it "only associates with a title that hasn't been associated before" do
70
+ @entry1.associated = true
71
+ @id3 = @id_map.associate "Installation using tarball"
72
+ @id3.should == @entry2.id
73
+ end
74
+
75
+ it "marks the corresponding entry as associated" do
76
+ @id_map.associate "Installation using tarball"
77
+ @id_map["Installation using tarball"].should be_associated
78
+ end
79
+
80
+ it "marks the corresponding entry as fuzzy" do
81
+ @id_map.associate "Installation using tarball"
82
+ @id_map["Installation using tarball"].should be_fuzzy
83
+ end
84
+ end
85
+
86
+ specify "title matching is case-insensitive" do
87
+ entry1 = @id_map.add("INSTALLATION USING A TARBALL", nil, false, false)
88
+ id = @id_map.associate "installation using tarball"
89
+ id.should == entry1.id
90
+ end
91
+ end
92
+
93
+ describe "if the given title is in the map and it hasn't been associated before" do
94
+ before :each do
95
+ @entry = @id_map.add("Installation", nil, false, false)
96
+ end
97
+
98
+ it "returns that title's previous ID" do
99
+ id = @id_map.associate "Installation"
100
+ id.should == @entry.id
101
+ end
102
+
103
+ it "marks the entry as associated" do
104
+ @id_map.associate "Installation"
105
+ @entry.should be_associated
106
+ end
107
+
108
+ it "preserves the entry's fuzziness" do
109
+ @id_map.associate "Installation"
110
+ @entry.should_not be_fuzzy
111
+
112
+ @entry2 = @id_map.add("Installation 2", nil, true, false)
113
+ @id_map.associate "Installation 2"
114
+ @entry2.should be_fuzzy
115
+ end
116
+ end
117
+
118
+ describe "if the given title is in the map and it has been associated before" do
119
+ it "raises an error" do
120
+ @entry = @id_map.add("Installation", nil, false, true)
121
+ lambda { @id_map.associate "Installation" }.should raise_error(Mizuho::IdMap::AlreadyAssociatedError)
122
+ end
123
+ end
124
+ end
125
+
126
+ describe "loading" do
127
+ before :each do
128
+ @io = StringIO.new
129
+ end
130
+
131
+ it "works" do
132
+ @io.puts "# This is a comment."
133
+ @io.puts ""
134
+ @io.puts "Installation => installation-1"
135
+ @io.puts "Configuration => configuration-2"
136
+ @io.puts "# fuzzy"
137
+ @io.puts "Troubleshooting => troubleshooting-1"
138
+ @io.rewind
139
+ @id_map.load(@io)
140
+
141
+ @id_map.entries.should have(3).items
142
+ @id_map.entries.each_value { |entry| entry.should_not be_associated }
143
+
144
+ entry = @id_map["Installation"]
145
+ entry.title.should == "Installation"
146
+ entry.id.should == "installation-1"
147
+ entry.should_not be_fuzzy
148
+
149
+ entry = @id_map["Configuration"]
150
+ entry.title.should == "Configuration"
151
+ entry.id.should == "configuration-2"
152
+ entry.should_not be_fuzzy
153
+
154
+ entry = @id_map["Troubleshooting"]
155
+ entry.title.should == "Troubleshooting"
156
+ entry.id.should == "troubleshooting-1"
157
+ entry.should be_fuzzy
158
+ end
159
+ end
160
+
161
+ describe "saving" do
162
+ before :each do
163
+ @io = StringIO.new
164
+ @id_map.add "1. Installation", "installation-1", false, true
165
+ @id_map.add "2. Configuration", "configuration-2", false, true
166
+ @id_map.add "3. Troubleshooting", "troubleshooting-1", true, true
167
+ @id_map.add "4. Administration", "administration-1", true, false
168
+ @id_map.add "5. Uninstallation", "uninstallation-1", false, false
169
+ @id_map.add "0. Introduction", "intro", false, true
170
+ end
171
+
172
+ it "saves all entries in alphabetical order, marks fuzzy entries as such and puts unassociated (orphaned) entries at the bottom" do
173
+ @id_map.save(@io)
174
+ @io.string.should ==
175
+ Mizuho::IdMap::BANNER +
176
+ "0. Introduction => intro\n\n" +
177
+ "1. Installation => installation-1\n\n" +
178
+ "2. Configuration => configuration-2\n\n" +
179
+ "# fuzzy\n" +
180
+ "3. Troubleshooting => troubleshooting-1\n\n" +
181
+ "\n" +
182
+ "### These sections appear to have been removed. Please check.\n\n" +
183
+ "# fuzzy\n" +
184
+ "4. Administration => administration-1\n\n" +
185
+ "5. Uninstallation => uninstallation-1\n\n"
186
+ end
187
+ end
188
+ end