Skip to content

Commit a96be9c

Browse files
committed
Run prettier on the example files
1 parent 26f94b1 commit a96be9c

File tree

6 files changed

+108
-129
lines changed

6 files changed

+108
-129
lines changed

Diff for: examples/basic.js

+24-29
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ var connection = null;
44
function log(msg, data) {
55
var tr = document.createElement('tr');
66
var th = document.createElement('th');
7-
th.setAttribute( "style", "text-align: left; vertical-align: top;" );
7+
th.setAttribute('style', 'text-align: left; vertical-align: top;');
88
var td;
99

10-
th.appendChild( document.createTextNode(msg) );
11-
tr.appendChild( th );
10+
th.appendChild(document.createTextNode(msg));
11+
tr.appendChild(th);
1212

1313
if (data) {
1414
td = document.createElement('td');
1515
pre = document.createElement('code');
16-
pre.setAttribute("style", "white-space: pre-wrap;");
16+
pre.setAttribute('style', 'white-space: pre-wrap;');
1717
td.appendChild(pre);
18-
pre.appendChild( document.createTextNode( vkbeautify.xml(data) ) );
18+
pre.appendChild(document.createTextNode(vkbeautify.xml(data)));
1919
tr.appendChild(td);
2020
} else {
2121
th.setAttribute('colspan', '2');
@@ -24,31 +24,28 @@ function log(msg, data) {
2424
$('#log').append(tr);
2525
}
2626

27-
function rawInput(data)
28-
{
27+
function rawInput(data) {
2928
log('RECV', data);
3029
}
3130

32-
function rawOutput(data)
33-
{
31+
function rawOutput(data) {
3432
log('SENT', data);
3533
}
3634

37-
function onConnect(status)
38-
{
35+
function onConnect(status) {
3936
if (status == Strophe.Status.CONNECTING) {
40-
log('Strophe is connecting.');
37+
log('Strophe is connecting.');
4138
} else if (status == Strophe.Status.CONNFAIL) {
42-
log('Strophe failed to connect.');
43-
$('#connect').get(0).value = 'connect';
39+
log('Strophe failed to connect.');
40+
$('#connect').get(0).value = 'connect';
4441
} else if (status == Strophe.Status.DISCONNECTING) {
45-
log('Strophe is disconnecting.');
42+
log('Strophe is disconnecting.');
4643
} else if (status == Strophe.Status.DISCONNECTED) {
47-
log('Strophe is disconnected.');
48-
$('#connect').get(0).value = 'connect';
44+
log('Strophe is disconnected.');
45+
$('#connect').get(0).value = 'connect';
4946
} else if (status == Strophe.Status.CONNECTED) {
50-
log('Strophe is connected.');
51-
connection.disconnect();
47+
log('Strophe is connected.');
48+
connection.disconnect();
5249
}
5350
}
5451

@@ -58,16 +55,14 @@ $(document).ready(function () {
5855
connection.rawOutput = rawOutput;
5956

6057
$('#connect').bind('click', function () {
61-
var button = $('#connect').get(0);
62-
if (button.value == 'connect') {
63-
button.value = 'disconnect';
58+
var button = $('#connect').get(0);
59+
if (button.value == 'connect') {
60+
button.value = 'disconnect';
6461

65-
connection.connect($('#jid').get(0).value,
66-
$('#pass').get(0).value,
67-
onConnect);
68-
} else {
69-
button.value = 'connect';
70-
connection.disconnect();
71-
}
62+
connection.connect($('#jid').get(0).value, $('#pass').get(0).value, onConnect);
63+
} else {
64+
button.value = 'connect';
65+
connection.disconnect();
66+
}
7267
});
7368
});

Diff for: examples/echobot.html

+4-6
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
<html xmlns="http://www.w3.org/1999/xhtml">
33
<head>
44
<title>Strophe.js Echobot Example</title>
5-
<script type='text/javascript'
6-
src='http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js'></script>
7-
<script type='text/javascript'
8-
src='../strophe.js'></script>
9-
<script type='text/javascript'
10-
src='echobot.js'></script>
5+
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js'></script>
6+
<script type='module' src='../src/index.js'></script>
7+
<!-- <script type='module' src='../dist/strophe.umd.js'></script> -->
8+
<script type='text/javascript' src='echobot.js'></script>
119
</head>
1210
<body>
1311
<div id='login' style='text-align: center'>

Diff for: examples/echobot.js

+40-43
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,53 @@
1-
var BOSH_SERVICE = '/xmpp-httpbind';
2-
var connection = null;
1+
/* global Strophe, $, $pres, $msg */
32

4-
function log(msg)
5-
{
6-
$('#log').append('<div></div>').append(document.createTextNode(msg));
3+
const BOSH_SERVICE = '/xmpp-httpbind';
4+
let connection = null;
5+
6+
function log(msg) {
7+
const log = document.querySelector('#log');
8+
const div = document.createElement('div');
9+
log.appendChild(div);
10+
div.appendChild(document.createTextNode(msg));
711
}
812

9-
function onConnect(status)
10-
{
13+
function onConnect(status) {
1114
if (status == Strophe.Status.CONNECTING) {
12-
log('Strophe is connecting.');
15+
log('Strophe is connecting.');
1316
} else if (status == Strophe.Status.CONNFAIL) {
14-
log('Strophe failed to connect.');
15-
$('#connect').get(0).value = 'connect';
17+
log('Strophe failed to connect.');
18+
$('#connect').get(0).value = 'connect';
1619
} else if (status == Strophe.Status.DISCONNECTING) {
17-
log('Strophe is disconnecting.');
20+
log('Strophe is disconnecting.');
1821
} else if (status == Strophe.Status.DISCONNECTED) {
19-
log('Strophe is disconnected.');
20-
$('#connect').get(0).value = 'connect';
22+
log('Strophe is disconnected.');
23+
$('#connect').get(0).value = 'connect';
2124
} else if (status == Strophe.Status.CONNECTED) {
22-
log('Strophe is connected.');
23-
log('ECHOBOT: Send a message to ' + connection.jid +
24-
' to talk to me.');
25+
log('Strophe is connected.');
26+
log('ECHOBOT: Send a message to ' + connection.jid + ' to talk to me.');
2527

26-
connection.addHandler(onMessage, null, 'message', null, null, null);
27-
connection.send($pres().tree());
28+
connection.addHandler(onMessage, null, 'message', null, null, null);
29+
connection.send($pres().tree());
2830
}
2931
}
3032

3133
function onMessage(msg) {
32-
var to = msg.getAttribute('to');
33-
var from = msg.getAttribute('from');
34-
var type = msg.getAttribute('type');
35-
var elems = msg.getElementsByTagName('body');
34+
const to = msg.getAttribute('to');
35+
const from = msg.getAttribute('from');
36+
const type = msg.getAttribute('type');
37+
const elems = msg.getElementsByTagName('body');
38+
39+
if (type == 'chat' && elems.length > 0) {
40+
const body = elems[0];
3641

37-
if (type == "chat" && elems.length > 0) {
38-
var body = elems[0];
42+
log('ECHOBOT: I got a message from ' + from + ': ' + Strophe.getText(body));
3943

40-
log('ECHOBOT: I got a message from ' + from + ': ' +
41-
Strophe.getText(body));
42-
43-
var reply = $msg({to: from, from: to, type: 'chat'})
44-
.cnode(Strophe.copyElement(body));
45-
connection.send(reply.tree());
44+
const reply = $msg({ to: from, from: to, type: 'chat' }).cnode(Strophe.copyElement(body));
45+
connection.send(reply.tree());
4646

47-
log('ECHOBOT: I sent ' + from + ': ' + Strophe.getText(body));
47+
log('ECHOBOT: I sent ' + from + ': ' + Strophe.getText(body));
4848
}
4949

50-
// we must return true to keep the handler alive.
50+
// we must return true to keep the handler alive.
5151
// returning false would remove it after it finishes.
5252
return true;
5353
}
@@ -62,18 +62,15 @@ $(document).ready(function () {
6262
// Uncomment the following line to see all the debug output.
6363
//Strophe.log = function (level, msg) { log('LOG: ' + msg); };
6464

65-
6665
$('#connect').bind('click', function () {
67-
var button = $('#connect').get(0);
68-
if (button.value == 'connect') {
69-
button.value = 'disconnect';
66+
const button = $('#connect').get(0);
67+
if (button.value == 'connect') {
68+
button.value = 'disconnect';
7069

71-
connection.connect($('#jid').get(0).value,
72-
$('#pass').get(0).value,
73-
onConnect);
74-
} else {
75-
button.value = 'connect';
76-
connection.disconnect();
77-
}
70+
connection.connect($('#jid').get(0).value, $('#pass').get(0).value, onConnect);
71+
} else {
72+
button.value = 'connect';
73+
connection.disconnect();
74+
}
7875
});
7976
});

Diff for: examples/main.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
config.baseUrl = '../';
22
require.config(config);
3-
if (typeof(require) === 'function') {
4-
require(["jquery", "strophe", ], function($, wrapper) {
3+
if (typeof require === 'function') {
4+
require(['jquery', 'strophe'], function ($, wrapper) {
55
Strophe = wrapper.Strophe;
66

77
var BOSH_SERVICE = 'http://bosh.metajack.im:5280/xmpp-httpbind';
@@ -44,11 +44,7 @@ if (typeof(require) === 'function') {
4444
var button = $('#connect').get(0);
4545
if (button.value == 'connect') {
4646
button.value = 'disconnect';
47-
connection.connect(
48-
$('#jid').get(0).value,
49-
$('#pass').get(0).value,
50-
onConnect
51-
);
47+
connection.connect($('#jid').get(0).value, $('#pass').get(0).value, onConnect);
5248
} else {
5349
button.value = 'connect';
5450
connection.disconnect();

Diff for: examples/prebind.js

+28-33
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,44 @@
11
// http-pre-bind example
22
// This example works with mod_http_pre_bind found here:
33
// http://github.com/thepug/Mod-Http-Pre-Bind
4-
//
4+
//
55
// It expects both /xmpp-httpbind to be proxied and /http-pre-bind
66
//
77
// If you want to test this out without setting it up, you can use Collecta's
8-
// at http://www.collecta.com/xmpp-httpbind and
8+
// at http://www.collecta.com/xmpp-httpbind and
99
// http://www.collecta.com/http-pre-bind
1010
// Use a JID of 'guest.collecta.com' to test.
1111

1212
var BOSH_SERVICE = '/xmpp-httpbind';
1313
var PREBIND_SERVICE = '/http-pre-bind';
1414
var connection = null;
1515

16-
function log(msg)
17-
{
16+
function log(msg) {
1817
$('#log').append('<div></div>').append(document.createTextNode(msg));
1918
}
2019

21-
function rawInput(data)
22-
{
20+
function rawInput(data) {
2321
log('RECV: ' + data);
2422
}
2523

26-
function rawOutput(data)
27-
{
24+
function rawOutput(data) {
2825
log('SENT: ' + data);
2926
}
3027

31-
function onConnect(status)
32-
{
28+
function onConnect(status) {
3329
if (status === Strophe.Status.CONNECTING) {
34-
log('Strophe is connecting.');
30+
log('Strophe is connecting.');
3531
} else if (status === Strophe.Status.CONNFAIL) {
36-
log('Strophe failed to connect.');
37-
$('#connect').get(0).value = 'connect';
32+
log('Strophe failed to connect.');
33+
$('#connect').get(0).value = 'connect';
3834
} else if (status === Strophe.Status.DISCONNECTING) {
39-
log('Strophe is disconnecting.');
35+
log('Strophe is disconnecting.');
4036
} else if (status === Strophe.Status.DISCONNECTED) {
41-
log('Strophe is disconnected.');
42-
$('#connect').get(0).value = 'connect';
37+
log('Strophe is disconnected.');
38+
$('#connect').get(0).value = 'connect';
4339
} else if (status === Strophe.Status.CONNECTED) {
44-
log('Strophe is connected.');
45-
connection.disconnect();
40+
log('Strophe is connected.');
41+
connection.disconnect();
4642
} else if (status === Strophe.Status.ATTACHED) {
4743
log('Strophe is attached.');
4844
connection.disconnect();
@@ -65,19 +61,16 @@ function attach(data) {
6561
connection = new Strophe.Connection(BOSH_SERVICE);
6662
connection.rawInput = rawInput;
6763
connection.rawOutput = rawOutput;
68-
64+
6965
var $body = $(data.documentElement);
70-
connection.attach($body.find('jid').text(),
71-
$body.attr('sid'),
72-
parseInt($body.attr('rid'), 10) + 1,
73-
onConnect);
66+
connection.attach($body.find('jid').text(), $body.attr('sid'), parseInt($body.attr('rid'), 10) + 1, onConnect);
7467
}
7568

7669
$(document).ready(function () {
7770
$('#connect').bind('click', function () {
78-
var button = $('#connect').get(0);
79-
if (button.value == 'connect') {
80-
button.value = 'disconnect';
71+
var button = $('#connect').get(0);
72+
if (button.value == 'connect') {
73+
button.value = 'disconnect';
8174

8275
// attempt prebind
8376
$.ajax({
@@ -89,15 +82,17 @@ $(document).ready(function () {
8982
to: Strophe.getDomainFromJid($('#jid').val()),
9083
rid: '' + Math.floor(Math.random() * 4294967295),
9184
wait: '60',
92-
hold: '1'}).toString(),
85+
hold: '1',
86+
}).toString(),
9387
dataType: 'xml',
9488
error: normal_connect,
95-
success: attach});
96-
} else {
97-
button.value = 'connect';
98-
if (connection) {
89+
success: attach,
90+
});
91+
} else {
92+
button.value = 'connect';
93+
if (connection) {
9994
connection.disconnect();
10095
}
101-
}
96+
}
10297
});
103-
});
98+
});

0 commit comments

Comments
 (0)