MCPcopy Create free account
hub / github.com/apache/cloudstack / textInputType

Function textInputType

tools/ngui/static/js/lib/angular.js:11499–11619  ·  view source on GitHub ↗
(scope, element, attr, ctrl, $sniffer, $browser)

Source from the content-addressed store, hash-verified

11497
11498
11499function textInputType(scope, element, attr, ctrl, $sniffer, $browser) {
11500
11501 var listener = function() {
11502 var value = trim(element.val());
11503
11504 if (ctrl.$viewValue !== value) {
11505 scope.$apply(function() {
11506 ctrl.$setViewValue(value);
11507 });
11508 }
11509 };
11510
11511 // if the browser does support "input" event, we are fine - except on IE9 which doesn't fire the
11512 // input event on backspace, delete or cut
11513 if ($sniffer.hasEvent('input')) {
11514 element.bind('input', listener);
11515 } else {
11516 var timeout;
11517
11518 var deferListener = function() {
11519 if (!timeout) {
11520 timeout = $browser.defer(function() {
11521 listener();
11522 timeout = null;
11523 });
11524 }
11525 };
11526
11527 element.bind('keydown', function(event) {
11528 var key = event.keyCode;
11529
11530 // ignore
11531 // command modifiers arrows
11532 if (key === 91 || (15 < key && key < 19) || (37 <= key && key <= 40)) return;
11533
11534 deferListener();
11535 });
11536
11537 // if user paste into input using mouse, we need "change" event to catch it
11538 element.bind('change', listener);
11539
11540 // if user modifies input value using context menu in IE, we need "paste" and "cut" events to catch it
11541 if ($sniffer.hasEvent('paste')) {
11542 element.bind('paste cut', deferListener);
11543 }
11544 }
11545
11546
11547 ctrl.$render = function() {
11548 element.val(isEmpty(ctrl.$viewValue) ? '' : ctrl.$viewValue);
11549 };
11550
11551 // pattern validator
11552 var pattern = attr.ngPattern,
11553 patternValidator;
11554
11555 var validate = function(regexp, value) {
11556 if (isEmpty(value) || regexp.test(value)) {

Callers 3

numberInputTypeFunction · 0.85
urlInputTypeFunction · 0.85
emailInputTypeFunction · 0.85

Calls 5

deferListenerFunction · 0.85
isEmptyFunction · 0.85
validateFunction · 0.85
intFunction · 0.85
matchMethod · 0.45

Tested by

no test coverage detected