symfony-collection-js
Advanced tools
Comparing version 4.3.0-js-only to 4.3.0
@@ -1,1 +0,1 @@ | ||
(function(){return"function"!=typeof window.CustomEvent&&void(window.CustomEvent=function(a,b){b=b||{bubbles:!1,cancelable:!1,detail:null};let c=document.createEvent("CustomEvent");return c.initCustomEvent(a,b.bubbles,b.cancelable,b.detail),c})})();let formCollection=function(a,b,c){let d,e="prototypeModified",f="addMethodCalled",g="deleteMethodCalled",h="clearMethodCalled",j="refreshAttributesMethodCalled",k=function(c,a){for(let b in a)a.hasOwnProperty(b)&&(c[b]=a[b]);return c},l=function(a){if("function"==typeof Event)return new Event(a);let b=document.createEvent("Event");return b.initEvent(a,!0,!0),b};if(b===void 0||"object"==typeof b){d=k({max_elems:100,call_pre_add_on_init:!1,call_post_add_on_init:!1,pre_add:function(){return!0},post_add:function(){return!0},pre_delete:function(){return!0},post_delete:function(){return!0},pre_up:function(){return!0},post_up:function(){return!0},pre_down:function(){return!0},post_down:function(){return!0},other_btn_add:null,btn_add_selector:".collection-add",btn_delete_selector:".collection-delete",btn_up_selector:".collection-up",btn_down_selector:".collection-down",prototype_name:"__name__"},b)}else if("string"==typeof b){if(-1===["add","delete","clear","refreshAttributes"].indexOf(b))return console.error("Invalid options"),!1;if("delete"===b&&void 0===c)return console.error("Missing index"),!1}a instanceof Node&&(a=[a]);for(let k,m=0;m<a.length;m++){switch(k=a[m],b){case"add":return void k.dispatchEvent(l(f));break;case"delete":return void k.dispatchEvent(new CustomEvent(g,{detail:c}));break;case"clear":return void k.dispatchEvent(l(h));break;case"refreshAttributes":return void k.dispatchEvent(new CustomEvent(j,{detail:c}));}let i=k.getAttribute("data-prototype"),o=k.children.length,n=[];k.addEventListener(e,function(a){a.target!==a.currentTarget||(n=[],i=this.getAttribute("data-prototype"),s(),w(0))}),k.addEventListener(f,function(a){C(formCollection.ADD_CONTEXT.ADD_METHOD)}),k.addEventListener(g,function(a){let b=a.detail,c=k.children[b];!1===d.pre_delete(c,formCollection.DELETE_CONTEXT.DELETE_METHOD,b)||(D(c),d.post_delete(c,formCollection.DELETE_CONTEXT.DELETE_METHOD,b))}),k.addEventListener(h,function(a){k.textContent="",o=0}),k.addEventListener(j,function(a){let b=a.detail;w(b)});let p=function(a,b){let c={path:a,attributes:b};return c},q=function(a){let b=document.createElement("div");return b.innerHTML=a.trim(),b.firstChild},r=function(a,b){let c=u(a,d.prototype_name);if(0<Object.keys(c).length&&n.push(p(b,c)),!("data-prototype"in c)){let c=a.children;for(let a=0;a<c.length;a++)r(c[a],b.concat([a]))}},s=function(){let a=q(i);r(a,[])},t=function(a){let b=a.querySelectorAll(d.btn_add_selector);for(let c=0;c<b.length;c++)b[c].addEventListener("click",function(){let b=y(a)+1;if(!1!==d.pre_add(formCollection.ADD_CONTEXT.BTN_ADD,b)){let c=B(a);d.post_add(c,formCollection.ADD_CONTEXT.BTN_ADD,b)}});let c=a.querySelectorAll(d.btn_delete_selector);for(let b=0;b<c.length;b++)c[b].addEventListener("click",function(){let b=y(a);!1===d.pre_delete(a,formCollection.DELETE_CONTEXT.BTN_DELETE,b)||(D(a),d.post_delete(a,formCollection.DELETE_CONTEXT.BTN_DELETE,b))});let e=a.querySelectorAll(d.btn_up_selector);for(let b=0;b<e.length;b++)e[b].addEventListener("click",function(){let b=y(a),c=a.previousElementSibling;c&&!1!==d.pre_up(a,c,b)&&(c=E(a),c&&d.post_up(a,c,b))});let f=a.querySelectorAll(d.btn_down_selector);for(let b=0;b<f.length;b++)f[b].addEventListener("click",function(){let b=y(a),c=a.nextElementSibling;c&&!1!==d.pre_down(a,c,b)&&(c=F(a),c&&d.post_down(a,c,b))})},u=function(a,b){let c={};for(let d,e=0;e<a.attributes.length;e++)d=a.attributes[e],d.value&&-1!==d.value.indexOf(b)&&(c[d.name]=d.value);return c},v=function(a,b){let c=new RegExp(d.prototype_name,"g");for(let d=0;d<n.length;d++){let f=n[d],g=a;for(let a,b=0;b<f.path.length;b++)a=f.path[b],g=g.children[a];let h=Object.keys(f.attributes);for(let a=0;a<h.length;a++){let d=h[a],e=f.attributes[d];g.setAttribute(d,e.replace(c,b))}"data-prototype"in g.attributes&&g.dispatchEvent(l(e))}},w=function(a){let b=k.children;for(let c=a;c<b.length;c++)v(b[c],c)},x=function(a){void 0===a&&(a=o);let b=i,c=new RegExp(d.prototype_name,"g");b=b.replace(c,a);let e=q(b);return t(e),e},y=function(a){let b=0;for(;null!=(a=a.previousElementSibling);)b++;return b},z=function(a,b){a.insertAdjacentElement("beforebegin",b)},A=function(a,b){a.insertAdjacentElement("afterend",b)},B=function(a){if(o>=d.max_elems)return!1;let b=x(y(a)+1);return A(a,b),o++,w(y(a)+2),b},C=function(a){if(o>=d.max_elems)return!1;if(!1!==d.pre_add(a,o)){let b=x();k.appendChild(b),o++,d.post_add(b,a,o-1)}},D=function(a){let b=y(a);a.parentNode.removeChild(a),o--,w(b)},E=function(a){let b=a.previousElementSibling;if(!b)return!1;let c=y(b);return z(b,a),v(a,c),v(b,c+1),b},F=function(a){let b=a.nextElementSibling;if(!b)return!1;let c=y(b);return A(b,a),v(a,c),v(b,c-1),b},G=function(){for(let a=0;a<k.children.length;a++){d.call_pre_add_on_init&&d.pre_add(formCollection.ADD_CONTEXT.INIT,a);let b=k.children[a];t(b),d.call_post_add_on_init&&d.post_add(b,formCollection.ADD_CONTEXT.INIT,a)}};if(G(),s(),d.other_btn_add){let a=null;if("string"==typeof d.other_btn_add?a=document.querySelectorAll(d.other_btn_add):d.other_btn_add instanceof Node?a=[d.other_btn_add]:formCollection.jQuery&&d.other_btn_add instanceof formCollection.jQuery||d.other_btn_add instanceof NodeList?a=d.other_btn_add:console.error("other_btn_add: bad value, can be a selector or nodes, or a jQuery object."),a)for(let b=0;b<a.length;b++)a[b].addEventListener("click",function(){C(formCollection.ADD_CONTEXT.OTHER_BTN_ADD)})}}};formCollection.ADD_CONTEXT={BTN_ADD:4,OTHER_BTN_ADD:8,INIT:15,ADD_METHOD:16},formCollection.DELETE_CONTEXT={BTN_DELETE:23,DELETE_METHOD:42},formCollection.POST_ADD_CONTEXT=formCollection.ADD_CONTEXT,formCollection.POST_DELETE_CONTEXT=formCollection.DELETE_CONTEXT,function(a,b){"function"==typeof define&&define.amd?define([],b):"object"==typeof module&&module.exports?module.exports=b():a.returnExports=b()}(this,function(){return formCollection}); | ||
(function(){return"function"!=typeof window.CustomEvent&&void(window.CustomEvent=function(a,b){b=b||{bubbles:!1,cancelable:!1,detail:null};let c=document.createEvent("CustomEvent");return c.initCustomEvent(a,b.bubbles,b.cancelable,b.detail),c})})();let formCollection=function(a,b,c){let d,e="prototypeModified",f="addMethodCalled",g="deleteMethodCalled",h="clearMethodCalled",j="refreshAttributesMethodCalled",k=function(c,a){for(let b in a)a.hasOwnProperty(b)&&(c[b]=a[b]);return c},l=function(a){if("function"==typeof Event)return new Event(a);let b=document.createEvent("Event");return b.initEvent(a,!0,!0),b};if(b===void 0||"object"==typeof b){d=k({max_elems:100,call_pre_add_on_init:!1,call_post_add_on_init:!1,pre_add:function(){return!0},post_add:function(){return!0},pre_delete:function(){return!0},post_delete:function(){return!0},pre_up:function(){return!0},post_up:function(){return!0},pre_down:function(){return!0},post_down:function(){return!0},other_btn_add:null,btn_add_selector:".collection-add",btn_delete_selector:".collection-delete",btn_up_selector:".collection-up",btn_down_selector:".collection-down",prototype_name:"__name__"},b)}else if("string"==typeof b){if(-1===["add","delete","clear","refreshAttributes"].indexOf(b))return console.error("Invalid options"),!1;if("delete"===b&&void 0===c)return console.error("Missing index"),!1}a instanceof Node&&(a=[a]);for(let k,m=0;m<a.length;m++){switch(k=a[m],b){case"add":return void k.dispatchEvent(l(f));break;case"delete":return void k.dispatchEvent(new CustomEvent(g,{detail:c}));break;case"clear":return void k.dispatchEvent(l(h));break;case"refreshAttributes":return void k.dispatchEvent(new CustomEvent(j,{detail:c}));}let i=k.getAttribute("data-prototype"),o=k.children.length,n=[];k.addEventListener(e,function(a){a.target!==a.currentTarget||(n=[],i=this.getAttribute("data-prototype"),s(),w(0))}),k.addEventListener(f,function(a){C(formCollection.ADD_CONTEXT.ADD_METHOD)}),k.addEventListener(g,function(a){let b=a.detail,c=k.children[b];!1===d.pre_delete(c,formCollection.DELETE_CONTEXT.DELETE_METHOD,b)||(D(c),d.post_delete(c,formCollection.DELETE_CONTEXT.DELETE_METHOD,b))}),k.addEventListener(h,function(a){k.textContent="",o=0}),k.addEventListener(j,function(a){let b=a.detail;w(b)});let p=function(a,b){let c={path:a,attributes:b};return c},q=function(a){let b=document.createElement("div");return b.innerHTML=a.trim(),b.firstChild},r=function(a,b){let c=u(a,d.prototype_name);if(0<Object.keys(c).length&&n.push(p(b,c)),!("data-prototype"in c)){let c=a.children;for(let a=0;a<c.length;a++)r(c[a],b.concat([a]))}},s=function(){let a=q(i);r(a,[])},t=function(a){let b=a.querySelectorAll(d.btn_add_selector);for(let c=0;c<b.length;c++)b[c].addEventListener("click",function(){let b=y(a)+1;if(!1!==d.pre_add(formCollection.ADD_CONTEXT.BTN_ADD,b)){let c=B(a);d.post_add(c,formCollection.ADD_CONTEXT.BTN_ADD,b)}});let c=a.querySelectorAll(d.btn_delete_selector);for(let b=0;b<c.length;b++)c[b].addEventListener("click",function(){let b=y(a);!1===d.pre_delete(a,formCollection.DELETE_CONTEXT.BTN_DELETE,b)||(D(a),d.post_delete(a,formCollection.DELETE_CONTEXT.BTN_DELETE,b))});let e=a.querySelectorAll(d.btn_up_selector);for(let b=0;b<e.length;b++)e[b].addEventListener("click",function(){let b=y(a),c=a.previousElementSibling;c&&!1!==d.pre_up(a,c,b)&&(c=E(a),c&&d.post_up(a,c,b))});let f=a.querySelectorAll(d.btn_down_selector);for(let b=0;b<f.length;b++)f[b].addEventListener("click",function(){let b=y(a),c=a.nextElementSibling;c&&!1!==d.pre_down(a,c,b)&&(c=F(a),c&&d.post_down(a,c,b))})},u=function(a,b){let c={};for(let d,e=0;e<a.attributes.length;e++)d=a.attributes[e],d.value&&-1!==d.value.indexOf(b)&&(c[d.name]=d.value);return c},v=function(a,b){let c=new RegExp(d.prototype_name,"g");for(let d=0;d<n.length;d++){let f=n[d],g=a;for(let a,b=0;b<f.path.length;b++)a=f.path[b],g=g.children[a];let h=Object.keys(f.attributes);for(let a=0;a<h.length;a++){let d=h[a],e=f.attributes[d];g.setAttribute(d,e.replace(c,b))}"data-prototype"in g.attributes&&g.dispatchEvent(l(e))}},w=function(a){let b=k.children;for(let c=a;c<b.length;c++)v(b[c],c)},x=function(a){void 0===a&&(a=o);let b=i,c=new RegExp(d.prototype_name,"g");b=b.replace(c,a);let e=q(b);return t(e),e},y=function(a){let b=0;for(;null!=(a=a.previousElementSibling);)b++;return b},z=function(a,b){a.insertAdjacentElement("beforebegin",b)},A=function(a,b){a.insertAdjacentElement("afterend",b)},B=function(a){if(o>=d.max_elems)return!1;let b=x(y(a)+1);return A(a,b),o++,w(y(a)+2),b},C=function(a){if(o>=d.max_elems)return!1;if(!1!==d.pre_add(a,o)){let b=x();k.appendChild(b),o++,d.post_add(b,a,o-1)}},D=function(a){let b=y(a);a.parentNode.removeChild(a),o--,w(b)},E=function(a){let b=a.previousElementSibling;if(!b)return!1;let c=y(b);return z(b,a),v(a,c),v(b,c+1),b},F=function(a){let b=a.nextElementSibling;if(!b)return!1;let c=y(b);return A(b,a),v(a,c),v(b,c-1),b},G=function(){for(let a=0;a<k.children.length;a++){d.call_pre_add_on_init&&d.pre_add(formCollection.ADD_CONTEXT.INIT,a);let b=k.children[a];t(b),d.call_post_add_on_init&&d.post_add(b,formCollection.ADD_CONTEXT.INIT,a)}};if(G(),s(),d.other_btn_add){let a=null;if("string"==typeof d.other_btn_add?a=document.querySelectorAll(d.other_btn_add):d.other_btn_add instanceof Node?a=[d.other_btn_add]:formCollection.jQuery&&d.other_btn_add instanceof formCollection.jQuery||d.other_btn_add instanceof NodeList?a=d.other_btn_add:console.error("other_btn_add: bad value, can be a selector or nodes, or a jQuery object."),a)for(let b=0;b<a.length;b++)a[b].addEventListener("click",function(){C(formCollection.ADD_CONTEXT.OTHER_BTN_ADD)})}}};formCollection.ADD_CONTEXT={BTN_ADD:4,OTHER_BTN_ADD:8,INIT:15,ADD_METHOD:16},formCollection.DELETE_CONTEXT={BTN_DELETE:23,DELETE_METHOD:42},formCollection.POST_ADD_CONTEXT=formCollection.ADD_CONTEXT,formCollection.POST_DELETE_CONTEXT=formCollection.DELETE_CONTEXT,formCollection.jQuery=null,function(a,b){"function"==typeof define&&define.amd?define(["jquery"],b):"object"==typeof module&&module.exports?module.exports=b(require("jquery")):"undefined"==typeof jQuery?a.returnExports=b():a.returnExports=b(jQuery)}(this,function(a){return"undefined"!=typeof jQuery&&jQuery&&(formCollection.jQuery=a,a.fn.formCollection=function(b,c){let d=[];for(let a=0;a<this.length;a++)d.push(this[a]);let e=formCollection(d,b,c);return Array.isArray(e)?a(this):e}),formCollection}); |
@@ -44,3 +44,2 @@ // Karma configuration | ||
coverageReporter: { | ||
type : 'html', | ||
dir : 'coverage/without_jquery/', | ||
@@ -103,2 +102,2 @@ reporters: [ | ||
}) | ||
} | ||
} |
{ | ||
"name": "symfony-collection-js", | ||
"version": "4.3.0-js-only", | ||
"version": "4.3.0", | ||
"description": "A plugin working with and without jquery to dynamically create elements of a symfony form collection.", | ||
@@ -5,0 +5,0 @@ "main": "symfonyCollectionJs.js", |
@@ -1,2 +0,2 @@ | ||
# symfonyCollectionJs ![GitHub](https://img.shields.io/github/license/ruano-a/symfonyCollectionJs) ![Maintenance](https://img.shields.io/maintenance/yes/2022) ![GitHub last commit](https://img.shields.io/github/last-commit/ruano-a/symfonyCollectionJs) ![npm](https://img.shields.io/npm/dm/symfony-collection-js?label=npm%20downloads) [![](https://data.jsdelivr.com/v1/package/npm/symfony-collection-js/badge)](https://www.jsdelivr.com/package/npm/symfony-collection-js) [![codecov](https://codecov.io/gh/ruano-a/symfonyCollectionJs/branch/master-js-only/graph/badge.svg?token=Z93Y3NTP1Q)](https://codecov.io/gh/ruano-a/symfonyCollectionJs) ![npm bundle size](https://img.shields.io/bundlephobia/min/symfony-collection-js) ![Dependencies](https://badgen.net/bundlephobia/dependency-count/symfony-collection-js) ![Badge count](https://img.shields.io/badge/badge%20count-enough%20%3C3-blue) | ||
# symfonyCollectionJs ![GitHub](https://img.shields.io/github/license/ruano-a/symfonyCollectionJs) ![Maintenance](https://img.shields.io/maintenance/yes/2022) ![GitHub last commit](https://img.shields.io/github/last-commit/ruano-a/symfonyCollectionJs) ![npm](https://img.shields.io/npm/dm/symfony-collection-js?label=npm%20downloads) [![](https://data.jsdelivr.com/v1/package/npm/symfony-collection-js/badge)](https://www.jsdelivr.com/package/npm/symfony-collection-js) [![codecov](https://codecov.io/gh/ruano-a/symfonyCollectionJs/branch/master/graph/badge.svg?token=Z93Y3NTP1Q)](https://codecov.io/gh/ruano-a/symfonyCollectionJs) ![npm bundle size](https://img.shields.io/bundlephobia/min/symfony-collection-js) ![Dependencies](https://badgen.net/bundlephobia/dependency-count/symfony-collection-js) ![Badge count](https://img.shields.io/badge/badge%20count-enough%20%3C3-blue) | ||
A plugin working with and without jquery to dynamically create elements of a symfony form collection. | ||
@@ -19,10 +19,10 @@ | ||
```html | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/symfonyCollectionJs/4.2.2-js-only/symfonyCollectionJs.min.js" integrity="sha512-n4/PStbGMF9UgqPuBeV0rWFP4A2pniUXzanDcxKYXe0oYeokYIK7wkoYcG/KoDDrXjGqX24LgTNPD5lzck74QQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/symfonyCollectionJs/4.2.2/symfonyCollectionJs.min.js" integrity="sha512-qpIx6aHqQROnCNHHFS+Iy/XwPltKFouhUaCkmV6ezBx9BDn0hEKNZ/MOxiDbh/DV+YO5y213L+3Yy3ELuS1pFw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script> | ||
``` | ||
jsDelivr | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/symfony-collection-js@4.2.2-js-only/dist/symfonyCollectionJs.js" integrity="sha256-9TfQnYOT8TpalGxz6TzhiggYuWade7TlqqhKBMTs2IE=" crossorigin="anonymous"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/symfony-collection-js@4.2.2/dist/symfonyCollectionJs.min.js" integrity="sha256-IO7KKu1yWhFkJucWVZN8Ot19gTXqOqbPF0AawG0IbPQ=" crossorigin="anonymous"></script> | ||
``` | ||
# Basic usage (Check [here](#can-i-use-this-package-without-symfony-) to use without symfony) | ||
# Basic usage (Check [here](#can-i-use-this-package-without-symfony) to use without symfony) | ||
@@ -128,4 +128,9 @@ Your collection container should have the prototype mentioned in the symfony documentation, and an id or a class. So in your form type: | ||
Yes! in the example folder, with and without jQuery, with and without loader. | ||
Yes ! in the example folder, with and without jQuery, with and without loader. | ||
# Can I use this package without symfony? | ||
Absolutely, you only need to have the data-prototype attribute properly set. | ||
We provide you with [this example](./example/simple_collection_example_without_symfony.php) in php, but you can do this in every language, and most likely with most frameworks. | ||
# Is there a Symfony UX integration? | ||
@@ -139,7 +144,2 @@ | ||
# Can I use this package without symfony? | ||
Absolutely, you only need to have the data-prototype attribute properly set. | ||
We provide you with [this example](./example/simple_collection_example_without_symfony.php) in php, but you can do this in every language, and most likely with most frameworks. | ||
# Notes | ||
@@ -146,0 +146,0 @@ If you're using this without jQuery, but with a loader (AMD, CommonJS, or anything), you MUST use a version on a branch / tag with "js-only" in the name! Otherwise it WILL NOT BUILD! (I didn't want to make several versions but tests ended showing that it was the best choice... Unless you have a better idea?) |
@@ -433,16 +433,33 @@ // Polyfill from https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent | ||
formCollection.POST_DELETE_CONTEXT = formCollection.DELETE_CONTEXT; // to avoid breaking changes, for now | ||
// UMD : Uses CommonJS, AMD or browser globals | ||
formCollection.jQuery = null; | ||
// UMD : Uses CommonJS, AMD or browser globals to create a jQuery plugin (if jQuery is there) | ||
(function(root, factory) { | ||
if (typeof define === 'function' && define.amd) { | ||
// AMD. Register as an anonymous module. | ||
define([], factory); | ||
define(['jquery'], factory); | ||
} else if (typeof module === 'object' && module.exports) { | ||
// Node/CommonJS | ||
module.exports = factory(); | ||
module.exports = factory(require('jquery')); | ||
} else { | ||
// Browser globals | ||
root.returnExports = factory(); | ||
if (typeof jQuery !== 'undefined') | ||
root.returnExports = factory(jQuery); | ||
else | ||
root.returnExports = factory(); | ||
} | ||
}(this, function() { | ||
}(this, function($) { | ||
if (typeof jQuery !== 'undefined' && jQuery) { | ||
formCollection.jQuery = $; // jQuery is not necessarily global so it's better to know easily if it's available | ||
$.fn.formCollection = function (options, param) { | ||
let nodeArray = []; | ||
for (let i = 0; i < this.length; i++) { | ||
nodeArray.push(this[i]); | ||
} | ||
let ret = formCollection(nodeArray, options, param); | ||
if (!Array.isArray(ret)) | ||
return ret; | ||
return $(this); | ||
}; | ||
} | ||
return formCollection; | ||
})); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
629135
34
11735