symfony-collection-js
Advanced tools
Comparing version 4.0.0 to 4.1.0-js-only
@@ -8,3 +8,3 @@ { | ||
], | ||
"description": "A jquery plugin to dynamically create elements of a symfony form collection.", | ||
"description": "A plugin working with and without jquery to dynamically create elements of a symfony form collection.", | ||
"keywords": [ | ||
@@ -11,0 +11,0 @@ "js", |
{ | ||
"name": "symfony-collection-js", | ||
"version": "4.0.0", | ||
"version": "4.1.0-js-only", | ||
"description": "A plugin working with and without jquery to dynamically create elements of a symfony form collection.", | ||
@@ -10,3 +10,14 @@ "main": "symfonyCollectionJs.js", | ||
"peerDependencies": {}, | ||
"dependencies": {} | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"karma": "^6.3.2", | ||
"karma-chrome-launcher": "^3.1.0", | ||
"karma-coverage": "^2.0.3", | ||
"karma-html2js-preprocessor": "^1.1.0", | ||
"karma-qunit": "^4.1.2", | ||
"qunit": "^2.15.0" | ||
}, | ||
"scripts": { | ||
"test": "bash ./test/start.sh" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# symfonyCollectionJs | ||
# symfonyCollectionJs ![GitHub](https://img.shields.io/github/license/ruano-a/symfonyCollectionJs) ![Maintenance](https://img.shields.io/maintenance/yes/2021) ![GitHub last commit](https://img.shields.io/github/last-commit/ruano-a/symfonyCollectionJs) [![](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) | ||
A plugin working with and without jquery to dynamically create elements of a symfony form collection. | ||
@@ -16,2 +16,7 @@ | ||
# Or include with a CDN | ||
```html | ||
<script src="https://cdn.jsdelivr.net/gh/ruano-a/symfonyCollectionJs@4.1.0-js-only/symfonyCollectionJs.min.js"></script> | ||
``` | ||
# Basic usage | ||
@@ -56,3 +61,3 @@ | ||
~~~~ | ||
In post_up and post_down, switched_elem is the moved elem that the user didn't click on. | ||
In post_up and post_down, switched_elem is the moved elem that the user didn't click on. | ||
prototype_name should probably be changed if you use nested collection (in the FormType too, with the same value). | ||
@@ -108,4 +113,3 @@ | ||
Just open the page index_with_jquery.html or index_without_jquery.html in the test folder. | ||
It starts the tests on opening. | ||
[Check this](./test/README.md) | ||
@@ -121,8 +125,7 @@ # Any advanced example ? | ||
# Notes | ||
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?) | ||
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?) | ||
This should theoretically work with unlimited nested collection. However if you encounter an issue, let me know. | ||
Don't hesitate to let me know if you're using this plugin, I'm super interested ! | ||
For advances features, you should use the plugin of ninsuo. | ||
The file test/prep_nojquery_tests.js contains a homemade micro version of jQuery, I guess it can interest some people. | ||
This should theoretically work with unlimited nested collection. However if you encounter an issue, let me know. | ||
Don't hesitate to let me know if you're using this plugin, I'm super interested ! | ||
For advances features, you should use the plugin of ninsuo. | ||
The file test/prep_nojquery_tests.js contains a homemade micro version of jQuery, I guess it can interest some people. |
@@ -31,4 +31,13 @@ // Polyfill from https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent | ||
return a; | ||
} | ||
}; | ||
var getEvent = function(eventName) { | ||
if (typeof(Event) === 'function') { | ||
return new Event(eventName); | ||
} | ||
var event = document.createEvent('Event'); | ||
event.initEvent(eventName, true, true); | ||
return event; | ||
}; | ||
if (options === undefined || typeof options === 'object') { | ||
@@ -75,3 +84,3 @@ var defaults = { | ||
case 'add': | ||
collection_root.dispatchEvent(new Event(eventAddMethodCalled)); | ||
collection_root.dispatchEvent(getEvent(eventAddMethodCalled)); | ||
return; | ||
@@ -84,3 +93,3 @@ break; | ||
case 'clear': | ||
collection_root.dispatchEvent(new Event(eventClearMethodCalled)); | ||
collection_root.dispatchEvent(getEvent(eventClearMethodCalled)); | ||
return; | ||
@@ -252,3 +261,3 @@ break; | ||
if ('data-prototype' in node.attributes) // if this node is a subcollection container | ||
node.dispatchEvent(new Event(eventPrototypeModified)); | ||
node.dispatchEvent(getEvent(eventPrototypeModified)); | ||
} | ||
@@ -388,33 +397,16 @@ }; | ||
}; | ||
formCollection.jQuery = null; | ||
// UMD : Uses CommonJS, AMD or browser globals to create a jQuery plugin (if jQuery is there) | ||
// UMD : Uses CommonJS, AMD or browser globals | ||
(function(root, factory) { | ||
if (typeof define === 'function' && define.amd) { | ||
// AMD. Register as an anonymous module. | ||
define(['jquery'], factory); | ||
define([], factory); | ||
} else if (typeof module === 'object' && module.exports) { | ||
// Node/CommonJS | ||
module.exports = factory(require('jquery')); | ||
module.exports = factory(); | ||
} else { | ||
// Browser globals | ||
if (typeof jQuery !== 'undefined') | ||
root.returnExports = factory(jQuery); | ||
else | ||
root.returnExports = factory(); | ||
root.returnExports = factory(); | ||
} | ||
}(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) { | ||
var nodeArray = []; | ||
for (var i = 0; i < this.length; i++) { | ||
nodeArray.push(this[i]); | ||
} | ||
var ret = formCollection(nodeArray, options, param); | ||
if (!Array.isArray(ret)) | ||
return ret; | ||
return $(this); | ||
}; | ||
} | ||
}(this, function() { | ||
return formCollection; | ||
})); |
@@ -16,2 +16,11 @@ /* | ||
var getEvent = function(eventName) { | ||
if (typeof(Event) === 'function') { | ||
return new Event(eventName); | ||
} | ||
var event = document.createEvent('Event'); | ||
event.initEvent(eventName, true, true); | ||
return event; | ||
}; | ||
var addMethods = function(result) { | ||
@@ -63,3 +72,3 @@ | ||
for (var i = 0; i < result.length; i++) { | ||
result[i].dispatchEvent(new Event('click')); | ||
result[i].dispatchEvent(getEvent('click')); | ||
} | ||
@@ -66,0 +75,0 @@ return result; |
@@ -213,5 +213,17 @@ var extend = function (a, b) { | ||
{ | ||
return new Set(arr).size !== arr.length; | ||
return arr.some( function(item) { | ||
return arr.indexOf(item) !== arr.lastIndexOf(item); | ||
}); | ||
} | ||
if (typeof window.__html__ !== 'undefined') { | ||
console.log('DEFINED') | ||
/*QUnit.testStart( details => { | ||
console.log( `Now running: ${details.module} ${details.name}` ); | ||
var fixture = document.getElementById('qunit-fixture'); | ||
fixture.innerHTML = window.__html__['test/base_fixtures']; | ||
});*/ | ||
QUnit.config.fixture = window.__html__['test/base_fixtures']; | ||
} | ||
/* Note : in assert.equal, the expected is the 2nd param */ | ||
@@ -218,0 +230,0 @@ QUnit.module('Registration / initializing', function() { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
339302
27
5744
128
6