hof 22.0.0-timeout-warning-beta.9 → 22.0.0-timeout-warning-beta.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.nyc_output/332fb170-672e-4e73-a6b5-5dfcf25ce16e.json +1 -0
- package/.nyc_output/processinfo/{7e766ffa-764d-4f40-8a66-4891d956c3ae.json → 332fb170-672e-4e73-a6b5-5dfcf25ce16e.json} +1 -1
- package/.nyc_output/processinfo/index.json +1 -1
- package/components/session-timeout-warning/index.js +8 -0
- package/config/hof-defaults.js +1 -1
- package/frontend/template-partials/views/exit.html +1 -1
- package/frontend/template-partials/views/partials/session-timeout-warning.html +7 -1
- package/frontend/themes/gov-uk/client-js/session-timeout-dialog.js +16 -1
- package/frontend/themes/gov-uk/styles/_session-timeout-dialog.scss +4 -0
- package/index.js +1 -12
- package/package.json +1 -1
- package/sandbox/.env +2 -0
- package/sandbox/apps/sandbox/translations/en/default.json +4 -2
- package/sandbox/apps/sandbox/translations/src/en/exit.json +4 -0
- package/sandbox/apps/sandbox/translations/src/en/pages.json +0 -2
- package/sandbox/public/css/app.css +4 -0
- package/sandbox/public/js/bundle.js +902 -19
- package/sandbox/server.js +1 -0
- package/.nyc_output/7e766ffa-764d-4f40-8a66-4891d956c3ae.json +0 -1
@@ -297,11 +297,12 @@ helpers.documentReady(cookieSettings.onLoad);
|
|
297
297
|
helpers.documentReady(characterCount);
|
298
298
|
helpers.documentReady(validation);
|
299
299
|
|
300
|
-
},{"../../../toolkit":12,"./cookieSettings":1,"./govuk-cookies":2,"./session-timeout-dialog":4,"./skip-to-main":5,"govuk-frontend":
|
300
|
+
},{"../../../toolkit":12,"./cookieSettings":1,"./govuk-cookies":2,"./session-timeout-dialog":4,"./skip-to-main":5,"govuk-frontend":14}],4:[function(require,module,exports){
|
301
301
|
/* eslint max-len: 0 */
|
302
302
|
'use strict';
|
303
303
|
|
304
304
|
const $ = require('jquery');
|
305
|
+
window.dialogPolyfill = require('dialog-polyfill');
|
305
306
|
|
306
307
|
// Modal dialog prototype
|
307
308
|
window.GOVUK.sessionDialog = {
|
@@ -309,6 +310,7 @@ window.GOVUK.sessionDialog = {
|
|
309
310
|
$el: $('#js-modal-dialog'),
|
310
311
|
$lastFocusedEl: null,
|
311
312
|
$closeButton: $('.modal-dialog .js-dialog-close'),
|
313
|
+
$fallBackElement: $('.govuk-timeout-warning-fallback'),
|
312
314
|
dialogIsOpenClass: 'dialog-is-open',
|
313
315
|
timers: [],
|
314
316
|
warningTextPrefix: 'To protect your information, this page will time out in ',
|
@@ -543,7 +545,7 @@ window.GOVUK.sessionDialog = {
|
|
543
545
|
// Add additional information in extraText which will get announced to AT the
|
544
546
|
// first time the time out opens
|
545
547
|
const countdownText = window.GOVUK.sessionDialog.countdownText(minutesLeft, secondsLeft);
|
546
|
-
const text = window.GOVUK.sessionDialog.warningTextPrefix + '<strong>' + countdownText + '</strong>' + window.GOVUK.sessionDialog.warningTextSuffix;
|
548
|
+
const text = window.GOVUK.sessionDialog.warningTextPrefix + '<strong>' + countdownText + '</strong>' + window.GOVUK.sessionDialog.warningTextSuffix + '<p>' + window.GOVUK.sessionDialog.warningText + '</p>';
|
547
549
|
const countdownAtText = window.GOVUK.sessionDialog.countdownAtText(minutesLeft, secondsLeft);
|
548
550
|
const atText = window.GOVUK.sessionDialog.warningTextPrefix + countdownAtText + window.GOVUK.sessionDialog.warningTextSuffix + ' ' + window.GOVUK.sessionDialog.warningText;
|
549
551
|
const extraText = '\n' + window.GOVUK.sessionDialog.warningTextExtra;
|
@@ -625,14 +627,27 @@ window.GOVUK.sessionDialog = {
|
|
625
627
|
init: function (options) {
|
626
628
|
$.extend(window.GOVUK.sessionDialog, options);
|
627
629
|
if (window.GOVUK.sessionDialog.el && window.GOVUK.sessionDialog.isConfigured()) {
|
630
|
+
// Native dialog is not supported by some browsers so use polyfill
|
631
|
+
if (typeof HTMLDialogElement !== 'function') {
|
632
|
+
try {
|
633
|
+
window.dialogPolyfill.registerDialog(window.GOVUK.sessionDialog.el);
|
634
|
+
return true;
|
635
|
+
} catch (error) {
|
636
|
+
// Doesn't support polyfill (IE8) - display fallback element
|
637
|
+
window.GOVUK.sessionDialog.$fallBackElement.classList.add('govuk-!-display-block');
|
638
|
+
return false;
|
639
|
+
}
|
640
|
+
}
|
628
641
|
window.GOVUK.sessionDialog.bindUIElements();
|
629
642
|
window.GOVUK.sessionDialog.controller();
|
643
|
+
return true;
|
630
644
|
}
|
645
|
+
return false;
|
631
646
|
}
|
632
647
|
};
|
633
648
|
window.GOVUK.sessionDialog.init();
|
634
649
|
|
635
|
-
},{"jquery":
|
650
|
+
},{"dialog-polyfill":13,"jquery":15}],5:[function(require,module,exports){
|
636
651
|
const skipToMain = function () {
|
637
652
|
const skipToMainLink = document.getElementById('skip-to-main');
|
638
653
|
const firstControlId = skipToMainLink.hash.split('#')[1] ? skipToMainLink.hash.split('#')[1] : 'main-content';
|
@@ -857,7 +872,7 @@ function formFocus() {
|
|
857
872
|
|
858
873
|
module.exports = formFocus;
|
859
874
|
|
860
|
-
},{"./helpers":8,"lodash":
|
875
|
+
},{"./helpers":8,"lodash":16}],8:[function(require,module,exports){
|
861
876
|
/* eslint-disable max-len, no-var, no-param-reassign, vars-on-top, no-extend-native */
|
862
877
|
'use strict';
|
863
878
|
|
@@ -1036,7 +1051,7 @@ helpers.pagehide = function (func) {
|
|
1036
1051
|
|
1037
1052
|
module.exports = helpers;
|
1038
1053
|
|
1039
|
-
},{"lodash":
|
1054
|
+
},{"lodash":16}],9:[function(require,module,exports){
|
1040
1055
|
/* eslint-disable max-len, no-var, no-param-reassign, vars-on-top */
|
1041
1056
|
'use strict';
|
1042
1057
|
|
@@ -1110,7 +1125,7 @@ function progressiveReveal() {
|
|
1110
1125
|
|
1111
1126
|
module.exports = progressiveReveal;
|
1112
1127
|
|
1113
|
-
},{"./helpers":8,"lodash":
|
1128
|
+
},{"./helpers":8,"lodash":16}],10:[function(require,module,exports){
|
1114
1129
|
/* eslint-disable max-len, no-var, no-shadow, vars-on-top */
|
1115
1130
|
var each = require('lodash').forEach;
|
1116
1131
|
|
@@ -1183,7 +1198,7 @@ function validation() {
|
|
1183
1198
|
|
1184
1199
|
module.exports = validation;
|
1185
1200
|
|
1186
|
-
},{"./helpers":8,"lodash":
|
1201
|
+
},{"./helpers":8,"lodash":16}],11:[function(require,module,exports){
|
1187
1202
|
/* eslint-disable max-len, no-var, no-cond-assign, no-param-reassign, vars-on-top */
|
1188
1203
|
// <details> polyfill
|
1189
1204
|
// http://caniuse.com/#feat=details
|
@@ -1387,6 +1402,874 @@ module.exports = {
|
|
1387
1402
|
};
|
1388
1403
|
|
1389
1404
|
},{"./assets/javascript/character-count":6,"./assets/javascript/form-focus":7,"./assets/javascript/helpers":8,"./assets/javascript/progressive-reveal":9,"./assets/javascript/validation":10,"./assets/javascript/vendor/details.polyfill":11}],13:[function(require,module,exports){
|
1405
|
+
(function (global, factory) {
|
1406
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
1407
|
+
typeof define === 'function' && define.amd ? define(factory) :
|
1408
|
+
(global = global || self, global.dialogPolyfill = factory());
|
1409
|
+
}(this, function () { 'use strict';
|
1410
|
+
|
1411
|
+
// nb. This is for IE10 and lower _only_.
|
1412
|
+
var supportCustomEvent = window.CustomEvent;
|
1413
|
+
if (!supportCustomEvent || typeof supportCustomEvent === 'object') {
|
1414
|
+
supportCustomEvent = function CustomEvent(event, x) {
|
1415
|
+
x = x || {};
|
1416
|
+
var ev = document.createEvent('CustomEvent');
|
1417
|
+
ev.initCustomEvent(event, !!x.bubbles, !!x.cancelable, x.detail || null);
|
1418
|
+
return ev;
|
1419
|
+
};
|
1420
|
+
supportCustomEvent.prototype = window.Event.prototype;
|
1421
|
+
}
|
1422
|
+
|
1423
|
+
/**
|
1424
|
+
* Dispatches the passed event to both an "on<type>" handler as well as via the
|
1425
|
+
* normal dispatch operation. Does not bubble.
|
1426
|
+
*
|
1427
|
+
* @param {!EventTarget} target
|
1428
|
+
* @param {!Event} event
|
1429
|
+
* @return {boolean}
|
1430
|
+
*/
|
1431
|
+
function safeDispatchEvent(target, event) {
|
1432
|
+
var check = 'on' + event.type.toLowerCase();
|
1433
|
+
if (typeof target[check] === 'function') {
|
1434
|
+
target[check](event);
|
1435
|
+
}
|
1436
|
+
return target.dispatchEvent(event);
|
1437
|
+
}
|
1438
|
+
|
1439
|
+
/**
|
1440
|
+
* @param {Element} el to check for stacking context
|
1441
|
+
* @return {boolean} whether this el or its parents creates a stacking context
|
1442
|
+
*/
|
1443
|
+
function createsStackingContext(el) {
|
1444
|
+
while (el && el !== document.body) {
|
1445
|
+
var s = window.getComputedStyle(el);
|
1446
|
+
var invalid = function(k, ok) {
|
1447
|
+
return !(s[k] === undefined || s[k] === ok);
|
1448
|
+
};
|
1449
|
+
|
1450
|
+
if (s.opacity < 1 ||
|
1451
|
+
invalid('zIndex', 'auto') ||
|
1452
|
+
invalid('transform', 'none') ||
|
1453
|
+
invalid('mixBlendMode', 'normal') ||
|
1454
|
+
invalid('filter', 'none') ||
|
1455
|
+
invalid('perspective', 'none') ||
|
1456
|
+
s['isolation'] === 'isolate' ||
|
1457
|
+
s.position === 'fixed' ||
|
1458
|
+
s.webkitOverflowScrolling === 'touch') {
|
1459
|
+
return true;
|
1460
|
+
}
|
1461
|
+
el = el.parentElement;
|
1462
|
+
}
|
1463
|
+
return false;
|
1464
|
+
}
|
1465
|
+
|
1466
|
+
/**
|
1467
|
+
* Finds the nearest <dialog> from the passed element.
|
1468
|
+
*
|
1469
|
+
* @param {Element} el to search from
|
1470
|
+
* @return {HTMLDialogElement} dialog found
|
1471
|
+
*/
|
1472
|
+
function findNearestDialog(el) {
|
1473
|
+
while (el) {
|
1474
|
+
if (el.localName === 'dialog') {
|
1475
|
+
return /** @type {HTMLDialogElement} */ (el);
|
1476
|
+
}
|
1477
|
+
if (el.parentElement) {
|
1478
|
+
el = el.parentElement;
|
1479
|
+
} else if (el.parentNode) {
|
1480
|
+
el = el.parentNode.host;
|
1481
|
+
} else {
|
1482
|
+
el = null;
|
1483
|
+
}
|
1484
|
+
}
|
1485
|
+
return null;
|
1486
|
+
}
|
1487
|
+
|
1488
|
+
/**
|
1489
|
+
* Blur the specified element, as long as it's not the HTML body element.
|
1490
|
+
* This works around an IE9/10 bug - blurring the body causes Windows to
|
1491
|
+
* blur the whole application.
|
1492
|
+
*
|
1493
|
+
* @param {Element} el to blur
|
1494
|
+
*/
|
1495
|
+
function safeBlur(el) {
|
1496
|
+
// Find the actual focused element when the active element is inside a shadow root
|
1497
|
+
while (el && el.shadowRoot && el.shadowRoot.activeElement) {
|
1498
|
+
el = el.shadowRoot.activeElement;
|
1499
|
+
}
|
1500
|
+
|
1501
|
+
if (el && el.blur && el !== document.body) {
|
1502
|
+
el.blur();
|
1503
|
+
}
|
1504
|
+
}
|
1505
|
+
|
1506
|
+
/**
|
1507
|
+
* @param {!NodeList} nodeList to search
|
1508
|
+
* @param {Node} node to find
|
1509
|
+
* @return {boolean} whether node is inside nodeList
|
1510
|
+
*/
|
1511
|
+
function inNodeList(nodeList, node) {
|
1512
|
+
for (var i = 0; i < nodeList.length; ++i) {
|
1513
|
+
if (nodeList[i] === node) {
|
1514
|
+
return true;
|
1515
|
+
}
|
1516
|
+
}
|
1517
|
+
return false;
|
1518
|
+
}
|
1519
|
+
|
1520
|
+
/**
|
1521
|
+
* @param {HTMLFormElement} el to check
|
1522
|
+
* @return {boolean} whether this form has method="dialog"
|
1523
|
+
*/
|
1524
|
+
function isFormMethodDialog(el) {
|
1525
|
+
if (!el || !el.hasAttribute('method')) {
|
1526
|
+
return false;
|
1527
|
+
}
|
1528
|
+
return el.getAttribute('method').toLowerCase() === 'dialog';
|
1529
|
+
}
|
1530
|
+
|
1531
|
+
/**
|
1532
|
+
* @param {!DocumentFragment|!Element} hostElement
|
1533
|
+
* @return {?Element}
|
1534
|
+
*/
|
1535
|
+
function findFocusableElementWithin(hostElement) {
|
1536
|
+
// Note that this is 'any focusable area'. This list is probably not exhaustive, but the
|
1537
|
+
// alternative involves stepping through and trying to focus everything.
|
1538
|
+
var opts = ['button', 'input', 'keygen', 'select', 'textarea'];
|
1539
|
+
var query = opts.map(function(el) {
|
1540
|
+
return el + ':not([disabled])';
|
1541
|
+
});
|
1542
|
+
// TODO(samthor): tabindex values that are not numeric are not focusable.
|
1543
|
+
query.push('[tabindex]:not([disabled]):not([tabindex=""])'); // tabindex != "", not disabled
|
1544
|
+
var target = hostElement.querySelector(query.join(', '));
|
1545
|
+
|
1546
|
+
if (!target && 'attachShadow' in Element.prototype) {
|
1547
|
+
// If we haven't found a focusable target, see if the host element contains an element
|
1548
|
+
// which has a shadowRoot.
|
1549
|
+
// Recursively search for the first focusable item in shadow roots.
|
1550
|
+
var elems = hostElement.querySelectorAll('*');
|
1551
|
+
for (var i = 0; i < elems.length; i++) {
|
1552
|
+
if (elems[i].tagName && elems[i].shadowRoot) {
|
1553
|
+
target = findFocusableElementWithin(elems[i].shadowRoot);
|
1554
|
+
if (target) {
|
1555
|
+
break;
|
1556
|
+
}
|
1557
|
+
}
|
1558
|
+
}
|
1559
|
+
}
|
1560
|
+
return target;
|
1561
|
+
}
|
1562
|
+
|
1563
|
+
/**
|
1564
|
+
* Determines if an element is attached to the DOM.
|
1565
|
+
* @param {Element} element to check
|
1566
|
+
* @return {boolean} whether the element is in DOM
|
1567
|
+
*/
|
1568
|
+
function isConnected(element) {
|
1569
|
+
return element.isConnected || document.body.contains(element);
|
1570
|
+
}
|
1571
|
+
|
1572
|
+
/**
|
1573
|
+
* @param {!Event} event
|
1574
|
+
* @return {?Element}
|
1575
|
+
*/
|
1576
|
+
function findFormSubmitter(event) {
|
1577
|
+
if (event.submitter) {
|
1578
|
+
return event.submitter;
|
1579
|
+
}
|
1580
|
+
|
1581
|
+
var form = event.target;
|
1582
|
+
if (!(form instanceof HTMLFormElement)) {
|
1583
|
+
return null;
|
1584
|
+
}
|
1585
|
+
|
1586
|
+
var submitter = dialogPolyfill.formSubmitter;
|
1587
|
+
if (!submitter) {
|
1588
|
+
var target = event.target;
|
1589
|
+
var root = ('getRootNode' in target && target.getRootNode() || document);
|
1590
|
+
submitter = root.activeElement;
|
1591
|
+
}
|
1592
|
+
|
1593
|
+
if (!submitter || submitter.form !== form) {
|
1594
|
+
return null;
|
1595
|
+
}
|
1596
|
+
return submitter;
|
1597
|
+
}
|
1598
|
+
|
1599
|
+
/**
|
1600
|
+
* @param {!Event} event
|
1601
|
+
*/
|
1602
|
+
function maybeHandleSubmit(event) {
|
1603
|
+
if (event.defaultPrevented) {
|
1604
|
+
return;
|
1605
|
+
}
|
1606
|
+
var form = /** @type {!HTMLFormElement} */ (event.target);
|
1607
|
+
|
1608
|
+
// We'd have a value if we clicked on an imagemap.
|
1609
|
+
var value = dialogPolyfill.imagemapUseValue;
|
1610
|
+
var submitter = findFormSubmitter(event);
|
1611
|
+
if (value === null && submitter) {
|
1612
|
+
value = submitter.value;
|
1613
|
+
}
|
1614
|
+
|
1615
|
+
// There should always be a dialog as this handler is added specifically on them, but check just
|
1616
|
+
// in case.
|
1617
|
+
var dialog = findNearestDialog(form);
|
1618
|
+
if (!dialog) {
|
1619
|
+
return;
|
1620
|
+
}
|
1621
|
+
|
1622
|
+
// Prefer formmethod on the button.
|
1623
|
+
var formmethod = submitter && submitter.getAttribute('formmethod') || form.getAttribute('method');
|
1624
|
+
if (formmethod !== 'dialog') {
|
1625
|
+
return;
|
1626
|
+
}
|
1627
|
+
event.preventDefault();
|
1628
|
+
|
1629
|
+
if (value != null) {
|
1630
|
+
// nb. we explicitly check against null/undefined
|
1631
|
+
dialog.close(value);
|
1632
|
+
} else {
|
1633
|
+
dialog.close();
|
1634
|
+
}
|
1635
|
+
}
|
1636
|
+
|
1637
|
+
/**
|
1638
|
+
* @param {!HTMLDialogElement} dialog to upgrade
|
1639
|
+
* @constructor
|
1640
|
+
*/
|
1641
|
+
function dialogPolyfillInfo(dialog) {
|
1642
|
+
this.dialog_ = dialog;
|
1643
|
+
this.replacedStyleTop_ = false;
|
1644
|
+
this.openAsModal_ = false;
|
1645
|
+
|
1646
|
+
// Set a11y role. Browsers that support dialog implicitly know this already.
|
1647
|
+
if (!dialog.hasAttribute('role')) {
|
1648
|
+
dialog.setAttribute('role', 'dialog');
|
1649
|
+
}
|
1650
|
+
|
1651
|
+
dialog.show = this.show.bind(this);
|
1652
|
+
dialog.showModal = this.showModal.bind(this);
|
1653
|
+
dialog.close = this.close.bind(this);
|
1654
|
+
|
1655
|
+
dialog.addEventListener('submit', maybeHandleSubmit, false);
|
1656
|
+
|
1657
|
+
if (!('returnValue' in dialog)) {
|
1658
|
+
dialog.returnValue = '';
|
1659
|
+
}
|
1660
|
+
|
1661
|
+
if ('MutationObserver' in window) {
|
1662
|
+
var mo = new MutationObserver(this.maybeHideModal.bind(this));
|
1663
|
+
mo.observe(dialog, {attributes: true, attributeFilter: ['open']});
|
1664
|
+
} else {
|
1665
|
+
// IE10 and below support. Note that DOMNodeRemoved etc fire _before_ removal. They also
|
1666
|
+
// seem to fire even if the element was removed as part of a parent removal. Use the removed
|
1667
|
+
// events to force downgrade (useful if removed/immediately added).
|
1668
|
+
var removed = false;
|
1669
|
+
var cb = function() {
|
1670
|
+
removed ? this.downgradeModal() : this.maybeHideModal();
|
1671
|
+
removed = false;
|
1672
|
+
}.bind(this);
|
1673
|
+
var timeout;
|
1674
|
+
var delayModel = function(ev) {
|
1675
|
+
if (ev.target !== dialog) { return; } // not for a child element
|
1676
|
+
var cand = 'DOMNodeRemoved';
|
1677
|
+
removed |= (ev.type.substr(0, cand.length) === cand);
|
1678
|
+
window.clearTimeout(timeout);
|
1679
|
+
timeout = window.setTimeout(cb, 0);
|
1680
|
+
};
|
1681
|
+
['DOMAttrModified', 'DOMNodeRemoved', 'DOMNodeRemovedFromDocument'].forEach(function(name) {
|
1682
|
+
dialog.addEventListener(name, delayModel);
|
1683
|
+
});
|
1684
|
+
}
|
1685
|
+
// Note that the DOM is observed inside DialogManager while any dialog
|
1686
|
+
// is being displayed as a modal, to catch modal removal from the DOM.
|
1687
|
+
|
1688
|
+
Object.defineProperty(dialog, 'open', {
|
1689
|
+
set: this.setOpen.bind(this),
|
1690
|
+
get: dialog.hasAttribute.bind(dialog, 'open')
|
1691
|
+
});
|
1692
|
+
|
1693
|
+
this.backdrop_ = document.createElement('div');
|
1694
|
+
this.backdrop_.className = 'backdrop';
|
1695
|
+
this.backdrop_.addEventListener('mouseup' , this.backdropMouseEvent_.bind(this));
|
1696
|
+
this.backdrop_.addEventListener('mousedown', this.backdropMouseEvent_.bind(this));
|
1697
|
+
this.backdrop_.addEventListener('click' , this.backdropMouseEvent_.bind(this));
|
1698
|
+
}
|
1699
|
+
|
1700
|
+
dialogPolyfillInfo.prototype = /** @type {HTMLDialogElement.prototype} */ ({
|
1701
|
+
|
1702
|
+
get dialog() {
|
1703
|
+
return this.dialog_;
|
1704
|
+
},
|
1705
|
+
|
1706
|
+
/**
|
1707
|
+
* Maybe remove this dialog from the modal top layer. This is called when
|
1708
|
+
* a modal dialog may no longer be tenable, e.g., when the dialog is no
|
1709
|
+
* longer open or is no longer part of the DOM.
|
1710
|
+
*/
|
1711
|
+
maybeHideModal: function() {
|
1712
|
+
if (this.dialog_.hasAttribute('open') && isConnected(this.dialog_)) { return; }
|
1713
|
+
this.downgradeModal();
|
1714
|
+
},
|
1715
|
+
|
1716
|
+
/**
|
1717
|
+
* Remove this dialog from the modal top layer, leaving it as a non-modal.
|
1718
|
+
*/
|
1719
|
+
downgradeModal: function() {
|
1720
|
+
if (!this.openAsModal_) { return; }
|
1721
|
+
this.openAsModal_ = false;
|
1722
|
+
this.dialog_.style.zIndex = '';
|
1723
|
+
|
1724
|
+
// This won't match the native <dialog> exactly because if the user set top on a centered
|
1725
|
+
// polyfill dialog, that top gets thrown away when the dialog is closed. Not sure it's
|
1726
|
+
// possible to polyfill this perfectly.
|
1727
|
+
if (this.replacedStyleTop_) {
|
1728
|
+
this.dialog_.style.top = '';
|
1729
|
+
this.replacedStyleTop_ = false;
|
1730
|
+
}
|
1731
|
+
|
1732
|
+
// Clear the backdrop and remove from the manager.
|
1733
|
+
this.backdrop_.parentNode && this.backdrop_.parentNode.removeChild(this.backdrop_);
|
1734
|
+
dialogPolyfill.dm.removeDialog(this);
|
1735
|
+
},
|
1736
|
+
|
1737
|
+
/**
|
1738
|
+
* @param {boolean} value whether to open or close this dialog
|
1739
|
+
*/
|
1740
|
+
setOpen: function(value) {
|
1741
|
+
if (value) {
|
1742
|
+
this.dialog_.hasAttribute('open') || this.dialog_.setAttribute('open', '');
|
1743
|
+
} else {
|
1744
|
+
this.dialog_.removeAttribute('open');
|
1745
|
+
this.maybeHideModal(); // nb. redundant with MutationObserver
|
1746
|
+
}
|
1747
|
+
},
|
1748
|
+
|
1749
|
+
/**
|
1750
|
+
* Handles mouse events ('mouseup', 'mousedown', 'click') on the fake .backdrop element, redirecting them as if
|
1751
|
+
* they were on the dialog itself.
|
1752
|
+
*
|
1753
|
+
* @param {!Event} e to redirect
|
1754
|
+
*/
|
1755
|
+
backdropMouseEvent_: function(e) {
|
1756
|
+
if (!this.dialog_.hasAttribute('tabindex')) {
|
1757
|
+
// Clicking on the backdrop should move the implicit cursor, even if dialog cannot be
|
1758
|
+
// focused. Create a fake thing to focus on. If the backdrop was _before_ the dialog, this
|
1759
|
+
// would not be needed - clicks would move the implicit cursor there.
|
1760
|
+
var fake = document.createElement('div');
|
1761
|
+
this.dialog_.insertBefore(fake, this.dialog_.firstChild);
|
1762
|
+
fake.tabIndex = -1;
|
1763
|
+
fake.focus();
|
1764
|
+
this.dialog_.removeChild(fake);
|
1765
|
+
} else {
|
1766
|
+
this.dialog_.focus();
|
1767
|
+
}
|
1768
|
+
|
1769
|
+
var redirectedEvent = document.createEvent('MouseEvents');
|
1770
|
+
redirectedEvent.initMouseEvent(e.type, e.bubbles, e.cancelable, window,
|
1771
|
+
e.detail, e.screenX, e.screenY, e.clientX, e.clientY, e.ctrlKey,
|
1772
|
+
e.altKey, e.shiftKey, e.metaKey, e.button, e.relatedTarget);
|
1773
|
+
this.dialog_.dispatchEvent(redirectedEvent);
|
1774
|
+
e.stopPropagation();
|
1775
|
+
},
|
1776
|
+
|
1777
|
+
/**
|
1778
|
+
* Focuses on the first focusable element within the dialog. This will always blur the current
|
1779
|
+
* focus, even if nothing within the dialog is found.
|
1780
|
+
*/
|
1781
|
+
focus_: function() {
|
1782
|
+
// Find element with `autofocus` attribute, or fall back to the first form/tabindex control.
|
1783
|
+
var target = this.dialog_.querySelector('[autofocus]:not([disabled])');
|
1784
|
+
if (!target && this.dialog_.tabIndex >= 0) {
|
1785
|
+
target = this.dialog_;
|
1786
|
+
}
|
1787
|
+
if (!target) {
|
1788
|
+
target = findFocusableElementWithin(this.dialog_);
|
1789
|
+
}
|
1790
|
+
safeBlur(document.activeElement);
|
1791
|
+
target && target.focus();
|
1792
|
+
},
|
1793
|
+
|
1794
|
+
/**
|
1795
|
+
* Sets the zIndex for the backdrop and dialog.
|
1796
|
+
*
|
1797
|
+
* @param {number} dialogZ
|
1798
|
+
* @param {number} backdropZ
|
1799
|
+
*/
|
1800
|
+
updateZIndex: function(dialogZ, backdropZ) {
|
1801
|
+
if (dialogZ < backdropZ) {
|
1802
|
+
throw new Error('dialogZ should never be < backdropZ');
|
1803
|
+
}
|
1804
|
+
this.dialog_.style.zIndex = dialogZ;
|
1805
|
+
this.backdrop_.style.zIndex = backdropZ;
|
1806
|
+
},
|
1807
|
+
|
1808
|
+
/**
|
1809
|
+
* Shows the dialog. If the dialog is already open, this does nothing.
|
1810
|
+
*/
|
1811
|
+
show: function() {
|
1812
|
+
if (!this.dialog_.open) {
|
1813
|
+
this.setOpen(true);
|
1814
|
+
this.focus_();
|
1815
|
+
}
|
1816
|
+
},
|
1817
|
+
|
1818
|
+
/**
|
1819
|
+
* Show this dialog modally.
|
1820
|
+
*/
|
1821
|
+
showModal: function() {
|
1822
|
+
if (this.dialog_.hasAttribute('open')) {
|
1823
|
+
throw new Error('Failed to execute \'showModal\' on dialog: The element is already open, and therefore cannot be opened modally.');
|
1824
|
+
}
|
1825
|
+
if (!isConnected(this.dialog_)) {
|
1826
|
+
throw new Error('Failed to execute \'showModal\' on dialog: The element is not in a Document.');
|
1827
|
+
}
|
1828
|
+
if (!dialogPolyfill.dm.pushDialog(this)) {
|
1829
|
+
throw new Error('Failed to execute \'showModal\' on dialog: There are too many open modal dialogs.');
|
1830
|
+
}
|
1831
|
+
|
1832
|
+
if (createsStackingContext(this.dialog_.parentElement)) {
|
1833
|
+
console.warn('A dialog is being shown inside a stacking context. ' +
|
1834
|
+
'This may cause it to be unusable. For more information, see this link: ' +
|
1835
|
+
'https://github.com/GoogleChrome/dialog-polyfill/#stacking-context');
|
1836
|
+
}
|
1837
|
+
|
1838
|
+
this.setOpen(true);
|
1839
|
+
this.openAsModal_ = true;
|
1840
|
+
|
1841
|
+
// Optionally center vertically, relative to the current viewport.
|
1842
|
+
if (dialogPolyfill.needsCentering(this.dialog_)) {
|
1843
|
+
dialogPolyfill.reposition(this.dialog_);
|
1844
|
+
this.replacedStyleTop_ = true;
|
1845
|
+
} else {
|
1846
|
+
this.replacedStyleTop_ = false;
|
1847
|
+
}
|
1848
|
+
|
1849
|
+
// Insert backdrop.
|
1850
|
+
this.dialog_.parentNode.insertBefore(this.backdrop_, this.dialog_.nextSibling);
|
1851
|
+
|
1852
|
+
// Focus on whatever inside the dialog.
|
1853
|
+
this.focus_();
|
1854
|
+
},
|
1855
|
+
|
1856
|
+
/**
|
1857
|
+
* Closes this HTMLDialogElement. This is optional vs clearing the open
|
1858
|
+
* attribute, however this fires a 'close' event.
|
1859
|
+
*
|
1860
|
+
* @param {string=} opt_returnValue to use as the returnValue
|
1861
|
+
*/
|
1862
|
+
close: function(opt_returnValue) {
|
1863
|
+
if (!this.dialog_.hasAttribute('open')) {
|
1864
|
+
throw new Error('Failed to execute \'close\' on dialog: The element does not have an \'open\' attribute, and therefore cannot be closed.');
|
1865
|
+
}
|
1866
|
+
this.setOpen(false);
|
1867
|
+
|
1868
|
+
// Leave returnValue untouched in case it was set directly on the element
|
1869
|
+
if (opt_returnValue !== undefined) {
|
1870
|
+
this.dialog_.returnValue = opt_returnValue;
|
1871
|
+
}
|
1872
|
+
|
1873
|
+
// Triggering "close" event for any attached listeners on the <dialog>.
|
1874
|
+
var closeEvent = new supportCustomEvent('close', {
|
1875
|
+
bubbles: false,
|
1876
|
+
cancelable: false
|
1877
|
+
});
|
1878
|
+
safeDispatchEvent(this.dialog_, closeEvent);
|
1879
|
+
}
|
1880
|
+
|
1881
|
+
});
|
1882
|
+
|
1883
|
+
var dialogPolyfill = {};
|
1884
|
+
|
1885
|
+
dialogPolyfill.reposition = function(element) {
|
1886
|
+
var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
|
1887
|
+
var topValue = scrollTop + (window.innerHeight - element.offsetHeight) / 2;
|
1888
|
+
element.style.top = Math.max(scrollTop, topValue) + 'px';
|
1889
|
+
};
|
1890
|
+
|
1891
|
+
dialogPolyfill.isInlinePositionSetByStylesheet = function(element) {
|
1892
|
+
for (var i = 0; i < document.styleSheets.length; ++i) {
|
1893
|
+
var styleSheet = document.styleSheets[i];
|
1894
|
+
var cssRules = null;
|
1895
|
+
// Some browsers throw on cssRules.
|
1896
|
+
try {
|
1897
|
+
cssRules = styleSheet.cssRules;
|
1898
|
+
} catch (e) {}
|
1899
|
+
if (!cssRules) { continue; }
|
1900
|
+
for (var j = 0; j < cssRules.length; ++j) {
|
1901
|
+
var rule = cssRules[j];
|
1902
|
+
var selectedNodes = null;
|
1903
|
+
// Ignore errors on invalid selector texts.
|
1904
|
+
try {
|
1905
|
+
selectedNodes = document.querySelectorAll(rule.selectorText);
|
1906
|
+
} catch(e) {}
|
1907
|
+
if (!selectedNodes || !inNodeList(selectedNodes, element)) {
|
1908
|
+
continue;
|
1909
|
+
}
|
1910
|
+
var cssTop = rule.style.getPropertyValue('top');
|
1911
|
+
var cssBottom = rule.style.getPropertyValue('bottom');
|
1912
|
+
if ((cssTop && cssTop !== 'auto') || (cssBottom && cssBottom !== 'auto')) {
|
1913
|
+
return true;
|
1914
|
+
}
|
1915
|
+
}
|
1916
|
+
}
|
1917
|
+
return false;
|
1918
|
+
};
|
1919
|
+
|
1920
|
+
dialogPolyfill.needsCentering = function(dialog) {
|
1921
|
+
var computedStyle = window.getComputedStyle(dialog);
|
1922
|
+
if (computedStyle.position !== 'absolute') {
|
1923
|
+
return false;
|
1924
|
+
}
|
1925
|
+
|
1926
|
+
// We must determine whether the top/bottom specified value is non-auto. In
|
1927
|
+
// WebKit/Blink, checking computedStyle.top == 'auto' is sufficient, but
|
1928
|
+
// Firefox returns the used value. So we do this crazy thing instead: check
|
1929
|
+
// the inline style and then go through CSS rules.
|
1930
|
+
if ((dialog.style.top !== 'auto' && dialog.style.top !== '') ||
|
1931
|
+
(dialog.style.bottom !== 'auto' && dialog.style.bottom !== '')) {
|
1932
|
+
return false;
|
1933
|
+
}
|
1934
|
+
return !dialogPolyfill.isInlinePositionSetByStylesheet(dialog);
|
1935
|
+
};
|
1936
|
+
|
1937
|
+
/**
|
1938
|
+
* @param {!Element} element to force upgrade
|
1939
|
+
*/
|
1940
|
+
dialogPolyfill.forceRegisterDialog = function(element) {
|
1941
|
+
if (window.HTMLDialogElement || element.showModal) {
|
1942
|
+
console.warn('This browser already supports <dialog>, the polyfill ' +
|
1943
|
+
'may not work correctly', element);
|
1944
|
+
}
|
1945
|
+
if (element.localName !== 'dialog') {
|
1946
|
+
throw new Error('Failed to register dialog: The element is not a dialog.');
|
1947
|
+
}
|
1948
|
+
new dialogPolyfillInfo(/** @type {!HTMLDialogElement} */ (element));
|
1949
|
+
};
|
1950
|
+
|
1951
|
+
/**
|
1952
|
+
* @param {!Element} element to upgrade, if necessary
|
1953
|
+
*/
|
1954
|
+
dialogPolyfill.registerDialog = function(element) {
|
1955
|
+
if (!element.showModal) {
|
1956
|
+
dialogPolyfill.forceRegisterDialog(element);
|
1957
|
+
}
|
1958
|
+
};
|
1959
|
+
|
1960
|
+
/**
|
1961
|
+
* @constructor
|
1962
|
+
*/
|
1963
|
+
dialogPolyfill.DialogManager = function() {
|
1964
|
+
/** @type {!Array<!dialogPolyfillInfo>} */
|
1965
|
+
this.pendingDialogStack = [];
|
1966
|
+
|
1967
|
+
var checkDOM = this.checkDOM_.bind(this);
|
1968
|
+
|
1969
|
+
// The overlay is used to simulate how a modal dialog blocks the document.
|
1970
|
+
// The blocking dialog is positioned on top of the overlay, and the rest of
|
1971
|
+
// the dialogs on the pending dialog stack are positioned below it. In the
|
1972
|
+
// actual implementation, the modal dialog stacking is controlled by the
|
1973
|
+
// top layer, where z-index has no effect.
|
1974
|
+
this.overlay = document.createElement('div');
|
1975
|
+
this.overlay.className = '_dialog_overlay';
|
1976
|
+
this.overlay.addEventListener('click', function(e) {
|
1977
|
+
this.forwardTab_ = undefined;
|
1978
|
+
e.stopPropagation();
|
1979
|
+
checkDOM([]); // sanity-check DOM
|
1980
|
+
}.bind(this));
|
1981
|
+
|
1982
|
+
this.handleKey_ = this.handleKey_.bind(this);
|
1983
|
+
this.handleFocus_ = this.handleFocus_.bind(this);
|
1984
|
+
|
1985
|
+
this.zIndexLow_ = 100000;
|
1986
|
+
this.zIndexHigh_ = 100000 + 150;
|
1987
|
+
|
1988
|
+
this.forwardTab_ = undefined;
|
1989
|
+
|
1990
|
+
if ('MutationObserver' in window) {
|
1991
|
+
this.mo_ = new MutationObserver(function(records) {
|
1992
|
+
var removed = [];
|
1993
|
+
records.forEach(function(rec) {
|
1994
|
+
for (var i = 0, c; c = rec.removedNodes[i]; ++i) {
|
1995
|
+
if (!(c instanceof Element)) {
|
1996
|
+
continue;
|
1997
|
+
} else if (c.localName === 'dialog') {
|
1998
|
+
removed.push(c);
|
1999
|
+
}
|
2000
|
+
removed = removed.concat(c.querySelectorAll('dialog'));
|
2001
|
+
}
|
2002
|
+
});
|
2003
|
+
removed.length && checkDOM(removed);
|
2004
|
+
});
|
2005
|
+
}
|
2006
|
+
};
|
2007
|
+
|
2008
|
+
/**
|
2009
|
+
* Called on the first modal dialog being shown. Adds the overlay and related
|
2010
|
+
* handlers.
|
2011
|
+
*/
|
2012
|
+
dialogPolyfill.DialogManager.prototype.blockDocument = function() {
|
2013
|
+
document.documentElement.addEventListener('focus', this.handleFocus_, true);
|
2014
|
+
document.addEventListener('keydown', this.handleKey_);
|
2015
|
+
this.mo_ && this.mo_.observe(document, {childList: true, subtree: true});
|
2016
|
+
};
|
2017
|
+
|
2018
|
+
/**
|
2019
|
+
* Called on the first modal dialog being removed, i.e., when no more modal
|
2020
|
+
* dialogs are visible.
|
2021
|
+
*/
|
2022
|
+
dialogPolyfill.DialogManager.prototype.unblockDocument = function() {
|
2023
|
+
document.documentElement.removeEventListener('focus', this.handleFocus_, true);
|
2024
|
+
document.removeEventListener('keydown', this.handleKey_);
|
2025
|
+
this.mo_ && this.mo_.disconnect();
|
2026
|
+
};
|
2027
|
+
|
2028
|
+
/**
|
2029
|
+
* Updates the stacking of all known dialogs.
|
2030
|
+
*/
|
2031
|
+
dialogPolyfill.DialogManager.prototype.updateStacking = function() {
|
2032
|
+
var zIndex = this.zIndexHigh_;
|
2033
|
+
|
2034
|
+
for (var i = 0, dpi; dpi = this.pendingDialogStack[i]; ++i) {
|
2035
|
+
dpi.updateZIndex(--zIndex, --zIndex);
|
2036
|
+
if (i === 0) {
|
2037
|
+
this.overlay.style.zIndex = --zIndex;
|
2038
|
+
}
|
2039
|
+
}
|
2040
|
+
|
2041
|
+
// Make the overlay a sibling of the dialog itself.
|
2042
|
+
var last = this.pendingDialogStack[0];
|
2043
|
+
if (last) {
|
2044
|
+
var p = last.dialog.parentNode || document.body;
|
2045
|
+
p.appendChild(this.overlay);
|
2046
|
+
} else if (this.overlay.parentNode) {
|
2047
|
+
this.overlay.parentNode.removeChild(this.overlay);
|
2048
|
+
}
|
2049
|
+
};
|
2050
|
+
|
2051
|
+
/**
|
2052
|
+
* @param {Element} candidate to check if contained or is the top-most modal dialog
|
2053
|
+
* @return {boolean} whether candidate is contained in top dialog
|
2054
|
+
*/
|
2055
|
+
dialogPolyfill.DialogManager.prototype.containedByTopDialog_ = function(candidate) {
|
2056
|
+
while (candidate = findNearestDialog(candidate)) {
|
2057
|
+
for (var i = 0, dpi; dpi = this.pendingDialogStack[i]; ++i) {
|
2058
|
+
if (dpi.dialog === candidate) {
|
2059
|
+
return i === 0; // only valid if top-most
|
2060
|
+
}
|
2061
|
+
}
|
2062
|
+
candidate = candidate.parentElement;
|
2063
|
+
}
|
2064
|
+
return false;
|
2065
|
+
};
|
2066
|
+
|
2067
|
+
dialogPolyfill.DialogManager.prototype.handleFocus_ = function(event) {
|
2068
|
+
var target = event.composedPath ? event.composedPath()[0] : event.target;
|
2069
|
+
|
2070
|
+
if (this.containedByTopDialog_(target)) { return; }
|
2071
|
+
|
2072
|
+
if (document.activeElement === document.documentElement) { return; }
|
2073
|
+
|
2074
|
+
event.preventDefault();
|
2075
|
+
event.stopPropagation();
|
2076
|
+
safeBlur(/** @type {Element} */ (target));
|
2077
|
+
|
2078
|
+
if (this.forwardTab_ === undefined) { return; } // move focus only from a tab key
|
2079
|
+
|
2080
|
+
var dpi = this.pendingDialogStack[0];
|
2081
|
+
var dialog = dpi.dialog;
|
2082
|
+
var position = dialog.compareDocumentPosition(target);
|
2083
|
+
if (position & Node.DOCUMENT_POSITION_PRECEDING) {
|
2084
|
+
if (this.forwardTab_) {
|
2085
|
+
// forward
|
2086
|
+
dpi.focus_();
|
2087
|
+
} else if (target !== document.documentElement) {
|
2088
|
+
// backwards if we're not already focused on <html>
|
2089
|
+
document.documentElement.focus();
|
2090
|
+
}
|
2091
|
+
}
|
2092
|
+
|
2093
|
+
return false;
|
2094
|
+
};
|
2095
|
+
|
2096
|
+
dialogPolyfill.DialogManager.prototype.handleKey_ = function(event) {
|
2097
|
+
this.forwardTab_ = undefined;
|
2098
|
+
if (event.keyCode === 27) {
|
2099
|
+
event.preventDefault();
|
2100
|
+
event.stopPropagation();
|
2101
|
+
var cancelEvent = new supportCustomEvent('cancel', {
|
2102
|
+
bubbles: false,
|
2103
|
+
cancelable: true
|
2104
|
+
});
|
2105
|
+
var dpi = this.pendingDialogStack[0];
|
2106
|
+
if (dpi && safeDispatchEvent(dpi.dialog, cancelEvent)) {
|
2107
|
+
dpi.dialog.close();
|
2108
|
+
}
|
2109
|
+
} else if (event.keyCode === 9) {
|
2110
|
+
this.forwardTab_ = !event.shiftKey;
|
2111
|
+
}
|
2112
|
+
};
|
2113
|
+
|
2114
|
+
/**
|
2115
|
+
* Finds and downgrades any known modal dialogs that are no longer displayed. Dialogs that are
|
2116
|
+
* removed and immediately readded don't stay modal, they become normal.
|
2117
|
+
*
|
2118
|
+
* @param {!Array<!HTMLDialogElement>} removed that have definitely been removed
|
2119
|
+
*/
|
2120
|
+
dialogPolyfill.DialogManager.prototype.checkDOM_ = function(removed) {
|
2121
|
+
// This operates on a clone because it may cause it to change. Each change also calls
|
2122
|
+
// updateStacking, which only actually needs to happen once. But who removes many modal dialogs
|
2123
|
+
// at a time?!
|
2124
|
+
var clone = this.pendingDialogStack.slice();
|
2125
|
+
clone.forEach(function(dpi) {
|
2126
|
+
if (removed.indexOf(dpi.dialog) !== -1) {
|
2127
|
+
dpi.downgradeModal();
|
2128
|
+
} else {
|
2129
|
+
dpi.maybeHideModal();
|
2130
|
+
}
|
2131
|
+
});
|
2132
|
+
};
|
2133
|
+
|
2134
|
+
/**
|
2135
|
+
* @param {!dialogPolyfillInfo} dpi
|
2136
|
+
* @return {boolean} whether the dialog was allowed
|
2137
|
+
*/
|
2138
|
+
dialogPolyfill.DialogManager.prototype.pushDialog = function(dpi) {
|
2139
|
+
var allowed = (this.zIndexHigh_ - this.zIndexLow_) / 2 - 1;
|
2140
|
+
if (this.pendingDialogStack.length >= allowed) {
|
2141
|
+
return false;
|
2142
|
+
}
|
2143
|
+
if (this.pendingDialogStack.unshift(dpi) === 1) {
|
2144
|
+
this.blockDocument();
|
2145
|
+
}
|
2146
|
+
this.updateStacking();
|
2147
|
+
return true;
|
2148
|
+
};
|
2149
|
+
|
2150
|
+
/**
|
2151
|
+
* @param {!dialogPolyfillInfo} dpi
|
2152
|
+
*/
|
2153
|
+
dialogPolyfill.DialogManager.prototype.removeDialog = function(dpi) {
|
2154
|
+
var index = this.pendingDialogStack.indexOf(dpi);
|
2155
|
+
if (index === -1) { return; }
|
2156
|
+
|
2157
|
+
this.pendingDialogStack.splice(index, 1);
|
2158
|
+
if (this.pendingDialogStack.length === 0) {
|
2159
|
+
this.unblockDocument();
|
2160
|
+
}
|
2161
|
+
this.updateStacking();
|
2162
|
+
};
|
2163
|
+
|
2164
|
+
dialogPolyfill.dm = new dialogPolyfill.DialogManager();
|
2165
|
+
dialogPolyfill.formSubmitter = null;
|
2166
|
+
dialogPolyfill.imagemapUseValue = null;
|
2167
|
+
|
2168
|
+
/**
|
2169
|
+
* Installs global handlers, such as click listers and native method overrides. These are needed
|
2170
|
+
* even if a no dialog is registered, as they deal with <form method="dialog">.
|
2171
|
+
*/
|
2172
|
+
if (window.HTMLDialogElement === undefined) {
|
2173
|
+
|
2174
|
+
/**
|
2175
|
+
* If HTMLFormElement translates method="DIALOG" into 'get', then replace the descriptor with
|
2176
|
+
* one that returns the correct value.
|
2177
|
+
*/
|
2178
|
+
var testForm = document.createElement('form');
|
2179
|
+
testForm.setAttribute('method', 'dialog');
|
2180
|
+
if (testForm.method !== 'dialog') {
|
2181
|
+
var methodDescriptor = Object.getOwnPropertyDescriptor(HTMLFormElement.prototype, 'method');
|
2182
|
+
if (methodDescriptor) {
|
2183
|
+
// nb. Some older iOS and older PhantomJS fail to return the descriptor. Don't do anything
|
2184
|
+
// and don't bother to update the element.
|
2185
|
+
var realGet = methodDescriptor.get;
|
2186
|
+
methodDescriptor.get = function() {
|
2187
|
+
if (isFormMethodDialog(this)) {
|
2188
|
+
return 'dialog';
|
2189
|
+
}
|
2190
|
+
return realGet.call(this);
|
2191
|
+
};
|
2192
|
+
var realSet = methodDescriptor.set;
|
2193
|
+
/** @this {HTMLElement} */
|
2194
|
+
methodDescriptor.set = function(v) {
|
2195
|
+
if (typeof v === 'string' && v.toLowerCase() === 'dialog') {
|
2196
|
+
return this.setAttribute('method', v);
|
2197
|
+
}
|
2198
|
+
return realSet.call(this, v);
|
2199
|
+
};
|
2200
|
+
Object.defineProperty(HTMLFormElement.prototype, 'method', methodDescriptor);
|
2201
|
+
}
|
2202
|
+
}
|
2203
|
+
|
2204
|
+
/**
|
2205
|
+
* Global 'click' handler, to capture the <input type="submit"> or <button> element which has
|
2206
|
+
* submitted a <form method="dialog">. Needed as Safari and others don't report this inside
|
2207
|
+
* document.activeElement.
|
2208
|
+
*/
|
2209
|
+
document.addEventListener('click', function(ev) {
|
2210
|
+
dialogPolyfill.formSubmitter = null;
|
2211
|
+
dialogPolyfill.imagemapUseValue = null;
|
2212
|
+
if (ev.defaultPrevented) { return; } // e.g. a submit which prevents default submission
|
2213
|
+
|
2214
|
+
var target = /** @type {Element} */ (ev.target);
|
2215
|
+
if ('composedPath' in ev) {
|
2216
|
+
var path = ev.composedPath();
|
2217
|
+
target = path.shift() || target;
|
2218
|
+
}
|
2219
|
+
if (!target || !isFormMethodDialog(target.form)) { return; }
|
2220
|
+
|
2221
|
+
var valid = (target.type === 'submit' && ['button', 'input'].indexOf(target.localName) > -1);
|
2222
|
+
if (!valid) {
|
2223
|
+
if (!(target.localName === 'input' && target.type === 'image')) { return; }
|
2224
|
+
// this is a <input type="image">, which can submit forms
|
2225
|
+
dialogPolyfill.imagemapUseValue = ev.offsetX + ',' + ev.offsetY;
|
2226
|
+
}
|
2227
|
+
|
2228
|
+
var dialog = findNearestDialog(target);
|
2229
|
+
if (!dialog) { return; }
|
2230
|
+
|
2231
|
+
dialogPolyfill.formSubmitter = target;
|
2232
|
+
|
2233
|
+
}, false);
|
2234
|
+
|
2235
|
+
/**
|
2236
|
+
* Global 'submit' handler. This handles submits of `method="dialog"` which are invalid, i.e.,
|
2237
|
+
* outside a dialog. They get prevented.
|
2238
|
+
*/
|
2239
|
+
document.addEventListener('submit', function(ev) {
|
2240
|
+
var form = ev.target;
|
2241
|
+
var dialog = findNearestDialog(form);
|
2242
|
+
if (dialog) {
|
2243
|
+
return; // ignore, handle there
|
2244
|
+
}
|
2245
|
+
|
2246
|
+
var submitter = findFormSubmitter(ev);
|
2247
|
+
var formmethod = submitter && submitter.getAttribute('formmethod') || form.getAttribute('method');
|
2248
|
+
if (formmethod === 'dialog') {
|
2249
|
+
ev.preventDefault();
|
2250
|
+
}
|
2251
|
+
});
|
2252
|
+
|
2253
|
+
/**
|
2254
|
+
* Replace the native HTMLFormElement.submit() method, as it won't fire the
|
2255
|
+
* submit event and give us a chance to respond.
|
2256
|
+
*/
|
2257
|
+
var nativeFormSubmit = HTMLFormElement.prototype.submit;
|
2258
|
+
var replacementFormSubmit = function () {
|
2259
|
+
if (!isFormMethodDialog(this)) {
|
2260
|
+
return nativeFormSubmit.call(this);
|
2261
|
+
}
|
2262
|
+
var dialog = findNearestDialog(this);
|
2263
|
+
dialog && dialog.close();
|
2264
|
+
};
|
2265
|
+
HTMLFormElement.prototype.submit = replacementFormSubmit;
|
2266
|
+
}
|
2267
|
+
|
2268
|
+
return dialogPolyfill;
|
2269
|
+
|
2270
|
+
}));
|
2271
|
+
|
2272
|
+
},{}],14:[function(require,module,exports){
|
1390
2273
|
(function (global){(function (){
|
1391
2274
|
(function (global, factory) {
|
1392
2275
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
@@ -4006,7 +4889,7 @@ exports.Tabs = Tabs;
|
|
4006
4889
|
})));
|
4007
4890
|
|
4008
4891
|
}).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
4009
|
-
},{}],
|
4892
|
+
},{}],15:[function(require,module,exports){
|
4010
4893
|
/*!
|
4011
4894
|
* jQuery JavaScript Library v3.7.1
|
4012
4895
|
* https://jquery.com/
|
@@ -14724,7 +15607,7 @@ if ( typeof noGlobal === "undefined" ) {
|
|
14724
15607
|
return jQuery;
|
14725
15608
|
} );
|
14726
15609
|
|
14727
|
-
},{}],
|
15610
|
+
},{}],16:[function(require,module,exports){
|
14728
15611
|
(function (global){(function (){
|
14729
15612
|
/**
|
14730
15613
|
* @license
|
@@ -31937,7 +32820,7 @@ return jQuery;
|
|
31937
32820
|
}.call(this));
|
31938
32821
|
|
31939
32822
|
}).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
31940
|
-
},{}],
|
32823
|
+
},{}],17:[function(require,module,exports){
|
31941
32824
|
// shim for using process in browser
|
31942
32825
|
var process = module.exports = {};
|
31943
32826
|
|
@@ -32123,7 +33006,7 @@ process.chdir = function (dir) {
|
|
32123
33006
|
};
|
32124
33007
|
process.umask = function() { return 0; };
|
32125
33008
|
|
32126
|
-
},{}],
|
33009
|
+
},{}],18:[function(require,module,exports){
|
32127
33010
|
(function (setImmediate,clearImmediate){(function (){
|
32128
33011
|
var nextTick = require('process/browser.js').nextTick;
|
32129
33012
|
var apply = Function.prototype.apply;
|
@@ -32202,7 +33085,7 @@ exports.clearImmediate = typeof clearImmediate === "function" ? clearImmediate :
|
|
32202
33085
|
delete immediateIds[id];
|
32203
33086
|
};
|
32204
33087
|
}).call(this)}).call(this,require("timers").setImmediate,require("timers").clearImmediate)
|
32205
|
-
},{"process/browser.js":
|
33088
|
+
},{"process/browser.js":17,"timers":18}],19:[function(require,module,exports){
|
32206
33089
|
/* eslint-disable */
|
32207
33090
|
'use strict'
|
32208
33091
|
|
@@ -32274,9 +33157,9 @@ $('.typeahead').each(function applyTypeahead() {
|
|
32274
33157
|
});
|
32275
33158
|
});
|
32276
33159
|
|
32277
|
-
},{"../../../frontend/themes/gov-uk/client-js":3,"jquery":
|
32278
|
-
arguments[4][
|
32279
|
-
},{"dup":
|
33160
|
+
},{"../../../frontend/themes/gov-uk/client-js":3,"jquery":20,"typeahead-aria":23}],20:[function(require,module,exports){
|
33161
|
+
arguments[4][15][0].apply(exports,arguments)
|
33162
|
+
},{"dup":15}],21:[function(require,module,exports){
|
32280
33163
|
/*!
|
32281
33164
|
* typeahead.js 1.0.4
|
32282
33165
|
* https://github.com/twitter/typeahead.js
|
@@ -33229,7 +34112,7 @@ arguments[4][14][0].apply(exports,arguments)
|
|
33229
34112
|
}();
|
33230
34113
|
return Bloodhound;
|
33231
34114
|
});
|
33232
|
-
},{"jquery":
|
34115
|
+
},{"jquery":24}],22:[function(require,module,exports){
|
33233
34116
|
(function (setImmediate){(function (){
|
33234
34117
|
/*!
|
33235
34118
|
* typeahead.js 1.0.4
|
@@ -35826,7 +36709,7 @@ arguments[4][14][0].apply(exports,arguments)
|
|
35826
36709
|
})();
|
35827
36710
|
});
|
35828
36711
|
}).call(this)}).call(this,require("timers").setImmediate)
|
35829
|
-
},{"jquery":
|
36712
|
+
},{"jquery":24,"timers":18}],23:[function(require,module,exports){
|
35830
36713
|
'use strict';
|
35831
36714
|
|
35832
36715
|
module.exports = {
|
@@ -35834,7 +36717,7 @@ module.exports = {
|
|
35834
36717
|
"loadjQueryPlugin": function() {require("./dist/typeahead.bundle.js");}
|
35835
36718
|
};
|
35836
36719
|
|
35837
|
-
},{"./dist/bloodhound.js":
|
36720
|
+
},{"./dist/bloodhound.js":21,"./dist/typeahead.bundle.js":22}],24:[function(require,module,exports){
|
35838
36721
|
/*!
|
35839
36722
|
* jQuery JavaScript Library v3.6.0
|
35840
36723
|
* https://jquery.com/
|
@@ -46717,4 +47600,4 @@ if ( typeof noGlobal === "undefined" ) {
|
|
46717
47600
|
return jQuery;
|
46718
47601
|
} );
|
46719
47602
|
|
46720
|
-
},{}]},{},[
|
47603
|
+
},{}]},{},[19]);
|