Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
ac2c5f3e
Commit
ac2c5f3e
authored
Sep 21, 2016
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow the context to be passed in when registering event listeners
Similar to how backbone.js does it.
parent
05a57705
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
8 deletions
+20
-8
docs/CHANGES.md
docs/CHANGES.md
+4
-0
docs/source/development.rst
docs/source/development.rst
+4
-2
src/converse-api.js
src/converse-api.js
+4
-4
src/converse-core.js
src/converse-core.js
+8
-2
No files found.
docs/CHANGES.md
View file @
ac2c5f3e
# Changelog
## 2.0.1 (Unreleased)
-
Allow the context (i.e.
`this`
value) to be passed in when registering event
listeners with
`converse.listen.on`
and
`converse.listen.once`
. [jcbrand]
## 2.0.0 (2016-09-16)
-
#656 Online users count not shown initially [amanzur]
-
#674 Polish translation updated [ser]
...
...
docs/source/development.rst
View file @
ac2c5f3e
...
...
@@ -768,7 +768,7 @@ Converse.js emits events to which you can subscribe from your own Javascript.
Concerning events, the following methods are available under the "listen"
grouping:
* **on(eventName, callback)**:
* **on(eventName, callback
, [context]
)**:
Calling the ``on`` method allows you to subscribe to an event.
Every time the event fires, the callback method specified by ``callback`` will be
...
...
@@ -778,6 +778,7 @@ grouping:
* ``eventName`` is the event name as a string.
* ``callback`` is the callback method to be called when the event is emitted.
* ``context`` (optional), the value of the `this` parameter for the callback.
For example:
...
...
@@ -785,7 +786,7 @@ grouping:
converse.listen.on('message', function (event, messageXML) { ... });
* **once(eventName, callback)**:
* **once(eventName, callback
, [context]
)**:
Calling the ``once`` method allows you to listen to an event
exactly once.
...
...
@@ -794,6 +795,7 @@ grouping:
* ``eventName`` is the event name as a string.
* ``callback`` is the callback method to be called when the event is emitted.
* ``context`` (optional), the value of the `this` parameter for the callback.
For example:
...
...
src/converse-api.js
View file @
ac2c5f3e
...
...
@@ -160,11 +160,11 @@
}
},
'
listen
'
:
{
'
once
'
:
function
(
evt
,
handler
)
{
converse
.
once
(
evt
,
handler
);
'
once
'
:
function
(
evt
,
handler
,
context
)
{
converse
.
once
(
evt
,
handler
,
context
);
},
'
on
'
:
function
(
evt
,
handler
)
{
converse
.
on
(
evt
,
handler
);
'
on
'
:
function
(
evt
,
handler
,
context
)
{
converse
.
on
(
evt
,
handler
,
context
);
},
'
not
'
:
function
(
evt
,
handler
)
{
converse
.
off
(
evt
,
handler
);
...
...
src/converse-core.js
View file @
ac2c5f3e
...
...
@@ -65,14 +65,20 @@
$
(
event_context
).
trigger
(
evt
,
data
);
},
once
:
function
(
evt
,
handler
)
{
once
:
function
(
evt
,
handler
,
context
)
{
if
(
context
)
{
handler
=
handler
.
bind
(
context
);
}
$
(
event_context
).
one
(
evt
,
handler
);
},
on
:
function
(
evt
,
handler
)
{
on
:
function
(
evt
,
handler
,
context
)
{
if
(
_
.
contains
([
'
ready
'
,
'
initialized
'
],
evt
))
{
converse
.
log
(
'
Warning: The "
'
+
evt
+
'
" event has been deprecated and will be removed, please use "connected".
'
);
}
if
(
context
)
{
handler
=
handler
.
bind
(
context
);
}
$
(
event_context
).
bind
(
evt
,
handler
);
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment