diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-10-27 20:43:35 +0200 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-10-27 20:43:35 +0200 |
commit | 1c75fcaf02ceb144152d59557643c6fdd7264065 (patch) | |
tree | 5184af75f2fd27ca6b81c24a06b1676d17ca2c76 /src/css.js | |
parent | b1b776a710d0ce0a6259043b8ce0665e205195fa (diff) | |
download | svg.js-1c75fcaf02ceb144152d59557643c6fdd7264065.tar.gz svg.js-1c75fcaf02ceb144152d59557643c6fdd7264065.zip |
resolve circular references and make example working again
Diffstat (limited to 'src/css.js')
-rw-r--r-- | src/css.js | 100 |
1 files changed, 48 insertions, 52 deletions
@@ -1,70 +1,66 @@ import {camelCase} from './helpers.js' -import Element from './Element.js' -import {extend} from './tools.js' import {isBlank} from './regex.js' -extend(Element, { // Dynamic style generator - css (style, val) { - let ret = {} - let i - if (arguments.length === 0) { - // get full style as object - this.node.style.cssText.split(/\s*;\s*/) - .filter(function (el) { return !!el.length }) - .forEach(function (el) { - let t = el.split(/\s*:\s*/) - ret[t[0]] = t[1] - }) - return ret - } +export function css (style, val) { + let ret = {} + let i + if (arguments.length === 0) { + // get full style as object + this.node.style.cssText.split(/\s*;\s*/) + .filter(function (el) { return !!el.length }) + .forEach(function (el) { + let t = el.split(/\s*:\s*/) + ret[t[0]] = t[1] + }) + return ret + } - if (arguments.length < 2) { - // get style properties in the array - if (Array.isArray(style)) { - for (let name of style) { - let cased = camelCase(name) - ret[cased] = this.node.style(cased) - } - return ret + if (arguments.length < 2) { + // get style properties in the array + if (Array.isArray(style)) { + for (let name of style) { + let cased = camelCase(name) + ret[cased] = this.node.style(cased) } + return ret + } - // get style for property - if (typeof style === 'string') { - return this.node.style[camelCase(style)] - } + // get style for property + if (typeof style === 'string') { + return this.node.style[camelCase(style)] + } - // set styles in object - if (typeof style === 'object') { - for (name in style) { - // set empty string if null/undefined/'' was given - this.node.style[camelCase(name)] = - (style[name] == null || isBlank.test(style[name])) ? '' : style[name] - } + // set styles in object + if (typeof style === 'object') { + for (name in style) { + // set empty string if null/undefined/'' was given + this.node.style[camelCase(name)] = + (style[name] == null || isBlank.test(style[name])) ? '' : style[name] } } + } - // set style for property - if (arguments.length === 2) { - this.node.style[camelCase(style)] = - (val == null || isBlank.test(val)) ? '' : val - } + // set style for property + if (arguments.length === 2) { + this.node.style[camelCase(style)] = + (val == null || isBlank.test(val)) ? '' : val + } - return this - }, + return this +} // Show element - show () { - return this.css('display', '') - }, +export function show () { + return this.css('display', '') +} // Hide element - hide () { - return this.css('display', 'none') - }, +export function hide () { + return this.css('display', 'none') +} // Is element visible? - visible () { - return this.css('display') !== 'none' - } -}) +export function visible () { + return this.css('display') !== 'none' +} |