GetmeUK / ContentTools

A JS library for building WYSIWYG editors for HTML content.
http://getcontenttools.com
MIT License
3.95k stars 395 forks source link

Fixture returning parent element #448

Closed ollym closed 6 years ago

ollym commented 6 years ago

Given

<h1 data-fixture data-name="heading">Some <b>bold</b> text</h1>

I'd expect region.html() to return Some <b>bold</b> text as per your documentation:

The output of the html method for fixtures does not include the surrounding element, for example if a Fixture is created using a H1 element the HTML output will not contain the H1 element only its content. For non-block elements such as images the entire IMG element is returned.

Except right now it outputs the full HTML string:

<h1 data-fixture data-name="heading">Some <b>bold</b> text</h1>

For me, I don't even want any HTML inside the fixture, so my workaround thus far is this:

  var editor = ContentTools.EditorApp.get();
  editor.init('[data-editable], [data-fixture]', 'data-name');

  editor.addEventListener('saved', function (ev) {
    var payload = {}, regions;
    Object.keys(regions = editor.regions()).forEach(name => {
      payload[name] = (regions[name].type() == 'Fixture') ? regions[name].domElement().innerText : regions[name].html()
    })
   //...
  });

But it is inconsistent with your docs, so I was just curious what is wrong. Docs or api

anthonyjb commented 6 years ago

Hi @ollym - the docs need updating (good spot), this has changed in recent releases to cater for more complex fixture types, see the following CT and CE releases for details:

I'll update the docs too :+1:

anthonyjb commented 6 years ago

Documentation has now been updated to reflect the change in release 1.3.0