juek / CustomSections

Developer plugin for rapid prototyping of custom section types in Typesetter CMS
GNU General Public License v2.0
3 stars 7 forks source link

Add more JS callback functions #32

Closed thomasfrobieter closed 7 years ago

thomasfrobieter commented 7 years ago

Hey,

can we please add some more callback funktions inside the universal_editor/editor.js? Currently we just have "CustomSection:updated" available.

Specificly i added:

  gp_editor.getFormElements = function(){
    var form_elements = gp_editor.ui.controls
      //.find("input:not(.editor-ctl-no-submit, [type='checkbox'], [type='radio'], [data-applyto]), select:not([data-applyto]), textarea");
      .find("input:not(.editor-ctl-no-submit, [type='checkbox'], [type='radio']), select, textarea")
      .trigger("CustomSection:formElementsLoaded"); // NEW LINE
    return form_elements;
  };
juek commented 7 years ago

Sure thing.

When triggered frome here, this event will fire quite frequently:
Once on every form element, everytime checkDirty, resetDirty, SaveData or updateSection are called.

Are you sure you really need them this way? We also have the "editor_area:loaded" event

thomasfrobieter commented 7 years ago

Yes editor_area:loaded is exactly what i need, thank you! I just saw the "CustomSection:updated" callback. Can we add a list of callbacks to the description / readme?

juek commented 7 years ago

AFAIK, we currently only trigger the "CustomSection:updated" custom event in $gp.response.updateContent() Another way to execute JS is to write a

CustomSections.onUpdate = function(){ 
  $(this).doSomething(); // this is the currently edited section
};

which will be called in the same response.

editor_area:loaded will be triggered by Typesetter/inline_editing.js.

Some other useful events: section_sorting:loaded section_options:loaded SectionAdded SectionSorted PreviewAdded PreviewRemoved SectionRemoved

thomasfrobieter commented 7 years ago

Yeah i think you have shown me this callbacks a while a go, i already saved it (http://blog.frobieter.de/content/typesetter-documentation) - except editor_area:loaded :)

Thank's again!

thomasfrobieter commented 7 years ago

But the CustomSection:formElementsLoaded is still very helpfull, as it fires also if a bunch control popup is loaded.

thomasfrobieter commented 7 years ago

CustomSection:formElementsLoaded fires way to often on the position i choosed -_- I think we can remove it.

But i added some more helpfull callbacks for bunch controls, i will push the changes.

juek commented 7 years ago

regarding SectionCopied:

i already saved it (http://blog.frobieter.de/content/typesetter-documentation) -> SectionCopied (Unclear - looks like only SectionAdded fired if a section is copied)

True. CopySection() in fact creates a clone (non-deep) via JS, which is - from the CMS point-of-view - nothing but an additional section, once saved. Source and copy aren't linked in any way (no inheritance or common properties). Therefore the SectionAdded event gets fired.

Hmm, maybe we should also fire a "SectionCopied" event, e.g. for cases where we need to generate new unique ids. Actually, IMO such ids should be (re)generated client-side when SectionAdded fires.