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.1.3 to 1.1.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 c=n.shift();if(!c)return t;if(e.isObject(t)&&e.isObject(c))for(const n in c)e.isObject(c[n])?(t[n]||Object.assign(t,{[n]:{}}),e.deepMerge(t[n],c[n])):Object.assign(t,{[n]:c[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 c=document.createElement("style");c.id="checkbox-style"+n,c.appendChild(document.createTextNode("")),document.head.appendChild(c);let i=document.styleSheets[document.styleSheets.length-1];for(let c in t)t.hasOwnProperty(c)&&e.compatInsertRule(i,c,e.buildRules(t[c]),n)},buildRules(e){let t="";for(let[n,c]of Object.entries(e))n=n.replace(/([A-Z])/g,(e=>`-${e[0].toLowerCase()}`)),t+=`${n}:${c};`;return t},compatInsertRule(e,t,n,c){let i=t.replace(".check-box",".check-box-"+c);e.insertRule(i+"{"+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 <span class="checkmark"></span>\n <label class="checkbox-label"></label>\n </div>\n `,isEmpty:e=>!e?.length,handleCheckboxTitle(t,n){let c=!1,i=null,l=t?.title||t?.dataset?.checkboxTitle;return n&&"LABEL"===n.tagName&&(l=(()=>{if(!e.isEmpty(t.id)){if(n?.htmlFor===t.id)return c=!0,!0;if(n?.dataset?.checkboxFor===t.id)return!0}return t?.dataset?.checkboxId&&n?.dataset?.checkboxFor===t?.dataset?.checkboxId?(i=e.isEmpty(t.id)&&e.isEmpty(n.htmlFor)?"check-"+e.createUniqueID(6):null,!0):null})()),[l,c,i]},insertCheckbox(t,n,c,i){let l=e.getTemplate(t),o=document.createElement("div");o.innerHTML=l.trim();let h=e.getElem(".checkmark",o),s=e.getElem("label",o),a=n.cloneNode(!0);return c&&(a.removeAttribute("data-checkbox-id"),a.id=c),!0===i&&(s.htmlFor=a.id),h.addEventListener("click",(e=>{e.preventDefault(),a.click()})),h.parentNode.insertBefore(a,h),[a,o,s]},insertCheckboxTitle(e,t,n,c){e?(n.textContent=e,!0===t&&(n.classList.add("checkbox-labeled"),n.addEventListener("click",(e=>{e.preventDefault(),c.click()})))):n.parentNode.removeChild(n)},toggleCheckStatus(e,t){t?(e.checked=!0,e.setAttribute("checked","checked")):(e.checked=!1,e.removeAttribute("checked"))},toggleCheckAll(t,n){let c=e.getElem(t);c&&(n&&n.checked&&n.input?e.toggleCheckStatus(c,!1==(n.checked.length!==n.input.length||0===n.checked.length)):e.toggleCheckStatus(c,!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,c,i){let l=e.getElem(n,"all");(!l||l.length<1)&&function(e){throw new Error(e)}("Cannot find elements : "+n),this.id=i,this.element=n,this.allElement=[],this.option=e.deepMerge({},t.defaultOption,c),this.total={checked:[],list:[],input:[]};let o={};if(this.option?.checkMark&&(o={".check-box input[type=checkbox] + .checkmark:after":{"background-image":"url("+this.option.checkMark+")"}}),this.option?.styles&&Object.keys(this.option.styles).length>0&&(o=e.deepMerge({},this.option.styles,o)),o&&e.injectStylesheet(o,this.id),this.onChange=(e,t)=>{this.option?.onChange&&this.option.onChange(e,t)},this.onCheckAll=e=>{this.option?.onCheckAll&&this.option.onCheckAll(e)},l.forEach(((t,n)=>{if("checkbox"!==t.type)return;if(t.hasAttribute("data-checkbox"))return;t.setAttribute("data-checkbox","true");let c=t.nextElementSibling,i=this.option.bindLabel,[o,h,s]=e.handleCheckboxTitle(t,c);i=!0===h||i,!0===o&&(o=c.textContent,c.parentNode.removeChild(c)),t.checked?e.toggleCheckStatus(t,!0):this.option?.checked&&("boolean"==typeof this.option.checked&&1===l.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[a,r,d]=e.insertCheckbox(this.id,t,s,h);t.parentNode.replaceChild(r.firstElementChild,t),e.insertCheckboxTitle(o,i,d,a);let k=this.checkBoxChange.bind(this,!0,a);a.addEventListener("change",k),a.checkBoxChange=k,this.allElement.push(a)})),this.option?.checkAll){const t=e.getElem(this.option.checkAll);if(t&&"checkbox"===t?.type){let n=t.nextElementSibling,c=this.option?.bindLabel,[i,l,o]=e.handleCheckboxTitle(t,n);c=!0===l||c,!0===i&&(i=n.textContent,n.parentNode.removeChild(n));let[h,s,a]=e.insertCheckbox(this.id,t,o,l);t.parentNode.replaceChild(s.firstElementChild,t),e.insertCheckboxTitle(i,c,a,h);let r=(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",r),h.checkAllChange=r,this.checkAll=h}}return this}checkBoxChange(t,n=null){const c=this.total;c.list=[],c.input=[],c.checked=[],this.allElement.forEach((e=>{c.input.push(e),e.checked&&(c.list.push(e.value),c.checked.push(e))})),t&&e.toggleCheckAll(this.option.checkAll,c),this.onChange(c,n),n&&e.toggleCheckStatus(n,n.checked);const i=e.createEvent("checkbox-change");i.total=c,document.dispatchEvent(i)}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.1.3",t.instance=[],t.defaultOption={checkMark:null,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,c)=>"object"==typeof e?e:void 0===t&&void 0===c?isNaN(1*e)?document.querySelector(e):document.getElementById(e):"all"===t||null===t?void 0===c?document.querySelectorAll(e):c.querySelectorAll(e):"object"==typeof t&&void 0===c?t.querySelector(e):void 0,isObject:e=>e&&"object"==typeof e&&!Array.isArray(e),deepMerge(t,...c){const n=c.shift();if(!n)return t;if(e.isObject(t)&&e.isObject(n))for(const c in n)e.isObject(n[c])?(t[c]||Object.assign(t,{[c]:{}}),e.deepMerge(t[c],n[c])):Object.assign(t,{[c]:n[c]});return e.deepMerge(t,...c)},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,c){let n=document.createElement("style");n.id="checkbox-style"+c,n.appendChild(document.createTextNode("")),document.head.appendChild(n);let i=document.styleSheets[document.styleSheets.length-1];for(let n in t)t.hasOwnProperty(n)&&e.compatInsertRule(i,n,e.buildRules(t[n]),c)},buildRules(e){let t="";for(let[c,n]of Object.entries(e))c=c.replace(/([A-Z])/g,(e=>`-${e[0].toLowerCase()}`)),t+=`${c}:${n};`;return t},compatInsertRule(e,t,c,n){let i=t.replace(".check-box",".check-box-"+n);e.insertRule(i+"{"+c+"}",0)},removeStylesheet(t){let c=e.getElem("#checkbox-style"+t);c&&c.parentNode.removeChild(c)},createUniqueID:(e=8)=>Math.random().toString(36).substring(2,2+e),getTemplate:e=>`\n <div class="checkbox check-box-${e}">\n <span class="checkmark"></span>\n <label class="checkbox-label"></label>\n </div>\n `,isEmpty:e=>!e?.length,handleCheckboxTitle(t,c){let n=!1,i=null,l=t?.title||t?.dataset?.checkboxTitle;return c&&"LABEL"===c.tagName&&(l=(()=>{if(!e.isEmpty(t.id)){if(c?.htmlFor===t.id)return n=!0,!0;if(c?.dataset?.checkboxFor===t.id)return!0}return t?.dataset?.checkboxId&&c?.dataset?.checkboxFor===t?.dataset?.checkboxId?(i=e.isEmpty(t.id)&&e.isEmpty(c.htmlFor)?"check-"+e.createUniqueID(6):null,!0):null})()),[l,n,i]},insertCheckbox(t,c,n,i){let l=e.getTemplate(t),o=document.createElement("div");o.innerHTML=l.trim();let h=e.getElem(".checkmark",o),s=e.getElem("label",o),a=c.cloneNode(!0);return n&&(a.removeAttribute("data-checkbox-id"),a.id=n),!0===i&&(s.htmlFor=a.id),h.addEventListener("click",(e=>{e.preventDefault(),a.click()})),h.parentNode.insertBefore(a,h),[a,o,s]},insertCheckboxTitle(e,t,c,n){e?(c.textContent=e,!0===t&&(c.classList.add("checkbox-labeled"),c.addEventListener("click",(e=>{e.preventDefault(),n.click()})))):c.parentNode.removeChild(c)},toggleCheckStatus(e,t){t?(e.checked=!0,e.setAttribute("checked","checked")):(e.checked=!1,e.removeAttribute("checked"))},toggleCheckAll(t,c){let n=e.getElem(t);n&&(c&&c.checked&&c.input?e.toggleCheckStatus(n,!1==(c.checked.length!==c.input.length||0===c.checked.length)):e.toggleCheckStatus(n,!1))}};class t{constructor(e,c={}){void 0===t.firstLoad&&(t.firstLoad=!0),this.init(e,c,t.instance.length),t.instance.push(this),1===t.instance.length&&!0===t.firstLoad&&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(c,n,i){let l=e.getElem(c,"all");(!l||l.length<1)&&function(e){throw new Error(e)}("Cannot find elements : "+c),this.id=i,this.element=c,this.allElement=[],this.option=e.deepMerge({},t.defaultOption,n),this.total={checked:[],list:[],input:[]};let o={};if(this.option?.checkMark&&(o={".check-box input[type=checkbox] + .checkmark:after":{"background-image":"url("+this.option.checkMark+")"}}),this.option?.styles&&Object.keys(this.option.styles).length>0&&(o=e.deepMerge({},this.option.styles,o)),o&&e.injectStylesheet(o,this.id),this.onChange=(e,t)=>{this.option?.onChange&&this.option.onChange(e,t)},this.onCheckAll=e=>{this.option?.onCheckAll&&this.option.onCheckAll(e)},l.forEach(((t,c)=>{if("checkbox"!==t.type)return;if(t.hasAttribute("data-checkbox"))return;t.setAttribute("data-checkbox","true");let n=t.nextElementSibling,i=this.option.bindLabel,[o,h,s]=e.handleCheckboxTitle(t,n);i=!0===h||i,!0===o&&(o=n.textContent,n.parentNode.removeChild(n)),t.checked?e.toggleCheckStatus(t,!0):this.option?.checked&&("boolean"==typeof this.option.checked&&1===l.length&&e.toggleCheckStatus(t,!0),t?.value!==this.option.checked&&c!==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[a,r,d]=e.insertCheckbox(this.id,t,s,h);t.parentNode.replaceChild(r.firstElementChild,t),e.insertCheckboxTitle(o,i,d,a);let k=this.checkBoxChange.bind(this,!0,a);a.addEventListener("change",k),a.checkBoxChange=k,this.allElement.push(a)})),this.option?.checkAll){const t=e.getElem(this.option.checkAll);if(t&&"checkbox"===t?.type){if(t.hasAttribute("data-checkbox"))return;t.setAttribute("data-checkbox","true");let c=t.nextElementSibling,n=this.option?.bindLabel,[i,l,o]=e.handleCheckboxTitle(t,c);n=!0===l||n,!0===i&&(i=c.textContent,c.parentNode.removeChild(c));let[h,s,a]=e.insertCheckbox(this.id,t,o,l);t.parentNode.replaceChild(s.firstElementChild,t),e.insertCheckboxTitle(i,n,a,h);let r=(t=>{const c=t.target.checked;this.allElement.forEach((t=>{e.toggleCheckStatus(t,c)})),this.checkBoxChange(!1),this.onCheckAll(c)}).bind(this);h.addEventListener("change",r),h.checkAllChange=r,this.checkAll=h}}return this}checkBoxChange(t,c=null){const n=this.total;n.list=[],n.input=[],n.checked=[],this.allElement.forEach((e=>{n.input.push(e),e.checked&&(n.list.push(e.value),n.checked.push(e))})),t&&e.toggleCheckAll(this.option.checkAll,n),this.onChange(n,c),c&&e.toggleCheckStatus(c,c.checked);const i=e.createEvent("checkbox-change");i.total=n,document.dispatchEvent(i)}getCheckBox(){return this.total}refresh(){this.init(this.element,this.option)}destroy(){return t.firstLoad=!1,this.allElement.forEach((e=>{e.removeEventListener("change",e.checkBoxChange),e.checkBoxChange=null,e.removeAttribute("data-checkbox"),e.parentNode.parentNode.replaceChild(e,e.parentNode)})),this.checkAll&&(this.checkAll.removeEventListener("change",this.checkAll.checkAllChange),this.checkAll.checkAllChange=null,this.checkAll.removeAttribute("data-checkbox"),this.checkAll.parentNode.parentNode.replaceChild(this.checkAll,this.checkAll.parentNode)),this.allElement=[],this.total={},e.removeStylesheet(this.id),t.instance.splice(this.id,1),this}}return t.version="1.1.4",t.instance=[],t.defaultOption={checkMark:null,checkAll:null,onChange:null,onCheckAll:null,bindLabel:!0,styles:{}},t}));
{
"name": "@carry0987/check-box",
"version": "1.1.3",
"version": "1.1.4",
"description": "A library for create and manage checkbox elements",

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

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