From 42cd1d8661a395fa37f98f56937774525e16c97a Mon Sep 17 00:00:00 2001 From: llaffont <llaffont@afi-sa.fr> Date: Fri, 12 Jun 2015 11:26:53 +0200 Subject: [PATCH] defer together js loading --- library/Class/ScriptLoader.php | 4 ++-- library/ZendAfi/Controller/Plugin/TogetherJS.php | 4 ++-- tests/application/modules/opac/controllers/TogetherJSTest.php | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/library/Class/ScriptLoader.php b/library/Class/ScriptLoader.php index c23c25708df..4549710826b 100644 --- a/library/Class/ScriptLoader.php +++ b/library/Class/ScriptLoader.php @@ -240,11 +240,11 @@ class Class_ScriptLoader { /** * @return ScriptLoader */ - public function addScript($file) { + public function addScript($file, $defer=false) { if (false === strpos($file, '.js')) $file .= '.js'; $file = $this->_addVersionParam($file); - return $this->_scriptsAddLine(sprintf('<script src="%s" type="text/javascript"></script>', $file)); + return $this->_scriptsAddLine(sprintf('<script src="%s" '.($defer ? 'defer ' : '').'type="text/javascript"></script>', $file)); } diff --git a/library/ZendAfi/Controller/Plugin/TogetherJS.php b/library/ZendAfi/Controller/Plugin/TogetherJS.php index 07d8c86d0a2..cf72c653e80 100644 --- a/library/ZendAfi/Controller/Plugin/TogetherJS.php +++ b/library/ZendAfi/Controller/Plugin/TogetherJS.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class ZendAfi_Controller_Plugin_TogetherJS extends Zend_Controller_Plugin_Abstract { @@ -24,7 +24,7 @@ class ZendAfi_Controller_Plugin_TogetherJS extends Zend_Controller_Plugin_Abstra if (!Class_AdminVar::isModuleEnabled('ENABLE_COLLABORATIVE_BROWSING')) return; Class_ScriptLoader::getInstance() - ->addScript('https://togetherjs.com/togetherjs-min.js') + ->addScript('https://togetherjs.com/togetherjs-min.js', true) ->addJQueryReady('$("<button onclick=\'TogetherJS(this);return false\'>Start TogetherJS</button>") .css("position", "absolute") .css("top", "0") diff --git a/tests/application/modules/opac/controllers/TogetherJSTest.php b/tests/application/modules/opac/controllers/TogetherJSTest.php index b44f5a089bd..68ec5b619f8 100644 --- a/tests/application/modules/opac/controllers/TogetherJSTest.php +++ b/tests/application/modules/opac/controllers/TogetherJSTest.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ abstract class TogetherJSTestCase extends AbstractControllerTestCase { @@ -73,7 +73,7 @@ class TogetherJSEnabledTest extends TogetherJSTestCase { /** @test */ public function onOPACIndexTogetherJSShouldBePresent() { $this->dispatch('/'); - $this->assertXPath('//script[contains(@src, "togetherjs")]'); + $this->assertXPath('//script[contains(@src, "togetherjs")][@defer]'); } -- GitLab