MCPcopy
hub / github.com/ampproject/amphtml / patchValueProperty

Function patchValueProperty

third_party/inputmask/inputmask.js:2481–2596  ·  view source on GitHub ↗
(npt)

Source from the content-addressed store, hash-verified

2479 function mask(elem) {
2480 function isElementTypeSupported(input, opts) {
2481 function patchValueProperty(npt) {
2482 var valueGet;
2483 var valueSet;
2484 function patchValhook(type) {
2485 if ($.valHooks && ($.valHooks[type] === undefined || $.valHooks[type].inputmaskpatch !== true)) {
2486 var valhookGet = $.valHooks[type] && $.valHooks[type].get ? $.valHooks[type].get : function(elem) {
2487 return elem.value;
2488 };
2489 var valhookSet = $.valHooks[type] && $.valHooks[type].set ? $.valHooks[type].set : function(elem, value) {
2490 elem.value = value;
2491 return elem;
2492 };
2493 $.valHooks[type] = {
2494 get: function(elem) {
2495 if (elem.inputmask) {
2496 if (elem.inputmask.opts.autoUnmask) {
2497 return elem.inputmask.unmaskedvalue();
2498 } else {
2499 var result = valhookGet(elem);
2500 return getLastValidPosition(undefined, undefined, elem.inputmask.maskset.validPositions) !== -1 || opts.nullable !== true ? result : "";
2501 }
2502 } else return valhookGet(elem);
2503 },
2504 set: function(elem, value) {
2505 var $elem = $(elem), result;
2506 result = valhookSet(elem, value);
2507 if (elem.inputmask) {
2508 $elem.trigger("setvalue", [ value ]);
2509 }
2510 return result;
2511 },
2512 inputmaskpatch: true
2513 };
2514 }
2515 }
2516 function getter() {
2517 if (this.inputmask) {
2518 return this.inputmask.opts.autoUnmask ? this.inputmask.unmaskedvalue() : getLastValidPosition() !== -1 || opts.nullable !== true ? document.activeElement === this && opts.clearMaskOnLostFocus ? (isRTL ? clearOptionalTail(getBuffer().slice()).reverse() : clearOptionalTail(getBuffer().slice())).join("") : valueGet.call(this) : "";
2519 } else return valueGet.call(this);
2520 }
2521 function setter(value) {
2522 valueSet.call(this, value);
2523 if (this.inputmask) {
2524 $(this).trigger("setvalue", [ value ]);
2525 }
2526 }
2527 function installNativeValueSetFallback(npt) {
2528 EventRuler.on(npt, "mouseenter", function(event) {
2529 var $input = $(this), input = this, value = input.inputmask._valueGet();
2530 if (!opts.showMaskOnHover) {
2531 return;
2532 }
2533 if (value !== getBuffer().join("")) {
2534 $input.trigger("setvalue");
2535 }
2536 });
2537 }
2538 if (!npt.inputmask.__valueGet) {

Callers 1

isElementTypeSupportedFunction · 0.85

Calls 3

patchValhookFunction · 0.85
reverseMethod · 0.45

Tested by

no test coverage detected