Skip to content

Instantly share code, notes, and snippets.

@h3nn3s
Forked from ahoffmeyer/Modal.js
Last active March 31, 2016 08:39
Show Gist options
  • Save h3nn3s/729e730e46e9f6bb1040df43b3f5e893 to your computer and use it in GitHub Desktop.
Save h3nn3s/729e730e46e9f6bb1040df43b3f5e893 to your computer and use it in GitHub Desktop.
TYPO3 Modalbox with single content or full page selection using jQuery (working example for TYPO3 7 LTS)
(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');
}
$(function(){
$('body').on('click', function(event) {
$('#modal').remove();
});
});
})(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 {
where.data = GP:cid
where.intval = 1
where.if.isTrue.data = GP:cid
where.wrap = uid=|
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment