UNPKG

pbar

Version:

Tiny progress bar widget in css and js es5

138 lines (97 loc) 4.33 kB
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <base data-ice="baseUrl" href="../../"> <title data-ice="title">src/pbar.js | API Document</title> <link type="text/css" rel="stylesheet" href="css/style.css"> <link type="text/css" rel="stylesheet" href="css/prettify-tomorrow.css"> <script src="script/prettify/prettify.js"></script> <script src="script/manual.js"></script> </head> <body class="layout-container" data-ice="rootContainer"> <header> <a href="./">Home</a> <a href="identifiers.html">Reference</a> <a href="source.html">Source</a> <a data-ice="repoURL" href="https://github.com/StoneCypher/pbar" class="repo-url-github">Repository</a> <div class="search-box"> <span> <img src="./image/search.png"> <span class="search-input-edge"></span><input class="search-input"><span class="search-input-edge"></span> </span> <ul class="search-result"></ul> </div> </header> <nav class="navigation" data-ice="nav"><div> <ul> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/pbar.js~pbar.html">pbar</a></span></span></li> </ul> </div> </nav> <div class="content" data-ice="content"><h1 data-ice="title">src/pbar.js</h1> <pre class="source-code line-number raw-source-code"><code class="prettyprint linenums" data-ice="content"> &apos;use strict&apos;; /******** * * Progress Bar * */ class pbar { constructor(opts) { opts = opts || {}; let defaults = { color : &apos;#40B3CC&apos;, background : &apos;transparent&apos;, border : &apos;0 solid transparent&apos;, height : &apos;4px&apos;, position : opts.target? &apos;absolute&apos; : &apos;fixed&apos;, target : document.body, transition : &apos;0.35s&apos;, value : &apos;50%&apos; }; this.opts = {}; Object.keys(defaults).map(key =&gt; this.opts[key] = opts[key] || defaults[key]); if (typeof this.opts.target === &apos;string&apos;) { this.opts.target = document.getElementById(this.opts.target); } this.frame = document.createElement(&apos;div&apos;); this.bar = document.createElement(&apos;div&apos;); this.frame.appendChild(this.bar); var frameStyles = {left: &apos;0&apos;, right: &apos;0&apos;, top: &apos;0&apos;, position: this.opts.position}; Object.keys(frameStyles).map(k =&gt; this.fs(k, frameStyles[k])); this.bs(&apos;height&apos;, &apos;100%&apos;); [&apos;height&apos;, &apos;border&apos;, &apos;color&apos;, &apos;background&apos;, &apos;transition&apos;, &apos;value&apos;].map(s =&gt; this[s] = this.opts[s]); this.opts.target.appendChild(this.frame); } fs(style, val) { this.frame.style[style] = val; } bs(style, val) { this.bar.style[style] = val; } get color() { return this.opts.color; } set color(c) { this.opts.color = c; this.bs(&apos;backgroundColor&apos;, c); } get background() { return this.opts.background; } set background(b) { this.opts.background = b; this.fs(&apos;backgroundColor&apos;, b); } get border() { return this.opts.border; } set border(b) { this.opts.border = b; this.fs(&apos;border&apos;, b); } get height() { return this.opts.height; } set height(h) { this.opts.height = h; this.fs(&apos;height&apos;, h); } get value() { return this.opts.value; } set value(v) { this.opts.value = v; this.bs(&apos;width&apos;, v); } get position() { return this.opts.position; } // no position setter get target() { return this.opts.target; } // no target setter get transition() { return this.opts.height; } set transition(t) { this.opts.transition = t; this.bs(&apos;transition&apos;, `width ${t}`); } }; export {pbar}; </code></pre> </div> <footer class="footer"> Generated by <a href="https://esdoc.org">ESDoc<span data-ice="esdocVersion">(0.4.6)</span></a> </footer> <script src="script/search_index.js"></script> <script src="script/search.js"></script> <script src="script/pretty-print.js"></script> <script src="script/inherited-summary.js"></script> <script src="script/test-summary.js"></script> <script src="script/inner-link.js"></script> <script src="script/patch-for-local.js"></script> </body> </html>