Giter Site home page Giter Site logo

Comments (6)

PonteIneptique avatar PonteIneptique commented on August 20, 2024

Note that the following does not work either :

        CETEIcean.addBehaviors({
          "namespaces": {
            "tei": "http://www.tei-c.org/ns/1.0"
          },
          "tei": {
              "div": function(element) {
                  return element;
              },
              "w": ["<span data-tooltip=\"$rw@lemma\">","</a>"],
              "quote": function (element) {
                  return element;
              }
          }
        });

from ceteicean.

PonteIneptique avatar PonteIneptique commented on August 20, 2024

It seems that recursivity only works if the lamba returns HTML nodes. I don't think I have seen doc pointers about it ?

CETEIcean.addBehaviors({
          "namespaces": {
            "tei": "http://www.tei-c.org/ns/1.0"
          },
          "tei": {
              "div": function(element) {
                  var data = function (attr) {
                      return element.getAttribute(attr);
                  };
                  var div = document.createElement("div");
                  div.innerHTML = "<dl>\n" +
                      "   <dt>Subjects:</dt><dd>"+data("ana")+"</dd>\n" +
                      "   <dt>Adams Page:</dt><dd>"+data("corresp")+"</dd>\n" +
                      "</dl>" + element.innerHTML;
                  return div;
              },
              "w": ["<span data-tooltip=\"$rw@lemma\">","</a>"],
              "quote": function (element) {
                  var q = document.createElement("p");

                  q.innerHTML = "<em>Source: " + element.getAttribute("source") + "</em><br />" +
                                element.innerHTML;
                  return q;
              }
          }
        });

from ceteicean.

hcayless avatar hcayless commented on August 20, 2024

From the docs on behaviors:

Behavior functions take the element to be modified as a parameter and return an element to be appended to the parameter element. They may also return nothing and simply modify the passed element (e.g. by adding an attribute) or they may modify another part of the DOM. In general, we recommend avoiding side effects in behavior functions, but it may occasionally be necessary.

I’m pretty sure you can’t append an element to itself, so I don’t see how your example could work, but it probably points to a weakness in the documentation. What would help make it clearer?

from ceteicean.

PonteIneptique avatar PonteIneptique commented on August 20, 2024

Ok, thank you for the quick response.

I think, this could get a better light on it (a subtitle for example like "Behavior function parameter and return"

But what threw me is probably this example :

 "graphic": function(elt) {
      let content = new Image();
      content.src = this.rw(elt.getAttribute("url")); // "this" is the CETEI object.
      if (elt.hasAttribute("width")) {
        content.setAttribute("width",elt.getAttribute("width"));
      }
      if (elt.hasAttribute("height")) {
        content.setAttribute("height",elt.getAttribute("height"));
      }
      return content;
    },

And if I look at this, it feels like it should work somehow, from a user point of view.

Note : I'll let another point after because I just understood something.

from ceteicean.

PonteIneptique avatar PonteIneptique commented on August 20, 2024

Ok, so I read an reread writing the response up there, and what I finally understood :

Behavior functions take the element to be modified as a parameter and return an element to be appended to the parameter element.

This is completely counter-intuitive for someone who does XSLT I think. Not that it is bad, but I would definitely stress this in any way you can find, because this is not what you expect (though one should read the doc hm ?).

Is it helpful ?

from ceteicean.

PonteIneptique avatar PonteIneptique commented on August 20, 2024

May-be I'd add an example stating everystep that is taken by one behavior element and the result in between steps (1. creating the component. 2. checking the function 3. modifying the html and appending the return value inside the component) :)

from ceteicean.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.