mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 11:05:55 +02:00
Merge pull request #90 from mateusz/previews-by-id
Change the preview iframe to use injected SubsiteID GET/POST params.
This commit is contained in:
commit
1538e49e1b
@ -222,6 +222,29 @@ class SiteTreeSubsites extends DataExtension {
|
|||||||
return $url;
|
return $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use the CMS domain for iframed CMS previews to prevent single-origin violations
|
||||||
|
* and SSL cert problems.
|
||||||
|
*/
|
||||||
|
function alternatePreviewLink($action = null) {
|
||||||
|
$url = Director::absoluteURL($this->owner->Link());
|
||||||
|
if($this->owner->SubsiteID) {
|
||||||
|
$url = HTTP::setGetVar('SubsiteID', $this->owner->SubsiteID, $url);
|
||||||
|
}
|
||||||
|
return $url;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inject the subsite ID into the content so it can be used by frontend scripts.
|
||||||
|
*/
|
||||||
|
function MetaTags(&$tags) {
|
||||||
|
if($this->owner->SubsiteID) {
|
||||||
|
$tags .= "<meta name=\"x-subsite-id\" content=\"" . $this->owner->SubsiteID . "\" />\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $tags;
|
||||||
|
}
|
||||||
|
|
||||||
function augmentSyncLinkTracking() {
|
function augmentSyncLinkTracking() {
|
||||||
// Set LinkTracking appropriately
|
// Set LinkTracking appropriately
|
||||||
$links = HTTP::getLinksIn($this->owner->Content);
|
$links = HTTP::getLinksIn($this->owner->Content);
|
||||||
|
@ -57,4 +57,49 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$.entwine('ss.preview', function($){
|
||||||
|
|
||||||
|
$('.cms-preview').entwine({
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update links and forms with GET/POST SubsiteID param, so we remaing on the current subsite.
|
||||||
|
* The initial link for the iframe comes from SiteTreeSubsites::alternatePreviewLink.
|
||||||
|
*
|
||||||
|
* This is done so we can use the CMS domain for displaying previews so we prevent single-origin
|
||||||
|
* violations and SSL cert problems that come up when iframing content from a different URL.
|
||||||
|
*/
|
||||||
|
onafterIframeAdjustedForPreview: function(event, doc) {
|
||||||
|
var subsiteId = $(doc).find('meta[name=x-subsite-id]').attr('content');
|
||||||
|
|
||||||
|
if (!subsiteId) return;
|
||||||
|
|
||||||
|
// Inject the SubsiteID into internal links.
|
||||||
|
$(doc).find('a').each(function() {
|
||||||
|
var href = $(this).attr('href');
|
||||||
|
|
||||||
|
if (!href.match(/^http:\/\//)) {
|
||||||
|
|
||||||
|
$(this).attr('href', $.path.addSearchParams(href, {
|
||||||
|
'SubsiteID': subsiteId
|
||||||
|
}));
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Inject the SubsiteID as a hidden input into all forms submitting to the local site.
|
||||||
|
$(doc).find('form').each(function() {
|
||||||
|
|
||||||
|
if (!$(this).attr('action').match(/^http:\/\//)) {
|
||||||
|
$(doc).find('form').append('<input type=hidden name="SubsiteID" value="' + subsiteId + '" >');
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
})(jQuery);
|
})(jQuery);
|
Loading…
Reference in New Issue
Block a user