Coder Social home page Coder Social logo

cogizmo / sajax-content Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 1.0 89 KB

Custom Element that transcludes a document (in whole or part) into the current document at its current location.

License: ISC License

JavaScript 98.66% HTML 1.34%
custom-element web-component native-web-component ajax segmented-ajax transclude-html

sajax-content's Introduction

<sajax-content>

Transcludes HTML content from an external HTML resource.

Usage

Fetch the HTML document and replace itself with the HTML body contents.

<sajax-content src="path/to/external.html" auto></sajax-content>

Installation

<sajax-content> is available on NPM and may be installed as a dependency.

> npm install @cogizmo/sajax-content
  1. Place the files on your server.

  2. Install the appropriate cogizmo/Cogizmo.

    • From npm
    > npm install @cogizmo/cogizmo
    
    • From github
  3. Add Cogizmo to your document <head>.

    <script src="path/to/Cogizmo.js"></script>
  4. Add <sajax-content> element to your document.

    <script src="path/to/sajax-content.js"></script>
  5. Use element whereever you want to transclude html.

    <sajax-content src="path/to/external.html"></sajax-content>

Declarative API (HTML)

auto attribute

Boolean

When true, will fetch the external HTML when a valid src attribute. When false, will wait until auto attribute is true or transclude is called.

True:

<sajax-content auto></sajax-content>

False:

<sajax-content></sajax-content>

select attribute

String<CSSSelector> = "*"

Determines which elements are transcluded from the external HTML document's <body>. Valid values are any selector that can be used as an argument for HTMLElement.querySelectorAll(). The following gets all <p>s that are children of elements with class="container".

<sajax-content select=".container > p"></sajax-content>

src attribute

String - Required

URL pointing to the desired external HTML document. URLs are calculated in relation to the current document.

<sajax-content src="path/to/external.html"></sajax-content>

Imperative API (JS/ES)

element.auto

Returns Boolean - ReadOnly

When true, will fetch the external HTML when a valid src attribute. When false, will wait until auto attribute is true or transclude is called.

element.select

Returns String<CSSSelector> = "*"

Determines which elements are transcluded from the external HTML document's <body>. Valid values are any selector that can be used as an argument for HTMLElement.querySelectorAll(). The following gets all <p>s that are children of elements with class="container".

element.src

Returns String - ReadOnly

URL pointing to the desired external HTML document. URLs are calculated in relation to the current document.

element.transclude()

Gets an external HTML document from src attribute, queries the document for the elements using the select attribute, and imports them into the current HTML document.

DOM Events

<sajax-content> events try to behave as close to native DOM as possible. This means that you may cancel <sajax-content>s default behavior without having to worry about order of listeners or hierarchy. There is a single limitation to maintain defaultable and cancelable behavior. do not add an event listener to <sajax-content> events on the window/global object.

response

Fires when transclude() has retrieved a URL successfully.

Detail: The response object containing the data retrieved by the URL.

sajax-success

Fires when the transclusion process has successfully retrieved elements from an HTML document.

Detail: The NodeList query results from the external HTML document. The nodes are not yet imported.

sajax-import

Fires when the transclusion process has imported the NodeList results.

Detail: An Array containing the imported nodes.

sajax-attach

Fires when the transclusion process has attached the imported nodes from the external HTML document.

Detail: An Array containing the attached nodes.

sajax-content's People

Watchers

 avatar  avatar

Forkers

fuzzicallogic

sajax-content's Issues

Add test suites

Cogizmo, itself is fully tested, but none of the components that utilize Cogizmo are. This really has to be done before a release to 1.0.

Test suites required:

Unit Tests
Behavior Tests
Basic Integration Tests
Browser Compatibility Tests

Add module

ES Modules used correctly reduce global pollution, dependency conflicts, and transport requests. Used correctly, they can also provide multi-version support for code consumers.

Also see: import and export.

Make Cogizmo optional

Cogizmo is a convenience and doesn't do anything special but reduce instructions and logic. While generally, it is simpler, more readable and promotes some strong practices, all of these things may be easily replicated by those who need finer control.

  • Feature check for Cogizmo
  • Use HTMLElement as a fallback

Add noconflict mode

NoConflict mode would allow for code consumers to utilize multiple versions of <sajax-content>.

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.