Skip to content

Instantly share code, notes, and snippets.

@stevewithington
Forked from mattlevine/README.md
Created March 22, 2018 21:08
Show Gist options
  • Save stevewithington/c64dcc172cba366c7ad5f815cc78b0f5 to your computer and use it in GitHub Desktop.
Save stevewithington/c64dcc172cba366c7ad5f815cc78b0f5 to your computer and use it in GitHub Desktop.
Super Simple CaaS example

Super Simple CaaS Example

This is just an example to build upon and in no way represents best practice. You most like would use a web component framework like React.js or Vue.js with Mura.js rather than vanilla js.

For this to work:

  1. You must be on Mura 7.1.137 or greater

  2. set your site's contentRenderer.cfc's this.hashURLs=true;

  3. In your site's settings, set the following attributes

    1. Domain= The domain of the remote site that the the content will be served on.
    2. Is Remote = true
    3. Remote Context = The directory structure off of the remote site's web root that the site lives
    4. Remote Port = The port of the remote site
    5. Resource Domain = The domain that Mura will use the access resource like css and js scripts that are dynamically loaded.
  4. Reload Mura and test.

Also:

  1. Since Mura calendars uses fullcalendar.js you'll need to also include jQuery if needed.

  2. If you run into CORS errors including from from the resource domain you will need to add Access-Control-Allow-Origin header to your Mura instances web server

<!DOCTYPE html>
<html>
<head>
<!-- This is the config to be used -->
<script>
MuraCaaSConfig={
siteid:'caas',
endpoint:'http://localhost:8080',
CaaSContainerSelector:'body'
};
</script>
<!-- This is include the main Mura.js lib -->
<script src="http://localhost:8080/core/modules/v1/core_assets/js/mura.js"></script>
<!-- This is a simple template for Mura to use for it's content. This could be another file -->
<script id="mura-template-default" type="text/x-mura-template">
<div class="mura-nav">
<h3>Primary Nav</h3>
<ul class="mura-primary-nav"></ul>
<h3>Crumb Nav</h3>
<ul class="mura-crumb-nav"></ul>
<h3>Child Nav</h3>
<ul class="mura-child-nav"></ul>
</div>
<div class="mura-content"></div>
<div class="mura-region-container" data-region="maincontent"></div>
<div class="mura-html-queues"></div>
</script>
<!-- This init's Mura.js and renders the content. This could be another file -->
<script>
Mura.init(MuraCaaSConfig);
Mura(function(){
Mura.loader()
.loadcss(Mura.endpoint + '/core/modules/v1/core_assets/css/mura.7.1.min.css')
.loadcss(Mura.endpoint + '/core/modules/v1/core_assets/css/mura.7.1.skin.css');
function buildNav(container,parentid){
container.html('');
if(parentid=='00000000000000000000000000000000001'){
container.html('<li><a href="./#">Home</a></li>');
}
Mura.getFeed('content')
.where()
.prop('parentid').isEQ(parentid)
.getQuery()
.then(function(collection){
collection.forEach(function(item){
container.append('<li><a href="' + item.get('url') + '">' + item.get('menutitle') + '</a></li>');
});
})
}
function renderNav(container,collection){
container.html('');
collection.forEach(function(item){
container.append('<li><a href="' + item.get('url') + '">' + item.get('menutitle') + '</a></li>');
});
}
function buildCrumbs(content){
content.get('crumbs').then(function(collection){
collection.get('items').reverse()
renderNav( Mura('.mura-crumb-nav'),collection);
})
}
function render(){
let hash= location.hash || '#';
Mura.renderFilename(
hash.split('#')[1],
Mura.getQueryStringParams()
).then(function(content){
Mura('.mura-content').html(content.get('body'));
Mura('.mura-html-queues').html(content.get('htmlheadqueue') + content.get('htmlfootqueue'));
Mura.extend(Mura,content.get('config'));
Mura('.mura-region-container').each(function(){
var item=Mura(this);
item.html(
content.renderDisplayRegion(
item.data('region')
)
);
})
if(content.hasParent()
&& content.get('type') != 'Folder'
&& content.get('type') != 'Calendar'){
buildNav(
Mura('.mura-child-nav'),
content.get('contentid')
);
} else {
Mura('.mura-child-nav').html('');
}
buildCrumbs(content);
Mura(document).processMarkup();
});
}
Mura(Mura.CaaSContainerSelector).append(Mura('#mura-template-default').html());
buildNav(
Mura('.mura-primary-nav'),
'00000000000000000000000000000000001'
);
render();
Mura(window).on('hashchange', render);
});
</script>
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment