mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
rework dialogs
This commit is contained in:
parent
5a71a65637
commit
5b66bb9ecb
39 changed files with 486 additions and 121 deletions
|
@ -9,6 +9,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||
-->
|
||||
|
||||
<link rel="import" href="../polymer/polymer.html">
|
||||
<link rel="import" href="../iron-a11y-announcer/iron-a11y-announcer.html">
|
||||
<link rel="import" href="../iron-validatable-behavior/iron-validatable-behavior.html">
|
||||
|
||||
<script>
|
||||
|
@ -68,18 +69,22 @@ is separate from validation, and `allowed-pattern` does not affect how the input
|
|||
},
|
||||
|
||||
/**
|
||||
* Set to true to prevent the user from entering invalid input. The new input characters are
|
||||
* matched with `allowedPattern` if it is set, otherwise it will use the `type` attribute (only
|
||||
* supported for `type=number`).
|
||||
* Set to true to prevent the user from entering invalid input. If `allowedPattern` is set,
|
||||
* any character typed by the user will be matched against that pattern, and rejected if it's not a match.
|
||||
* Pasted input will have each character checked individually; if any character
|
||||
* doesn't match `allowedPattern`, the entire pasted string will be rejected.
|
||||
* If `allowedPattern` is not set, it will use the `type` attribute (only supported for `type=number`).
|
||||
*/
|
||||
preventInvalidInput: {
|
||||
type: Boolean
|
||||
},
|
||||
|
||||
/**
|
||||
* Regular expression expressing a set of characters to enforce the validity of input characters.
|
||||
* The recommended value should follow this format: `[a-ZA-Z0-9.+-!;:]` that list the characters
|
||||
* allowed as input.
|
||||
* Regular expression that list the characters allowed as input.
|
||||
* This pattern represents the allowed characters for the field; as the user inputs text,
|
||||
* each individual character will be checked against the pattern (rather than checking
|
||||
* the entire value as a whole). The recommended format should be a list of allowed characters;
|
||||
* for example, `[a-zA-Z0-9.+-!;:]`
|
||||
*/
|
||||
allowedPattern: {
|
||||
type: String,
|
||||
|
@ -103,6 +108,46 @@ is separate from validation, and `allowed-pattern` does not affect how the input
|
|||
'keypress': '_onKeypress'
|
||||
},
|
||||
|
||||
registered: function() {
|
||||
// Feature detect whether we need to patch dispatchEvent (i.e. on FF and IE).
|
||||
if (!this._canDispatchEventOnDisabled()) {
|
||||
this._origDispatchEvent = this.dispatchEvent;
|
||||
this.dispatchEvent = this._dispatchEventFirefoxIE;
|
||||
}
|
||||
},
|
||||
|
||||
created: function() {
|
||||
Polymer.IronA11yAnnouncer.requestAvailability();
|
||||
},
|
||||
|
||||
_canDispatchEventOnDisabled: function() {
|
||||
var input = document.createElement('input');
|
||||
var canDispatch = false;
|
||||
input.disabled = true;
|
||||
|
||||
input.addEventListener('feature-check-dispatch-event', function() {
|
||||
canDispatch = true;
|
||||
});
|
||||
|
||||
try {
|
||||
input.dispatchEvent(new Event('feature-check-dispatch-event'));
|
||||
} catch(e) {}
|
||||
|
||||
return canDispatch;
|
||||
},
|
||||
|
||||
_dispatchEventFirefoxIE: function() {
|
||||
// Due to Firefox bug, events fired on disabled form controls can throw
|
||||
// errors; furthermore, neither IE nor Firefox will actually dispatch
|
||||
// events from disabled form controls; as such, we toggle disable around
|
||||
// the dispatch to allow notifying properties to notify
|
||||
// See issue #47 for details
|
||||
var disabled = this.disabled;
|
||||
this.disabled = false;
|
||||
this._origDispatchEvent.apply(this, arguments);
|
||||
this.disabled = disabled;
|
||||
},
|
||||
|
||||
get _patternRegExp() {
|
||||
var pattern;
|
||||
if (this.allowedPattern) {
|
||||
|
@ -143,6 +188,7 @@ is separate from validation, and `allowed-pattern` does not affect how the input
|
|||
if (this.preventInvalidInput && !this._patternAlreadyChecked) {
|
||||
var valid = this._checkPatternValidity();
|
||||
if (!valid) {
|
||||
this._announceInvalidCharacter('Invalid string of characters not entered.');
|
||||
this.value = this._previousValidInput;
|
||||
}
|
||||
}
|
||||
|
@ -203,6 +249,7 @@ is separate from validation, and `allowed-pattern` does not affect how the input
|
|||
var thisChar = String.fromCharCode(event.charCode);
|
||||
if (this._isPrintable(event) && !regexp.test(thisChar)) {
|
||||
event.preventDefault();
|
||||
this._announceInvalidCharacter('Invalid character ' + thisChar + ' not entered.');
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -225,23 +272,29 @@ is separate from validation, and `allowed-pattern` does not affect how the input
|
|||
* @return {boolean} True if the value is valid.
|
||||
*/
|
||||
validate: function() {
|
||||
// Empty, non-required input is valid.
|
||||
if (!this.required && this.value == '') {
|
||||
this.invalid = false;
|
||||
return true;
|
||||
// First, check what the browser thinks. Some inputs (like type=number)
|
||||
// behave weirdly and will set the value to "" if something invalid is
|
||||
// entered, but will set the validity correctly.
|
||||
var valid = this.checkValidity();
|
||||
|
||||
// Only do extra checking if the browser thought this was valid.
|
||||
if (valid) {
|
||||
// Empty, required input is invalid
|
||||
if (this.required && this.value === '') {
|
||||
valid = false;
|
||||
} else if (this.hasValidator()) {
|
||||
valid = Polymer.IronValidatableBehavior.validate.call(this, this.value);
|
||||
}
|
||||
}
|
||||
|
||||
var valid;
|
||||
if (this.hasValidator()) {
|
||||
valid = Polymer.IronValidatableBehavior.validate.call(this, this.value);
|
||||
} else {
|
||||
valid = this.checkValidity();
|
||||
this.invalid = !valid;
|
||||
}
|
||||
this.invalid = !valid;
|
||||
this.fire('iron-input-validate');
|
||||
return valid;
|
||||
}
|
||||
},
|
||||
|
||||
_announceInvalidCharacter: function(message) {
|
||||
this.fire('iron-announce', { text: message });
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue