1.0.0 • Published 7 years ago

oujs v1.0.0

Weekly downloads
6
License
MIT
Repository
github
Last release
7 years ago

About

ŌūJs is simple wrapper, extensions and shorthands for Vanilla JS. It uses really short method name to make code quicker. ŌūJS contains common HTMLElement shorthands and other commonly used funcitons in day-to-dat routine work.

Why?

Today pure JavaScript sometimes also called Vanilla JS. Is pretty powerful enough and you don't need 3rd-party libraries like jQuery. Usually 3rd-party libraries are overbloated and fat and people don't use 80% of it's power in everyproject. Today everything can be achieved with pure JavaScript. But native method names and object chains are really long, as the result code is also very long. This is why I deciced to create ŌūJs.

What is Ōū?

Ōū (pronounced ˈʔoːʔuː) is small Hawaiian bird (Psittirostra psittacea) it is small and beautiful as well as ŌūJS. Wikipedia

Method naming convention

The idea was to create methods names as short as possible. Methods consist of 2 parts: method and object. One char is used for method and 3 chars are used element.

Table of shortenings

ShortLong
gget
hhas
aadd
rremove
ttoggle
clsclass
atrattribute
elmelement
alall

Examples

gatr (g - stands for get, atr for attribute, means short version of getAttribute) gal (g - stands for get, al for all, shortening of getAll) tcls (t - toggle, cls class = toggleClass) aatr (a - add, atr attribute = addAttribute)

API

methodVanilla JS equivalent
Ou.g(selector)document.querySelector()
Ou.gal(selector)document.querySelectorAll()
Ou.relm()document.remove()*
Element.aatr(name, value)Element.setAttribute()
Element.gatr(name)Element.getAttribute()
Element.ratr(name)Element.removeAttribute()
Element.hatr(name)Element.hasAttribute()
Element.acls(name1, name2, ..., nameN)Element.classList.add()
Element.rcls(name1, name2, ..., nameN)Element.classList.remove()
Element.tcls(name)Element.classList.toggle()
Element.hcls(name)Element.classList.contains()
Ou.ajax(params)AJAX call made for backwards compatibiliy. For AJAX calls it's strongly recommended to use native JS fetch() funtion. See AJAX params below

*IE11 has workaround

AJAX params

Parametertypedefault
urlstring''
urlmethod'GET'
successfunctionfunction (xhr) {}
errorfunctionfunction (xhr) {}
asyncbooleantrue
dataobject{}
userstringnull
pwdstringnull
typestring'html'
filebinaryBlobnull
corsstringfalse

Project's webpage