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
add3b8ef
Commit
add3b8ef
authored
Aug 15, 2017
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
utils now no longer depends on jquery.
parent
6c3aa34c
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
221 additions
and
177 deletions
+221
-177
spec/controlbox.js
spec/controlbox.js
+11
-0
src/converse-muc.js
src/converse-muc.js
+7
-6
src/converse-register.js
src/converse-register.js
+1
-1
src/templates/field.html
src/templates/field.html
+2
-1
src/utils.js
src/utils.js
+193
-162
tests/mock.js
tests/mock.js
+7
-7
No files found.
spec/controlbox.js
View file @
add3b8ef
...
@@ -137,6 +137,17 @@
...
@@ -137,6 +137,17 @@
});
});
_converse
.
rosterview
.
update
();
// XXX: Will normally called as event handler
_converse
.
rosterview
.
update
();
// XXX: Will normally called as event handler
}
}
$
.
fn
.
hasScrollBar
=
function
()
{
if
(
!
$
.
contains
(
document
,
this
.
get
(
0
)))
{
return
false
;
}
if
(
this
.
parent
().
height
()
<
this
.
get
(
0
).
scrollHeight
)
{
return
true
;
}
return
false
;
};
return
test_utils
.
waitUntil
(
function
()
{
return
test_utils
.
waitUntil
(
function
()
{
if
(
_converse
.
rosterview
.
$roster
.
hasScrollBar
())
{
if
(
_converse
.
rosterview
.
$roster
.
hasScrollBar
())
{
return
$filter
.
is
(
'
:visible
'
);
return
$filter
.
is
(
'
:visible
'
);
...
...
src/converse-muc.js
View file @
add3b8ef
...
@@ -191,11 +191,12 @@
...
@@ -191,11 +191,12 @@
_converse
.
api
.
listen
.
on
(
'
serviceDiscovered
'
,
this
.
featureAdded
,
this
);
_converse
.
api
.
listen
.
on
(
'
serviceDiscovered
'
,
this
.
featureAdded
,
this
);
// Features could have been added before the controlbox was
// Features could have been added before the controlbox was
// initialized. We're only interested in MUC
// initialized. We're only interested in MUC
const
feature
=
_converse
.
disco_entities
[
_converse
.
domain
].
features
.
findWhere
({
const
entity
=
_converse
.
disco_entities
[
_converse
.
domain
];
'
var
'
:
Strophe
.
NS
.
MUC
if
(
!
_
.
isUndefined
(
entity
))
{
});
const
feature
=
entity
.
features
.
findWhere
({
'
var
'
:
Strophe
.
NS
.
MUC
});
if
(
feature
)
{
if
(
feature
)
{
this
.
featureAdded
(
feature
);
this
.
featureAdded
(
feature
);
}
}
}
});
});
},
},
...
@@ -1283,7 +1284,7 @@
...
@@ -1283,7 +1284,7 @@
$fieldset
.
append
(
$
(
'
<p class="instructions">
'
).
text
(
instructions
));
$fieldset
.
append
(
$
(
'
<p class="instructions">
'
).
text
(
instructions
));
}
}
_
.
each
(
$fields
,
function
(
field
)
{
_
.
each
(
$fields
,
function
(
field
)
{
$fieldset
.
append
(
utils
.
xForm2webForm
(
$
(
field
),
$
stanza
));
$fieldset
.
append
(
utils
.
xForm2webForm
(
field
,
stanza
));
});
});
$form
.
append
(
'
<fieldset></fieldset>
'
);
$form
.
append
(
'
<fieldset></fieldset>
'
);
$fieldset
=
$form
.
children
(
'
fieldset:last
'
);
$fieldset
=
$form
.
children
(
'
fieldset:last
'
);
...
...
src/converse-register.js
View file @
add3b8ef
...
@@ -356,7 +356,7 @@
...
@@ -356,7 +356,7 @@
if
(
this
.
form_type
===
'
xform
'
)
{
if
(
this
.
form_type
===
'
xform
'
)
{
$fields
=
$stanza
.
find
(
'
field
'
);
$fields
=
$stanza
.
find
(
'
field
'
);
_
.
each
(
$fields
,
(
field
)
=>
{
_
.
each
(
$fields
,
(
field
)
=>
{
$form
.
append
(
utils
.
xForm2webForm
.
bind
(
this
,
$
(
field
),
$
stanza
));
$form
.
append
(
utils
.
xForm2webForm
.
bind
(
this
,
field
,
stanza
));
});
});
}
else
{
}
else
{
// Show fields
// Show fields
...
...
src/templates/field.html
View file @
add3b8ef
<field
var=
"{{{name}}}"
>
{[ if (_.isArray(value)) { ]}
<field
var=
"{{{name}}}"
>
{[ if (_.isArray(value)) { ]}
{[ _.each(value,function(arrayValue) { ]}
<value>
{{{arrayValue}}}
</value>
{[ }); ]}
{[ _.each(value,function(arrayValue) { ]}
<value>
{{{arrayValue}}}
</value>
{[ }); ]}
{[ } else { ]}
{[ } else { ]}
<value>
{{{value}}}
</value>
<value>
{{{value}}}
</value>
...
...
src/utils.js
View file @
add3b8ef
// Converse.js (A browser based XMPP chat client)
// http://conversejs.org
//
// This is the utilities module.
//
// Copyright (c) 2012-2017, Jan-Carel Brand <jc@opkode.com>
// Licensed under the Mozilla Public License (MPLv2)
//
/*global define, escape, locales, Jed */
/*global define, escape, locales, Jed */
(
function
(
root
,
factory
)
{
(
function
(
root
,
factory
)
{
define
([
define
([
"
jquery.noconflict
"
,
"
sizzle
"
,
"
sizzle
"
,
"
es6-promise
"
,
"
es6-promise
"
,
"
jquery.browser
"
,
"
jquery.browser
"
,
...
@@ -19,7 +26,6 @@
...
@@ -19,7 +26,6 @@
"
tpl!form_captcha
"
"
tpl!form_captcha
"
],
factory
);
],
factory
);
}(
this
,
function
(
}(
this
,
function
(
$
,
sizzle
,
sizzle
,
Promise
,
Promise
,
jQBrowser
,
jQBrowser
,
...
@@ -36,7 +42,6 @@
...
@@ -36,7 +42,6 @@
tpl_form_input
,
tpl_form_input
,
tpl_form_captcha
tpl_form_captcha
)
{
)
{
"
use strict
"
;
"
use strict
"
;
locales
=
locales
||
{};
locales
=
locales
||
{};
const
b64_sha1
=
Strophe
.
SHA1
.
b64_sha1
;
const
b64_sha1
=
Strophe
.
SHA1
.
b64_sha1
;
...
@@ -93,16 +98,6 @@
...
@@ -93,16 +98,6 @@
});
});
};
};
$
.
fn
.
hasScrollBar
=
function
()
{
if
(
!
$
.
contains
(
document
,
this
.
get
(
0
)))
{
return
false
;
}
if
(
this
.
parent
().
height
()
<
this
.
get
(
0
).
scrollHeight
)
{
return
true
;
}
return
false
;
};
function
calculateSlideStep
(
height
)
{
function
calculateSlideStep
(
height
)
{
if
(
height
>
100
)
{
if
(
height
>
100
)
{
return
10
;
return
10
;
...
@@ -113,12 +108,12 @@
...
@@ -113,12 +108,12 @@
}
}
}
}
var
u
tils
=
{};
var
u
=
{};
// Translation machinery
// Translation machinery
// ---------------------
// ---------------------
u
tils
.
__
=
function
(
str
)
{
u
.
__
=
function
(
str
)
{
if
(
!
u
tils
.
isConverseLocale
(
this
.
locale
)
||
this
.
locale
===
'
en
'
)
{
if
(
!
u
.
isConverseLocale
(
this
.
locale
)
||
this
.
locale
===
'
en
'
)
{
return
Jed
.
sprintf
.
apply
(
Jed
,
arguments
);
return
Jed
.
sprintf
.
apply
(
Jed
,
arguments
);
}
}
if
(
typeof
this
.
jed
===
"
undefined
"
)
{
if
(
typeof
this
.
jed
===
"
undefined
"
)
{
...
@@ -132,7 +127,7 @@
...
@@ -132,7 +127,7 @@
}
}
};
};
u
tils
.
___
=
function
(
str
)
{
u
.
___
=
function
(
str
)
{
/* XXX: This is part of a hack to get gettext to scan strings to be
/* XXX: This is part of a hack to get gettext to scan strings to be
* translated. Strings we cannot send to the function above because
* translated. Strings we cannot send to the function above because
* they require variable interpolation and we don't yet have the
* they require variable interpolation and we don't yet have the
...
@@ -143,7 +138,7 @@
...
@@ -143,7 +138,7 @@
return
str
;
return
str
;
};
};
u
tils
.
isLocaleAvailable
=
function
(
locale
,
available
)
{
u
.
isLocaleAvailable
=
function
(
locale
,
available
)
{
/* Check whether the locale or sub locale (e.g. en-US, en) is supported.
/* Check whether the locale or sub locale (e.g. en-US, en) is supported.
*
*
* Parameters:
* Parameters:
...
@@ -159,7 +154,7 @@
...
@@ -159,7 +154,7 @@
}
}
};
};
u
tils
.
addHyperlinks
=
function
(
text
)
{
u
.
addHyperlinks
=
function
(
text
)
{
const
list
=
text
.
match
(
URL_REGEX
)
||
[];
const
list
=
text
.
match
(
URL_REGEX
)
||
[];
var
links
=
[];
var
links
=
[];
_
.
each
(
list
,
(
match
)
=>
{
_
.
each
(
list
,
(
match
)
=>
{
...
@@ -179,7 +174,7 @@
...
@@ -179,7 +174,7 @@
return
text
;
return
text
;
};
};
u
tils
.
renderImageURLs
=
function
(
obj
)
{
u
.
renderImageURLs
=
function
(
obj
)
{
const
list
=
obj
.
textContent
.
match
(
URL_REGEX
)
||
[];
const
list
=
obj
.
textContent
.
match
(
URL_REGEX
)
||
[];
_
.
forEach
(
list
,
function
(
url
)
{
_
.
forEach
(
list
,
function
(
url
)
{
isImage
(
url
).
then
(
function
(
img
)
{
isImage
(
url
).
then
(
function
(
img
)
{
...
@@ -191,23 +186,23 @@
...
@@ -191,23 +186,23 @@
return
obj
;
return
obj
;
};
};
u
tils
.
slideInAllElements
=
function
(
elements
)
{
u
.
slideInAllElements
=
function
(
elements
)
{
return
Promise
.
all
(
return
Promise
.
all
(
_
.
map
(
_
.
map
(
elements
,
elements
,
_
.
partial
(
u
tils
.
slideIn
,
_
,
600
)
_
.
partial
(
u
.
slideIn
,
_
,
600
)
));
));
};
};
u
tils
.
slideToggleElement
=
function
(
el
)
{
u
.
slideToggleElement
=
function
(
el
)
{
if
(
_
.
includes
(
el
.
classList
,
'
collapsed
'
))
{
if
(
_
.
includes
(
el
.
classList
,
'
collapsed
'
))
{
return
u
tils
.
slideOut
(
el
);
return
u
.
slideOut
(
el
);
}
else
{
}
else
{
return
u
tils
.
slideIn
(
el
);
return
u
.
slideIn
(
el
);
}
}
};
};
u
tils
.
slideOut
=
function
(
el
,
duration
=
900
)
{
u
.
slideOut
=
function
(
el
,
duration
=
900
)
{
/* Shows/expands an element by sliding it out of itself. */
/* Shows/expands an element by sliding it out of itself. */
function
calculateEndHeight
(
el
)
{
function
calculateEndHeight
(
el
)
{
...
@@ -237,7 +232,7 @@
...
@@ -237,7 +232,7 @@
window
.
clearInterval
(
interval_marker
);
window
.
clearInterval
(
interval_marker
);
}
}
const
end_height
=
calculateEndHeight
(
el
);
const
end_height
=
calculateEndHeight
(
el
);
if
(
$
.
fx
.
off
)
{
// Effects are disabled (for tests)
if
(
window
.
converse_disable_effects
)
{
// Effects are disabled (for tests)
el
.
style
.
height
=
end_height
+
'
px
'
;
el
.
style
.
height
=
end_height
+
'
px
'
;
wrapup
(
el
);
wrapup
(
el
);
resolve
();
resolve
();
...
@@ -266,7 +261,7 @@
...
@@ -266,7 +261,7 @@
});
});
};
};
u
tils
.
slideIn
=
function
(
el
,
duration
=
600
)
{
u
.
slideIn
=
function
(
el
,
duration
=
600
)
{
/* Hides/collapses an element by sliding it into itself. */
/* Hides/collapses an element by sliding it into itself. */
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
_
.
isNil
(
el
))
{
if
(
_
.
isNil
(
el
))
{
...
@@ -275,7 +270,7 @@
...
@@ -275,7 +270,7 @@
return
reject
(
new
Error
(
err
));
return
reject
(
new
Error
(
err
));
}
else
if
(
_
.
includes
(
el
.
classList
,
'
collapsed
'
))
{
}
else
if
(
_
.
includes
(
el
.
classList
,
'
collapsed
'
))
{
return
resolve
();
return
resolve
();
}
else
if
(
$
.
fx
.
off
)
{
// Effects are disabled (for tests)
}
else
if
(
window
.
converse_disable_effects
)
{
// Effects are disabled (for tests)
el
.
classList
.
add
(
'
collapsed
'
);
el
.
classList
.
add
(
'
collapsed
'
);
el
.
style
.
height
=
""
;
el
.
style
.
height
=
""
;
return
resolve
();
return
resolve
();
...
@@ -307,11 +302,11 @@
...
@@ -307,11 +302,11 @@
});
});
};
};
u
tils
.
fadeIn
=
function
(
el
,
callback
)
{
u
.
fadeIn
=
function
(
el
,
callback
)
{
if
(
_
.
isNil
(
el
))
{
if
(
_
.
isNil
(
el
))
{
console
.
warn
(
"
Undefined or null element passed into fadeIn
"
);
console
.
warn
(
"
Undefined or null element passed into fadeIn
"
);
}
}
if
(
$
.
fx
.
off
)
{
if
(
window
.
converse_disable_effects
)
{
// Effects are disabled (for tests)
el
.
classList
.
remove
(
'
hidden
'
);
el
.
classList
.
remove
(
'
hidden
'
);
if
(
_
.
isFunction
(
callback
))
{
if
(
_
.
isFunction
(
callback
))
{
callback
();
callback
();
...
@@ -331,12 +326,12 @@
...
@@ -331,12 +326,12 @@
}
}
};
};
u
tils
.
isSameBareJID
=
function
(
jid1
,
jid2
)
{
u
.
isSameBareJID
=
function
(
jid1
,
jid2
)
{
return
Strophe
.
getBareJidFromJid
(
jid1
).
toLowerCase
()
===
return
Strophe
.
getBareJidFromJid
(
jid1
).
toLowerCase
()
===
Strophe
.
getBareJidFromJid
(
jid2
).
toLowerCase
();
Strophe
.
getBareJidFromJid
(
jid2
).
toLowerCase
();
};
};
u
tils
.
isNewMessage
=
function
(
message
)
{
u
.
isNewMessage
=
function
(
message
)
{
/* Given a stanza, determine whether it's a new
/* Given a stanza, determine whether it's a new
* message, i.e. not a MAM archived one.
* message, i.e. not a MAM archived one.
*/
*/
...
@@ -347,13 +342,13 @@
...
@@ -347,13 +342,13 @@
}
}
};
};
u
tils
.
isOTRMessage
=
function
(
message
)
{
u
.
isOTRMessage
=
function
(
message
)
{
var
body
=
message
.
querySelector
(
'
body
'
),
var
body
=
message
.
querySelector
(
'
body
'
),
text
=
(
!
_
.
isNull
(
body
)
?
body
.
textContent
:
undefined
);
text
=
(
!
_
.
isNull
(
body
)
?
body
.
textContent
:
undefined
);
return
text
&&
!!
text
.
match
(
/^
\?
OTR/
);
return
text
&&
!!
text
.
match
(
/^
\?
OTR/
);
};
};
u
tils
.
isHeadlineMessage
=
function
(
message
)
{
u
.
isHeadlineMessage
=
function
(
message
)
{
var
from_jid
=
message
.
getAttribute
(
'
from
'
);
var
from_jid
=
message
.
getAttribute
(
'
from
'
);
if
(
message
.
getAttribute
(
'
type
'
)
===
'
headline
'
)
{
if
(
message
.
getAttribute
(
'
type
'
)
===
'
headline
'
)
{
return
true
;
return
true
;
...
@@ -370,7 +365,7 @@
...
@@ -370,7 +365,7 @@
return
false
;
return
false
;
};
};
u
tils
.
merge
=
function
merge
(
first
,
second
)
{
u
.
merge
=
function
merge
(
first
,
second
)
{
/* Merge the second object into the first one.
/* Merge the second object into the first one.
*/
*/
for
(
var
k
in
second
)
{
for
(
var
k
in
second
)
{
...
@@ -382,7 +377,7 @@
...
@@ -382,7 +377,7 @@
}
}
};
};
u
tils
.
applyUserSettings
=
function
applyUserSettings
(
context
,
settings
,
user_settings
)
{
u
.
applyUserSettings
=
function
applyUserSettings
(
context
,
settings
,
user_settings
)
{
/* Configuration settings might be nested objects. We only want to
/* Configuration settings might be nested objects. We only want to
* add settings which are whitelisted.
* add settings which are whitelisted.
*/
*/
...
@@ -398,7 +393,7 @@
...
@@ -398,7 +393,7 @@
}
}
};
};
u
tils
.
refreshWebkit
=
function
()
{
u
.
refreshWebkit
=
function
()
{
/* This works around a webkit bug. Refreshes the browser's viewport,
/* This works around a webkit bug. Refreshes the browser's viewport,
* otherwise chatboxes are not moved along when one is closed.
* otherwise chatboxes are not moved along when one is closed.
*/
*/
...
@@ -412,34 +407,69 @@
...
@@ -412,34 +407,69 @@
}
}
};
};
utils
.
webForm2xForm
=
function
(
field
)
{
u
.
stringToDOM
=
function
(
s
)
{
/* Converts an HTML string into a DOM element.
*
* Parameters:
* (String) s - The HTML string
*/
var
div
=
document
.
createElement
(
'
div
'
);
div
.
innerHTML
=
s
;
return
div
.
childNodes
;
};
u
.
matchesSelector
=
function
(
el
,
selector
)
{
/* Checks whether the DOM element matches the given selector.
*
* Parameters:
* (DOMElement) el - The DOM element
* (String) selector - The selector
*/
return
(
el
.
matches
||
el
.
matchesSelector
||
el
.
msMatchesSelector
||
el
.
mozMatchesSelector
||
el
.
webkitMatchesSelector
||
el
.
oMatchesSelector
).
call
(
el
,
selector
);
};
u
.
queryChildren
=
function
(
el
,
selector
)
{
/* Returns a list of children of the DOM element that match the
* selector.
*
* Parameters:
* (DOMElement) el - the DOM element
* (String) selector - the selector they should be matched
* against.
*/
return
_
.
filter
(
el
.
children
,
_
.
partial
(
u
.
matchesSelector
,
_
,
selector
));
};
u
.
webForm2xForm
=
function
(
field
)
{
/* Takes an HTML DOM and turns it into an XForm field.
/* Takes an HTML DOM and turns it into an XForm field.
*
*
* Parameters:
* Parameters:
* (DOMElement) field - the field to convert
* (DOMElement) field - the field to convert
*/
*/
var
$input
=
$
(
field
),
value
;
let
value
;
if
(
$input
.
is
(
'
[type=checkbox]
'
))
{
if
(
field
.
getAttribute
(
'
type
'
)
===
'
checkbox
'
)
{
value
=
$input
.
is
(
'
:checked
'
)
&&
1
||
0
;
value
=
field
.
checked
&&
1
||
0
;
}
else
if
(
$input
.
is
(
'
textarea
'
))
{
}
else
if
(
field
.
tagName
==
"
textarea
"
)
{
value
=
[];
value
=
_
.
filter
(
field
.
value
.
split
(
'
\n
'
),
_
.
trim
);
var
lines
=
$input
.
val
().
split
(
'
\n
'
);
for
(
var
vk
=
0
;
vk
<
lines
.
length
;
vk
++
)
{
var
val
=
$
.
trim
(
lines
[
vk
]);
if
(
val
===
''
)
continue
;
value
.
push
(
val
);
}
}
else
{
}
else
{
value
=
$input
.
val
()
;
value
=
field
.
value
;
}
}
return
$
(
tpl_field
({
return
u
.
stringToDOM
(
name
:
$input
.
attr
(
'
name
'
),
tpl_field
({
value
:
value
name
:
field
.
getAttribute
(
'
name
'
),
}))[
0
];
value
:
value
})
)[
0
];
};
};
u
tils
.
contains
=
function
(
attr
,
query
)
{
u
.
contains
=
function
(
attr
,
query
)
{
return
function
(
item
)
{
return
function
(
item
)
{
if
(
typeof
attr
===
'
object
'
)
{
if
(
typeof
attr
===
'
object
'
)
{
var
value
=
false
;
var
value
=
false
;
...
@@ -455,94 +485,95 @@
...
@@ -455,94 +485,95 @@
};
};
};
};
u
tils
.
xForm2webForm
=
function
(
$field
,
$
stanza
)
{
u
.
xForm2webForm
=
function
(
field
,
stanza
)
{
/* Takes a field in XMPP XForm (XEP-004: Data Forms) format
/* Takes a field in XMPP XForm (XEP-004: Data Forms) format
* and turns it into a HTML DOM field.
* and turns it into an HTML field.
*
*
* Parameters:
* Returns either text or a DOM element (which is not ideal, but fine
* (XMLElement) field - the field to convert
* for now).
*/
*
* Parameters:
// FIXME: take <required> into consideration
* (XMLElement) field - the field to convert
var
options
=
[],
j
,
$options
,
$values
,
value
,
values
;
*/
if
(
field
.
getAttribute
(
'
type
'
)
===
'
list-single
'
||
if
(
$field
.
attr
(
'
type
'
)
===
'
list-single
'
||
$field
.
attr
(
'
type
'
)
===
'
list-multi
'
)
{
field
.
getAttribute
(
'
type
'
)
===
'
list-multi
'
)
{
values
=
[];
$values
=
$field
.
children
(
'
value
'
);
const
values
=
_
.
map
(
for
(
j
=
0
;
j
<
$values
.
length
;
j
++
)
{
u
.
queryChildren
(
field
,
'
value
'
),
values
.
push
(
$
(
$values
[
j
]).
text
());
_
.
partial
(
_
.
get
,
_
,
'
textContent
'
)
}
);
$options
=
$field
.
children
(
'
option
'
);
const
options
=
_
.
map
(
for
(
j
=
0
;
j
<
$options
.
length
;
j
++
)
{
u
.
queryChildren
(
field
,
'
option
'
),
value
=
$
(
$options
[
j
]).
find
(
'
value
'
).
text
();
function
(
option
)
{
options
.
push
(
tpl_select_option
({
const
value
=
_
.
get
(
option
.
querySelector
(
'
value
'
),
'
textContent
'
);
value
:
value
,
return
tpl_select_option
({
label
:
$
(
$options
[
j
]).
attr
(
'
label
'
),
'
value
'
:
value
,
selected
:
_
.
startsWith
(
values
,
value
),
'
label
'
:
option
.
getAttribute
(
'
label
'
),
required
:
$field
.
find
(
'
required
'
).
length
'
selected
'
:
_
.
startsWith
(
values
,
value
),
}));
'
required
'
:
_
.
isNil
(
field
.
querySelector
(
'
required
'
))
}
})
}
);
return
tpl_form_select
({
return
tpl_form_select
({
name
:
$field
.
attr
(
'
var
'
),
'
name
'
:
field
.
getAttribute
(
'
var
'
),
label
:
$field
.
attr
(
'
label
'
),
'
label
'
:
field
.
getAttribute
(
'
label
'
),
options
:
options
.
join
(
''
),
'
options
'
:
options
.
join
(
''
),
multiple
:
(
$field
.
attr
(
'
type
'
)
===
'
list-multi
'
),
'
multiple
'
:
(
field
.
getAttribute
(
'
type
'
)
===
'
list-multi
'
),
required
:
$field
.
find
(
'
required
'
).
length
'
required
'
:
_
.
isNil
(
field
.
querySelector
(
'
required
'
))
});
})
}
else
if
(
$field
.
attr
(
'
type
'
)
===
'
fixed
'
)
{
}
else
if
(
field
.
getAttribute
(
'
type
'
)
===
'
fixed
'
)
{
return
$
(
'
<p class="form-help">
'
).
text
(
$field
.
find
(
'
value
'
).
text
());
const
text
=
_
.
get
(
field
.
querySelector
(
'
value
'
),
'
textContent
'
);
}
else
if
(
$field
.
attr
(
'
type
'
)
===
'
jid-multi
'
)
{
const
el
=
u
.
stringToDOM
(
'
<p class="form-help">
'
);
el
.
textContent
=
text
;
return
el
;
}
else
if
(
field
.
getAttribute
(
'
type
'
)
===
'
jid-multi
'
)
{
return
tpl_form_textarea
({
return
tpl_form_textarea
({
name
:
$field
.
attr
(
'
var
'
),
'
name
'
:
field
.
getAttribute
(
'
var
'
),
label
:
$field
.
attr
(
'
label
'
)
||
''
,
'
label
'
:
field
.
getAttribute
(
'
label
'
)
||
''
,
value
:
$field
.
find
(
'
value
'
).
text
(
),
'
value
'
:
_
.
get
(
field
.
querySelector
(
'
value
'
),
'
textContent
'
),
required
:
$field
.
find
(
'
required
'
).
length
'
required
'
:
_
.
isNil
(
field
.
querySelector
(
'
required
'
))
})
;
})
}
else
if
(
$field
.
attr
(
'
type
'
)
===
'
boolean
'
)
{
}
else
if
(
field
.
getAttribute
(
'
type
'
)
===
'
boolean
'
)
{
return
tpl_form_checkbox
({
return
tpl_form_checkbox
({
name
:
$field
.
attr
(
'
var
'
),
'
name
'
:
field
.
getAttribute
(
'
var
'
),
type
:
XFORM_TYPE_MAP
[
$field
.
attr
(
'
type
'
)],
'
type
'
:
XFORM_TYPE_MAP
[
field
.
getAttribute
(
'
type
'
)],
label
:
$field
.
attr
(
'
label
'
)
||
''
,
'
label
'
:
field
.
getAttribute
(
'
label
'
)
||
''
,
checked
:
$field
.
find
(
'
value
'
).
text
(
)
===
"
1
"
&&
'
checked="1"
'
||
''
,
'
checked
'
:
_
.
get
(
field
.
querySelector
(
'
value
'
),
'
textContent
'
)
===
"
1
"
&&
'
checked="1"
'
||
''
,
required
:
$field
.
find
(
'
required
'
).
length
'
required
'
:
_
.
isNil
(
field
.
querySelector
(
'
required
'
))
})
;
})
}
else
if
(
$field
.
attr
(
'
type
'
)
&&
$field
.
attr
(
'
var
'
)
===
'
username
'
)
{
}
else
if
(
field
.
getAttribute
(
'
type
'
)
&&
field
.
getAttribute
(
'
var
'
)
===
'
username
'
)
{
return
tpl_form_username
({
return
tpl_form_username
({
domain
:
'
@
'
+
this
.
domain
,
'
domain
'
:
'
@
'
+
this
.
domain
,
name
:
$field
.
attr
(
'
var
'
),
'
name
'
:
field
.
getAttribute
(
'
var
'
),
type
:
XFORM_TYPE_MAP
[
$field
.
attr
(
'
type
'
)],
'
type
'
:
XFORM_TYPE_MAP
[
field
.
getAttribute
(
'
type
'
)],
label
:
$field
.
attr
(
'
label
'
)
||
''
,
'
label
'
:
field
.
getAttribute
(
'
label
'
)
||
''
,
value
:
$field
.
find
(
'
value
'
).
text
(
),
'
value
'
:
_
.
get
(
field
.
querySelector
(
'
value
'
),
'
textContent
'
),
required
:
$field
.
find
(
'
required
'
).
length
'
required
'
:
_
.
isNil
(
field
.
querySelector
(
'
required
'
))
})
;
})
}
else
if
(
$field
.
attr
(
'
type
'
))
{
}
else
if
(
field
.
getAttribute
(
'
type
'
))
{
return
tpl_form_input
({
return
tpl_form_input
({
name
:
$field
.
attr
(
'
var
'
),
'
name
'
:
field
.
getAttribute
(
'
var
'
),
type
:
XFORM_TYPE_MAP
[
$field
.
attr
(
'
type
'
)],
'
type
'
:
XFORM_TYPE_MAP
[
field
.
getAttribute
(
'
type
'
)],
label
:
$field
.
attr
(
'
label
'
)
||
''
,
'
label
'
:
field
.
getAttribute
(
'
label
'
)
||
''
,
value
:
$field
.
find
(
'
value
'
).
text
(
),
'
value
'
:
_
.
get
(
field
.
querySelector
(
'
value
'
),
'
textContent
'
),
required
:
$field
.
find
(
'
required
'
).
length
'
required
'
:
_
.
isNil
(
field
.
querySelector
(
'
required
'
))
})
;
})
}
else
{
}
else
{
if
(
$field
.
attr
(
'
var
'
)
===
'
ocr
'
)
{
// Captcha
if
(
field
.
getAttribute
(
'
var
'
)
===
'
ocr
'
)
{
// Captcha
return
_
.
reduce
(
_
.
map
(
$field
.
find
(
'
uri
'
),
const
uri
=
field
.
querySelector
(
'
uri
'
);
$
.
proxy
(
function
(
uri
)
{
const
el
=
sizzle
(
'
data[cid="
'
+
uri
.
textContent
.
replace
(
/^cid:/
,
''
)
+
'
"]
'
,
stanza
)[
0
];
return
tpl_form_captcha
({
return
tpl_form_captcha
({
label
:
this
.
$field
.
attr
(
'
label
'
),
'
label
'
:
field
.
getAttribute
(
'
label
'
),
name
:
this
.
$field
.
attr
(
'
var
'
),
'
name
'
:
field
.
getAttribute
(
'
var
'
),
data
:
this
.
$stanza
.
find
(
'
data[cid="
'
+
uri
.
textContent
.
replace
(
/^cid:/
,
''
)
+
'
"]
'
).
text
(),
'
data
'
:
_
.
get
(
el
,
'
textContent
'
),
type
:
uri
.
getAttribute
(
'
type
'
),
'
type
'
:
uri
.
getAttribute
(
'
type
'
),
required
:
this
.
$field
.
find
(
'
required
'
).
length
'
required
'
:
_
.
isNil
(
field
.
querySelector
(
'
required
'
))
});
})
},
{
'
$stanza
'
:
$stanza
,
'
$field
'
:
$field
})
),
function
(
memo
,
num
)
{
return
memo
+
num
;
},
''
);
}
}
}
}
}
}
u
tils
.
detectLocale
=
function
(
library_check
)
{
u
.
detectLocale
=
function
(
library_check
)
{
/* Determine which locale is supported by the user's system as well
/* Determine which locale is supported by the user's system as well
* as by the relevant library (e.g. converse.js or moment.js).
* as by the relevant library (e.g. converse.js or moment.js).
*
*
...
@@ -552,36 +583,36 @@
...
@@ -552,36 +583,36 @@
*/
*/
var
locale
,
i
;
var
locale
,
i
;
if
(
window
.
navigator
.
userLanguage
)
{
if
(
window
.
navigator
.
userLanguage
)
{
locale
=
u
tils
.
isLocaleAvailable
(
window
.
navigator
.
userLanguage
,
library_check
);
locale
=
u
.
isLocaleAvailable
(
window
.
navigator
.
userLanguage
,
library_check
);
}
}
if
(
window
.
navigator
.
languages
&&
!
locale
)
{
if
(
window
.
navigator
.
languages
&&
!
locale
)
{
for
(
i
=
0
;
i
<
window
.
navigator
.
languages
.
length
&&
!
locale
;
i
++
)
{
for
(
i
=
0
;
i
<
window
.
navigator
.
languages
.
length
&&
!
locale
;
i
++
)
{
locale
=
u
tils
.
isLocaleAvailable
(
window
.
navigator
.
languages
[
i
],
library_check
);
locale
=
u
.
isLocaleAvailable
(
window
.
navigator
.
languages
[
i
],
library_check
);
}
}
}
}
if
(
window
.
navigator
.
browserLanguage
&&
!
locale
)
{
if
(
window
.
navigator
.
browserLanguage
&&
!
locale
)
{
locale
=
u
tils
.
isLocaleAvailable
(
window
.
navigator
.
browserLanguage
,
library_check
);
locale
=
u
.
isLocaleAvailable
(
window
.
navigator
.
browserLanguage
,
library_check
);
}
}
if
(
window
.
navigator
.
language
&&
!
locale
)
{
if
(
window
.
navigator
.
language
&&
!
locale
)
{
locale
=
u
tils
.
isLocaleAvailable
(
window
.
navigator
.
language
,
library_check
);
locale
=
u
.
isLocaleAvailable
(
window
.
navigator
.
language
,
library_check
);
}
}
if
(
window
.
navigator
.
systemLanguage
&&
!
locale
)
{
if
(
window
.
navigator
.
systemLanguage
&&
!
locale
)
{
locale
=
u
tils
.
isLocaleAvailable
(
window
.
navigator
.
systemLanguage
,
library_check
);
locale
=
u
.
isLocaleAvailable
(
window
.
navigator
.
systemLanguage
,
library_check
);
}
}
return
locale
||
'
en
'
;
return
locale
||
'
en
'
;
};
};
u
tils
.
isConverseLocale
=
function
(
locale
)
{
u
.
isConverseLocale
=
function
(
locale
)
{
if
(
!
_
.
isString
(
locale
))
{
return
false
;
}
if
(
!
_
.
isString
(
locale
))
{
return
false
;
}
return
_
.
includes
(
_
.
keys
(
locales
||
{}),
locale
);
return
_
.
includes
(
_
.
keys
(
locales
||
{}),
locale
);
};
};
u
tils
.
isMomentLocale
=
function
(
locale
)
{
u
.
isMomentLocale
=
function
(
locale
)
{
if
(
!
_
.
isString
(
locale
))
{
return
false
;
}
if
(
!
_
.
isString
(
locale
))
{
return
false
;
}
return
moment
.
locale
()
!==
moment
.
locale
(
locale
);
return
moment
.
locale
()
!==
moment
.
locale
(
locale
);
};
};
u
tils
.
getLocale
=
function
(
preferred_locale
,
isSupportedByLibrary
)
{
u
.
getLocale
=
function
(
preferred_locale
,
isSupportedByLibrary
)
{
if
(
_
.
isString
(
preferred_locale
))
{
if
(
_
.
isString
(
preferred_locale
))
{
if
(
preferred_locale
===
'
en
'
||
isSupportedByLibrary
(
preferred_locale
))
{
if
(
preferred_locale
===
'
en
'
||
isSupportedByLibrary
(
preferred_locale
))
{
return
preferred_locale
;
return
preferred_locale
;
...
@@ -593,28 +624,28 @@
...
@@ -593,28 +624,28 @@
console
.
log
(
e
);
console
.
log
(
e
);
}
}
}
}
return
u
tils
.
detectLocale
(
isSupportedByLibrary
)
||
'
en
'
;
return
u
.
detectLocale
(
isSupportedByLibrary
)
||
'
en
'
;
};
};
u
tils
.
isOfType
=
function
(
type
,
item
)
{
u
.
isOfType
=
function
(
type
,
item
)
{
return
item
.
get
(
'
type
'
)
==
type
;
return
item
.
get
(
'
type
'
)
==
type
;
};
};
u
tils
.
isInstance
=
function
(
type
,
item
)
{
u
.
isInstance
=
function
(
type
,
item
)
{
return
item
instanceof
type
;
return
item
instanceof
type
;
};
};
u
tils
.
getAttribute
=
function
(
key
,
item
)
{
u
.
getAttribute
=
function
(
key
,
item
)
{
return
item
.
get
(
key
);
return
item
.
get
(
key
);
};
};
u
tils
.
contains
.
not
=
function
(
attr
,
query
)
{
u
.
contains
.
not
=
function
(
attr
,
query
)
{
return
function
(
item
)
{
return
function
(
item
)
{
return
!
(
u
tils
.
contains
(
attr
,
query
)(
item
));
return
!
(
u
.
contains
(
attr
,
query
)(
item
));
};
};
};
};
u
tils
.
createFragmentFromText
=
function
(
markup
)
{
u
.
createFragmentFromText
=
function
(
markup
)
{
/* Returns a DocumentFragment containing DOM nodes based on the
/* Returns a DocumentFragment containing DOM nodes based on the
* passed-in markup text.
* passed-in markup text.
*/
*/
...
@@ -630,7 +661,7 @@
...
@@ -630,7 +661,7 @@
return
frag
return
frag
};
};
u
tils
.
addEmoji
=
function
(
_converse
,
emojione
,
text
)
{
u
.
addEmoji
=
function
(
_converse
,
emojione
,
text
)
{
if
(
_converse
.
use_emojione
)
{
if
(
_converse
.
use_emojione
)
{
return
emojione
.
toImage
(
text
);
return
emojione
.
toImage
(
text
);
}
else
{
}
else
{
...
@@ -638,7 +669,7 @@
...
@@ -638,7 +669,7 @@
}
}
}
}
u
tils
.
getEmojisByCategory
=
function
(
_converse
,
emojione
)
{
u
.
getEmojisByCategory
=
function
(
_converse
,
emojione
)
{
/* Return a dict of emojis with the categories as keys and
/* Return a dict of emojis with the categories as keys and
* lists of emojis in that category as values.
* lists of emojis in that category as values.
*/
*/
...
@@ -684,11 +715,11 @@
...
@@ -684,11 +715,11 @@
return
_converse
.
emojis_by_category
;
return
_converse
.
emojis_by_category
;
};
};
u
tils
.
getTonedEmojis
=
function
(
_converse
)
{
u
.
getTonedEmojis
=
function
(
_converse
)
{
_converse
.
toned_emojis
=
_
.
uniq
(
_converse
.
toned_emojis
=
_
.
uniq
(
_
.
map
(
_
.
map
(
_
.
filter
(
_
.
filter
(
u
tils
.
getEmojisByCategory
(
_converse
).
people
,
u
.
getEmojisByCategory
(
_converse
).
people
,
(
person
)
=>
_
.
includes
(
person
.
_shortname
,
'
_tone
'
)
(
person
)
=>
_
.
includes
(
person
.
_shortname
,
'
_tone
'
)
),
),
(
person
)
=>
person
.
_shortname
.
replace
(
/_tone
[
1-5
]
/
,
''
)
(
person
)
=>
person
.
_shortname
.
replace
(
/_tone
[
1-5
]
/
,
''
)
...
@@ -696,11 +727,11 @@
...
@@ -696,11 +727,11 @@
return
_converse
.
toned_emojis
;
return
_converse
.
toned_emojis
;
};
};
u
tils
.
isPersistableModel
=
function
(
model
)
{
u
.
isPersistableModel
=
function
(
model
)
{
return
model
.
collection
&&
model
.
collection
.
browserStorage
;
return
model
.
collection
&&
model
.
collection
.
browserStorage
;
};
};
u
tils
.
getWrappedPromise
=
function
()
{
u
.
getWrappedPromise
=
function
()
{
const
wrapper
=
{};
const
wrapper
=
{};
wrapper
.
promise
=
new
Promise
((
resolve
,
reject
)
=>
{
wrapper
.
promise
=
new
Promise
((
resolve
,
reject
)
=>
{
wrapper
.
resolve
=
resolve
;
wrapper
.
resolve
=
resolve
;
...
@@ -709,12 +740,12 @@
...
@@ -709,12 +740,12 @@
return
wrapper
;
return
wrapper
;
};
};
u
tils
.
safeSave
=
function
(
model
,
attributes
)
{
u
.
safeSave
=
function
(
model
,
attributes
)
{
if
(
u
tils
.
isPersistableModel
(
model
))
{
if
(
u
.
isPersistableModel
(
model
))
{
model
.
save
(
attributes
);
model
.
save
(
attributes
);
}
else
{
}
else
{
model
.
set
(
attributes
);
model
.
set
(
attributes
);
}
}
}
}
return
u
tils
;
return
u
;
}));
}));
tests/mock.js
View file @
add3b8ef
(
function
(
root
,
factory
)
{
(
function
(
root
,
factory
)
{
define
(
"
mock
"
,
[
'
jquery.noconflict
'
,
'
converse
'
],
factory
);
define
(
"
mock
"
,
[
'
jquery.noconflict
'
,
'
converse
'
],
factory
);
}(
this
,
function
(
$
,
converse
_api
)
{
}(
this
,
function
(
$
,
converse
)
{
var
_
=
converse
_api
.
env
.
_
;
var
_
=
converse
.
env
.
_
;
var
Promise
=
converse
_api
.
env
.
Promise
;
var
Promise
=
converse
.
env
.
Promise
;
var
Strophe
=
converse
_api
.
env
.
Strophe
;
var
Strophe
=
converse
.
env
.
Strophe
;
var
$iq
=
converse
_api
.
env
.
$iq
;
var
$iq
=
converse
.
env
.
$iq
;
var
mock
=
{};
var
mock
=
{};
// Names from http://www.fakenamegenerator.com/
// Names from http://www.fakenamegenerator.com/
mock
.
req_names
=
[
mock
.
req_names
=
[
...
@@ -99,7 +99,7 @@
...
@@ -99,7 +99,7 @@
});
});
}
}
var
_converse
=
converse
_api
.
initialize
(
_
.
extend
({
var
_converse
=
converse
.
initialize
(
_
.
extend
({
'
i18n
'
:
'
en
'
,
'
i18n
'
:
'
en
'
,
'
auto_subscribe
'
:
false
,
'
auto_subscribe
'
:
false
,
'
play_sounds
'
:
false
,
'
play_sounds
'
:
false
,
...
@@ -113,7 +113,7 @@
...
@@ -113,7 +113,7 @@
'
debug
'
:
false
'
debug
'
:
false
},
settings
||
{}));
},
settings
||
{}));
_converse
.
ChatBoxViews
.
prototype
.
trimChat
=
function
()
{};
_converse
.
ChatBoxViews
.
prototype
.
trimChat
=
function
()
{};
_converse
.
disable_effects
=
true
;
window
.
converse_
disable_effects
=
true
;
$
.
fx
.
off
=
true
;
$
.
fx
.
off
=
true
;
return
_converse
;
return
_converse
;
}
}
...
...
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