Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

> Yokto simply means smallest SI prefix.

No framework framework 😛
Simple/tiny jQuery replacement/alternative library 😛

YoktoJS is supposed to be used with VanillaJS, using any frameworks* parallelly might bug things up!
--
\*frameworks as in: jQuery, etc.
YoktoJS is supposed to be used with VanillaJS, using any library/frameworks* parallelly might bug things up!
---
\*library/frameworks as in: jQuery, etc. (Basically any library/framework that uses `$_`, `$`, `$$`, `_`, `__` since Yokto uses it.)
24 changes: 19 additions & 5 deletions yokto.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,38 @@ const _ = (parentSelector, tag, attrs, innerText) => {
};
parentElem.appendChild(elem);
};
const $$ = (callback) => {
window.addEventListener("DOMContentLoaded", () => {
callback();
const $$ = (fn) => {
if (typeof fn !== 'function') {
throw new Error('Argument passed to ready should be a function');
}

if (document.readyState != 'loading') {
fn();
} else if (document.addEventListener) {
document.addEventListener('DOMContentLoaded', fn, {
once: true // A boolean value indicating that the listener should be invoked at most once after being added. If true, the listener would be automatically removed when invoked.
});
} else {
document.attachEvent('onreadystatechange', function() {
if (document.readyState != 'loading')
fn();
});
}
};
const $_ = async (method, url, data) => {
var headers = {};
if (data) {
headers['Content-Type'] = 'application/json';
headers['Accept'] = 'application/json';
};
const resp = await fetch(url, {
method: method,
mode: 'same-origin',
mode: 'cors',
cache: 'no-cache',
credentials: 'same-origin',
headers: headers,
redirect: 'follow',
referrerPolicy: 'no-referrer',
referrerPolicy: 'unsafe-url',
body: JSON.stringify(data)
});
return await resp.json();
Expand Down