Dev: Small improvements

This commit is contained in:
surunzi
2016-12-31 17:23:50 +08:00
parent 5467df54d1
commit c3738be312
7 changed files with 150 additions and 37 deletions

View File

@@ -2,11 +2,23 @@
## $ ## $
jQuery like style dom manipulator. TODO jQuery like style dom manipulator.
### Available methods
offset, hide, show, first, last, get, eq, on, off, html, text, val, css, attr,
data, rmAttr, remove, addClass, rmClass, toggleClass, hasClass, append, prepend,
before, after
```javascript ```javascript
var $btn = $('#btn'); var $btn = $('#btn');
$btn.html('eustia'); $btn.html('eustia');
$btn.addClass('btn');
$btn.show();
$btn.on('click', function ()
{
// Do something...
});
``` ```
## $attr ## $attr
@@ -148,13 +160,15 @@ $data('#test', 'attr1', 'eustia');
## $event ## $event
bind events to certain dom elements. TODO bind events to certain dom elements.
```javascript ```javascript
event.on('#test', 'click', function () function clickHandler()
{ {
// ... // Do something...
}); }
$event.on('#test', 'click', clickHandler);
$event.off('#test', 'click', clickHandler);
``` ```
## $insert ## $insert
@@ -294,19 +308,19 @@ var People = Class({
var Student = People.extend({ var Student = People.extend({
initialize: function (name, age, school) initialize: function (name, age, school)
{ {
this.callSuper('initialize', name, age); this.callSuper(People, 'initialize', arguments);
this.school = school. this.school = school;
}, },
introduce: function () introduce: function ()
{ {
return this.callSuper('introduce') + '\n I study at ' + this.school + '.'. return this.callSuper(People, 'introduce') + '\n I study at ' + this.school + '.'.
} }
}, { }, {
is: function (obj) is: function (obj)
{ {
return obj instanceof Student; return obj instanceof Student;
} }
}); });
var a = new Student('allen', 17, 'Hogwarts'); var a = new Student('allen', 17, 'Hogwarts');
@@ -523,7 +537,32 @@ defaults({name: 'RedHood'}, {name: 'Unknown', age: 24}); // -> {name: 'RedHood',
## delegate ## delegate
TODO Event delegation.
### add
Add event delegation.
|Name |Type |Desc |
|--------|--------|--------------|
|el |element |Parent element|
|type |string |Event type |
|selector|string |Match selector|
|cb |function|Event callback|
### remove
Remove event delegation.
```javascript
var container = document.getElementById('container');
function clickHandler()
{
// Do something...
}
delegate.add(container, 'click', '.children', clickHandler);
delegate.remove(container, 'click', '.children', clickHandler);
```
## each ## each
@@ -566,6 +605,10 @@ Escapes a string for insertion into HTML, replacing &, <, >, ", `, and ' charact
escape('You & Me'); -> // -> 'You &amp; Me' escape('You & Me'); -> // -> 'You &amp; Me'
``` ```
## escapeJsonStr
No documentation.
## escapeRegExp ## escapeRegExp
Escape special chars to be used as literals in RegExp constructors. Escape special chars to be used as literals in RegExp constructors.
@@ -590,7 +633,7 @@ Copy all of the properties in the source objects over to the destination object.
|Name |Type |Desc | |Name |Type |Desc |
|------|------|------------------| |------|------|------------------|
|obj |object|Destination object| |obj |object|Destination object|
|*src |object|Sources objects | |...src|object|Sources objects |
|return|object|Destination object| |return|object|Destination object|
```javascript ```javascript
@@ -637,6 +680,10 @@ No documentation.
No documentation. No documentation.
## getObjType
No documentation.
## has ## has
Checks if key is a direct property. Checks if key is a direct property.
@@ -666,7 +713,7 @@ identity('a'); // -> 'a'
## idxOf ## idxOf
Get the index at which the first occurrence of value. TODO Get the index at which the first occurrence of value.
|Name |Type |Desc | |Name |Type |Desc |
|-----------|------|--------------------| |-----------|------|--------------------|
@@ -964,7 +1011,19 @@ last([1, 2]); // -> 2
## loadJs ## loadJs
Inject script tag into page with given src value. TODO Inject script tag into page with given src value.
|Name|Type |Desc |
|----|--------|---------------|
|src |string |Script source |
|cb |function|Onload callback|
```javascript
loadJs('main.js', function ()
{
// Do something...
});
```
## lpad ## lpad
@@ -1017,7 +1076,31 @@ map([4, 8], function (n) { return n * n; }); // -> [16, 64]
## matcher ## matcher
TODO Return a predicate function that checks if attrs are contained in an object.
|Name |Type |Desc |
|------|--------|----------------------------------|
|attrs |object |Object of property values to match|
|return|function|New predicate function |
```javascript
var objects = [
{a: 1, b: 2, c: 3 },
{a: 4, b: 5, c: 6 }
];
filter(objects, matcher({a: 4, c: 6 })); // -> [{a: 4, b: 5, c: 6 }]
```
## memStorage
Memory-backed implementation of the Web Storage API.
A replacement for environments where localStorage or sessionStorage is not available.
```javascript
var localStorage = window.localStorage || memStorage;
localStorage.setItem('test', 'eris');
```
## noop ## noop
@@ -1066,7 +1149,7 @@ initOnce(); // -> init is invoked once
## optimizeCb ## optimizeCb
TODO Used for function context binding.
## orientation ## orientation
@@ -1140,7 +1223,11 @@ rtrim('_abc_', ['c', '_']); // -> '_ab'
## safeCb ## safeCb
Create callback based on input value. TODO Create callback based on input value.
## safeStorage
No documentation.
## slice ## slice
@@ -1246,6 +1333,7 @@ Convert value to an integer.
```javascript ```javascript
toInt(1.1); // -> 1 toInt(1.1); // -> 1
toInt(undefined); // -> 0
``` ```
## toNum ## toNum
@@ -1303,7 +1391,7 @@ Generate a globally-unique id.
|return|string|Globally-unique id| |return|string|Globally-unique id|
```javascript ```javascript
uniqueId('eusita_'); // -> 'eustia_xxx' uniqId('eusita_'); // -> 'eustia_xxx'
``` ```
## unique ## unique
@@ -1330,7 +1418,7 @@ Convert the first character of string to upper case.
|return|string|Converted string | |return|string|Converted string |
```javascript ```javascript
upperFirst('red'); // -> RED upperFirst('red'); // -> Red
``` ```
## values ## values
@@ -1345,3 +1433,21 @@ Creates an array of the own enumerable property values of object.
```javascript ```javascript
values({one: 1, two: 2}); // -> [1, 2] values({one: 1, two: 2}); // -> [1, 2]
``` ```
## wrap
Wrap the function inside a wrapper function, passing it as the first argument.
|Name |Type |Desc |
|-------|--------|----------------|
|fn |* |Function to wrap|
|wrapper|function|Wrapper function|
|return |function|New function |
```javascript
var p = wrap(escape, function(fn, text)
{
return '<p>' + fn(text) + '</p>';
});
p('You & Me'); // -> '<p>You &amp; Me</p>'
```

View File

@@ -5,10 +5,10 @@
"main": "eruda.js", "main": "eruda.js",
"scripts": { "scripts": {
"build": "webpack --config script/webpack.dev.js && webpack -p --config script/webpack.release.js", "build": "webpack --config script/webpack.dev.js && webpack -p --config script/webpack.release.js",
"dev": "webpack-dev-server --config script/webpack.dev.js", "dev": "webpack-dev-server --config script/webpack.dev.js --host 0.0.0.0",
"cpTestLib": "script/cpTestLib.sh", "cpTestLib": "script/cpTestLib.sh",
"lint": "eslint --ext .es6 src", "lint": "eslint --ext .es6 src",
"utilDoc": "eustia doc src/lib/util.js -f md -o doc/Util_Api.md -t \"Eruda Util Documentation\"" "utilDoc": "eustia doc src/lib/util.js -f md -o doc/UTIl_API.md -t \"Eruda Util Documentation\""
}, },
"repository": { "repository": {
"type": "git", "type": "git",

View File

@@ -100,8 +100,8 @@ export default class DevTools extends util.Emitter
var cfg = this.config = config.create('eruda-dev-tools'); var cfg = this.config = config.create('eruda-dev-tools');
cfg.set(util.defaults(cfg.get(), { cfg.set(util.defaults(cfg.get(), {
transparency: '100%', transparency: '95%',
displaySize: '100%', displaySize: '80%',
tinyNavBar: false, tinyNavBar: false,
activeEruda: false activeEruda: false
})); }));

View File

@@ -169,18 +169,21 @@
box-shadow: $box-shadow; box-shadow: $box-shadow;
margin-bottom: 10px; margin-bottom: 10px;
background: #fff; background: #fff;
border-radius: $border-radius;
overflow: hidden;
.listener-type { .listener-type {
padding: $padding; padding: $padding;
background: $blue; background: $blue;
color: #fff; color: #fff;
} }
.listener-content li { .listener-content {
@include overflow-auto(x); li {
padding: $padding; @include overflow-auto(x);
border: 1px solid $gray; padding: $padding;
border-top: none; border-top: none;
&.capture { &.capture {
background: $gray-light; background: $gray-light;
}
} }
} }
} }

View File

@@ -26,7 +26,7 @@
} }
} }
.performance-timing-data { .performance-timing-data {
padding: 0 10px 10px; padding-bottom: $padding;
text-align: center; text-align: center;
display: none; display: none;
table { table {
@@ -38,10 +38,13 @@
background: $gray; background: $gray;
text-align: left; text-align: left;
color: #fff; color: #fff;
font-size: $font-size;
}
td {
font-size: $font-size-s;
} }
th, td { th, td {
padding: 10px; padding: 10px;
font-size: 14px;
} }
} }
} }
@@ -84,4 +87,4 @@
max-height: 200px; max-height: 200px;
} }
} }
} } } }

