-
-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kryazhev Alexey
committed
Apr 17, 2017
1 parent
03a7b68
commit bb8703e
Showing
7 changed files
with
174 additions
and
29 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import BaseMask from './base'; | ||
import {extendDetailsAdjustments} from '../utils'; | ||
|
||
|
||
export default | ||
class PipeMask extends BaseMask { | ||
constructor (el, opts) { | ||
super(el, opts); | ||
|
||
this.multipass = opts.multipass; | ||
|
||
this._compiledMasks = this.mask.map(m => IMask.MaskFactory(el, m)); | ||
} | ||
|
||
resolve (str, details) { | ||
var res = this._pipe(str, details); | ||
if (!this.multipass) return res; | ||
|
||
var cursorPos = details.cursorPos; | ||
|
||
var stepRes; | ||
var tempRes = res; | ||
|
||
while (stepRes !== tempRes) { | ||
stepRes = tempRes; | ||
tempRes = this._pipe(stepRes, { | ||
cursorPos: stepRes.length, | ||
oldValue: stepRes, | ||
oldSelection: { | ||
start: 0, | ||
end: stepRes.length | ||
} | ||
}); | ||
} | ||
|
||
details.cursorPos = cursorPos - (res.length - stepRes.length); | ||
|
||
return stepRes; | ||
} | ||
|
||
_pipe (str, details) { | ||
return this._compiledMasks.reduce((s, m) => { | ||
var d = extendDetailsAdjustments(s, details); | ||
var res = m.resolve(s, d); | ||
details.cursorPos = d.cursorPos; | ||
return res; | ||
}, str); | ||
} | ||
|
||
bindEvents () { | ||
super.bindEvents(); | ||
this._compiledMasks.forEach(m => { | ||
m.bindEvents(); | ||
// disable basemask events for child masks | ||
BaseMask.prototype.unbindEvents.apply(m); | ||
}); | ||
} | ||
|
||
unbindEvents () { | ||
super.unbindEvents(); | ||
this._compiledMasks.forEach(m => m.unbindEvents()); | ||
} | ||
} |