Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

radio-component

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

radio-component - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

.npmignore

37

index.js

@@ -1,28 +0,23 @@

var computedStyle = require('computed-style')
var classes = require('classes')
/**
* Check if element is invalid
* add class to el and remove it from the same tagName siblings
*
* @param {Element} el
* @param {Element} [topEl] optional top element to check
* @param {String} [default:active] [className] optional class added for el
* @api public
*/
module.exports = function (el, topEl) {
topEl = topEl || document.body
do {
if (el.disabled) return true
if (hidden(el)) return true
el = el.parentNode
// parent could be removed
if (!el || el === topEl) break
} while(el)
return false
module.exports = function (el, className) {
var children = el.parentNode.childNodes
var tagName = el.tagName
className = className || 'active'
for (var i = 0, l = children.length; i < l; i++) {
var node = children[i]
if (!node || (node.nodeType !== 1) || (node.tagName !== tagName)) continue
if (node === el) {
classes(node).add(className)
} else {
classes(node).remove(className)
}
}
}
function hidden(el) {
var display = computedStyle(el, 'display')
if (display === 'none') return true
var visibility = computedStyle(el, 'visibility')
if (visibility === 'hidden') return true
return false
}
{
"name": "radio-component",
"version": "0.0.1",
"version": "0.0.2",
"description": "radio element className",

@@ -36,6 +36,7 @@ "main": "index.js",

"browser": {
"classes": "component-classes"
},
"dependencies": {
"computed-style": "^0.3.0"
"component-classes": "^1.2.4"
}
}

@@ -1,13 +0,10 @@

# Invalid
# Radio
[![Build Status](https://secure.travis-ci.org/chemzqm/invalid.png)](http://travis-ci.org/chemzqm/invalid)
[![Build Status](https://secure.travis-ci.org/chemzqm/radio.png)](http://travis-ci.org/chemzqm/radio)
An element is considered as invalid when one of these match:
Addd a className(default: active) to element and remove the same className from it's silbings with same tagName
* `disabled` or display is `none` or visibility is `hidden`
* one of it's parentNode display is `none` or visibility is `hidden`
## Install
npm i invalid-component
npm i radio-component

@@ -17,7 +14,16 @@ ## Usage

```
var invalid = require('invalid-component')
el.parentNode.style.display = 'none'
invalid(el) //true
var radio = require('radio-component')
radio(el)
radio(el, 'highlight')
```
See [test.js](https://github.com/chemzqm/invalid/blob/master/test/test.js)
See [test.js](https://github.com/chemzqm/radio/blob/master/test/test.js)
## MIT license
Copyright (c) 2015 chemzqm@gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
/*global describe, it, beforeEach, afterEach*/
var assert = require('assert')
var invalid = require('..')
var radio = require('..')
;(function () {
var css = '.hide{ display:none; } .hidden{visibility:hidden;}',
head = document.head || document.getElementsByTagName('head')[0],
style = document.createElement('style')
style.type = 'text/css'
if (style.styleSheet){
style.styleSheet.cssText = css
} else {
style.appendChild(document.createTextNode(css))
}
head.appendChild(style)
})()
function create() {
return document.createElement('div')
}
describe('invalid component', function () {
var initEl
describe('radio component', function () {
var el
var ul
var firstEl
beforeEach(function () {
initEl = create()
var child = create()
initEl.appendChild(child)
child.appendChild(create())
el = document.createElement('input')
child.childNodes[0].appendChild(el)
document.body.appendChild(initEl)
ul = document.createElement('ul')
document.body.appendChild(ul)
var li
for (var i = 0; i < 5; i++) {
li = document.createElement('li')
ul.appendChild(li)
}
el = li
firstEl = ul.firstChild
})
afterEach(function (done) {
document.body.removeChild(initEl)
document.body.removeChild(ul)
el = null

@@ -43,29 +27,15 @@ setTimeout(done, 200)

it('should be invalid when el disabled', function () {
el.disabled = true
assert.equal(invalid(el), true)
it('should radio default className', function () {
firstEl.className = 'active'
radio(el)
assert.equal(el.className, 'active')
assert.equal(firstEl.className, '')
})
it('should be invalid when el is hidden', function () {
el.style.display = 'none'
assert.equal(invalid(el), true)
el.style.display = 'block'
assert.equal(invalid(el), false)
el.style.display = ''
el.className = 'hide'
assert.equal(invalid(el), true)
it('should radio user defined className', function () {
firstEl.className = 'custom'
radio(el, 'custom')
assert.equal(el.className, 'custom')
assert.equal(firstEl.className, '')
})
it('should be invalid when el parent is hidden', function () {
initEl.style.display = 'none'
assert.equal(invalid(el), true)
initEl.style.display = ''
assert.equal(invalid(el), false)
initEl.className = 'hide'
assert.equal(invalid(el), true)
initEl.className = 'hidden'
assert.equal(invalid(el), true)
initEl.className = ''
assert.equal(invalid(el), false)
})
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc