Namespace Pot.Signal
Defined in: <pot.js>.
Constructor Attributes | Constructor Name and Description |
---|---|
Signal/Event utilities.
|
Method Attributes | Method Name and Description |
---|---|
<static> |
Pot.Signal.cancelEvent(ev)
Cancel and stop event.
|
<static> |
Pot.Signal.detach(object, (signalName), (callback), (useCapture))
Detaches a signal.
|
<static> |
Pot.Signal.detachAll((object), (signals))
Removes all set of signals connected with object.
|
<static> |
Pot.Signal.isHandler(x)
Check whether the argument object is an instance of Pot.Signal.Handler.
|
<static> |
Pot.Signal.isObserver(x)
Check whether the argument object is an instance of Pot.Signal.Observer.
|
<static> |
Pot.Signal.signal(object, signalName)
`signal` will send signal to a connected with object and triggered.
|
Method Detail
<static>
{Function}
Pot.Signal.cancelEvent(ev)
Cancel and stop event.
attach('#foo', 'click', function(ev) { myProcess(); return cancelEvent(ev); });
- Parameters:
- {Event} ev
- The event object.
- Returns:
- {Boolean} Returns always false.
<static>
{Function}
Pot.Signal.detach(object, (signalName), (callback), (useCapture))
Detaches a signal.
To detach a signal, pass its handler identifier returned by attach().
This is similar to how the setTimeout and clearTimeout works.
// This is similar to how the setTimeout and clearTimeout works. var handler = attach('#foo', 'click', function(ev) {...}); // Release the signal(Event). detach(handler);
- Parameters:
- {Object|Function} object
- An instance identifier of Pot.Signal.Handler object that returned by attach(). Or if signal using DOM object, you can specify the same as the removeEventListener arguments usage.
- {String} (signalName)
- (Optional) If `object` is a DOM object, you can specify same as the removeEventListener arguments usage. `signalName` is the signal/event in string.
- {Function} (callback)
- (Optional) If `object` is a DOM object, you can specify same as the removeEventListener arguments usage. `callback` is a trigger function.
- {Boolean} (useCapture)
- (Optional) If `object` is a DOM object, you can specify same as the removeEventListener arguments usage. `useCapture` is 3rd argument of removeEventListener if environment is available it on DOM.
- Returns:
- {Boolean} Success or failure.
<static>
{Function}
Pot.Signal.detachAll((object), (signals))
Removes all set of signals connected with object.
// Release all of element's event. var foo = document.getElementById('foo'); attach(foo, 'click', function(ev) {...}); attach(foo, 'mouseover', function(ev) {...}); attach(foo, 'mouseout', function(ev) {...}); // Detach all of foo's events. detachAll(foo);
// Release all of signals. attach(window, 'load', function(ev) {...}); attach(document.body, 'mousemove', function(ev) {...}); attach('#foo', 'click', function(ev) {...}); // Detach all of signals. detachAll();
- Parameters:
- {Object|Function} (object)
- (Optional) An instance identifier of Pot.Signal.Handler object that returned by attach(). If omitted, a global object will be target.
- {String|Array} (signals)
- (Optional) A signal or an event name in string for detach and remove. If passed as an Array, will be target all signal items.
<static>
{Function}
Pot.Signal.isHandler(x)
Check whether the argument object is an instance of Pot.Signal.Handler.
- Parameters:
- {Object|*} x
- The target object to test.
- Returns:
- {Boolean} Return true if the argument object is an instance of Pot.Signal.Handler, otherwise return false.
<static>
{Function}
Pot.Signal.isObserver(x)
Check whether the argument object is an instance of Pot.Signal.Observer.
- Parameters:
- {Object|*} x
- The target object to test.
- Returns:
- {Boolean} Return true if the argument object is an instance of Pot.Signal.Observer, otherwise return false.
<static>
{Function}
Pot.Signal.signal(object, signalName)
`signal` will send signal to a connected with object and triggered.
When signal is called with an object and the specify signal,
the observer function will be triggered.
Note that when using this function for DOM signals,
a single event argument is expected by most listeners.
// Example code of signal for Object usage. var MyObj = {}; // Register your own signal. var handler = attach(MyObj, 'clear-data', function() { // To initialize the properties etc. MyObj.data = null; MyObj.time = null; }); attach(window, 'load', function() { // Send a signal to initialize. signal(MyObj, 'clear-data'); // Also set to clear when you press the reset button. attach('#reset', 'click', function() { signal(MyObj, 'clear-data'); }); // Existing processing etc. myLoadProcess(); //... });
- Parameters:
- {Object|Function} object
- An instance identifier of Pot.Signal.Handler object that returned by attach().
- {String|Array} signalName
- A signal or an event name in string for signal.
- Returns:
- {Deferred} Return result of triggered as an instance of Pot.Deferred.