MCPcopy Create free account
hub / github.com/cafebazaar/blacksmith / baseInputType

Function baseInputType

web/static/bower_components/angular/angular.js:21640–21728  ·  view source on GitHub ↗
(scope, element, attr, ctrl, $sniffer, $browser)

Source from the content-addressed store, hash-verified

21638}
21639
21640function baseInputType(scope, element, attr, ctrl, $sniffer, $browser) {
21641 var type = lowercase(element[0].type);
21642
21643 // In composition mode, users are still inputing intermediate text buffer,
21644 // hold the listener until composition is done.
21645 // More about composition events: https://developer.mozilla.org/en-US/docs/Web/API/CompositionEvent
21646 if (!$sniffer.android) {
21647 var composing = false;
21648
21649 element.on('compositionstart', function(data) {
21650 composing = true;
21651 });
21652
21653 element.on('compositionend', function() {
21654 composing = false;
21655 listener();
21656 });
21657 }
21658
21659 var listener = function(ev) {
21660 if (timeout) {
21661 $browser.defer.cancel(timeout);
21662 timeout = null;
21663 }
21664 if (composing) return;
21665 var value = element.val(),
21666 event = ev && ev.type;
21667
21668 // By default we will trim the value
21669 // If the attribute ng-trim exists we will avoid trimming
21670 // If input type is 'password', the value is never trimmed
21671 if (type !== 'password' && (!attr.ngTrim || attr.ngTrim !== 'false')) {
21672 value = trim(value);
21673 }
21674
21675 // If a control is suffering from bad input (due to native validators), browsers discard its
21676 // value, so it may be necessary to revalidate (by calling $setViewValue again) even if the
21677 // control's value is the same empty value twice in a row.
21678 if (ctrl.$viewValue !== value || (value === '' && ctrl.$$hasNativeValidators)) {
21679 ctrl.$setViewValue(value, event);
21680 }
21681 };
21682
21683 // if the browser does support "input" event, we are fine - except on IE9 which doesn't fire the
21684 // input event on backspace, delete or cut
21685 if ($sniffer.hasEvent('input')) {
21686 element.on('input', listener);
21687 } else {
21688 var timeout;
21689
21690 var deferListener = function(ev, input, origValue) {
21691 if (!timeout) {
21692 timeout = $browser.defer(function() {
21693 timeout = null;
21694 if (!input || input.value !== origValue) {
21695 listener(ev);
21696 }
21697 });

Callers 5

textInputTypeFunction · 0.85
createDateInputTypeFunction · 0.85
numberInputTypeFunction · 0.85
urlInputTypeFunction · 0.85
emailInputTypeFunction · 0.85

Calls 3

lowercaseFunction · 0.85
listenerFunction · 0.85
deferListenerFunction · 0.85

Tested by

no test coverage detected