UNPKG

edo-htqw

Version:

A easier HTML element's dom operation libary.

56 lines (55 loc) 1.83 kB
import edoTypeError from './error/edoTypeError'; export default function (edo) { edo.css = function (options, a2) { const head = document.querySelector('head'); let str = ''; if (options instanceof Object) { for (let s in options) { str += `${s}{`; let temp = options[s]; for (let s2 in temp) { str += `${s2}:${temp[s2]};`; } str += '}'; } } else if (typeof options === 'string') { str += `${options}{`; if (typeof a2 === 'string') { str += a2; } else if (a2 instanceof Object) { for (let s in a2) { str += `${s}:${a2[s]};`; } } else { throw new edoTypeError(`This type should is Object or string, fault ${Object.prototype.toString.call(a2).split(' ')[1].replace(']', '')}`); } str += `}`; } else { throw new edoTypeError(`This type should is Object or string, fault ${Object.prototype.toString.call(options).split(' ')[1].replace(']', '')}`); } head.innerHTML += `<style>${str}</style>`; }; edo.proto('css', function (a1, a2) { if (a2 === undefined) { if (typeof a1 === 'string') { this.el.style = a1; } else { for (let s in a1) { this.el.style[s] = a1[s]; } } } else { this.el.style[a1] = a2; } return true; }); edo.proto('getCss', function (name) { return this.el.style[name]; }); }