')
.attr('id', 'previewImgWin')
.addClass('modWin')
.appendTo('#leg')
modalWinJquery_str = '#previewImgWin'; // Set this to apply css and event handlers
// Add the iframe and pass the URi as an argument for the destination HTML to parse
$(modalWinJquery_str)
.html('
')
.prepend('

')
.prepend('
Large image view
')
// If the closelink is pressed, close the window
$('a', modalWinJquery_str)
.on('click', function(e) {
e.preventDefault();
closeModWin()
});
// Set the width and height as large as the viewable window
height = 0.9 * winH
width = 0.9 * winW
// Set the positioning
topPos = $(window).scrollTop() + (0.0125 * winH);
leftPos = winW/2-width/2;
// Remove scrollbars from the bg
$('body').css('overflow', 'hidden');
}
// Legacy browser detection is no longer avialable since new jquery doesnot suppot $.browser
// // IE6 doesn't support fixed position
// if ($.browser.msie && parseInt($.browser.version) < 7) {
// var position = "absolute";
// } else if (option.type == 'previewImg') {
// var position = "absolute";
// } else {
// var position = "fixed";
// }
const isOldIE = (ua => ua.indexOf('MSIE ') > 0 ? parseInt(ua.substring(ua.indexOf('MSIE ') + 5, ua.indexOf('.', ua.indexOf('MSIE ')))) < 7 : false)(window.navigator.userAgent);
// IE6 doesn't support fixed position
if (isOldIE) {
var position = "absolute";
} else if (option.type == 'previewImg') {
var position = "absolute";
} else {
var position = "fixed";
}
// Apply the popup window to center and style elements within
$(modalWinJquery_str).css({'top': topPos, 'position': position, 'height': height, 'width': width, 'left': leftPos});
$('iframe', modalWinJquery_str).css({height: '90%', width: '98%'}).hide // used for image option
// Set the background width to the window width so that there's no
// horizontal nav bars
$(option.bgJqueryStr).css({'width':$(document).width(),'height':$(document).height()});
// Show animation
$(modalWinJquery_str).show(option.fadeLength);
$(option.bgJqueryStr).fadeTo(option.fadeLength, 0.8).css({'width':$(document).width(),'height':$(document).height()});
$('iframe', modalWinJquery_str).fadeIn("slow");
});
// Escape key also closes the modalwin
$(document).on('keypress', function(e) {
if (e.keyCode == 27) {
closeModWin()
}
});
// Close function
function closeModWin() {
if (option.type == 'previewImg') {
$(modalWinJquery_str).remove();
$('body').css('overflow', 'visible');
} else {
$(modalWinJquery_str).hide(option.fadeLength);
}
$(option.bgJqueryStr).fadeOut(option.fadeLength);
}
});
// return this to keep chaining alive
return this;
};
/*
(c) Crown copyright
You may use and re-use this code free of charge under the terms of the Open Government Licence v3.0
http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3
*/
/**
* Small banner plugin to add banners to the main site.
*
* Optionally can have onClose() and onClick() handlers passed to allow for cookie persistence management.
*
* The option.doShow() function should return a boolean value to determine if the banner is shown or not.
*
* @param {[{[id]: string, [closeBtnSelector]: string, [doShow]: function|boolean, [onClose]: function, [onClick]: function}]} options
* Options for the plugin.
* @returns {[]|jQuery|HTMLElement}
* jQuery chaining/fluent interface.
*/
$.fn.simpleBanner = function (options) {
return $(this).each(function () {
var defaultOptions = {
closeBtnSelector: '.banner-close',
doShow: function () {
return true;
}
};
options = options || {};
options = $.extend(defaultOptions, options);
var $banner = $('
');
var context = this;
if (options.id) {
$banner.attr('id', options.id);
}
$banner.append(this);
if (options.doShow && options.doShow()) {
$('#top').after($banner);
} else {
return;
}
if (options.closeBtnSelector) {
var $button = $banner.find(options.closeBtnSelector);
$button.on('click', function (e) {
e.preventDefault();
options.onClose(e);
context.close();
});
}
if (options.onClick) {
$banner.on('click', function (event) {
options.onClick.call(context, event);
});
}
this.close = function () {
$banner.slideUp(500, function () {
$banner.remove();
});
}
});
}
/*
(c) Crown copyright
You may use and re-use this code free of charge under the terms of the Open Government Licence v3.0
http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3
*/
/**
* Legislation Table of Contents (ToC) Expand and Collapse.
*
* Used to add expand/collapse functionality to a ToC link element (that is created by another process), e.g.:
* $(link).legTocExpandCollapse('pageId', 5);
*
* @param {string} pageId
* Uniquely identifiable page name.
* @param {number} cookieExpire
* How long to persist the cookie.
* @returns {jQuery}
* jQuery chaining/fluent interface.
*/
$.fn.legTocExpandCollapse = function (pageId, cookieExpire) {
var COOKIE_ID = 'legTocExpandCollapse';
var state = {};
var $this = $(this);
var useCookies = function () {
return window.legGlobals.cookiePolicy.settings;
};
if (useCookies()) {
state = readCookie();
} else {
eraseCookie();
}
// Using this method for inserting text and relying on CSS to show correct attribute as less intensive on DOM.
// The divider is made available in case CSS is disabled.
$this
.html('
' + config.links.message3[LANG] + '' +
'
/' +
'
' + config.links.message4[LANG] + '');
// if cookie stored for related id, expand part
$this.each(function () {
var $link = $(this);
var $part = $link.parent();
// if saved and default expanded, collapse. Saved and default collapsed, expand
if (readIdInState($part.attr('id'))) {
if ($part.is('.tocDefaultExpanded')) {
$link.nextAll('ol').slideUp(0);
} else {
$link.addClass('expand');
}
} else {
// default expanded: expand. default collapsed: collapse
if ($part.is('.tocDefaultExpanded')) {
$link.addClass('expand');
} else {
$link.nextAll('ol').slideUp(0);
}
}
});
// toggle between expand and collapse. State appended to cookie if different from default
$this.each(function () {
$(this).on('click', function (e) {
var $link = $(this);
// disable anchor link
e.preventDefault();
var $part = $link.parent();
$link.toggleClass('expand');
$link.nextAll('ol').slideToggle(400).toggleClass('expanded');
if ($part.is('.tocDefaultExpanded') && !$link.is('.expand')) {
updateId($part.attr('id'));
} else if ($part.is('.tocDefaultCollapse') && $link.is('.expand')) {
updateId($part.attr('id'));
} else {
deleteId($part.attr('id'));
}
});
});
/**
* Update the state with the value of the ID.
*
* @param {string} id
*/
function updateId(id) {
state[id] = '';
if (useCookies()) {
updateCookie();
}
}
/**
* Delete the ID from the state.
*
* @param {string} id
*/
function deleteId(id) {
delete state[id];
if (useCookies()) {
updateCookie();
}
}
// ------------------------------
// Cookie functions
// ------------------------------
/**
* Write state contents to cookie.
*/
function updateCookie() {
var cookieContents = pageId + ';';
for (var i in state) {
cookieContents += (i + '#');
}
$.cookie(COOKIE_ID, cookieContents, {path: '/', expires: cookieExpire});
}
/**
* Read and deserialize the cookie values into an object.
*
* @returns {{}}
* Values by ID key.
*/
function readCookie() {
var associative = {};
var name = $.cookie(COOKIE_ID);
if (name) {
var split = name.split(';');
if (split.length > 1) {
var values = split[1].split('#');
for (var i = 0; i < values.length; i++) {
if (values[i] !== '') {
associative[values[i]] = '';
}
}
}
}
return associative;
}
/**
* Read the value of the passed ID.
*
* @param {string} id
* @returns {*|null}
*/
function readIdInState(id) {
return state && state[id] === '';
}
/**
* Delete the cookie used for persistence.
*/
function eraseCookie() {
if ($.cookie(COOKIE_ID)) {
$.removeCookie(COOKIE_ID, {path: '/'});
}
}
return $this;
};
/**
* Injecting images into code to perform server-side analytics in case of GTM failures.
*/
$(function () {
function isStringRgb(strToCheck) {
return strToCheck[0] === 'r';
}
/**
* Check whether the status update banner is red/green for revised legislation only.
*
* Ignores Points in Time (which are yellow) and as enacted legislation.
*/
function checkForChanges() {
var colours = {
'rgb(255, 200, 0)': 'PiT',
'rgb(0, 200, 50)': 'upToDate',
'rgb(240, 0, 100)': 'outstandingChanges'
};
var borderColour = $updateBanner.css('border-color').toLowerCase();
// The browser is giving strange results and therefore is ignored.
if (!isStringRgb(borderColour)) {
return;
}
var status = colours[borderColour];
// End early if the colour does not exist or if a Point in Time
if (!status || status === 'PiT') {
return;
}
// Inject an image depending on status.
var $img = $('
![]()
');
$img.attr('src', '/images/analytics/' + status + '.gif');
$img.appendTo('body');
}
var $updateBanner = $('#statusWarning');
if ($updateBanner.length) {
checkForChanges();
}
})
/*
(c) Crown copyright
You may use and re-use this code free of charge under the terms of the Open Government Licence v3.0
http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3
*/
function previousNextTextMatchLinks(){
// Add the skip links
$("#viewLegContents").prepend('
');
// If the referrer is a text search, add a button back to search
if (document.referrer.match(/^http:\/\/www\.legislation\.gov\.uk\/.*(\?|&)text=.*/)){
$('#skipLinks li').first().after('
' + config.viewLegContents.backToSearch[LANG] + '');
}
var previousLink = 0;
// Test if anchor is for next/previous links
var currentLink = window.location.hash.match(/match-[0-9]*/) ? window.location.hash.split('-')[1] : 1;
// Find the number of matches for comparisons
var lastMatchNum = $('.LegSearchResult').last().attr('id').split('-')[1];
// If the next match is higher than the total, reset to the highest
if (currentLink > lastMatchNum) {
currentLink = lastMatchNum;
}
var nextLink = Number(currentLink)+1;
var $nextLink = $('#next');
var $prevLink = $('#previous');
// Initialise the next/previous links
setPreviouslink();
setNextLink();
// Event handlers
$nextLink.on('click', function(e) {
e.preventDefault();
var matchAnchor = $(this).attr('href');
$('html').stop().animate({scrollTop: $(matchAnchor).offset().top}, 500);
// add limit logic
if (currentLink
1) {
currentLink--;
}
setPreviouslink();
setNextLink();
});
// Private functions
function setPreviouslink(){
previousLink = Number(currentLink) - 1;
// Check the limits, if there are no previous links, then amend the html
if (previousLink<1) {
$prevLink.html('First match').attr('href', '#match-1');
} else {
$prevLink.html('Previous match').attr('href', '#match-' + previousLink);
}
}
function setNextLink(){
nextLink = Number(currentLink) + 1;
// Check the limits, if the nextLink is out of the limit then amend the html
if (nextLink<=lastMatchNum) {
$nextLink.html('Next match').attr('href', '#match-' + nextLink);
} else {
$nextLink.html('Last match').attr('href', '#match-'+lastMatchNum);
}
}
};
/*
(c) Crown copyright
You may use and re-use this code free of charge under the terms of the Open Government Licence v3.0
http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3
*/
/*
Legislation Modal Window
One-liner: Overlays a div on top of the main content containing useful information to be displayed
Usage: $(.linkClass).showModalDialog()
Requirements:
jQuery framework- http://jquery.com/
to be attached to the XHTML document
CSS to control z-index for overlays
Div acting as modal window to already have been loaded
*/
/*$.fn.showModalDialog = function(options) {
var defaults = {
classes: {
modalWindow: 'modWin',
messageTitle: 'title webWarningTitle',
message: 'content',
messageINterface: 'interface'
},
modalId: 'invitationToSurvey',
titleText: 'Invitiation to survey',
textLine1: 'Thank you for using legislation.gov.uk',
textLine2: 'Can you help us to better understand how users read and interact with legislation by taking our survey? ',
textLine3: 'Survey closes on 22 September 2012.',
debug: false,
continueURL: function() {return '/'}
},
cfg = $.extend(defaults, options),
$modalDialog = $('
').addClass(cfg.classes.modalWindow).attr('id', cfg.modalId)
$('
').addClass(cfg.classes.messageTitle)
.append( $('
').addClass(cfg.classes.message)
.append('
' + cfg.textLine1+ '
')
.append ('
' + cfg.textLine2 + '
')
.append('
' + cfg.textLine3 + '
') )
.append('
')
.appendTo($modalDialog);
var homePage= $("body").find("#siteLinks");
if(homePage.length)console.log("home");
$("#siteLinks").append($modalDialog);
var parentDiv= $("body").find('#invitationToSurvey');
var continueUrl =window.location.pathname.split('/');
var welsh = continueUrl[1];
if($("body").attr('id') != 'error'){
// if((welsh == 'mwa') || (welsh == 'anaw') || (welsh == 'wsi') || (welsh == 'wdsi'))
// {
// if(($("body").find('#layout2').attr('class') == "legToc") && ($("body").find('#layout2').attr('class') != undefined) && ($("body").find('#layout2').attr('class') != '')){
// $(this).legModalWinOnce({type: 'testingModal', closeLinkTxt: 'Close', parentDiv: parentDiv});
// }
// }
}
};
*/
/*
* Opens the modal window to display a message on page load, this function does not require any click event to trigger itself.
*
*/
$.fn.legModalWinOnce = function(options){
// required for chaining, refer to jQuery API for more details
// Create variables and constants for storage, these can be overwritten in the normal jQuery way
var modalWinJquery_str;
var settings = {
type: 'defaultWin',
fadeLength: 400,
bgJqueryStr: '#modalBg',
closeLinkId_str: '#',
closeLinkIdJQuery_str: '#',
closeLinkTxt: 'Cancel'
};
var option = $.extend(settings, options);
if (option.type == 'defaultWin'){
// The default modal window is a link to a pre-existing disalogue box
modalWinJquery_str = $($(this).attr('href'));
// Create a close this window link and attach to the modal window, along with the event handler
$("
")
.addClass('cancel')
.html('
'+option.closeLinkTxt+'')
.prependTo($(modalWinJquery_str).children("div").last().children("ul"))
.on('click', function(event){
event.preventDefault();
closeModWin();
});
// Once user clicks continue, the modalwin closes
$("li.continue a", modalWinJquery_str).on('click', closeModWin);
}
/* else if(option.type=='testingModal'){
modalWinJquery_str = option.parentDiv;
// Create a close this window link and attach to the modal window, along with the event handler
var close= modalWinJquery_str.find('.close')
close.click(function(event){
event.preventDefault();
closeModWin();
});
var survey =modalWinJquery_str.find('.continue a');
survey.click(function(event){
event.preventDefault();
closeModWin();
window.open("http://www.surveygizmo.co.uk/s3/987479/legislation-survey-0812");
});
}
*/
// When the link that opens the modal win is clicked
//Get the window height and width
var winH = window.innerHeight; // get W3C val for browsers that can handle it
if (!winH)
winH = $(window).height(); // use jQuery if they can't
var winW = window.innerWidth;
if (!winW)
winW = $(window).width();
// Work out centering of the window and special functions
var topPos, leftPos, height, width;
if (option.type == 'defaultWin'){
// The default option requires minor positioning
topPos = winH/2-$(modalWinJquery_str).height()/2;
leftPos = winW/2-$(modalWinJquery_str).width()/2;
height = 'auto'
} else if (option.type == 'testingModal'){
topPos = winH/2-$(modalWinJquery_str).height()/2;
leftPos = winW/2-$(modalWinJquery_str).width()/2;
height = 'auto'
}
else {
// The previewImg type of modal window is a link from a thumbnail or preview image
// Find the Image URI and create the SRC attribute for iFrame
var modalWinIframeSrc = 'http://www.legislation.gov.uk/tools/displayimage?URL=' + $(this).attr('href');
// As this
isn;t embedded into the XHTML the modal win needs to be created here
$('
')
.attr('id', 'previewImgWin')
.addClass('modWin')
.appendTo('#leg')
modalWinJquery_str = '#previewImgWin'; // Set this to apply css and event handlers
// Add the iframe and pass the URi as an argument for the destination HTML to parse
$(modalWinJquery_str)
.html('
')
.prepend('

')
.prepend('
'+ config.modalwin.title[LANG] + '
')
// If the closelink is pressed, close the window
$('a', modalWinJquery_str)
.on('click', function(e) {
e.preventDefault();
closeModWin()
});
// Set the width and height as large as the viewable window
height = 0.9 * winH
width = 0.9 * winW
// Set the positioning
topPos = $(window).scrollTop() + (0.0125 * winH);
leftPos = winW/2-width/2;
// Remove scrollbars from the bg
$('body').css('overflow', 'hidden');
}
// Legacy browser detection is no longer avialable since new jquery doesnot suppot $.browser
// // IE6 doesn't support fixed position
// if ($.browser.msie && parseInt($.browser.version) < 7) {
// var position = "absolute";
// } else if (option.type == 'previewImg') {
// var position = "absolute";
// } else {
// var position = "fixed";
// }
const isOldIE = (ua => ua.indexOf('MSIE ') > 0 ? parseInt(ua.substring(ua.indexOf('MSIE ') + 5, ua.indexOf('.', ua.indexOf('MSIE ')))) < 7 : false)(window.navigator.userAgent);
// IE6 doesn't support fixed position
if (isOldIE) {
var position = "absolute";
} else if (option.type == 'previewImg') {
var position = "absolute";
} else {
var position = "fixed";
}
// Apply the popup window to center and style elements within
$(modalWinJquery_str).css({'top': topPos, 'position': position, 'height': height, 'width': width, 'left': leftPos});
$('iframe', modalWinJquery_str).css({height: '90%', width: '98%'}).hide // used for image option
// Set the background width to the window width so that there's no
// horizontal nav bars
$(option.bgJqueryStr).css({'width':$(document).width(),'height':$(document).height()});
// Show animation
$(modalWinJquery_str).show(option.fadeLength);
$(option.bgJqueryStr).fadeTo(option.fadeLength, 0.8).css({'width':$(document).width(),'height':$(document).height()});
$('iframe', modalWinJquery_str).fadeIn("slow");
// Escape key also closes the modalwin
$(document).on('keypress', function(e) {
if (e.keyCode == 27) {
closeModWin()
}
});
// Close function
function closeModWin() {
if (option.type == 'previewImg') {
$(modalWinJquery_str).remove();
$('body').css('overflow', 'visible');
} else {
$(modalWinJquery_str).hide(option.fadeLength);
}
$(option.bgJqueryStr).fadeOut(option.fadeLength);
}
};