Skip to content

Commit 4ef0718

Browse files
committed
update readme
1 parent 7e446f4 commit 4ef0718

File tree

8 files changed

+93
-26
lines changed

8 files changed

+93
-26
lines changed

README.md

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
js-mobile-console
22
=====
33

4+
![js-mobile-console](mobile_screen.png)
45

56
## Install
67
**Zip archive**:
@@ -9,18 +10,31 @@ js-mobile-console
910
**Browserify**:
1011
> npm install js-mobile-console
1112
13+
[![NPM](https://nodei.co/npm/js-mobile-console.png)](https://nodei.co/npm/js-mobile-console/)
14+
1215
**Bower**:
1316
> bower install js-mobile-console
1417
1518
##Overview
1619

1720
[Live demo](http://msemenistyi.github.io/js-mobile-console/).
1821

19-
###Usage
22+
It is extremely nice, that we are on the road of specifying and unifying remote
23+
debugging protocol and we can already remotely debug web applications on desktop
24+
chrome, but what if we want to get it working also on Android browser or
25+
Safari for iOs?
26+
27+
MobileConsole can be embedded within any page for debugging, it will catch errors
28+
and behave exactly as native js console in browser. It also outputs all the logs
29+
you've written via an API of window.console.
30+
31+
###Loading
32+
Css file should be included within html:
33+
<link rel="stylesheet" href="./style/mobile-console.min.css">
2034

2135
Console may be used without any modular system:
2236
```html
23-
<script src="./js-mobile-console.js"></script>
37+
<script src="./mobile-console.min.js"></script>
2438
```
2539

2640
With help of browserify:
@@ -33,11 +47,50 @@ Or AMD style (RequireJS):
3347
define(['js-mobile-console'], function(mobileConsole))
3448
```
3549

36-
The actual usage:
50+
###Usage
51+
52+
Simple usage:
53+
```js
54+
mobileConsole.show();
55+
```
56+
57+
Advanced usage:
3758
```js
38-
mobileConsole.show(options);
59+
mobileConsole.options({
60+
showOnError: true,
61+
proxyConsole: false,
62+
isCollapsed: true,
63+
catchErrors: true
64+
});
3965
```
4066

67+
Conditional toggling:
68+
```js
69+
if (condition){
70+
mobileConsole.show();
71+
} else {
72+
mobileConsole.hide();
73+
}
74+
```
75+
76+
###API
77+
78+
- **show** - show console with default options.
79+
- **hide** - hide console.
80+
- **options** - method to initialize console, by default will show console,
81+
accepts hash of options.
82+
83+
###Options
84+
85+
- **showOnError** - *Default* false. Console will be hidden if no show method
86+
was called, but it will appear if any error occurs.
87+
- **proxyConsole** - *Default* true. Determines if window.console methods are
88+
proxied to mobile console.
89+
- **isCollapsed** - *Default* false. Determines if Console is collpased on startup.
90+
- **catchErrors** - *Default* false. Determines if Console is registring
91+
window.onerror method in order to catch errors.
92+
93+
4194
##Contributing
4295
Feel free to open issues and send PRs.
4396

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "js-mobile-console",
3-
"version": "0.0.0",
3+
"version": "0.1.0",
44
"authors": [
55
"msemenistyi <nikeiwe@gmail.com>"
66
],

mobile-console.js

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
var containerHtml = '' +
1212
'<div id="jsmc-collapse"></div>' +
13-
'<div id="jsmc-clear">&#x2717;</div>' +
13+
'<div id="jsmc-clear">&#xd7</div>' +
1414
'<div id="jsmc-content">' +
1515
' <input id="jsmc-button" type="button" value="Run"/>' +
1616
' <div id="jsmc-log">' +
@@ -30,15 +30,24 @@
3030
props: {
3131
showOnError: false,
3232
proxyConsole: true,
33-
isCollapsed: false
33+
isCollapsed: false,
34+
catchErrors: false
3435
},
3536

3637
init: function(){
3738
if (!this.initialized){
38-
this.bindErrorListener();
39+
if (this.props.catchErrors){
40+
this.bindErrorListener();
41+
}
3942
this.initializeContainers();
4043
this.bindListeners();
4144
this.initialized = true;
45+
46+
if (this.props.proxyConsole){
47+
this.decorateConsole();
48+
} else {
49+
this.undecorateConsole();
50+
}
4251
}
4352
},
4453

@@ -55,9 +64,6 @@
5564
var el = document.getElementById('js-mobile-console');
5665
if (!el){
5766
this.init();
58-
if (this.props.proxyConsole){
59-
this.decorateConsole();
60-
}
6167
}
6268
this.$el.container.style.display = 'block';
6369

@@ -67,9 +73,8 @@
6773
},
6874

6975
hide: function(){
70-
var el = document.getElementById('js-mobile-console');
71-
if (el){
72-
el.style.display = 'none';
76+
if (this.$el && this.$el.container){
77+
this.$el.container.style.display = 'none';
7378
}
7479
},
7580

@@ -78,7 +83,7 @@
7883
el.parentNode.removeChild(el);
7984
},
8085

81-
initializeContainers: function(){
86+
initializeContainers: function(options){
8287
this.$el = {};
8388
el = this.$el.container = document.createElement('div');
8489
el.id = 'js-mobile-console';
@@ -176,16 +181,26 @@
176181
this.consoleDecorated = true;
177182
if (window.console){
178183
if (window.console.log){
179-
var log = window.console.log;
184+
this.oldLog = window.console.log;
180185
window.console.log = function(){
181186
var args = [].slice.call(arguments);
182-
log.apply(window.console, args);
187+
self.oldLog.apply(window.console, args);
183188
self.logValue(args.join(' '));
184189
};
185190
}
186191
}
187192
},
188193

194+
undecorateConsole: function(){
195+
var self = this;
196+
if (this.consoleDecorated){
197+
window.console.log = function(){
198+
var args = [].slice.call(arguments);
199+
self.oldLog.apply(window.console, args);
200+
};
201+
}
202+
},
203+
189204
logValue: function(value, error){
190205
var logEl = document.createElement('div');
191206
logEl.className = 'jsmc-log-el';

mobile-console.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mobile_screen.png

28.6 KB
Loading

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "js-mobile-console",
3-
"version": "0.0.0",
3+
"version": "0.1.0",
44
"description": "JS console emulator for mobile devices",
55
"main": "mobile-console.js",
66
"scripts": {

style/mobile-console.css

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
max-height: 100px;
1010
overflow-y: auto;
1111
margin-right: 10px;
12+
font-size: 1em;
1213
}
1314

1415
#jsmc-input-container{
@@ -50,7 +51,8 @@
5051
clear: both;
5152
}
5253

53-
#jsmc-collapse{
54+
#jsmc-collapse,
55+
#jsmc-clear{
5456
cursor: pointer;
5557
width: 25px;
5658
background: white;
@@ -61,11 +63,6 @@
6163
}
6264

6365
#jsmc-clear{
64-
cursor: pointer;
65-
width: 25px;
66-
background: white;
67-
text-align: center;
68-
color: gray;
69-
border: 1px solid #808080;
70-
float: left;
66+
font-weight: bolder;
67+
display: none;
7168
}

style/mobile-console.min.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)