]> source.dussan.org Git - nextcloud-server.git/commitdiff
make sure styles and scripts are only loaded once
authorThomas Müller <thomas.mueller@tmit.eu>
Wed, 10 Dec 2014 14:41:38 +0000 (15:41 +0100)
committerMorris Jobke <hey@morrisjobke.de>
Tue, 16 Dec 2014 17:26:43 +0000 (18:26 +0100)
apps/files_external/templates/settings.php
lib/private/util.php

index 072f856dfbdeea7b4eee731f060737960e34292e..79950f30385e09ef413676d28f385597b3cda076 100644 (file)
@@ -76,7 +76,7 @@
                                                                <?php endif; ?>
                                                        <?php endif; ?>
                                                <?php endforeach; ?>
-                                               <?php if (isset($_['backends'][$mount['class']]['custom']) && !in_array('files_external/js/'.$_['backends'][$mount['class']]['custom'], \OC_Util::$scripts)): ?>
+                                               <?php if (isset($_['backends'][$mount['class']]['custom'])): ?>
                                                        <?php OCP\Util::addScript('files_external', $_['backends'][$mount['class']]['custom']); ?>
                                                <?php endif; ?>
                                        <?php endif; ?>
index 6ccb9dba0870cd08e9c0f95a6af6f3bca27e24fb..b97c0684629283a324857945f9e6ab24d247b98d 100644 (file)
@@ -333,9 +333,9 @@ class OC_Util {
        /**
         * generates a path for JS/CSS files. If no application is provided it will create the path for core.
         *
-        * @param $application application to get the files from
-        * @param $directory directory withing this application (css, js, vendor, etc)
-        * @param $file the file inside of the above folder
+        * @param string $application application to get the files from
+        * @param string $directory directory withing this application (css, js, vendor, etc)
+        * @param string $file the file inside of the above folder
         * @return string the path
         */
        private static function generatePath($application, $directory, $file) {
@@ -358,7 +358,10 @@ class OC_Util {
         * @return void
         */
        public static function addScript($application, $file = null) {
-               self::$scripts[] = OC_Util::generatePath($application, 'js', $file);
+               $path = OC_Util::generatePath($application, 'js', $file);
+               if (!in_array($path, self::$scripts)) {
+                       self::$scripts[] = $path;
+               }
        }
 
        /**
@@ -369,7 +372,10 @@ class OC_Util {
         * @return void
         */
        public static function addVendorScript($application, $file = null) {
-               self::$scripts[] = OC_Util::generatePath($application, 'vendor', $file);
+               $path = OC_Util::generatePath($application, 'vendor', $file);
+               if (!in_array($path, self::$scripts)) {
+                       self::$scripts[] = $path;
+               }
        }
 
        /**
@@ -384,9 +390,12 @@ class OC_Util {
                        $languageCode = $l->getLanguageCode($application);
                }
                if (!empty($application)) {
-                       self::$scripts[] = "$application/l10n/$languageCode";
+                       $path = "$application/l10n/$languageCode";
                } else {
-                       self::$scripts[] = "l10n/$languageCode";
+                       $path = "l10n/$languageCode";
+               }
+               if (!in_array($path, self::$scripts)) {
+                       self::$scripts[] = $path;
                }
        }
 
@@ -398,7 +407,10 @@ class OC_Util {
         * @return void
         */
        public static function addStyle($application, $file = null) {
-               self::$styles[] = OC_Util::generatePath($application, 'css', $file);
+               $path = OC_Util::generatePath($application, 'css', $file);
+               if (!in_array($path, self::$styles)) {
+                       self::$styles[] = $path;
+               }
        }
 
        /**
@@ -409,7 +421,10 @@ class OC_Util {
         * @return void
         */
        public static function addVendorStyle($application, $file = null) {
-               self::$styles[] = OC_Util::generatePath($application, 'vendor', $file);
+               $path = OC_Util::generatePath($application, 'vendor', $file);
+               if (!in_array($path, self::$styles)) {
+                       self::$styles[] = $path;
+               }
        }
 
        /**
@@ -1344,4 +1359,5 @@ class OC_Util {
        public static function isPhpCharSetUtf8() {
                return ini_get('default_charset') === 'UTF-8';
        }
+
 }