Skip to content

Instantly share code, notes, and snippets.

@jonihietala

jonihietala/Initializer.js Secret

Created Sep 25, 2017
Embed
What would you like to do?
Adding a "View on website" -button to context menu in navigation tree in Episerver
define([
"dojo",
"dojo/_base/declare",
"epi-cms/plugin-area/navigation-tree",
// Parent class
"epi/_Module",
// Commands
"alloy/ViewOnWebsite/ViewOnWebsite"
], function (
// Dojo
dojo,
declare,
navigationTreePluginArea,
// Parent class
module,
// Commands
viewOnWebsite
) {
return declare([module], {
initialize: function () {
this.inherited(arguments);
navigationTreePluginArea.add(viewOnWebsite);
}
});
});
<?xml version="1.0" encoding="utf-8"?>
<module>
<assemblies>
<!-- This adds the Alloy template assembly to the "default module" -->
<add assembly="AlloyDemoKit" />
</assemblies>
<clientResources>
<add name="epi-cms.widgets.base" path="Styles/Styles.css" resourceType="Style"/>
</clientResources>
<dojo>
<!-- Add a mapping from alloy to ~/ClientResources/Scripts to the dojo loader configuration -->
<paths>
<add name="alloy" path="Scripts" />
</paths>
</dojo>
<clientModule initializer="alloy.Initializer">
<moduleDependencies>
<add dependency="CMS" type="RunAfter" />
</moduleDependencies>
</clientModule>
</module>
define([
"dojo/topic",
"dojo/_base/declare",
"epi/dependency",
"epi/shell/command/_Command"
], function (topic, declare, dependency, command) {
return declare([command], {
label: "View on Website",
iconClass: "epi-iconNewWindow",
constructor: function () {
var registry = dependency.resolve("epi.storeregistry");
this.store = registry.get("epi.cms.contentdata");
},
_execute: function () {
if (this.model != null && this.model.publicUrl != null) {
var publicUrl = location.protocol + "//" + location.host + this.model.publicUrl;
window.open(publicUrl, "_blank");
}
},
_onModelChange: function () {
this.set("canExecute", true);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.