Skip to content

Commit

Permalink
Move inline JS as jQuery no longer present there.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Feb 8, 2021
1 parent 9124cc4 commit d3cfe48
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 71 deletions.
29 changes: 16 additions & 13 deletions www/docs/admin/banner.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,25 @@
print $out;
?>
<script>
$('#preview').on('click', function bannerPreview() {
var text = $('#banner_text').val();
document.getElementById('preview').addEventListener('click', function(e) {
var text = document.getElementById('banner_text').value;
var banner_el = document.querySelector('.banner__content');
if ( text ) {
var banner_el = $('#surveyPromoBanner');
var fadeDelay = 1000;
if ( !banner_el.length ) {
fadeDelay = 0;
banner_el = $('<div id="surveyPromoBanner" style="clear:both;padding:1em;margin-top:24px;background:#DDD;">&nbsp;</div>');
$('body').prepend(banner_el);
if ( !banner_el ) {
var body = document.body;
banner_el1 = document.createElement('div');
banner_el1.classList.add('banner');
var banner_el2 = document.createElement('div');
banner_el2.classList.add('full-page__row');
var banner_el = document.createElement('div');
banner_el.classList.add('banner__content');
banner_el2.appendChild(banner_el);
banner_el1.appendChild(banner_el2);
body.insertBefore(banner_el1, body.firstChild);
}
banner_el.fadeOut(fadeDelay, function updateBannerText() {
banner_el.html($('#banner_text').val());
banner_el.fadeIn(1000);
});
banner_el.innerHTML = text;
} else {
banner_el = $('#surveyPromoBanner').remove();
banner_el.parentNode.removeChild(banner_el);
}
});
</script>
Expand Down
36 changes: 36 additions & 0 deletions www/docs/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,42 @@ $(function(){
t.parent().next(".nav-menu").toggleClass('closed');
});

$('.js-show-all-votes').on('click', function(){
$(this).fadeOut();
$('.policy-vote--minor').slideDown();
$('#policy-votes-type').text('All');
});

$('a[href="#past-list-dates"]').on('click', function(e){
e.preventDefault();
$(this).trigger('blur');
$('#past-list-dates').slideToggle();
})

// Move advanced search options to appear *before* results.
// (This means non-javascript users don't have to scroll past it
// to see their search results.)
$('.js-search-form-without-options').replaceWith( $('.js-search-form-with-options') );

// Show/hide advanced search options.
$('.js-toggle-search-options').on('click', function(e){
e.preventDefault();
var id = $(this).attr('href'); // #options
if($(id).is(':visible')){
$('.js-toggle-search-options[href="' + id + '"]').removeClass('toggled');
$(id).slideUp(250, function(){
// Disable the inputs *after* they're hidden (less distracting).
$(id).find(':input').attr('disabled', 'disabled');
});
} else {
$('.js-toggle-search-options[href="' + id + '"]').addClass('toggled');
$(id).find(':input:disabled').removeAttr('disabled');
$(id).slideDown(250);
}
});
if (!$('#options').data('advanced')) {
$("#options").find(":input").attr("disabled", "disabled");
}
});

// Backwards-compatible functions for the click/submit trackers on MP pages
Expand Down
29 changes: 9 additions & 20 deletions www/includes/easyparliament/templates/html/mp/divisions.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
<?php if ($has_voting_record) { ?>

<?php foreach ($policydivisions as $policy) { ?>
<?php
$show_all = FALSE;
if ( $policy['weak_count'] == 0 || $policy['weak_count'] == count($policy['divisions']) ) {
$show_all = TRUE;
}
?>

<?php if ( isset($policy['header']) ) { ?>
<div class="panel policy-votes-hero" style="background-image: url('<?php echo $policy['header']['image']; ?>');">
Expand Down Expand Up @@ -73,7 +79,9 @@
data on PublicWhip.org.uk</a>.
</p>

<h3 class="policy-votes-list-header"><span id="policy-votes-type">All</span> votes about <?= $policy['desc'] ?>:</h3>
<h3 class="policy-votes-list-header"><span id="policy-votes-type"><?=
$show_all ? 'All' : 'Key';
?></span> votes about <?= $policy['desc'] ?>:</h3>
<?php } else { ?>
<h3 class="policy-vote-overall-stance">
We don&rsquo;t have enough information to calculate <?= $full_name ?>&rsquo;s position on this issue
Expand All @@ -85,12 +93,6 @@
<?php } ?>

<ul class="vote-descriptions policy-votes">
<?php
$show_all = FALSE;
if ( $policy['weak_count'] == 0 || $policy['weak_count'] == count($policy['divisions']) ) {
$show_all = TRUE;
}
?>
<?php foreach ($policy['divisions'] as $division) {
include('_division_description.php');
$displayed_votes = TRUE;
Expand All @@ -108,19 +110,6 @@
</p>
</div>

<script type="text/javascript">
$(function(){
<?php if ( !$show_all ) { ?>
$('#policy-votes-type').text('Key');
<?php } ?>
$('.js-show-all-votes').on('click', function(){
$(this).fadeOut();
$('.policy-vote--minor').slideDown();
$('#policy-votes-type').text('All');
});
})
</script>

</div>
<?php } ?>
<?php } ?>
Expand Down
13 changes: 3 additions & 10 deletions www/includes/easyparliament/templates/html/people/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@
suitable for Excel
</p>
<?php if ( $type == 'mps' ) { ?>
<style>
.js #past-list-dates { display: none; }
</style>
<form method="get" action="<?= $urls['plain'] ?>" class="sidebar-item-with-icon sidebar-item-with-icon--date">
<p>
Or view a past list
Expand Down Expand Up @@ -250,16 +253,6 @@
</p>
</form>

<script type="text/javascript">
$(function(){
$('#past-list-dates').hide();
$('a[href="#past-list-dates"]').on('click', function(e){
e.preventDefault();
$(this).trigger('blur');
$('#past-list-dates').slideToggle();
})
});
</script>
<?php } else if ( $type == 'msps' ) { ?>
<p class="past-list-dates" id="past-list-dates">
<a href="<?= $urls['plain'] ?>?date=2011-05-05">MSPs at 2011 election</a>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="search-page__section search-page__section--options" id="options">
<div class="search-page__section search-page__section--options" id="options" data-advanced="<?=$is_adv ?>">
<div class="search-page__section__primary">
<h2>Advanced search</h2>

Expand Down Expand Up @@ -109,30 +109,3 @@
<p><input type="submit" class="button" value="Search"></p>
</div>
</div>

<script type="text/javascript">
$(function(){
// Move advanced search options to appear *before* results.
// (This means non-javascript users don't have to scroll past it
// to see their search results.)
$('.js-search-form-without-options').replaceWith( $('.js-search-form-with-options') );

// Show/hide advanced search options.
$('.js-toggle-search-options').on('click', function(e){
e.preventDefault();
var id = $(this).attr('href'); // #options
if($(id).is(':visible')){
$('.js-toggle-search-options[href="' + id + '"]').removeClass('toggled');
$(id).slideUp(250, function(){
// Disable the inputs *after* they're hidden (less distracting).
$(id).find(':input').attr('disabled', 'disabled');
});
} else {
$('.js-toggle-search-options[href="' + id + '"]').addClass('toggled');
$(id).find(':input:disabled').removeAttr('disabled');
$(id).slideDown(250);
}
});
<?= $is_adv ? '' : '$("#options").find(":input").attr("disabled", "disabled");' ?>
});
</script>

0 comments on commit d3cfe48

Please sign in to comment.