diff options
| author | RblSb <msrblsb@gmail.com> | 2020-02-24 01:19:30 +0300 |
|---|---|---|
| committer | RblSb <msrblsb@gmail.com> | 2020-02-24 01:19:30 +0300 |
| commit | c561fb9e2e42e4968f2b48cd535f208e90f8c12c (patch) | |
| tree | 0c7e1ffc99744aabbb240864b371b9555a611d92 /src/client/Utils.hx | |
| parent | 113b06e895f5dc752e8393c2a4f3f1669a7d0aab (diff) | |
More playlist and video control
Diffstat (limited to 'src/client/Utils.hx')
| -rw-r--r-- | src/client/Utils.hx | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/client/Utils.hx b/src/client/Utils.hx new file mode 100644 index 0000000..37de672 --- /dev/null +++ b/src/client/Utils.hx @@ -0,0 +1,63 @@ +package client; + +import js.html.Element; +import js.Browser.document; +import js.Browser.window; + +class Utils { + + public static function prepend(parent:Element, child:Element):Void { + if (parent.firstChild == null) parent.appendChild(child); + else parent.insertBefore(child, parent.firstChild); + } + + public static function insertAtIndex(parent:Element, child:Element, i:Int) { + if (i >= parent.children.length) parent.appendChild(child); + else parent.insertBefore(child, parent.children[i]); + } + + public static function toggleFullScreen(el:Element):Bool { + var state = true; + final doc:Dynamic = document; + final el2:Dynamic = el; + if (document.fullscreenElement == null && + doc.mozFullScreenElement == null && + doc.webkitFullscreenElement == null) { + if (el.requestFullscreen != null) { + el.requestFullscreen(); + } else if (el2.mozRequestFullScreen != null) { + el2.mozRequestFullScreen(); + } else if (el2.webkitRequestFullscreen != null) { + el2.webkitRequestFullscreen(untyped Element.ALLOW_KEYBOARD_INPUT); + } else state = false; + } else { + if (doc.cancelFullScreen != null) doc.cancelFullScreen(); + else if (doc.mozCancelFullScreen != null) doc.mozCancelFullScreen(); + else if (doc.webkitCancelFullScreen != null) doc.webkitCancelFullScreen(); + state = false; + } + return state; + } + + public static function copyToClipboard(text:String):Void { + final clipboardData = (window : Dynamic).clipboardData; + if (clipboardData != null && clipboardData.setData != null) { + // IE-specific code path to prevent textarea being shown while dialog is visible. + clipboardData.setData("Text", text); + return; + } else if ((document : Dynamic).queryCommandSupported != null) { + final textarea = document.createTextAreaElement(); + textarea.textContent = text; + // Prevent scrolling to bottom of page in Microsoft Edge. + textarea.style.position = "fixed"; + document.body.appendChild(textarea); + textarea.select(); + try { + // Security exception may be thrown by some browsers. + document.execCommand("copy"); + } + document.body.removeChild(textarea); + } + } + +} |
