Merge pull request #3767 from betagouv/dev

2019-04-09-01
This commit is contained in:
Paul Chavard 2019-04-09 18:11:45 +02:00 committed by GitHub
commit 14875350d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 126 additions and 1 deletions

View file

@ -53,7 +53,7 @@ module ApplicationHelper
script = "(function() {"; script = "(function() {";
script << "var el = document.querySelector('#{selector}');" script << "var el = document.querySelector('#{selector}');"
method = (inner ? "el.innerHTML = ''" : "el.parentNode.removeChild(el)") method = (inner ? "el.innerHTML = ''" : "el.parentNode.removeChild(el)")
script << "setTimeout(function() { #{method}; }, #{timeout});"; script << "if (el) { setTimeout(function() { #{method}; }, #{timeout}); }";
script << "})();" script << "})();"
# rubocop:disable Rails/OutputSafety # rubocop:disable Rails/OutputSafety
raw(script); raw(script);

View file

@ -3,3 +3,5 @@
// required by the browsers we support will be included. // required by the browsers we support will be included.
import '@babel/polyfill'; import '@babel/polyfill';
import 'dom4'; import 'dom4';
import './polyfills/insertAdjacentElement';
import './polyfills/dataset';

View file

@ -0,0 +1,75 @@
/*
@preserve dataset polyfill for IE < 11. See https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset and http://caniuse.com/#search=dataset
@author ShirtlessKirk copyright 2015
@license WTFPL (http://www.wtfpl.net/txt/copying)
*/
const dash = /-([a-z])/gi;
const dataRegEx = /^data-(.+)/;
const hasEventListener = !!document.addEventListener;
const test = document.createElement('_');
const DOMAttrModified = 'DOMAttrModified';
let mutationSupport = false;
function clearDataset(event) {
delete event.target._datasetCache;
}
function toCamelCase(string) {
return string.replace(dash, function(_, letter) {
return letter.toUpperCase();
});
}
function getDataset() {
const dataset = {};
for (let attribute of this.attributes) {
let match = attribute.name.match(dataRegEx);
if (match) {
dataset[toCamelCase(match[1])] = attribute.value;
}
}
return dataset;
}
function mutation() {
if (hasEventListener) {
test.removeEventListener(DOMAttrModified, mutation, false);
} else {
test.detachEvent(`on${DOMAttrModified}`, mutation);
}
mutationSupport = true;
}
if (!test.dataset) {
if (hasEventListener) {
test.addEventListener(DOMAttrModified, mutation, false);
} else {
test.attachEvent(`on${DOMAttrModified}`, mutation);
}
// trigger event (if supported)
test.setAttribute('foo', 'bar');
Object.defineProperty(Element.prototype, 'dataset', {
get: mutationSupport
? function get() {
if (!this._datasetCache) {
this._datasetCache = getDataset.call(this);
}
return this._datasetCache;
}
: getDataset
});
if (mutationSupport && hasEventListener) {
// < IE9 supports neither
document.addEventListener(DOMAttrModified, clearDataset, false);
}
}

View file

@ -0,0 +1,47 @@
/*
Updated w/ insertAdjacentElement
@author Dan Levy @justsml
2016-06-23
Credit: @lyleunderwood - afterend patch/fix
2011-10-10
By Eli Grey, http://eligrey.com
Public Domain.
NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
*/
function insertAdjacentElement(position, elem) {
const _this = this;
const parent = this.parentNode;
let node, first;
switch (position.toLowerCase()) {
case 'beforebegin':
while ((node = elem.firstChild)) {
parent.insertBefore(node, _this);
}
break;
case 'afterbegin':
first = _this.firstChild;
while ((node = elem.lastChild)) {
first = _this.insertBefore(node, first);
}
break;
case 'beforeend':
while ((node = elem.firstChild)) {
_this.appendChild(node);
}
break;
case 'afterend':
parent.insertBefore(elem, _this.nextSibling);
break;
}
return elem;
}
// Method missing in Firefox < 48
if (!HTMLElement.prototype.insertAdjacentElement) {
HTMLElement.prototype.insertAdjacentElement = insertAdjacentElement;
}

View file

@ -1,2 +1,3 @@
<%= render_flash(timeout: 5000, sticky: true) %> <%= render_flash(timeout: 5000, sticky: true) %>
<%= remove_element("#piece_justificative_#{@champ.id}") %> <%= remove_element("#piece_justificative_#{@champ.id}") %>
<%= show_element("#champs_#{@champ.id}") %>