Skip to content

Instantly share code, notes, and snippets.

@jonihietala
Created September 25, 2017 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonihietala/237b0d6ab53bbeef1a66e9f6a24b16cb to your computer and use it in GitHub Desktop.
Save jonihietala/237b0d6ab53bbeef1a66e9f6a24b16cb to your computer and use it in GitHub Desktop.
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