Last active
August 29, 2015 14:25
-
-
Save ginsterbusch/b79d15bed7a5d7ab738f to your computer and use it in GitHub Desktop.
Example for an external link redirect out of a WP menu (JS overlay, centered message, CSS).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Essentially this could be used with any kind of JS library; in this case, it's ki.js ;) | |
* Missing: Separate close button and "click anywhere on overlay to close (except the redirect link)" | |
* | |
* @author Fabian Wolf (@link http://usability-idealist.de/) | |
* @license GNU GPL v2 | |
*/ | |
$('.menu li.menu-item.ext-redirect').on('click', function(e) { | |
e.preventDefault(); | |
var strRedirectURL = this.href; | |
var strOverlay = '<div class="redirect-overlay"><div class="redirect-overlay-content">Redirect zu externem Anbieter<br /><a href="'+strRedirectURL+'">Nach 5 Sekunden geht es weiter - falls nicht, einfach diesen Link anklicken ..</a></div></div>'; | |
var overlayContentCSS = {'left':0,'top':0}; | |
// attach right behind the start of the body tag | |
$('body')[0].insertAdjacentHTML('afterbegin', strOverlay); | |
// calculate position of the overlay content | |
overlayContentCSS.left = Math.round( (jQuery(window).width() - jQuery('.redirect-overlay-content').width() ) / 2 ) + 'px'; | |
overlayContentCSS.top = Math.round( ( jQuery(window).height() - jQuery('.redirect-overlay-content').height() ) / 2 ) + 'px'; | |
// add css to the overlay content | |
$('.redirect-overlay-content').css(overlayContentCSS); | |
// fire up redirect timeout | |
window.setTimeout( function() { | |
window.location.href = strRedirectURL; | |
}, 5000 ); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* NOTE: I've intentionally NOT added a file name, because else Github Gist is using it as name of the gist, instead of the JS file, which would be the correct 'name'. | |
*/ | |
.redirect-overlay { | |
background: rgba(255,255,255,0.8); | |
color: #000; | |
width: 100%; | |
height: 100%; | |
display: block; | |
position: fixed; | |
z-index: 9999; | |
} | |
.redirect-overlay-content { | |
display: block; | |
min-width: 250px; | |
min-height: 100px; | |
position: fixed; | |
border: 1px solid #bbb; | |
padding: 0.5em 1em; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment