1.13.0 • Published 7 months ago

ojs-core v1.13.0

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

ojs-core

Open source JavaScript library for creating Object-oriented Web user interfaces. Core OrangutanJS module.

Install using npm:

npm i -D ojs-core

Quick start

input:
import o from 'ojs-core';
(...)

o('div').class('section border').id('first_section').add(
    o('h1').class('section__header').text('Hello oJS!!'),
    o('p').class('section__paragraph').text('This is OrangutanJS.')
]);
output:
<div class="section border" id="first_section">
    <h1 class="section__header">Hello oJS!</h1>
    <p class="section__paragraph">This is OrangutanJS.</p>
</div>

Render ojs to DOM:

import o, { oRender } from 'ojs-core';

const ojsContent = o('div').class('section border').id('first_section').add(
    o('h1').class('section__header').text('Hello oJS!!'),
    o('p').class('section__paragraph').text('This is OrangutanJS.')
]);

oRender(
    document.body,
    ojsContent
);

oJS instance

Before you use init method ojs instance is an object that you can work with using various methods.

o('div');           // o{ element: div, (...)}
o('div').init();    // <div></div>

You don't need to use init method when you are using oRender method. oRender would do it on its own.

oRender

oRender(parentNode: HTMLElement, childNode: HTMLElement | ojsInstance, cleanParentContent: boolean = false)

oFragment

oFragment is shadowElement where you can add multiple elements without creating unnecessary HTML Element.

oFragment(children: Array<HTMLElement|ojsInstance>)

Important: You can pass children in Array or just separated by a comma.

Example:

import o, { oRender, oFragment } from 'ojs-core';

oRender(
    document.body,
    oFragment(
        o('p').text('p1'),
        o('p').text('p2')
    )
)

Result:

<body>
    <p>p1</p>
    <p>p2</p>
</body>

.add()

You don't have to pass children elements right away when creating oFragment instance

Example:

import o, { oFragment } from 'ojs-core';

const fragment = oFragment();
const paragraphs = ['p1', 'p2'];

fragment.add(
    paragraphs.map(paragraph => o('p').text(paragraph))
)

oFragment - .init()

Init method returns Array of all children from instance;

Example:

const fragment = oFragment(
    o('p').text('p1').init(),
    o('p').text('p2').init()
);

fragment.init();
// [
//  <p>p1</p>,
//  <p>p2</p>
// ]

oDom

oDom allows to get element from DOM using query selector (css selectors). Returns ojs object. Returns null in all other cases (element not found or wrong arguments);

oDom(selector: String, parentNode: DOMElement|ojsInstance = document)
  • selector - query selector (css selector)
  • parentNode - element in the node of which we are looking for wanted element. Default parentNode is document.

    Important - oDom returns always only one element!

Example:

import o,{ oDom } from 'ojs-core';

const pElement = oDom('#someParagraph');

pElement.text('new paragraph text set using ojs API');

Dev notes:

To run playground:

remove "type": "module" from package.json and

npm run dev
1.13.0

7 months ago

1.12.0

7 months ago

1.11.4

2 years ago

1.11.3

2 years ago

1.11.2

2 years ago

1.11.1

2 years ago

1.10.2

2 years ago

1.11.5

2 years ago

1.9.1

2 years ago

1.8.2

2 years ago

1.9.0

2 years ago

1.8.1

2 years ago

1.8.0

2 years ago

1.7.0

2 years ago

1.9.5

2 years ago

1.9.4

2 years ago

1.9.3

2 years ago

1.9.2

2 years ago

1.11.0

2 years ago

1.10.1

2 years ago

1.10.0

2 years ago

1.6.0

2 years ago

1.5.0

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.1.0

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago