event-valuechange.js revision 861747a48c2c1e64d00644e97b218a76d334f744
/**
* Adds a synthetic <code>valueChange</code> event that fires when the
* <code>value</code> property of an input field or textarea changes as a result
* of a keystroke, mouse operation, or input method editor (IME) input event.
*
* @module event-valuechange
*/
/**
* Provides the implementation for the synthetic <code>valueChange</code> event.
*
* @class ValueChange
* @static
*/
var VALUE = 'value',
VALUE_CHANGE = 'valueChange',
// Just a simple namespace to make methods overridable.
VC = {
// -- Static Constants -----------------------------------------------------
TIMEOUT: 10000,
// -- Protected Static Properties ------------------------------------------
_events : {},
_history : {},
_intervals: {},
_timeouts : {},
// -- Protected Static Methods ---------------------------------------------
_event : e,
});
}
},
_startPolling: function (node, e) {
// Poll for changes to the node's value. We can't rely on keyboard
// events for this, since the value may change due to a mouse-initiated
// paste event, an IME input event, or for some other reason that
// doesn't trigger a key event.
// If we don't see any changes within the timeout period (10 seconds by
// default), stop polling.
},
_stopPolling: function (node) {
},
// -- Protected Static Event Handlers --------------------------------------
_onBlur: function (e) {
},
_onKeyDown: function (e) {
},
_onKeyUp: function (e) {
// These charCodes indicate that an IME has started. We'll restart
// polling and give the IME up to 10 seconds (by default) to finish.
}
},
_onMouseDown: function (e) {
},
});
},
});
}
};
/**
* <p>
* Synthetic event that fires when the <code>value</code> property of an input
* field or textarea changes as a result of a keystroke, mouse operation, or
* input method editor (IME) input event.
* </p>
*
* <p>
* Unlike the <code>onchange</code> event, this event fires when the value
* actually changes and not when the element loses focus. This event also
* reports IME and multi-stroke input more reliably than <code>oninput</code> or
* the various key events across browsers.
* </p>
*
* <p>
* This event is provided by the <code>value-change</code> module.
* </p>
*
* <p>
* <strong>Usage example:</strong>
* </p>
*
* <code><pre>
* YUI().use('value-change', function (Y) {
* Y.one('input').on('valueChange', function (e) {
* // Handle valueChange events on the first input element on the page.
* });
* });
* </pre></code>
*
* @event valueChange
* @param {EventFacade} e Event facade with the following additional
* properties:
*
* <dl>
* <dt>prevVal (String)</dt>
* <dd>
* Previous value before the latest change.
* </dd>
*
* <dt>newVal (String)</dt>
* <dd>
* New value after the latest change.
* </dd>
* </dl>
*
* @for YUI
*/
broadcast: 1,
emitFacade: true
}
});
Y.ValueChange = VC;