MCPcopy Create free account
hub / github.com/binux/qiandao / textInputType

Function textInputType

web/static/components/angularjs/angular.js:16923–17072  ·  view source on GitHub ↗
(scope, element, attr, ctrl, $sniffer, $browser)

Source from the content-addressed store, hash-verified

16921}
16922
16923function textInputType(scope, element, attr, ctrl, $sniffer, $browser) {
16924 var validity = element.prop(VALIDITY_STATE_PROPERTY);
16925 var placeholder = element[0].placeholder, noevent = {};
16926 ctrl.$$validityState = validity;
16927
16928 // In composition mode, users are still inputing intermediate text buffer,
16929 // hold the listener until composition is done.
16930 // More about composition events: https://developer.mozilla.org/en-US/docs/Web/API/CompositionEvent
16931 if (!$sniffer.android) {
16932 var composing = false;
16933
16934 element.on('compositionstart', function(data) {
16935 composing = true;
16936 });
16937
16938 element.on('compositionend', function() {
16939 composing = false;
16940 listener();
16941 });
16942 }
16943
16944 var listener = function(ev) {
16945 if (composing) return;
16946 var value = element.val();
16947
16948 // IE (11 and under) seem to emit an 'input' event if the placeholder value changes.
16949 // We don't want to dirty the value when this happens, so we abort here. Unfortunately,
16950 // IE also sends input events for other non-input-related things, (such as focusing on a
16951 // form control), so this change is not entirely enough to solve this.
16952 if (msie && (ev || noevent).type === 'input' && element[0].placeholder !== placeholder) {
16953 placeholder = element[0].placeholder;
16954 return;
16955 }
16956
16957 // By default we will trim the value
16958 // If the attribute ng-trim exists we will avoid trimming
16959 // e.g. <input ng-model="foo" ng-trim="false">
16960 if (toBoolean(attr.ngTrim || 'T')) {
16961 value = trim(value);
16962 }
16963
16964 // If a control is suffering from bad input, browsers discard its value, so it may be
16965 // necessary to revalidate even if the control's value is the same empty value twice in
16966 // a row.
16967 var revalidate = validity && ctrl.$$hasNativeValidators;
16968 if (ctrl.$viewValue !== value || (value === '' && revalidate)) {
16969 if (scope.$$phase) {
16970 ctrl.$setViewValue(value);
16971 } else {
16972 scope.$apply(function() {
16973 ctrl.$setViewValue(value);
16974 });
16975 }
16976 }
16977 };
16978
16979 // if the browser does support "input" event, we are fine - except on IE9 which doesn't fire the
16980 // input event on backspace, delete or cut

Callers 3

numberInputTypeFunction · 0.85
urlInputTypeFunction · 0.85
emailInputTypeFunction · 0.85

Calls 6

listenerFunction · 0.85
deferListenerFunction · 0.85
validateRegexFunction · 0.85
minErrFunction · 0.85
startingTagFunction · 0.85
intFunction · 0.85

Tested by

no test coverage detected