Content deleted Content added
add ready() event listener/handler |
update comment |
||
(22 intermediate revisions by the same user not shown) | |||
Line 8:
The hot key is Shift-Alt-a.
IMPORTANT: The menu item for this script is not in the side bar menu.
It is in the more tab at the top of the page. This is because having
it in the sidebar menu interferes with the script's page scrolling adjustment.
There is probably a much more efficient method than this. If you happen to know of one, please let me know.▼
(The Transhumanist)▼
Currently, this script applies regex upon matches within the ID element 'mw-content-text'.
It wraps the annotations in <span class="anno"> and </span>. Then it hides/shows the elements
▲with that class. There is probably a much more efficient method than
Besides that, the script isn't finished yet. The current problem I'm trying to solve is this:
Hiding or showing annotations affects the position of the viewport, so unfortunately,
Line 38 ⟶ 23:
I'd like the material that was in the viewport to stay there, which means the viewport
must be repositioned relative to the top of the page each time the toggle is activated.
If you have any ideas on how to fix this, I'd be most interested.
Sincerely,
Brief comments are provided within the sourcecode below. For extensive explanatory
notes on what the source code does and how it works, see the Script's workshop on
the talk page.
*/
Line 52 ⟶ 46:
$(function() {
// End the script if "Editing " is in the page title (so it doesn't conflict with script editor)
if (document.title.indexOf("Editing ") === 0) {
// use a return statement to end the local function and hence the program's body
// important: this approach does not work outside of a function
return;
}
// =================== Prep work =====================
var y1; var y2;
Line 59 ⟶ 62:
cont.outerHTML = cont.outerHTML.replace(/(<li>.*?)( –.*)/g,'$1<span class="anno">$2</span>');
// ================= Core control structure =================
// Only activate on Vector skin▼
▲ // ================= Core control structure =================
▲ // Only activate on Vector skin
if ( mw.config.get( 'skin' ) === 'vector' ) {
$( function() {
Line 86 ⟶ 88:
// ============ Function to hide annotations ==============
function annoHide() {
localStorage.setItem("annostatus", "hide");
y1 =
// alert( "vertical scroll
//Select the set of annotations that are above where the viewpoint is scrolled to
y1 = window.scrollY;▼
var $annos_above =
}▼
} );▼
//For each annotation
▲ var rect = this.getBoundingClientRect();
var height_before =
var height_after =
scroll_amount = scroll_amount +
}
▲ } );
$( ".anno"
▲ $annos_above.each( function(){
▲ //Hide the remaining annotations (hide elements with the anno class)
y1 =
//Scroll the window by
▲ alert( "vertical scroll position is " + y1);
// now we have
// (referred to in
// annoSwitch = mw.util.addPortletLink( 'p-tb', '#', 'Annotations \(show\)', 'ca-anno', 'Show the annotations', 'a' );
▲ // To do that, first we remove it (if it exists):
▲ if ( annoSwitch ) {
▲ annoSwitch.parentNode.removeChild(annoSwitch);
▲ }
// make the menu
▲ annoSwitch = mw.util.addPortletLink( 'p-tb', '#', 'Annotations \(show\)', 'ca-anno', 'Show the annotations', 'a' );
$( annoSwitch ).click( function ( e ) {
e.preventDefault(); //
▲ // (which activates the actions between the curly brakets when clicked):
▲ annoShow();
▲ } );
▲ }
}
Line 158:
// and then we create it (or its replacement) from scratch:
annoSwitch = mw.util.addPortletLink( 'p-
// annoSwitch = mw.util.addPortletLink( 'p-tb', '#', 'Annotations \(hide\)', 'ca-anno', 'Hide the annotations', 'a' );
$( annoSwitch ).click( function ( e ) {
e.preventDefault(); // prevents any default action -- we want only the following action to run:
annoHide();
} );
Line 170:
// </syntaxhighlight>
// sample code for getting and setting viewport position:
▲// window.scrollTo(0, y);
// y = window.scrollY;
// alert( "vertical scroll position is " + y);
// window.scrollTo(0, y);
|