From f60e5a1aec5d0b5b6eeb6971af050db5dd061c9d Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Wed, 20 Aug 2014 13:47:20 +0100 Subject: Added more jsfiddles. --- jsfiddles/event_stream/demo.css | 17 +++++ jsfiddles/event_stream/demo.html | 23 ++++++ jsfiddles/event_stream/demo.js | 142 +++++++++++++++++++++++++++++++++++ jsfiddles/room_memberships/demo.css | 17 +++++ jsfiddles/room_memberships/demo.html | 37 +++++++++ jsfiddles/room_memberships/demo.js | 139 ++++++++++++++++++++++++++++++++++ 6 files changed, 375 insertions(+) create mode 100644 jsfiddles/event_stream/demo.css create mode 100644 jsfiddles/event_stream/demo.html create mode 100644 jsfiddles/event_stream/demo.js create mode 100644 jsfiddles/room_memberships/demo.css create mode 100644 jsfiddles/room_memberships/demo.html create mode 100644 jsfiddles/room_memberships/demo.js diff --git a/jsfiddles/event_stream/demo.css b/jsfiddles/event_stream/demo.css new file mode 100644 index 0000000000..48a55f372d --- /dev/null +++ b/jsfiddles/event_stream/demo.css @@ -0,0 +1,17 @@ +.loggedin { + visibility: hidden; +} + +p { + font-family: monospace; +} + +table +{ + border-spacing:5px; +} + +th,td +{ + padding:5px; +} diff --git a/jsfiddles/event_stream/demo.html b/jsfiddles/event_stream/demo.html new file mode 100644 index 0000000000..ee4fc3ea68 --- /dev/null +++ b/jsfiddles/event_stream/demo.html @@ -0,0 +1,23 @@ +
+

This event stream demo requires a home server to be running on http://localhost:8080

+
+
+ + + +
+
+
+ +
+

+ + + + + + + +
Room IDLatest message
+
+ diff --git a/jsfiddles/event_stream/demo.js b/jsfiddles/event_stream/demo.js new file mode 100644 index 0000000000..b657b809e2 --- /dev/null +++ b/jsfiddles/event_stream/demo.js @@ -0,0 +1,142 @@ +var accountInfo = {}; + +var eventStreamInfo = { + from: "END" +}; + +var roomInfo = []; + +var longpollEventStream = function() { + var url = "http://localhost:8080/matrix/client/api/v1/events?access_token=$token&from=$from"; + url = url.replace("$token", accountInfo.access_token); + url = url.replace("$from", eventStreamInfo.from); + + $.getJSON(url, function(data) { + eventStreamInfo.from = data.end; + + var hasNewLatestMessage = false; + for (var i=0; i"+roomList[i].room_id+"" + + ""+roomList[i].latest_message+"" + + ""; + rows += row; + } + + $("#rooms").append(rows); +}; + diff --git a/jsfiddles/room_memberships/demo.css b/jsfiddles/room_memberships/demo.css new file mode 100644 index 0000000000..48a55f372d --- /dev/null +++ b/jsfiddles/room_memberships/demo.css @@ -0,0 +1,17 @@ +.loggedin { + visibility: hidden; +} + +p { + font-family: monospace; +} + +table +{ + border-spacing:5px; +} + +th,td +{ + padding:5px; +} diff --git a/jsfiddles/room_memberships/demo.html b/jsfiddles/room_memberships/demo.html new file mode 100644 index 0000000000..96232e827a --- /dev/null +++ b/jsfiddles/room_memberships/demo.html @@ -0,0 +1,37 @@ +
+

This room membership demo requires a home server to be running on http://localhost:8080

+
+
+ + + +
+
+
+ +
+
+ + + + +
+
+ + +
+ + + + + + + + +
Room IDMy stateRoom Alias
+
+ diff --git a/jsfiddles/room_memberships/demo.js b/jsfiddles/room_memberships/demo.js new file mode 100644 index 0000000000..b3ce0f0e33 --- /dev/null +++ b/jsfiddles/room_memberships/demo.js @@ -0,0 +1,139 @@ +var accountInfo = {}; + +var showLoggedIn = function(data) { + accountInfo = data; + getCurrentRoomList(); + $(".loggedin").css({visibility: "visible"}); +}; + +$('.login').live('click', function() { + var user = $("#userLogin").val(); + var password = $("#passwordLogin").val(); + $.ajax({ + url: "http://localhost:8080/matrix/client/api/v1/login", + type: "POST", + contentType: "application/json; charset=utf-8", + data: JSON.stringify({ user: user, password: password, type: "m.login.password" }), + dataType: "json", + success: function(data) { + $("#rooms").find("tr:gt(0)").remove(); + showLoggedIn(data); + }, + error: function(err) { + alert(JSON.stringify($.parseJSON(err.responseText))); + } + }); +}); + +var getCurrentRoomList = function() { + $("#roomId").val(""); + // wipe the table and reload it. Using the event stream would be the best + // solution but that is out of scope of this fiddle. + $("#rooms").find("tr:gt(0)").remove(); + + var url = "http://localhost:8080/matrix/client/api/v1/im/sync?access_token=" + accountInfo.access_token + "&from=END&to=START&limit=1"; + $.getJSON(url, function(data) { + for (var i=0; i"+data.room_id+"" + + ""+data.membership+"" + + ""+data.room_alias+"" + + ""; + $("#rooms").append(row); +}; + +$('.changeMembership').live('click', function() { + var roomId = $("#roomId").val(); + var member = $("#targetUser").val(); + var membership = $("#membership").val(); + + if (roomId.length === 0) { + return; + } + + var url = "http://localhost:8080/matrix/client/api/v1/rooms/$roomid/members/$user/state?access_token=$token"; + url = url.replace("$token", accountInfo.access_token); + url = url.replace("$roomid", encodeURIComponent(roomId)); + url = url.replace("$user", encodeURIComponent(member)); + + if (membership === "leave") { + $.ajax({ + url: url, + type: "DELETE", + contentType: "application/json; charset=utf-8", + dataType: "json", + success: function(data) { + getCurrentRoomList(); + }, + error: function(err) { + alert(JSON.stringify($.parseJSON(err.responseText))); + } + }); + } + else { + var data = { + membership: membership + }; + + $.ajax({ + url: url, + type: "PUT", + contentType: "application/json; charset=utf-8", + data: JSON.stringify(data), + dataType: "json", + success: function(data) { + getCurrentRoomList(); + }, + error: function(err) { + alert(JSON.stringify($.parseJSON(err.responseText))); + } + }); + } +}); + +$('.joinAlias').live('click', function() { + var roomAlias = $("#roomAlias").val(); + var url = "http://localhost:8080/matrix/client/api/v1/join/$roomalias?access_token=$token"; + url = url.replace("$token", accountInfo.access_token); + url = url.replace("$roomalias", encodeURIComponent(roomAlias)); + $.ajax({ + url: url, + type: "PUT", + contentType: "application/json; charset=utf-8", + data: JSON.stringify({}), + dataType: "json", + success: function(data) { + getCurrentRoomList(); + }, + error: function(err) { + alert(JSON.stringify($.parseJSON(err.responseText))); + } + }); +}); -- cgit 1.4.1