From 40589f8e8ee75485ba241777f3b26cd35d8a05ea Mon Sep 17 00:00:00 2001 From: RblSb Date: Sat, 25 Apr 2020 02:03:49 +0300 Subject: VideoRemove api event --- src/client/JsApi.hx | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'src/client/JsApi.hx') diff --git a/src/client/JsApi.hx b/src/client/JsApi.hx index 810e2f2..2df9c57 100644 --- a/src/client/JsApi.hx +++ b/src/client/JsApi.hx @@ -5,18 +5,18 @@ import js.Browser.document; private typedef VideoChangeFunc = (item:VideoItem)->Void; - class JsApi { static final videoChange:Array = []; + static final videoRemove:Array = []; @:expose - public static function addPlugin(id:String, ?onLoaded:()->Void):Void { + static function addPlugin(id:String, ?onLoaded:()->Void):Void { addScriptToHead('/plugins/$id/index.js', onLoaded); } @:expose - public static function addScriptToHead(url:String, ?onLoaded:()->Void):Void { + static function addScriptToHead(url:String, ?onLoaded:()->Void):Void { var script = document.createScriptElement(); script.type = "text/javascript"; script.onload = onLoaded; @@ -25,7 +25,7 @@ class JsApi { } @:expose - public static function hasScriptInHead(url:String):Bool { + static function hasScriptInHead(url:String):Bool { for (child in document.getElementsByTagName("head")[0].children) { if ((child : Dynamic).src == url) return true; } @@ -33,12 +33,12 @@ class JsApi { } @:expose - public static function notifyOnVideoChange(func:VideoChangeFunc):Void { + static function notifyOnVideoChange(func:VideoChangeFunc):Void { videoChange.push(func); } @:expose - public static function removeFromVideoChange(func:VideoChangeFunc):Void { + static function removeFromVideoChange(func:VideoChangeFunc):Void { videoChange.remove(func); } @@ -46,4 +46,18 @@ class JsApi { for (func in videoChange) func(item); } + @:expose + static function notifyOnVideoRemove(func:VideoChangeFunc):Void { + videoRemove.push(func); + } + + @:expose + static function removeFromVideoRemove(func:VideoChangeFunc):Void { + videoRemove.remove(func); + } + + public static function fireVideoRemoveEvents(item:VideoItem):Void { + for (func in videoRemove) func(item); + } + } -- cgit v1.2.3