From ccdb76c7f127b10f92978d394d0156178a1563b0 Mon Sep 17 00:00:00 2001 From: surunzi Date: Sat, 14 Oct 2017 18:04:00 +0800 Subject: [PATCH] Dev: Border all snippet --- doc/UTIL_API.md | 94 ++++++++++++++++++++++++++++++++++++- eustia/evalCss.js | 1 - src/Snippets/defSnippets.js | 11 ++++- src/lib/util.js | 1 - 4 files changed, 103 insertions(+), 4 deletions(-) diff --git a/doc/UTIL_API.md b/doc/UTIL_API.md index 7c3ae70..62c37db 100644 --- a/doc/UTIL_API.md +++ b/doc/UTIL_API.md @@ -677,6 +677,25 @@ castPath('a[0].b'); // -> ['a', '0', 'b'] castPath('a.b.c', {'a.b.c': true}); // -> ['a.b.c'] ``` +## clamp + +Clamp number within the inclusive lower and upper bounds. + +|Name |Type |Desc | +|-------|------|---------------| +|n |number|Number to clamp| +|[lower]|number|Lower bound | +|upper |number|Upper bound | +|return |number|Clamped number | + +```javascript +clamp(-10, -5, 5); // -> -5 +clamp(10, -5, 5); // -> 5 +clamp(2, -5, 5); // -> 2 +clamp(10, 5); // -> 5 +clamp(2, 5); // -> 2 +``` + ## clone Create a shallow-copied clone of the provided plain object. @@ -926,7 +945,8 @@ escapeRegExp('[eris]'); // -> '\\[eris\\]' ## evalCss -No documentation. +dependencies +toStr each filter ## extend @@ -1500,6 +1520,70 @@ var fibonacci = memoize(function(n) }); ``` +## meta + +Document meta manipulation, turn name and content into key value pairs. + +Get meta content with given name. If name is omitted, all pairs will be return. + +|Name |Type |Desc | +|------|------------|------------| +|[name]|string array|Meta name | +|return|string |Meta content| + +Set meta content. + +|Name |Type |Desc | +|-------|------|------------| +|name |string|Meta name | +|content|string|Meta content| + +|Name |Type |Desc | +|-----|------|----------------------------| +|metas|object|Object of name content pairs| + +### remove + +Remove metas. + +|Name|Type |Desc | +|----|------------|---------| +|name|string array|Meta name| + +```javascript +// +meta(); // -> {a: '1', b: '2', c: '3'} +meta('a'); // -> '1' +meta(['a', 'c']); // -> {a: '1', c: '3'} +meta('d', '4'); +meta({ + d: '5', + e: '6', + f: '7' +}); +meta.remove('d'); +meta.remove(['e', 'f']); +``` + +## nextTick + +Next tick for both node and browser. + +|Name|Type |Desc | +|----|--------|----------------| +|cb |function|Function to call| + +Use process.nextTick if available. + +Otherwise setImmediate or setTimeout is used as fallback. + +```javascript +nextTick(function () +{ + // Do something... +}); +``` + ## noop A no-operation function. @@ -1899,6 +1983,14 @@ Create an array of the own enumerable property values of object. values({one: 1, two: 2}); // -> [1, 2] ``` +## viewportScale + +Get viewport scale. + +```javascript +viewportScale(); // -> 3 +``` + ## wrap Wrap the function inside a wrapper function, passing it as the first argument. diff --git a/eustia/evalCss.js b/eustia/evalCss.js index 7723e5a..336ef8b 100644 --- a/eustia/evalCss.js +++ b/eustia/evalCss.js @@ -39,7 +39,6 @@ exports.clear = function () exports.remove = function (style) { - console.log(style); styleList = filter(styleList, s => s !== style); style.container.removeChild(style.el); diff --git a/src/Snippets/defSnippets.js b/src/Snippets/defSnippets.js index fd5a1d3..b43ae36 100644 --- a/src/Snippets/defSnippets.js +++ b/src/Snippets/defSnippets.js @@ -2,12 +2,21 @@ import util from '../lib/util' import logger from '../lib/logger' import emitter from '../lib/emitter' +let style = null; + export default [ { name: 'Border All', fn() { - util.evalCss(borderCss); + if (style) + { + util.evalCss.remove(style); + style = null; + return; + } + + style = util.evalCss(borderCss); }, desc: 'Add color borders to all elements' }, diff --git a/src/lib/util.js b/src/lib/util.js index 23cb08d..cb12317 100644 --- a/src/lib/util.js +++ b/src/lib/util.js @@ -2408,7 +2408,6 @@ module.exports = (function () exports.remove = function (style) { - console.log(style); styleList = filter(styleList, s => s !== style); style.container.removeChild(style.el);