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

@carry0987/check-box

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@carry0987/check-box - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

2

dist/checkBox.min.js

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).CheckBox=t()}(this,(function(){"use strict";const e={getElem:(e,t,n)=>"object"==typeof e?e:void 0===t&&void 0===n?isNaN(1*e)?document.querySelector(e):document.getElementById(e):"all"===t||null===t?void 0===n?document.querySelectorAll(e):n.querySelectorAll(e):"object"==typeof t&&void 0===n?t.querySelector(e):void 0,isObject:e=>e&&"object"==typeof e&&!Array.isArray(e),deepMerge(t,...n){const i=n.shift();if(!i)return t;if(e.isObject(t)&&e.isObject(i))for(const n in i)e.isObject(i[n])?(t[n]||Object.assign(t,{[n]:{}}),e.deepMerge(t[n],i[n])):Object.assign(t,{[n]:i[n]});return e.deepMerge(t,...n)},createEvent(e){let t;return window.CustomEvent&&"function"==typeof window.CustomEvent?t=new CustomEvent(e):(t=document.createEvent("CustomEvent"),t.initCustomEvent(e,!1,!1,void 0)),t},injectStylesheet(t,n){let i=document.createElement("style");i.id="checkbox-style"+n,i.appendChild(document.createTextNode("")),document.head.appendChild(i);let l=document.styleSheets[document.styleSheets.length-1];for(let i in t)t.hasOwnProperty(i)&&e.compatInsertRule(l,i,e.buildRules(t[i]),n)},buildRules(e){let t="";for(let[n,i]of Object.entries(e))t+=`${n}:${i};`;return t},compatInsertRule(e,t,n,i){let l=t.replace(".check-box",".check-box-"+i);e.insertRule(l+"{"+n+"}",0)},removeStylesheet(t){let n=e.getElem("#checkbox-style"+t);n&&n.parentNode.removeChild(n)},createUniqueID:(e=8)=>Math.random().toString(36).substring(2,2+e),getTemplate:e=>`\n <div class="checkbox check-box-${e}">\n <label class="checkbox-label"></label>\n </div>\n `,isEmpty:e=>!e?.length,handleCheckboxTitle(t,n){let i=!1,l=null,o=t?.title||t?.dataset?.checkboxTitle;return n&&"LABEL"===n.tagName&&(o=(()=>{if(!e.isEmpty(t.id)){if(n?.htmlFor===t.id)return i=!0,!0;if(n?.dataset?.checkboxFor===t.id)return!0}return t?.dataset?.checkboxId&&n?.dataset?.checkboxFor===t?.dataset?.checkboxId?(l=e.isEmpty(t.id)&&e.isEmpty(n.htmlFor)?"check-"+e.createUniqueID(6):null,!0):null})()),[o,i,l]},insertCheckbox(t,n,i,l){let o=e.getTemplate(t),c=document.createElement("div");c.innerHTML=o.trim();let h=e.getElem("label",c),s=n.cloneNode(!0);return i&&(s.removeAttribute("data-checkbox-id"),s.id=i),!0===l&&(h.htmlFor=s.id),h.parentNode.insertBefore(s,h),[s,c,h]},insertCheckboxTitle(e,t,n,i){null===e?n.parentNode.removeChild(n):(n.textContent=e,!0===t&&(n.classList.add("checkbox-labeled"),n.addEventListener("click",(e=>{e.preventDefault(),i.click()}))))},toggleCheckStatus(e,t){t?(e.checked=!0,e.setAttribute("checked","checked")):(e.checked=!1,e.removeAttribute("checked"))},toggleCheckAll(t,n){let i=e.getElem(t);i&&(n&&n.checked&&n.input?e.toggleCheckStatus(i,!1==(n.checked.length!==n.input.length||0===n.checked.length)):e.toggleCheckStatus(i,!1))}};class t{constructor(e,n={}){this.init(e,n,t.instance.length),t.instance.push(this),1===t.instance.length&&function(e,t=!1){!0===t?console.log("Data Type : "+typeof e,"\nValue : "+e):"boolean"!=typeof t?console.log(t):console.log(e)}("CheckBox is loaded, version:"+t.version)}static destroyAll(){t.instance.forEach((e=>{e.destroy()})),t.instance=[]}init(n,i,l){let o=e.getElem(n,"all");if((!o||o.length<1)&&function(e){throw new Error(e)}("Cannot find elements : "+n),this.id=l,this.element=n,this.allElement=[],this.option=e.deepMerge({},t.defaultOption,i),this.total={checked:[],list:[],input:[]},this.option?.styles&&Object.keys(this.option.styles).length>0){let t=e.deepMerge({},this.option.styles);e.injectStylesheet(t,this.id)}if(this.onChange=(e,t)=>{this.option?.onChange&&this.option.onChange(e,t)},this.onCheckAll=e=>{this.option?.onCheckAll&&this.option.onCheckAll(e)},o.forEach(((t,n)=>{if("checkbox"!==t.type)return;if(t.hasAttribute("data-checkbox"))return;t.setAttribute("data-checkbox","true");let i=t.nextElementSibling,l=this.option.bindLabel,[c,h,s]=e.handleCheckboxTitle(t,i);l=!0===h||l,!0===c&&(c=i.textContent,i.parentNode.removeChild(i)),t.checked?e.toggleCheckStatus(t,!0):this.option?.checked&&("boolean"==typeof this.option.checked&&1===o.length&&e.toggleCheckStatus(t,!0),t?.value!==this.option.checked&&n!==this.option.checked||e.toggleCheckStatus(t,!0),"string"==typeof this.option.checked&&(this.option.checked=[this.option.checked]),Array.isArray(this.option.checked)&&(this.option.checked.includes(t.name)||this.option.checked.includes(t.id))&&e.toggleCheckStatus(t,!0));let[r,a,d]=e.insertCheckbox(this.id,t,s,h);t.parentNode.replaceChild(a.firstElementChild,t),e.insertCheckboxTitle(c,l,d,r);let u=this.checkBoxChange.bind(this,!0,r);r.addEventListener("change",u),r.checkBoxChange=u,this.allElement.push(r)})),this.option?.checkAll){const t=e.getElem(this.option.checkAll);if(t&&"checkbox"===t?.type){let n=t.nextElementSibling,i=this.option?.bindLabel,[l,o,c]=e.handleCheckboxTitle(t,n);i=!0===o||i,!0===l&&(l=n.textContent,n.parentNode.removeChild(n));let[h,s,r]=e.insertCheckbox(this.id,t,c,o);t.parentNode.replaceChild(s.firstElementChild,t),e.insertCheckboxTitle(l,i,r,h);let a=(t=>{const n=t.target.checked;this.allElement.forEach((t=>{e.toggleCheckStatus(t,n)})),this.checkBoxChange(!1),this.onCheckAll(n)}).bind(this);h.addEventListener("change",a),h.checkAllChange=a,this.checkAll=h}}return this}checkBoxChange(t,n=null){const i=this.total;i.list=[],i.input=[],i.checked=[],this.allElement.forEach((e=>{i.input.push(e),e.checked&&(i.list.push(e.value),i.checked.push(e))})),t&&e.toggleCheckAll(this.option.checkAll,i),this.onChange(i,n);const l=e.createEvent("checkbox-change");l.total=i,document.dispatchEvent(l)}getCheckBox(){return this.total}refresh(){this.init(this.element,this.option)}destroy(){return this.allElement.forEach((e=>{e.removeEventListener("change",e.checkBoxChange)})),this.checkAll&&this.checkAll.removeEventListener("change",this.checkAll.checkAllChange),this.allElement=[],this.total={},e.removeStylesheet(this.id),t.instance.splice(this.id,1),this}}return t.version="1.0.3",t.instance=[],t.defaultOption={checkAll:null,onChange:null,onCheckAll:null,bindLabel:!0,styles:{}},t}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).CheckBox=t()}(this,(function(){"use strict";const e={getElem:(e,t,n)=>"object"==typeof e?e:void 0===t&&void 0===n?isNaN(1*e)?document.querySelector(e):document.getElementById(e):"all"===t||null===t?void 0===n?document.querySelectorAll(e):n.querySelectorAll(e):"object"==typeof t&&void 0===n?t.querySelector(e):void 0,isObject:e=>e&&"object"==typeof e&&!Array.isArray(e),deepMerge(t,...n){const i=n.shift();if(!i)return t;if(e.isObject(t)&&e.isObject(i))for(const n in i)e.isObject(i[n])?(t[n]||Object.assign(t,{[n]:{}}),e.deepMerge(t[n],i[n])):Object.assign(t,{[n]:i[n]});return e.deepMerge(t,...n)},createEvent(e){let t;return window.CustomEvent&&"function"==typeof window.CustomEvent?t=new CustomEvent(e):(t=document.createEvent("CustomEvent"),t.initCustomEvent(e,!1,!1,void 0)),t},injectStylesheet(t,n){let i=document.createElement("style");i.id="checkbox-style"+n,i.appendChild(document.createTextNode("")),document.head.appendChild(i);let l=document.styleSheets[document.styleSheets.length-1];for(let i in t)t.hasOwnProperty(i)&&e.compatInsertRule(l,i,e.buildRules(t[i]),n)},buildRules(e){let t="";for(let[n,i]of Object.entries(e))t+=`${n}:${i};`;return t},compatInsertRule(e,t,n,i){let l=t.replace(".check-box",".check-box-"+i);e.insertRule(l+"{"+n+"}",0)},removeStylesheet(t){let n=e.getElem("#checkbox-style"+t);n&&n.parentNode.removeChild(n)},createUniqueID:(e=8)=>Math.random().toString(36).substring(2,2+e),getTemplate:e=>`\n <div class="checkbox check-box-${e}">\n <label class="checkbox-label"></label>\n </div>\n `,isEmpty:e=>!e?.length,handleCheckboxTitle(t,n){let i=!1,l=null,o=t?.title||t?.dataset?.checkboxTitle;return n&&"LABEL"===n.tagName&&(o=(()=>{if(!e.isEmpty(t.id)){if(n?.htmlFor===t.id)return i=!0,!0;if(n?.dataset?.checkboxFor===t.id)return!0}return t?.dataset?.checkboxId&&n?.dataset?.checkboxFor===t?.dataset?.checkboxId?(l=e.isEmpty(t.id)&&e.isEmpty(n.htmlFor)?"check-"+e.createUniqueID(6):null,!0):null})()),[o,i,l]},insertCheckbox(t,n,i,l){let o=e.getTemplate(t),c=document.createElement("div");c.innerHTML=o.trim();let h=e.getElem("label",c),s=n.cloneNode(!0);return i&&(s.removeAttribute("data-checkbox-id"),s.id=i),!0===l&&(h.htmlFor=s.id),h.parentNode.insertBefore(s,h),[s,c,h]},insertCheckboxTitle(e,t,n,i){null===e?n.parentNode.removeChild(n):(n.textContent=e,!0===t&&(n.classList.add("checkbox-labeled"),n.addEventListener("click",(e=>{e.preventDefault(),i.click()}))))},toggleCheckStatus(e,t){t?(e.checked=!0,e.setAttribute("checked","checked")):(e.checked=!1,e.removeAttribute("checked"))},toggleCheckAll(t,n){let i=e.getElem(t);i&&(n&&n.checked&&n.input?e.toggleCheckStatus(i,!1==(n.checked.length!==n.input.length||0===n.checked.length)):e.toggleCheckStatus(i,!1))}};class t{constructor(e,n={}){this.init(e,n,t.instance.length),t.instance.push(this),1===t.instance.length&&function(e,t=!1){!0===t?console.log("Data Type : "+typeof e,"\nValue : "+e):"boolean"!=typeof t?console.log(t):console.log(e)}("CheckBox is loaded, version:"+t.version)}static destroyAll(){t.instance.forEach((e=>{e.destroy()})),t.instance=[]}init(n,i,l){let o=e.getElem(n,"all");if((!o||o.length<1)&&function(e){throw new Error(e)}("Cannot find elements : "+n),this.id=l,this.element=n,this.allElement=[],this.option=e.deepMerge({},t.defaultOption,i),this.total={checked:[],list:[],input:[]},this.option?.styles&&Object.keys(this.option.styles).length>0){let t=e.deepMerge({},this.option.styles);e.injectStylesheet(t,this.id)}if(this.onChange=(e,t)=>{this.option?.onChange&&this.option.onChange(e,t)},this.onCheckAll=e=>{this.option?.onCheckAll&&this.option.onCheckAll(e)},o.forEach(((t,n)=>{if("checkbox"!==t.type)return;if(t.hasAttribute("data-checkbox"))return;t.setAttribute("data-checkbox","true");let i=t.nextElementSibling,l=this.option.bindLabel,[c,h,s]=e.handleCheckboxTitle(t,i);l=!0===h||l,!0===c&&(c=i.textContent,i.parentNode.removeChild(i)),t.checked?e.toggleCheckStatus(t,!0):this.option?.checked&&("boolean"==typeof this.option.checked&&1===o.length&&e.toggleCheckStatus(t,!0),t?.value!==this.option.checked&&n!==this.option.checked||e.toggleCheckStatus(t,!0),"string"==typeof this.option.checked&&(this.option.checked=[this.option.checked]),Array.isArray(this.option.checked)&&(this.option.checked.includes(t.name)||this.option.checked.includes(t.id))&&e.toggleCheckStatus(t,!0));let[r,a,d]=e.insertCheckbox(this.id,t,s,h);t.parentNode.replaceChild(a.firstElementChild,t),e.insertCheckboxTitle(c,l,d,r);let u=this.checkBoxChange.bind(this,!0,r);r.addEventListener("change",u),r.checkBoxChange=u,this.allElement.push(r)})),this.option?.checkAll){const t=e.getElem(this.option.checkAll);if(t&&"checkbox"===t?.type){let n=t.nextElementSibling,i=this.option?.bindLabel,[l,o,c]=e.handleCheckboxTitle(t,n);i=!0===o||i,!0===l&&(l=n.textContent,n.parentNode.removeChild(n));let[h,s,r]=e.insertCheckbox(this.id,t,c,o);t.parentNode.replaceChild(s.firstElementChild,t),e.insertCheckboxTitle(l,i,r,h);let a=(t=>{const n=t.target.checked;this.allElement.forEach((t=>{e.toggleCheckStatus(t,n)})),this.checkBoxChange(!1),this.onCheckAll(n)}).bind(this);h.addEventListener("change",a),h.checkAllChange=a,this.checkAll=h}}return this}checkBoxChange(t,n=null){const i=this.total;i.list=[],i.input=[],i.checked=[],this.allElement.forEach((e=>{i.input.push(e),e.checked&&(i.list.push(e.value),i.checked.push(e))})),t&&e.toggleCheckAll(this.option.checkAll,i),this.onChange(i,n);const l=e.createEvent("checkbox-change");l.total=i,document.dispatchEvent(l)}getCheckBox(){return this.total}refresh(){this.init(this.element,this.option)}destroy(){return this.allElement.forEach((e=>{e.removeEventListener("change",e.checkBoxChange)})),this.checkAll&&this.checkAll.removeEventListener("change",this.checkAll.checkAllChange),this.allElement=[],this.total={},e.removeStylesheet(this.id),t.instance.splice(this.id,1),this}}return t.version="1.0.4",t.instance=[],t.defaultOption={checkAll:null,onChange:null,onCheckAll:null,bindLabel:!0,styles:{}},t}));
{
"name": "@carry0987/check-box",
"version": "1.0.3",
"version": "1.0.4",
"description": "A library for create and manage checkbox elements",

@@ -5,0 +5,0 @@ "type": "module",

Sorry, the diff of this file is not supported yet

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