浏览代码

#3095 Froala: if not Iframely embed is used by default, then Embedly embeds inserted via Froala don't work properly

Alex Trofimov 5 年之前
父节点
当前提交
dc53070b74

+ 2 - 0
inc/classes/BxDolEmbed.php

@@ -38,6 +38,8 @@
  */
 class BxDolEmbed extends BxDolFactoryObject
 {
+    protected $_bCssJsAdded = false;
+
     /**
      * Get editor object instance by object name
      * @param $sObject object name

+ 0 - 4
inc/js/functions.js

@@ -815,10 +815,6 @@ function bx_time(sLang, isAutoupdate, sRootSel) {
             // process syntax hightlighing
             if ('undefined' !== typeof(Prism) && eElement.size())
                 Prism.highlightAllUnder(eElement[0]);
-
-            // process embeds
-            if ('undefined' !== typeof(bx_embed_dom_changed))
-                bx_embed_dom_changed(this);
         }
         if ('undefined' !== typeof(oCallback)) {
             oCallback(eElement);

+ 4 - 1
modules/boonex/froala/classes/BxFroalaModule.php

@@ -18,7 +18,7 @@ class BxFroalaModule extends BxDolModule
 
     public function serviceInjection()
     {
-        return "
+        $s = "
         <script>
             var fFroalaAddClass = function (s) {
                 $('.bx-content-description,.cmt-body,.bx-base-text-entity-content,.bx-tl-content').addClass('fr-view');
@@ -31,6 +31,9 @@ class BxFroalaModule extends BxDolModule
 
             fFroalaAddClass();
         </script>";
+
+        $oEmbed = BxDolEmbed::getObjectInstance('sys_embedly');
+        return $oEmbed ? $oEmbed->addJsCss() . $s : $s;
     }
 
     public function actionUpload()

+ 0 - 7
template/embed_embedly_integration.html

@@ -22,11 +22,4 @@ $(document).ready(function () {
     });
 });
 </bx_if:key>
-function bx_embed_link(e)
-{
-    embedly('card', e);
-}
-function bx_embed_dom_changed(e)
-{
-}
 </script>

+ 9 - 8
template/embed_iframely_integration.html

@@ -1,11 +1,12 @@
 <script async charset="utf-8" src="//cdn.iframe.ly/embed.js?api_key=__key__&iframe=card-small"></script>
 <script>
-function bx_embed_link(e)
-{
-    window.iframely && iframely.load(e);
-}
-function bx_embed_dom_changed(e)
-{
-    window.iframely && iframely.load();
-}
+$(document).ready(function () {
+    if (typeof glOnProcessHtml === 'undefined')
+        glOnProcessHtml = [];
+    if (glOnProcessHtml instanceof Array) {
+        glOnProcessHtml.push(function (e) {
+            window.iframely && iframely.load();
+        });
+    }
+});
 </script>

+ 15 - 0
template/scripts/BxBaseEmbedEmbedly.php

@@ -45,9 +45,24 @@ class BxBaseEmbedEmbedly extends BxDolEmbed
         ));
     }
 
+    public function addProcessLinkMethod ()
+    {
+        return "
+        <script>
+            function bx_embed_link(e)
+            {
+                embedly('card', e);
+            }
+        </script>";
+    }
+
     public function addJsCss ()
     {
+        if ($this->_bCssJsAdded)
+            return '';
+        
         $sKey = getParam('sys_embedly_api_key');
+        $this->_bCssJsAdded = true;
 
         return $this->_oTemplate->parseHtmlByName('embed_embedly_integration.html', array(
             'bx_if:key' => array (

+ 15 - 0
template/scripts/BxBaseEmbedIframely.php

@@ -45,9 +45,24 @@ class BxBaseEmbedIframely extends BxDolEmbed
         ));
     }
 
+    public function addProcessLinkMethod ()
+    {
+        return "
+        <script>
+            function bx_embed_link(e)
+            {
+                window.iframely && iframely.load(e);
+            }
+        </script>";
+    }
+
     public function addJsCss ()
     {
+        if ($this->_bCssJsAdded)
+            return '';
+
         $sKey = getParam('sys_iframely_api_key');
+        $this->_bCssJsAdded = true;
 
         return $this->_oTemplate->parseHtmlByName('embed_iframely_integration.html', array(
             'key' => $sKey,

+ 1 - 1
template/scripts/BxBaseFunctions.php

@@ -731,7 +731,7 @@ class BxBaseFunctions extends BxDolFactory implements iBxDolSingleton
         // Load embed files
         $oEmbed = BxDolEmbed::getObjectInstance(false);
         if ($oEmbed) 
-            return $oEmbed->addJsCss();
+            return $oEmbed->addJsCss() . $oEmbed->addProcessLinkMethod();
 
         return '';
     }