MCPcopy Create free account
hub / github.com/EricSimons/ionic-course / baseInputType

Function baseInputType

code/songhop/www/lib/angular/angular.js:19547–19631  ·  view source on GitHub ↗
(scope, element, attr, ctrl, $sniffer, $browser)

Source from the content-addressed store, hash-verified

19545}
19546
19547function baseInputType(scope, element, attr, ctrl, $sniffer, $browser) {
19548 var type = lowercase(element[0].type);
19549
19550 // In composition mode, users are still inputing intermediate text buffer,
19551 // hold the listener until composition is done.
19552 // More about composition events: https://developer.mozilla.org/en-US/docs/Web/API/CompositionEvent
19553 if (!$sniffer.android) {
19554 var composing = false;
19555
19556 element.on('compositionstart', function(data) {
19557 composing = true;
19558 });
19559
19560 element.on('compositionend', function() {
19561 composing = false;
19562 listener();
19563 });
19564 }
19565
19566 var listener = function(ev) {
19567 if (timeout) {
19568 $browser.defer.cancel(timeout);
19569 timeout = null;
19570 }
19571 if (composing) return;
19572 var value = element.val(),
19573 event = ev && ev.type;
19574
19575 // By default we will trim the value
19576 // If the attribute ng-trim exists we will avoid trimming
19577 // If input type is 'password', the value is never trimmed
19578 if (type !== 'password' && (!attr.ngTrim || attr.ngTrim !== 'false')) {
19579 value = trim(value);
19580 }
19581
19582 // If a control is suffering from bad input (due to native validators), browsers discard its
19583 // value, so it may be necessary to revalidate (by calling $setViewValue again) even if the
19584 // control's value is the same empty value twice in a row.
19585 if (ctrl.$viewValue !== value || (value === '' && ctrl.$$hasNativeValidators)) {
19586 ctrl.$setViewValue(value, event);
19587 }
19588 };
19589
19590 // if the browser does support "input" event, we are fine - except on IE9 which doesn't fire the
19591 // input event on backspace, delete or cut
19592 if ($sniffer.hasEvent('input')) {
19593 element.on('input', listener);
19594 } else {
19595 var timeout;
19596
19597 var deferListener = function(ev, input, origValue) {
19598 if (!timeout) {
19599 timeout = $browser.defer(function() {
19600 timeout = null;
19601 if (!input || input.value !== origValue) {
19602 listener(ev);
19603 }
19604 });

Callers 5

textInputTypeFunction · 0.70
createDateInputTypeFunction · 0.70
numberInputTypeFunction · 0.70
urlInputTypeFunction · 0.70
emailInputTypeFunction · 0.70

Calls 3

lowercaseFunction · 0.70
listenerFunction · 0.70
deferListenerFunction · 0.70

Tested by

no test coverage detected