Building Enterprise HTML5 Application


Convenenient jQuery brite extension return the entity reference object of the closest matching HTMLElement with the matching data-entity attribute


  • entityType {string} : If present, will look for the closest element matching this entityType, otherwise will match the first HTMLElement with a data-entity attribute.
  • returns {Object} the entity reference object with the following properties.

    • .type {string}: The data-entity attribute value.
    • .id {string}: The data-entity-id attribute value.
    • .name {string}: The data-entity-name attribute value if present. This is not always used, but can be useful to allow the user interface logic to have this common property in the DOM rather than doing a DAO request to get it.


    For example, for the following HTML.

    <div data-entity="Project" data-entity-id="001">  
        <li data-entity="Task" data-entity-id="101">My Task 1
           <button class="delete">Delete</button>
    var taskRef = $("button.delete").bEntity();
    //   === "101"
    // taskRef.type === "Task"
    // === undefined (because, was not present as attribute)
    // this will return the same object values as above, 
    // since bEntity use the jQuery.fn.closest to get its matching parent element
    var sameTaskRef = $("li").bEntity();
    var projectRef = $("button.delete").bEntity("Project");
    // === "001"
    // projectRef.type === "Project"
    // === undefined (because, was not present as attribute)
    // Note that bEntity() returns the first entity reference for the first match 
    // HTMLElement.

Ask, learn, share about brite.js

Go to brite.js G+ community