User:Wrh2/common.js

//mw.loader.load('//en.wikivoyage.org/w/index.php?title=User:Wrh2/Gadget-ListingEditor.js&action=raw&ctype=text/javascript'); /* MapExpander = function { var mapWrapper; var mapThumb; var mapIframe; var originalThumbWidth; var originalIframeWidth; var originalIframeHeight; var thumbCaptionDiv; var expandLink; var PREF_COOKIE_NAME = "map_pref"; var isExpanded = function { return mapWrapper.hasClass('expanded'); };	var setCookiePref = function(expanded) { $.cookie(PREF_COOKIE_NAME, expanded, {			expires : 60, //expires in 60 days			path : '/'		}); };	return { expandMap: function { mapWrapper.addClass('expanded'); mapWrapper.removeClass('tright'); mapThumb.css('width', ''); mapIframe.attr('width', '100%'); var resizedWidth = mapIframe.width; var relativeHeight = ((resizedWidth / originalIframeWidth) * originalIframeHeight); // do not allow ratio to exceed 16:9 var maxHeight = resizedWidth * (9/16); if (maxHeight < relativeHeight) { relativeHeight = maxHeight; }			mapIframe.attr('height', relativeHeight); MapExpander.toggleCaption; setCookiePref("true"); },		contractMap: function { mapWrapper.removeClass('expanded'); mapWrapper.addClass('tright')		; mapThumb.css('width', originalThumbWidth); mapIframe.attr('width', originalIframeWidth); mapIframe.attr('height', originalIframeHeight); MapExpander.toggleCaption; setCookiePref("false"); },		toggleMapSize: function { isExpanded ? MapExpander.contractMap : MapExpander.expandMap; return false; },		toggleCaption: function { isExpanded ? expandLink.text('Collapse the map') : expandLink.text('Expand map to full width'); },		init: function { mapWrapper = $('#mapwrap'); if (!mapWrapper) { return; }			mapThumb = $(mapWrapper.find('.thumbinner')[0]); mapIframe = $(mapWrapper.find('iframe')[0]); originalThumbWidth = mapThumb.css('width'); originalIframeWidth = mapIframe.attr('width'); originalIframeHeight = mapIframe.attr('height'); thumbCaptionDiv = $(mapThumb.find('.thumbcaption')[0]); expandLink = $("").on('click', MapExpander.toggleMapSize); thumbCaptionDiv.prepend(expandLink); var expandPref = $.cookie(PREF_COOKIE_NAME); if (expandPref == "true") { MapExpander.expandMap; } else { MapExpander.contractMap; }		}	}; }; // check to ensure links are valid. does not work due to http/https issues. LinkChecker = function { return { init: function { if (window.location.href.indexOf("links=") > 0) { $("#bodyContent a").each(function(index, link) {					LinkChecker.checkLink(link);				}); }		},		checkLink: function(link) { var target = $(link).attr("href"); if (!target) { return; }			target = target.toLowerCase; if (!target.toLowerCase.startsWith("http")) { return; }			if (target.indexOf("en.wikivoyage.org") > 0) { return; }			if (target.indexOf("en.wikipedia.org") > 0) { return; }			$.ajax({				url: target,				dataType: "jsonp"			}).always(function(jqXHR) {				if (jqXHR.statusCode == 200) {					$(link).css("background-color", "green");				} else {					$(link).css("background-color", "red");				}			}); }	}; };

$(document).ready(function {	// MapExpander.init;	// LinkCheker.init; }); // END dynamic maps test code