From 4eecfe6291fc24df5495450c915bcf4ce1d04ab5 Mon Sep 17 00:00:00 2001 From: Beatrice Olivera Date: Fri, 31 Aug 2018 11:55:03 +0100 Subject: [PATCH] fixed issue where modal trigger broke navbar --- app/assets/javascripts/signaling-server.js | 22 +++++++++++++++------- app/javascript/components/modal.js | 11 +++++++++++ app/javascript/packs/application.js | 9 +++++++-- app/javascript/packs/modal.js | 8 -------- app/views/layouts/application.html.erb | 1 + app/views/pages/_contact.html.erb | 1 - 6 files changed, 34 insertions(+), 18 deletions(-) create mode 100644 app/javascript/components/modal.js delete mode 100644 app/javascript/packs/modal.js diff --git a/app/assets/javascripts/signaling-server.js b/app/assets/javascripts/signaling-server.js index 25db06a..25d1e5e 100644 --- a/app/assets/javascripts/signaling-server.js +++ b/app/assets/javascripts/signaling-server.js @@ -16,10 +16,12 @@ let pcPeers = {}; // peer connection let localstream; window.onload = () => { - currentUser = document.getElementById("current-user").innerHTML; - console.log(currentUser) - localVideo = document.getElementById("local-video"); - remoteVideoContainer = document.getElementById("remote-video-container"); + if (document.getElementById("current-user")) { + currentUser = document.getElementById("current-user").innerHTML; + console.log(currentUser) + localVideo = document.getElementById("local-video"); + remoteVideoContainer = document.getElementById("remote-video-container"); + } }; // Ice Credentials @@ -35,8 +37,10 @@ document.onreadystatechange = async () => { }) localstream = stream; - localVideo.srcObject = stream - localVideo.muted = true + if (localVideo) { + localVideo.srcObject = stream + localVideo.muted = true + } } catch (e) { console.error(e); } } }; @@ -67,7 +71,11 @@ document.onreadystatechange = async () => { // } // }); // }; -const chatroomId = document.getElementById('chatroom-hook').dataset["chatroomId"] + +if (document.getElementById('chatroom-hook')) { + const chatroomId = document.getElementById('chatroom-hook').dataset["chatroomId"] + +} const handleJoinSession = async () => { App['chatroom' + chatroomId] = await App.cable.subscriptions.create({ diff --git a/app/javascript/components/modal.js b/app/javascript/components/modal.js new file mode 100644 index 0000000..25eb307 --- /dev/null +++ b/app/javascript/components/modal.js @@ -0,0 +1,11 @@ + +const triggerModalEvent = () => { + const btn = document.getElementById("modalTrigger"); + const modal = document.getElementById("myModal"); + + btn.addEventListener('click', function(event) { + $('#myModal').modal('show'); + }); +} + +export { triggerModalEvent } diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js index b4593fd..8a54864 100644 --- a/app/javascript/packs/application.js +++ b/app/javascript/packs/application.js @@ -1,4 +1,9 @@ import "bootstrap"; -import { profilePageAnimation } from '../users/lesson'; -profilePageAnimation(); +import { triggerModalEvent } from "../components/modal.js"; + +triggerModalEvent(); + +// import { profilePageAnimation } from '../users/lesson'; + +// profilePageAnimation(); diff --git a/app/javascript/packs/modal.js b/app/javascript/packs/modal.js deleted file mode 100644 index e9249f1..0000000 --- a/app/javascript/packs/modal.js +++ /dev/null @@ -1,8 +0,0 @@ -import "bootstrap"; - -const btn = document.getElementById("modalTrigger"); -const modal = document.getElementById("myModal"); - -btn.addEventListener('click', function(event) { - $('#myModal').modal('show'); -}); diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 7118264..cfec1f6 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -15,5 +15,6 @@ <%= yield %> <%= javascript_include_tag 'application' %> <%= javascript_pack_tag 'application' %> + diff --git a/app/views/pages/_contact.html.erb b/app/views/pages/_contact.html.erb index 1a77dbf..0551402 100644 --- a/app/views/pages/_contact.html.erb +++ b/app/views/pages/_contact.html.erb @@ -61,4 +61,3 @@ end -<%= javascript_pack_tag 'modal' %>