2.1.6 • Published 3 years ago

theroomjs v2.1.6

Weekly downloads
46
License
MIT
Repository
github
Last release
3 years ago

theroomjs

A vanilla javascript plugin that allows you to outline DOM elements like web inspectors.

Downloads install size

theroomjs can be accessable globally as theRoom. It's compatible with modern browsers such as Google Chrome, Mozilla Firefox, Safari, Edge and Internet Explorer.

Install

$ npm install theroomjs --save

Usage

  // setup/configure theRoom before inspection
  // this configurations can be passed in 'start' event as well
  window.theRoom.configure({
    inspector: '.inspector-element',
    blockRedirection: true,
    excludes: ['footer'],
    click: function (element) {
      console.log('element is clicked:', element)
    }
  })

  // start inspection
  window.theRoom.start()

  // dynamically bind event
  window.theRoom.on('mouseover', function (element) {
    console.log('the element is hovered', element)
  })

  // stop inspection
  // and reset inspector styles
  window.theRoom.stop(true)

  // dont emit mouseover and click events
  // if the target element id is 'yusufHayaloglu'
  window.theRoom.on('hook', function (event) {
    if (event.target.id === 'yusufHayaloglu') {
      return false
    }
  })

  console.log(
    window.theRoom.status() // will print out -> stopped
  )

Options

NameTypeDefaultDescription
inspectorstring or DOM node-Placeholder element for inspection. It will not be inspected
createInspectorbooleanfalseIf true and inspector option is not provided, theRoom will try to create an inspector element whose class is inspector-element for you and will be appended to <body/>
htmlClassbooleantrueIf true theRoom's namespace will be automatically added to <html/> element class list
blockRedirectionbooleanfalseIf true the page will not be redirected elsewhere. theRoom will override onbeforeunload to do that
excludesarray (string)-Elements that excluded for inspection. Basic CSS selectors are allowed. For more information please see document.querySelector

Events

NameDescription
startingFired when inspection is being started
startedFired when inspection is started
stoppingFired when inspection is being stopped
stoppedFired when inspection is stopped
clickFired when the inspected element is clicked. The element is passed as the first argument, Event passed as the second argument
mouseoverFired when the inspected element mouseovered. The element is passed as the first argument, Event passed as the second argument
hookFired before click and mouseover events. Event passed as the only argument. mouseover and click events wont be emitted if the hook event returns false

Events can also be defined in options.

theRoom object

theRoom global object exposes those:

OptionTypeParametersDescription
onfunctionevent name and handler functionTo dynamically event binding
startfunctionoptions (optional)To start inspection
stopfunctionresetInspector (optional)To stop inspection
configurefunctionoptionsTo override theRoom option(s) anytime
statusfunction-Gets inspection engine status. Can be idle, running and stopped

Related projects

  • path-finder - A Chrome extension to inspect and find out an HTML element unique CSS selector
2.1.2

3 years ago

2.1.4

3 years ago

2.1.3

3 years ago

2.1.6

3 years ago

2.1.5

3 years ago

2.1.1

4 years ago

2.0.8

4 years ago

2.0.4

4 years ago

2.0.7

4 years ago

2.0.6

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

5 years ago

1.0.2

5 years ago