diff options
| author | RblSb <msrblsb@gmail.com> | 2020-03-04 04:08:22 +0300 |
|---|---|---|
| committer | RblSb <msrblsb@gmail.com> | 2020-03-04 04:08:22 +0300 |
| commit | 4155b95cce55e1176aecb1531b9c06344a2e81b5 (patch) | |
| tree | 102a7693adebde04b9c5a6529753038c8f27c510 | |
| parent | dc83e4842f7bb6f8899872c9693ea6170f0b1724 (diff) | |
Improve iframe handling
| -rw-r--r-- | res/client.js | 39 | ||||
| -rw-r--r-- | src/client/Buttons.hx | 27 | ||||
| -rw-r--r-- | src/client/Main.hx | 4 | ||||
| -rw-r--r-- | src/client/Player.hx | 2 | ||||
| -rw-r--r-- | src/client/players/Iframe.hx | 3 |
5 files changed, 54 insertions, 21 deletions
diff --git a/res/client.js b/res/client.js index 470c0a8..e785320 100644 --- a/res/client.js +++ b/res/client.js @@ -520,19 +520,34 @@ client_Buttons.init = function(main) { }; var showMediaUrl = window.document.querySelector("#showmediaurl"); showMediaUrl.onclick = function(e12) { - showMediaUrl.classList.toggle("collapsed"); - showMediaUrl.classList.toggle("active"); - return window.document.querySelector("#addfromurl").classList.toggle("collapse"); + client_Buttons.showPlayerGroup(showMediaUrl); + return; }; var showCustomEmbed = window.document.querySelector("#showcustomembed"); showCustomEmbed.onclick = function(e13) { - showCustomEmbed.classList.toggle("collapsed"); - showCustomEmbed.classList.toggle("active"); - return window.document.querySelector("#customembed").classList.toggle("collapse"); + client_Buttons.showPlayerGroup(showCustomEmbed); + return; }; window.onresize = client_Buttons.onVideoResize; client_Buttons.initSplit(); }; +client_Buttons.showPlayerGroup = function(el) { + var groups = window.document.querySelectorAll("[data-target]"); + var _g = 0; + while(_g < groups.length) { + var group = groups[_g]; + ++_g; + if(el == group) { + continue; + } + group.classList.add("collapsed"); + group.classList.remove("active"); + window.document.querySelector(group.dataset.target).classList.add("collapse"); + } + el.classList.toggle("collapsed"); + el.classList.toggle("active"); + window.document.querySelector(el.dataset.target).classList.toggle("collapse"); +}; client_Buttons.initSplit = function(swapped) { if(swapped == null) { swapped = false; @@ -641,7 +656,7 @@ client_Buttons.initNavBar = function(main) { }; var removeBtn = window.document.querySelector("#removeVideoBtn"); removeBtn.onclick = function(e6) { - if(main.toggleVideoElement()) { + if(main.toggleVideoElement() || main.isListEmpty()) { removeBtn.innerText = Lang.get("removeVideo"); } else { removeBtn.innerText = Lang.get("addVideo"); @@ -915,6 +930,9 @@ client_Main.prototype = { } return this.player.hasVideo(); } + ,isListEmpty: function() { + return this.player.isListEmpty(); + } ,refreshPlayer: function() { this.player.refresh(); } @@ -935,7 +953,7 @@ client_Main.prototype = { var data = JSON.parse(e.data); var t = data.type; var t1 = t.charAt(0).toLowerCase() + HxOverrides.substr(t,1,null); - haxe_Log.trace("Event: " + data.type,{ fileName : "src/client/Main.hx", lineNumber : 253, className : "client.Main", methodName : "onMessage", customParams : [data[t1]]}); + haxe_Log.trace("Event: " + data.type,{ fileName : "src/client/Main.hx", lineNumber : 257, className : "client.Main", methodName : "onMessage", customParams : [data[t1]]}); switch(data.type) { case "AddVideo": this.player.addVideoItem(data.addVideo.item,data.addVideo.atEnd); @@ -1620,7 +1638,7 @@ client_Player.prototype = { return this.itemPos; } ,hasVideo: function() { - return this.player != null; + return this.playerEl.children.length != 0; } ,play: function() { if(!this.main.isSyncActive) { @@ -1744,6 +1762,9 @@ client_players_Iframe.prototype = { this.video = null; return; } + if(this.video.firstChild.nodeName == "IFRAME") { + this.video.setAttribute("sandbox","allow-scripts"); + } this.playerEl.appendChild(this.video); } ,removeVideo: function() { diff --git a/src/client/Buttons.hx b/src/client/Buttons.hx index dec8f04..318ba9a 100644 --- a/src/client/Buttons.hx +++ b/src/client/Buttons.hx @@ -132,23 +132,28 @@ class Buttons { } final showMediaUrl = ge("#showmediaurl"); - showMediaUrl.onclick = e -> { - showMediaUrl.classList.toggle("collapsed"); - showMediaUrl.classList.toggle("active"); - ge("#addfromurl").classList.toggle("collapse"); - } + showMediaUrl.onclick = e -> showPlayerGroup(showMediaUrl); final showCustomEmbed = ge("#showcustomembed"); - showCustomEmbed.onclick = e -> { - showCustomEmbed.classList.toggle("collapsed"); - showCustomEmbed.classList.toggle("active"); - ge("#customembed").classList.toggle("collapse"); - } + showCustomEmbed.onclick = e -> showPlayerGroup(showCustomEmbed); window.onresize = onVideoResize; initSplit(); } + static function showPlayerGroup(el:Element):Void { + final groups:Array<Element> = cast document.querySelectorAll('[data-target]'); + for (group in groups) { + if (el == group) continue; + group.classList.add("collapsed"); + group.classList.remove("active"); + ge(group.dataset.target).classList.add("collapse"); + } + el.classList.toggle("collapsed"); + el.classList.toggle("active"); + ge(el.dataset.target).classList.toggle("collapse"); + } + static function initSplit(swapped = false):Void { if (split != null) split.destroy(); final divs = ["#chatwrap", "#videowrap"]; @@ -245,7 +250,7 @@ class Buttons { final removeBtn = ge("#removeVideoBtn"); removeBtn.onclick = e -> { final has = main.toggleVideoElement(); - if (has) removeBtn.innerText = Lang.get("removeVideo"); + if (has || main.isListEmpty()) removeBtn.innerText = Lang.get("removeVideo"); else removeBtn.innerText = Lang.get("addVideo"); removeBtn.blur(); hideMenus(); diff --git a/src/client/Main.hx b/src/client/Main.hx index f32a80c..a5fe9bb 100644 --- a/src/client/Main.hx +++ b/src/client/Main.hx @@ -230,6 +230,10 @@ class Main { return player.hasVideo(); } + public function isListEmpty():Bool { + return player.isListEmpty(); + } + public function refreshPlayer():Void { player.refresh(); } diff --git a/src/client/Player.hx b/src/client/Player.hx index 7088580..4f1ecf6 100644 --- a/src/client/Player.hx +++ b/src/client/Player.hx @@ -293,7 +293,7 @@ class Player { } public function hasVideo():Bool { - return player != null; + return playerEl.children.length != 0; } public function play():Void { diff --git a/src/client/players/Iframe.hx b/src/client/players/Iframe.hx index 37d2fe6..f0a04c5 100644 --- a/src/client/players/Iframe.hx +++ b/src/client/players/Iframe.hx @@ -37,6 +37,9 @@ class Iframe implements IPlayer { video = null; return; } + if (video.firstChild.nodeName == "IFRAME") { + video.setAttribute("sandbox", "allow-scripts"); + } playerEl.appendChild(video); } |
