1
0
Эх сурвалжийг харах

Plyr: sometimes player is initialized earlier than css files are loaded #3598

Alex Trofimov 4 жил өмнө
parent
commit
90573e0ed2

+ 8 - 0
inc/js/functions.js

@@ -1255,4 +1255,12 @@ jQuery.bxGetCachedScript = function(sUrl, oOptions)
     return jQuery.ajax(oOptions);
 };
 
+function bx_is_selector_in_stylesheet(sSel)
+{
+    var o = [].slice.call(document.styleSheets)
+        .reduce( (prev, styleSheet) => [].slice.call(styleSheet.cssRules))
+        .reduce( (prev, cssRule) => prev + cssRule.cssText);
+    return jQuery.isFunction(o.includes) && o.includes('.plyr');
+}
+
 /** @} */

+ 8 - 1
modules/boonex/plyr/classes/BxPlyrPlayer.php

@@ -199,7 +199,14 @@ class BxPlyrPlayer extends BxDolPlayer
             $sScript = "
             <script>
                 $(document).ready(function () {
-                    $sInitEditor
+                    if (bx_is_selector_in_stylesheet('.plyr')) {
+                        $sInitEditor
+                    } 
+                    else {
+                    	setTimeout(function () {
+                        	$sInitEditor
+                        }, 250);
+                    }
                 });
             </script>";