Skip to content

Commit

Permalink
🐛🏗 Fix mask appearing on hover. Use patch pattern (ampproject#19873)
Browse files Browse the repository at this point in the history
* Fix mask appearing on hover. Use patch pattern

* Add wildcard patch
  • Loading branch information
cvializ authored and Noran Azmy committed Mar 22, 2019
1 parent 94a6f10 commit a7c3982
Show file tree
Hide file tree
Showing 11 changed files with 1,235 additions and 19 deletions.
20 changes: 13 additions & 7 deletions third_party/inputmask/README.amp
@@ -1,12 +1,18 @@
URL: https://github.com/RobinHerbots/Inputmask/tree/4.x
URL: https://github.com/RobinHerbots/Inputmask/tree/3.x
License: MIT
License File: https://github.com/RobinHerbots/Inputmask/blob/4.x/LICENSE.txt
License File: https://github.com/RobinHerbots/Inputmask/blob/3.x/LICENSE.txt

Description:
Copy of inputmask library and dependency library from release 4.x
https://github.com/vega/vega/tree/4.x
Copy of inputmask library and dependency library from release 3.x
https://github.com/RobinHerbots/Inputmask/tree/3.x

Local Modifications:
Replace the universal module definition with a factory wrapper.
Changed initial unmask behavior when value patching is disabled.
Altered trigger implementation to not use CustomElement for triggering events
- Patch 0000: Replace the universal module definition with a factory wrapper.
- Patch 0001: Reference Element from the global object dependency-injected into
the factory. This fixes behavior across iframe boundaries, like in tests.
- Patch 0002: Changed initial unmask behavior when value patching is disabled.
- Patch 0003: In `trigger` implementation, only use CustomEvent for custom
events, and use native Events for code-initiated user events like "click".
- Patch 0004: Check for showMaskOnHover in the mouseenter handler.
- Patch 0005: Remove extraneous whitespace.
- Patch 0006: Add support for the "?" mask character as a wildcard character.
10 changes: 10 additions & 0 deletions third_party/inputmask/compile.sh
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
# Run this file with bash to add AMP-specific changes to the
# inputmask library.

# Apply all the patches in third_party/inputmask/patches/
for patchfile in patches/*.patch
do
echo "Applying patch $patchfile"
patch < $patchfile
done
5 changes: 0 additions & 5 deletions third_party/inputmask/inputmask.dependencyLib.js
Expand Up @@ -6,9 +6,6 @@
* Version: 3.3.11
*/

// !function(factory) {
// "function" == typeof define && define.amd ? define([ "../global/window", "../global/document" ], factory) : "object" == typeof exports ? module.exports = factory(require("../global/window"), require("../global/document")) : window.dependencyLib = factory(window, document);
// }(function(window, document) {
export function factory(window, document) {
function indexOf(list, elem) {
for (var i = 0, len = list.length; i < len; i++) if (list[i] === elem) return i;
Expand Down Expand Up @@ -83,7 +80,6 @@ export function factory(window, document) {
};
if (document.createEvent) {
try {
// evnt = new CustomEvent(ev, params);
evnt = ["change","input","click"].indexOf(ev) > -1 ? new Event(ev, params) : new CustomEvent(ev, params);
} catch (e) {
(evnt = document.createEvent("CustomEvent")).initCustomEvent(ev, params.bubbles, params.cancelable, params.detail);
Expand Down Expand Up @@ -133,4 +129,3 @@ export function factory(window, document) {
evt;
}, DependencyLib.Event.prototype = window.Event.prototype), DependencyLib;
}
// });
9 changes: 2 additions & 7 deletions third_party/inputmask/inputmask.js 100755 → 100644
Expand Up @@ -6,9 +6,6 @@
* Version: 3.3.11
*/

// !function(factory) {
// "function" == typeof define && define.amd ? define([ "./dependencyLibs/inputmask.dependencyLib", "./global/window", "./global/document" ], factory) : "object" == typeof exports ? module.exports = factory(require("./dependencyLibs/inputmask.dependencyLib"), require("./global/window"), require("./global/document")) : window.Inputmask = factory(window.dependencyLib || jQuery, window, document);
// }(function($, window, document, undefined) {
export function factory($, window, document, undefined) {
function Inputmask(alias, options, internal) {
if (!(this instanceof Inputmask)) return new Inputmask(alias, options, internal);
Expand Down Expand Up @@ -1128,7 +1125,7 @@ export function factory($, window, document, undefined) {
}(npt.type), function(npt) {
EventRuler.on(npt, "mouseenter", function(event) {
var $input = $(this);
this.inputmask._valueGet() !== getBuffer().join("") && $input.trigger("setvalue");
opts.showMaskOnHover == !0 && this.inputmask._valueGet() !== getBuffer().join("") && $input.trigger("setvalue");
});
}(npt));
}
Expand Down Expand Up @@ -1290,7 +1287,7 @@ export function factory($, window, document, undefined) {
"*": {
validator: "[0-91-9A-Za-zА-яЁёÀ-ÿµ]",
cardinality: 1
},
}
},
aliases: {},
masksCache: {},
Expand Down Expand Up @@ -1332,7 +1329,6 @@ export function factory($, window, document, undefined) {
var scopedOpts = $.extend(!0, {}, that.opts);
importAttributeOptions(el, scopedOpts, $.extend(!0, {}, that.userOptions), that.dataAttribute);
var maskset = generateMaskSet(scopedOpts, that.noMasksCache);
// maskset !== undefined && (el.inputmask !== undefined && (el.inputmask.opts.autoUnmask = !0,
maskset !== undefined && (el.inputmask !== undefined && (el.inputmask.opts.autoUnmask = el.inputmask.opts.autoUnmask,
el.inputmask.remove()), el.inputmask = new Inputmask(undefined, undefined, !0),
el.inputmask.opts = scopedOpts, el.inputmask.noMasksCache = that.noMasksCache, el.inputmask.userOptions = $.extend(!0, {}, that.userOptions),
Expand Down Expand Up @@ -1630,4 +1626,3 @@ export function factory($, window, document, undefined) {
X: 88
}, Inputmask;
}
// });
44 changes: 44 additions & 0 deletions third_party/inputmask/patches/0000-remove-umd-wrapper.patch
@@ -0,0 +1,44 @@
diff --git a/third_party/inputmask/inputmask.dependencyLib.js b/third_party/inputmask/inputmask.dependencyLib.js
index 3916874f1..dabe6c770 100755
--- a/third_party/inputmask/inputmask.dependencyLib.js
+++ b/third_party/inputmask/inputmask.dependencyLib.js
@@ -6,9 +6,7 @@
* Version: 3.3.11
*/

-!function(factory) {
- "function" == typeof define && define.amd ? define([ "../global/window", "../global/document" ], factory) : "object" == typeof exports ? module.exports = factory(require("../global/window"), require("../global/document")) : window.dependencyLib = factory(window, document);
-}(function(window, document) {
+export function factory(window, document) {
function indexOf(list, elem) {
for (var i = 0, len = list.length; i < len; i++) if (list[i] === elem) return i;
return -1;
@@ -130,4 +128,4 @@
return evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail),
evt;
}, DependencyLib.Event.prototype = window.Event.prototype), DependencyLib;
-});
\ No newline at end of file
+}
diff --git a/third_party/inputmask/inputmask.js b/third_party/inputmask/inputmask.js
index c6836be84..71f7b99b6 100644
--- a/third_party/inputmask/inputmask.js
+++ b/third_party/inputmask/inputmask.js
@@ -6,9 +6,7 @@
* Version: 3.3.11
*/

-!function(factory) {
- "function" == typeof define && define.amd ? define([ "./dependencyLibs/inputmask.dependencyLib", "./global/window", "./global/document" ], factory) : "object" == typeof exports ? module.exports = factory(require("./dependencyLibs/inputmask.dependencyLib"), require("./global/window"), require("./global/document")) : window.Inputmask = factory(window.dependencyLib || jQuery, window, document);
-}(function($, window, document, undefined) {
+export function factory($, window, document, undefined) {
function Inputmask(alias, options, internal) {
if (!(this instanceof Inputmask)) return new Inputmask(alias, options, internal);
this.el = undefined, this.events = {}, this.maskset = undefined, this.refreshValue = !1,
@@ -1622,4 +1620,4 @@
WINDOWS: 91,
X: 88
}, Inputmask;
-});
\ No newline at end of file
+}
13 changes: 13 additions & 0 deletions third_party/inputmask/patches/0001-window-element.patch
@@ -0,0 +1,13 @@
diff --git a/third_party/inputmask/inputmask.dependencyLib.js b/third_party/inputmask/inputmask.dependencyLib.js
index dabe6c770..aff110fc5 100755
--- a/third_party/inputmask/inputmask.dependencyLib.js
+++ b/third_party/inputmask/inputmask.dependencyLib.js
@@ -22,7 +22,7 @@ export function factory(window, document) {
return "function" !== ltype && !isWindow(obj) && (!(1 !== obj.nodeType || !length) || ("array" === ltype || 0 === length || "number" == typeof length && length > 0 && length - 1 in obj));
}
function isValidElement(elem) {
- return elem instanceof Element;
+ return elem instanceof window.Element;
}
function DependencyLib(elem) {
return elem instanceof DependencyLib ? elem : this instanceof DependencyLib ? void (void 0 !== elem && null !== elem && elem !== window && (this[0] = elem.nodeName ? elem : void 0 !== elem[0] && elem[0].nodeName ? elem[0] : document.querySelector(elem),
13 changes: 13 additions & 0 deletions third_party/inputmask/patches/0002-use-real-event.patch
@@ -0,0 +1,13 @@
diff --git a/third_party/inputmask/inputmask.dependencyLib.js b/third_party/inputmask/inputmask.dependencyLib.js
index dabe6c770..509e91dd2 100755
--- a/third_party/inputmask/inputmask.dependencyLib.js
+++ b/third_party/inputmask/inputmask.dependencyLib.js
@@ -80,7 +80,7 @@ export function factory(window, document) {
};
if (document.createEvent) {
try {
- evnt = new CustomEvent(ev, params);
+ evnt = ["change","input","click"].indexOf(ev) > -1 ? new Event(ev, params) : new CustomEvent(ev, params);
} catch (e) {
(evnt = document.createEvent("CustomEvent")).initCustomEvent(ev, params.bubbles, params.cancelable, params.detail);
}
13 changes: 13 additions & 0 deletions third_party/inputmask/patches/0003-fix-unpatched-unmask.patch
@@ -0,0 +1,13 @@
diff --git a/third_party/inputmask/inputmask.js b/third_party/inputmask/inputmask.js
index 71f7b99b6..215e86839 100644
--- a/third_party/inputmask/inputmask.js
+++ b/third_party/inputmask/inputmask.js
@@ -1324,7 +1324,7 @@ export function factory($, window, document, undefined) {
var scopedOpts = $.extend(!0, {}, that.opts);
importAttributeOptions(el, scopedOpts, $.extend(!0, {}, that.userOptions), that.dataAttribute);
var maskset = generateMaskSet(scopedOpts, that.noMasksCache);
- maskset !== undefined && (el.inputmask !== undefined && (el.inputmask.opts.autoUnmask = !0,
+ maskset !== undefined && (el.inputmask !== undefined && (el.inputmask.opts.autoUnmask = el.inputmask.opts.autoUnmask,
el.inputmask.remove()), el.inputmask = new Inputmask(undefined, undefined, !0),
el.inputmask.opts = scopedOpts, el.inputmask.noMasksCache = that.noMasksCache, el.inputmask.userOptions = $.extend(!0, {}, that.userOptions),
el.inputmask.isRTL = scopedOpts.isRTL || scopedOpts.numericInput, el.inputmask.el = el,
13 changes: 13 additions & 0 deletions third_party/inputmask/patches/0004-fix-unpatched-hover.patch
@@ -0,0 +1,13 @@
diff --git a/third_party/inputmask/inputmask.js b/third_party/inputmask/inputmask.js
index c6836be84..ac471bcf3 100644
--- a/third_party/inputmask/inputmask.js
+++ b/third_party/inputmask/inputmask.js
@@ -1127,7 +1127,7 @@
}(npt.type), function(npt) {
EventRuler.on(npt, "mouseenter", function(event) {
var $input = $(this);
- this.inputmask._valueGet() !== getBuffer().join("") && $input.trigger("setvalue");
+ opts.showMaskOnHover == !0 && this.inputmask._valueGet() !== getBuffer().join("") && $input.trigger("setvalue");
});
}(npt));
}

0 comments on commit a7c3982

Please sign in to comment.