Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

How to dectect content changes in client-side

Vote:
 

Hi, 
I'am writing code which monitors the currently editable page and shows the error notification for the editor if structure is wrong (for example h1 is mising). I'm doing it  in client side, because there are multiple pages and multiple places where h1 could be placed. So I need to detect when the content on the page changes . Does episerver has any events for client side, for example pubblishing content, content changed and similar?

Regards,

Giedrius

#131485
Jul 28, 2015 14:49
Vote:
 

Hi,

If you are creating a widget, then you could use "epi-cms/_ContentContextMixin". It has a contextChanged event which allows developer to take action when content changed.

Just add the mixin and handle the event:

define([
// ... other dependencies
    "epi/cms/_ContentContextMixin",

], function (
// ... other dependencies
    _ContentContextMixin
) {
    return declare("namespace.component",
        [/*other mixins*/ _ContentContextMixin], {


        contextChanged: function (context, callerData) {
            this.inherited(arguments);
            // handling content hange
        }
    });
});

API reference is here.

And very simple example of using _ContentContextMixin is here.

#131498
Jul 28, 2015 21:06
Vote:
 

Hi,
Thank you, this works, but only partially. contextChanged event is not trigered when the content is updated reliably. It seems to be trigered only then current content changes and in some other instances, but actually editing ontent doesn't trigger this event.

Also is there any way to make component run in the background? because this only works if added to the assests pane, but i'd like it to be in background all the time.

Regards,
Giedrius

#131508
Jul 29, 2015 10:15
Vote:
 

I didn't found special event for Saving content. Usually Save occurs on content blur. So maybe you could combine contextChanged event and also try to subscribe to widget blur event:

 topic.subscribe("widgetBlur", lang.hitch(this, this.save111));

But it will be executed more frequently than Save action (for example when editor change the content tab).

If you need to run a client side code without adding a gadget you could prepare intialization code in your module.config:

<?xml version="1.0" encoding="utf-8"?>
<module>
  <clientResources>
    <add dependency="epi-cms.widgets.base" path="Scripts/samples/commandsInitializer.js" resourceType="Script"  />
  </clientResources>

  <clientModule initializer="commands.samples.commandsInitializer">
    <moduleDependencies>
      <add dependency="CMS" type="RunAfter" />
    </moduleDependencies>
  </clientModule>
  
  <dojo>
    <paths>
        <add name="commands" path="Scripts" />
    </paths>
  </dojo>
</module>

The commands.samples.commandsInitializer file have dependency on "CMS" and should be executed after CMS is initialized.

define([
    "dojo",
    "dojo/_base/declare",
    "epi/_Module",
    "epi/dependency",
    "epi/routes",
    "commands/samples/relatedPagesCommandProvider"
], function(
    dojo,
    declare,
    _Module,
    dependency,
    routes,
    RelatedPagesCommandProvider
) {
    return declare([_Module], {
        initialize: function() {
            this.inherited(arguments);
            // ... Initialization code ...
        }
    });
});

The example comes from my blog where I'm adding new command. 

#131631
Jul 31, 2015 14:26
Vote:
 

Hi,
Thank you for your response, it might work. However I'm still missing on part of this:
How should I create this module so that it responds to episerver events? Just creatting it doesn't help. I need to place it somewhere, but I am not sure where. In you example you are placing it in command registry, but this is not suitable for me.

Regards,
Giedrius

#131691
Aug 03, 2015 13:14
Vote:
 
#131891
Aug 07, 2015 17:49
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.