@@ -92,36 +92,40 @@ FixedFootnotes.prototype.removeRefreshListener = function(listener) {
92
92
* From here: "private" methods that user is not supposed to call directly.
93
93
*/
94
94
95
+ /*
96
+ * Create the fixed container that will host the footnotes.
97
+ */
98
+ FixedFootnotes . prototype . _createFixedContainer = function ( ) {
99
+ var fixedContainer = this . _window . document . createElement ( "div" ) ;
100
+ fixedContainer . id = this . options . fixedContainerId ;
101
+ fixedContainer . className = this . options . fixedContainerClass + " fixed-footnotes-empty" ;
102
+ fixedContainer . appendChild ( this . _window . document . createElement ( "ul" ) ) ;
103
+ this . _window . document . querySelector ( this . options . fixedContainerLocation ) . appendChild ( fixedContainer ) ;
104
+ return fixedContainer ;
105
+ }
106
+
95
107
/*
96
108
* Refresh the view.
97
109
*/
98
110
FixedFootnotes . prototype . _refreshView = function ( ) {
99
111
var self = this ;
100
112
util . emptyElement ( this . _fixedContainerList ) ;
101
- this . _fixedContainer . className = this . options . fixedContainerClass + " fixed-footnotes-empty" ;
113
+ var containerEmpty = true ;
102
114
this . _getReferences ( ) . forEach ( function ( reference ) {
103
115
var note = self . _getNoteFromRef ( reference ) ;
104
- if ( ! note ) return ;
105
- if ( util . isElementInViewport ( reference , self . _window ) && ! util . isElementInViewport ( note , self . _window ) ) {
116
+ if ( self . _shouldDisplayNoteFor ( reference , note ) ) {
106
117
self . _displayNote ( note ) ;
107
- self . _fixedContainer . className = self . options . fixedContainerClass ;
118
+ containerEmpty = false ;
108
119
}
109
120
} ) ;
121
+ if ( containerEmpty ) {
122
+ this . _fixedContainer . classList . add ( "fixed-footnotes-empty" ) ;
123
+ } else {
124
+ this . _fixedContainer . classList . remove ( "fixed-footnotes-empty" ) ;
125
+ }
110
126
this . _dispatchRefresh ( ) ;
111
127
} ;
112
128
113
- /*
114
- * Create the fixed container that will host the footnotes.
115
- */
116
- FixedFootnotes . prototype . _createFixedContainer = function ( ) {
117
- var fixedContainer = this . _window . document . createElement ( "div" ) ;
118
- fixedContainer . id = this . options . fixedContainerId ;
119
- fixedContainer . className = this . options . fixedContainerClass + " fixed-footnotes-empty" ;
120
- fixedContainer . appendChild ( this . _window . document . createElement ( "ul" ) ) ;
121
- this . _window . document . querySelector ( this . options . fixedContainerLocation ) . appendChild ( fixedContainer ) ;
122
- return fixedContainer ;
123
- }
124
-
125
129
/*
126
130
* Get all the references.
127
131
*/
@@ -130,11 +134,13 @@ FixedFootnotes.prototype._getReferences = function() {
130
134
} ;
131
135
132
136
/*
133
- * Given a reference, display the footnote in the fixed container if the reference is on screen .
134
- * It won't display the footnote in the fixed container if the footnote is already on screen .
137
+ * Return true if we should display the note of the given reference .
138
+ * Note must exist, reference must be visible, and original note must not be visible .
135
139
*/
136
- FixedFootnotes . prototype . _displayIfVisible = function ( reference ) {
137
-
140
+ FixedFootnotes . prototype . _shouldDisplayNoteFor = function ( reference , note ) {
141
+ return note != undefined &&
142
+ util . isElementInViewport ( reference , this . _window ) &&
143
+ ! util . isElementInViewport ( note , this . _window ) ;
138
144
} ;
139
145
140
146
/*
0 commit comments