Skip to content

Instantly share code, notes, and snippets.

@ahoffmeyer
Last active March 30, 2016 14:47
Show Gist options
  • Save ahoffmeyer/c53a8145166e6421dfd6 to your computer and use it in GitHub Desktop.
Save ahoffmeyer/c53a8145166e6421dfd6 to your computer and use it in GitHub Desktop.
TYPO3 Modalbox with single content or full page selection using jQuery
(function(window, document, $) {
"use strict"
// Just for testing purposes this function triggers on all links
$('a').on('click', function(event) {
event.preventDefault();
// remove all existing modalboxes in DOM
$('#result').remove();
var uri = [];
uri = $(this).attr('href').split('#');
// if there is an anchor referencing a content element
if (uri[1]) {
// TYPO3 uses strings with contetn UID as content identifier
// so first of all, all non numbers must be removed
var cid = uri[1].replace(/[a-z]/gi, '');
$.get(uri[0], {cid: cid, type: 123}, function(data, status) {
appendToBody(data, status);
});
return true;
}
// if there is no anchor, then request the whole page
$.get(uri[0], {type: 123}, function(data, status) {
appendToBody(data, status);
});
});
// helper function to render the modal box
function appendToBody(data, status) {
if (status !== 'success') {
throw Error('Error getting the content');
}
$('<div>', {
id: 'result',
css: {
position: 'absolute',
zIndex: 99,
top: '125px',
left: '50%',
width: '50%',
marginTop: -125/2,
marginLeft: '-25%',
padding: 25,
background: 'white',
boxShadow: '0 0 40px rgba(0,0,0,0.5)',
borderRadius: 10
}
}).html(data).appendTo('body');
}
})(window, document, jQuery);
/*
this snippet assumes that jQuery is included in your page TypoScript in your configs
*/
modal = PAGE
modal {
// the type number references the querystring "type"
// see JavaScript
typeNum = 123
// Don't cache or render any header data
config {
no_cache = 1
disableAllHeaderCode = 1
disablePrefixComment = 1
}
10 < styles.content.get
10 {
select {
// get the content by uid
// cid => uid
andWhere.data = GP:cid
// get the content only if there is a query paramter
// if not, the whole page content will be fetched
andWhere.if.isTrue.data = GP:cid
andWhere.wrap = uid=|
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment