10

I'm doing a GUI Extension of User Interface (SiteEdit) by overriding the behaviour of one of the javascript files, to add some funcionality. The javascript file is "/Scripts/Components/ExtComponentField.js" and the target is "SiteEdit" extending:

Tridion.Web.UI.Editors.SiteEdit.Views.Content

All works well with the extension, and I have what I wanted to have, but now I'm trying to use the

settings/customconfiguration/clientconfiguration

node of the extension config, to use some initialization parameters, but there is no way to access $config element in the javascript, and Tridion.Core.Configuration.Editors["myExt"].configuration is null.

I've seen using this customconfiguration in various javascripts like "Dashboard" or "Footprints", but is it possible to have it on "Content"? am I missing something on the extension config?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Raúl Escudero
  • 448
  • 4
  • 11

3 Answers3

3

I'm afraid I didn't test this but you should be able to use:

Extensions.YourExt.getConfigurationItem = function (itemName, editorName)
{
    var editor = $config.Editors[editorName].configuration;
    if (editor)
    {
        var confXml = $xml.getNewXmlDocument(editor);
        var confObj = $xml.toJson(confXml);

        if (confObj[itemName])
            return confObj[itemName];
        else
            return "";
    }
}

You can then use it in the following way:

$this.getConfigurationItem("YOUR_CONFIG_ITEM_NAME", "YOUR_EDITOR_NAME").toString();

In your extension configuration (below the <theme> node) you can enter your own configuration values:

<customconfiguration>
  <clientconfiguration xmlns="http://www.sdltridion.com/2009/GUI/Configuration/Merge">
  <YOUR_CONFIG_ITEM_NAME>The value</YOUR_CONFIG_ITEM_NAME>

Can you confirm :)

johnwinter
  • 3,624
  • 15
  • 24
  • That was exactly how I was trying to use the customconfiguration, but there is no $config object, and Tridion.Core.Configuration.Editors["myExt"].configuration is null – Raúl Escudero Nov 20 '12 at 23:03
  • Thanks John, the way you state is ok when the javascript is loaded in a block where config is available. In this case the .js is in the "Content" block and no config is there. By **blocks** I mean the group in which the javascript is loaded like Bootstrap, Views, Editor, etc. I think there has to be a way to include this config in the Content group by adding some _dependency_ in the extension config. – Raúl Escudero Nov 21 '12 at 08:59
3

I usually use a separate JS file with the following:

Type.registerNamespace("Extensions.Namespace");

Extensions.Namespace.getEditorConfigSection = function Editor$getEditorConfigSection() {
    if (this._settings === undefined) {
        var editor = $config.Editors["ThisEditorName"];
        if (editor && editor.configuration && !String.isNullOrEmpty(editor.configuration)) {
            var configSectionXmlDoc = $xml.getNewXmlDocument(editor.configuration);
            this._settings = $xml.toJson(configSectionXmlDoc.documentElement);
        }
    }
    return this._settings;
};

and in the configuration add it in a separate group:

<cfg:group name="Extensions.Namespace" merge="always">
    <cfg:fileset>
        <cfg:file type="script">/Scripts/Definitions.js</cfg:file>
    </cfg:fileset>
</cfg:group>

Then wherever you need it, you can add the following dependency:

<cfg:dependency>Extensions.Namespace</cfg:dependency>

Then I usually use a function like this to get a certain configuration value:

Extensions.Namespace.Something.prototype._getMyConfigValue = function Something$_getMyConfigValue() {
    var configSection = Extensions.Namespace.getEditorConfigSection();
    if (configSection) {
        return configSection.myconfigvalue;
    }
};
Bart Koopman
  • 4,835
  • 17
  • 30
  • Thanks Bart, Is the same thing, the $config is not available in the **.../WebUI/Editors/SiteEdit/Views/Content_v6.1.0.55920.29_.aspx?mode=js** where the code of the extension is loaded. I'm extending the target **Tridion.Web.UI.Editors.SiteEdit.Views.Content** and it seems that in this context, the config object is not loaded. Probably is a question of dependencies. – Raúl Escudero Nov 22 '12 at 16:22
3

The code contained in the "Content" group is running inside of the IFRAME which is hosting your published web page. As you can imagine, the amount of files included there should be minimized and so quite a lot of functionality is not available.

My suggestion would be to read the configuration only in the main window and then pass along the settings that you need to the code running in the IFRAME -- through the use of the Tridion.Utils.CrossDomainMessaging utility class ($xdm).

Peter Kjaer
  • 4,316
  • 13
  • 23