|
|
@@ -47,30 +47,36 @@ module.exports = {
|
|
|
// if the directive has filters, we need to
|
|
|
// record cursor position and restore it after updating
|
|
|
// the input with the filtered value.
|
|
|
- this.listener = function textInputListener () {
|
|
|
- if (cpLocked) return
|
|
|
- var charsOffset
|
|
|
- // some HTML5 input types throw error here
|
|
|
- try {
|
|
|
- // record how many chars from the end of input
|
|
|
- // the cursor was at
|
|
|
- charsOffset = el.value.length - el.selectionStart
|
|
|
- } catch (e) {}
|
|
|
- set()
|
|
|
- // force a value update, because in
|
|
|
- // certain cases the write filters output the same
|
|
|
- // result for different input values, and the Observer
|
|
|
- // set events won't be triggered.
|
|
|
- _.nextTick(function () {
|
|
|
- var newVal = self._watcher.value
|
|
|
- self.update(newVal)
|
|
|
- if (charsOffset != null) {
|
|
|
- var cursorPos =
|
|
|
- _.toString(newVal).length - charsOffset
|
|
|
- el.setSelectionRange(cursorPos, cursorPos)
|
|
|
+ this.listener = this.filters
|
|
|
+ ? function textInputListener () {
|
|
|
+ if (cpLocked) return
|
|
|
+ var charsOffset
|
|
|
+ // some HTML5 input types throw error here
|
|
|
+ try {
|
|
|
+ // record how many chars from the end of input
|
|
|
+ // the cursor was at
|
|
|
+ charsOffset = el.value.length - el.selectionStart
|
|
|
+ } catch (e) {}
|
|
|
+ set()
|
|
|
+ _.nextTick(function () {
|
|
|
+ // force a value update, because in
|
|
|
+ // certain cases the write filters output the
|
|
|
+ // same result for different input values, and
|
|
|
+ // the Observer set events won't be triggered.
|
|
|
+ var newVal = self._watcher.value
|
|
|
+ self.update(newVal)
|
|
|
+ if (charsOffset != null) {
|
|
|
+ var cursorPos =
|
|
|
+ _.toString(newVal).length - charsOffset
|
|
|
+ el.setSelectionRange(cursorPos, cursorPos)
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
- })
|
|
|
- }
|
|
|
+ : function textInputListener () {
|
|
|
+ if (cpLocked) return
|
|
|
+ set()
|
|
|
+ }
|
|
|
+
|
|
|
this.event = lazy ? 'change' : 'input'
|
|
|
_.on(el, this.event, this.listener)
|
|
|
|