View File

@@ -28,6 +28,7 @@
} }
} }
.link-list { .link-list {
font-size: $font-size-s;
li { li {
padding: 10px; padding: 10px;
background: #fff; background: #fff;
@@ -39,6 +40,7 @@
} }
.image-list { .image-list {
@include clear-float(); @include clear-float();
font-size: $font-size-s;
background: #fff; background: #fff;
padding: $padding !important; padding: $padding !important;
li { li {
@@ -58,6 +60,7 @@
table { table {
border-collapse: collapse; border-collapse: collapse;
width: 100%; width: 100%;
font-size: $font-size-s;
td { td {
padding: 10px; padding: 10px;
word-break: break-all; word-break: break-all;
@@ -89,4 +92,4 @@
background: #fff; background: #fff;
} }
} }
} } } }

View File

@@ -1037,7 +1037,7 @@ module.exports = (function ()
* |Name |Type |Desc | * |Name |Type |Desc |
* |------|------|------------------| * |------|------|------------------|
* |obj |object|Destination object| * |obj |object|Destination object|
* |*src |object|Sources objects | * |...src|object|Sources objects |
* |return|object|Destination object| * |return|object|Destination object|
* *
* ```javascript * ```javascript
@@ -1910,7 +1910,7 @@ module.exports = (function ()
* is: function (obj) * is: function (obj)
* { * {
* return obj instanceof Student; * return obj instanceof Student;
* } * }
* }); * });
* *
* var a = new Student('allen', 17, 'Hogwarts'); * var a = new Student('allen', 17, 'Hogwarts');
@@ -1924,8 +1924,6 @@ module.exports = (function ()
return Base.extend(methods, statics); return Base.extend(methods, statics);
} }
var regCallSuper = /callSuper/;
function makeClass(parent, methods, statics) function makeClass(parent, methods, statics)
{ {
statics = statics || {}; statics = statics || {};