1 | # theroomjs
|
2 | > A vanilla javascript plugin that allows you to outline dom elements like web inspectors.
|
3 |
|
4 | [![NPM](https://nodei.co/npm/theroomjs.png)](https://nodei.co/npm/theroomjs/)
|
5 |
|
6 | `theroomjs` can be accessable globally as `theRoom`. It's compatible with modern browsers such as Google Chrome, Mozilla Firefox, Safari, Edge and Internet Explorer.
|
7 |
|
8 | ## Options
|
9 |
|
10 | | Name | Type | Default | Description |
|
11 | | --- | --- | --- | --- |
|
12 | | inspector | string or DOM node | - | Placeholder element for inspection. It will not be inspected |
|
13 | | createInspector | boolean | false | If `true` and inspector option is not provided, theRoom will try to create an inspector element whose class is `inspector-element` for you and will append it directly to the `<body/>` |
|
14 | | htmlClass | boolean | true | If `true` namespace theRoom will be automatically added to `<html>` element class list |
|
15 | | blockRedirection | boolean | false | If `true` the page will not be redirected elsewhere. The library will override `onbeforeunload` for prevention |
|
16 | | excludes | array | - | Element list that excluded for inspection. Basic CSS selectors are allowed. For more information please see [document.querySelector](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector) |
|
17 |
|
18 | ## Events
|
19 |
|
20 | | Name | Description |
|
21 | | --- | --- |
|
22 | | starting | Fired when inspection is being started inspection |
|
23 | | started | Fired when inspection is started inspection |
|
24 | | stopping | Fired when inspection is being stopped |
|
25 | | stopped | Fired when inspection is stopped |
|
26 | | click | Fired when inspected element is clicked. The element will be passed as first argument |
|
27 | | mouseover | Fired when inspected element mouseovered. The element will be passed as first argument |
|
28 | | hook | Fired at the very beginning of `click` and `mouseover` event listeners. [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event) passed as argument |
|
29 |
|
30 | > Events can also be defined in options.
|
31 |
|
32 | ## theRoom object
|
33 |
|
34 | `theRoom` object exposes:
|
35 |
|
36 | | Option | Type | Parameters | Description |
|
37 | | --- | --- | --- | --- |
|
38 | | on | function | `event name` and `handler function` | To dynamically event binding |
|
39 | | start | function | `options` (optional) | To start inspection |
|
40 | | stop | function | `resetInspector` (optional) | To stop inspection |
|
41 | | configure | function | `options` | To override theRoom option(s) anytime |
|
42 | | status | function | - | Gets inspection engine status. Can be `idle`, `running` and `stopped` |
|
43 |
|
44 | ## Usage
|
45 |
|
46 | ```javascript
|
47 | window.theRoom.configure({
|
48 | inspector: '.inspector-element',
|
49 | blockRedirection: true,
|
50 | excludes: ['footer'],
|
51 | click: function (element) {
|
52 | console.log('the element is clicked:', element)
|
53 | }
|
54 | })
|
55 |
|
56 | // start inspection
|
57 | window.theRoom.start()
|
58 |
|
59 | // dynamically event binding
|
60 | window.theRoom.on('mouseover', function (element) {
|
61 | console.log('the element is hovered', element)
|
62 | })
|
63 |
|
64 | // stop inspection
|
65 | // and reset inspector styles
|
66 | window.theRoom.stop(true)
|
67 |
|
68 | // log the current status
|
69 | console.log(
|
70 | window.theRoom.status() // will print out -> stopped
|
71 | )
|
72 | ```
|
73 |
|
74 | ## Contribution
|
75 | Contributions and pull requests are kindly welcomed!
|
76 |
|
77 | ## License
|
78 | This project is licensed under the terms of the [MIT license](https://github.com/hsynlms/theroomjs/blob/master/LICENSE).
|