Difference between revisions of "MediaWiki:Common.js"

From WikiCorporates
Jump to navigation Jump to search
m
Line 3: Line 3:
  
 
/*
 
/*
−
Trying to get show/hide working for Company Structure, _not_ References!
+
* Show/Hide for Company Structure
−
Looking at Ballotpedia page https://ballotpedia.org/Robert_Rowling
+
* From Ballotpedia page https://ballotpedia.org/Robert_Rowling
−
And at WikiPolitiks page http://wikipolitiks.local/wiki/National_Grid_plc
+
* Testing out on ...
−
 
+
*/
−
<script type="text/javascript">
+
$(document).ready( function($) {
−
if(document.getElementsByClassName("reference").length==0) if(document.getElementById('References')!==null) document.getElementById('References').parentNode.style.display = 'none';
+
// Add expand/contract functionality to references sections:
−
</script>
+
if ($('.references-small').height()>=140) {
−
... ...
+
$('.references-small').css('overflow','hidden').after('<div class="references-toggle"><span id="references-message">Only the first few references on this page are shown above.</span>  <a href="#">Click to show more.</a></div>');
−
<div class="references-toggle" style="text-align:center; border-top:1px dotted #cccccc;">Only the first few references on this page are shown above. [[Click to show more]]</div>
+
$('.references-toggle > a').click(function(e){ e.preventDefault(); $(this).parent().prev('.references-small').toggleClass('expanded'); $('<style></style>').appendTo($(document.body)).remove(); if($(this).html()=='Click to show more.'){ $(this).html('Click to show less.'); $("#references-message").html("");} else { $(this).html('Click to show more.'); $("#references-message").html("Only the first few references on this page are shown above.");} });
−
*/
+
}
 +
});

Revision as of 13:13, 18 July 2019

/* Any JavaScript here will be loaded for all users on every page load. */


/*
 * Show/Hide for Company Structure
 * From Ballotpedia page https://ballotpedia.org/Robert_Rowling
 * Testing out on ...
 */
$(document).ready( function($) {
// Add expand/contract functionality to references sections:
if ($('.references-small').height()>=140) {
$('.references-small').css('overflow','hidden').after('<div class="references-toggle"><span id="references-message">Only the first few references on this page are shown above.</span>  <a href="#">Click to show more.</a></div>');
$('.references-toggle > a').click(function(e){ e.preventDefault(); $(this).parent().prev('.references-small').toggleClass('expanded'); $('<style></style>').appendTo($(document.body)).remove(); if($(this).html()=='Click to show more.'){ $(this).html('Click to show less.'); $("#references-message").html("");} else { $(this).html('Click to show more.'); $("#references-message").html("Only the first few references on this page are shown above.");} });
}
});