reuse code
This commit is contained in:
parent
79bbda994b
commit
1835462ec4
|
@ -457,19 +457,12 @@ class OC_Util {
|
||||||
*/
|
*/
|
||||||
public static function addScript($application, $file = null, $prepend = false) {
|
public static function addScript($application, $file = null, $prepend = false) {
|
||||||
$path = OC_Util::generatePath($application, 'js', $file);
|
$path = OC_Util::generatePath($application, 'js', $file);
|
||||||
//TODO eliminate double code
|
|
||||||
if (!in_array($path, self::$scripts)) {
|
// core js files need separate handling
|
||||||
// core js files need separate handling
|
if ($application !== 'core' && $file !== null) {
|
||||||
if ($application !== 'core' && $file !== null) {
|
self::addTranslations ( $application );
|
||||||
self::addTranslations($application);
|
|
||||||
}
|
|
||||||
if ($prepend===true) {
|
|
||||||
array_unshift(self::$scripts, $path);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
self::$scripts[] = $path;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
self::addExternalResource($application, $prepend, $path, "script");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -482,14 +475,7 @@ class OC_Util {
|
||||||
*/
|
*/
|
||||||
public static function addVendorScript($application, $file = null, $prepend = false) {
|
public static function addVendorScript($application, $file = null, $prepend = false) {
|
||||||
$path = OC_Util::generatePath($application, 'vendor', $file);
|
$path = OC_Util::generatePath($application, 'vendor', $file);
|
||||||
//TODO eliminate double code
|
self::addExternalResource($application, $prepend, $path, "script");
|
||||||
if (! in_array ( $path, self::$scripts )) {
|
|
||||||
if ($prepend === true) {
|
|
||||||
array_unshift ( self::$scripts, $path );
|
|
||||||
} else {
|
|
||||||
self::$scripts [] = $path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -508,14 +494,7 @@ class OC_Util {
|
||||||
} else {
|
} else {
|
||||||
$path = "l10n/$languageCode";
|
$path = "l10n/$languageCode";
|
||||||
}
|
}
|
||||||
//TODO eliminate double code
|
self::addExternalResource($application, $prepend, $path, "script");
|
||||||
if (!in_array($path, self::$scripts)) {
|
|
||||||
if ($prepend === true) {
|
|
||||||
array_unshift ( self::$scripts, $path );
|
|
||||||
} else {
|
|
||||||
self::$scripts [] = $path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -528,14 +507,7 @@ class OC_Util {
|
||||||
*/
|
*/
|
||||||
public static function addStyle($application, $file = null, $prepend = false) {
|
public static function addStyle($application, $file = null, $prepend = false) {
|
||||||
$path = OC_Util::generatePath($application, 'css', $file);
|
$path = OC_Util::generatePath($application, 'css', $file);
|
||||||
//TODO eliminate double code
|
self::addExternalResource($application, $prepend, $path, "style");
|
||||||
if (!in_array($path, self::$styles)) {
|
|
||||||
if ($prepend === true) {
|
|
||||||
array_unshift ( self::$styles, $path );
|
|
||||||
} else {
|
|
||||||
self::$styles[] = $path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -548,13 +520,36 @@ class OC_Util {
|
||||||
*/
|
*/
|
||||||
public static function addVendorStyle($application, $file = null, $prepend = false) {
|
public static function addVendorStyle($application, $file = null, $prepend = false) {
|
||||||
$path = OC_Util::generatePath($application, 'vendor', $file);
|
$path = OC_Util::generatePath($application, 'vendor', $file);
|
||||||
//TODO eliminate double code
|
self::addExternalResource($application, $prepend, $path, "style");
|
||||||
if (!in_array($path, self::$styles)) {
|
}
|
||||||
if ($prepend === true) {
|
|
||||||
array_unshift ( self::$styles, $path );
|
/**
|
||||||
} else {
|
* add an external resource css/js file
|
||||||
self::$styles[] = $path;
|
*
|
||||||
}
|
* @param string $application application id
|
||||||
|
* @param bool $prepend prepend the file to the beginning of the list
|
||||||
|
* @param string $path
|
||||||
|
* @param string $type (script or style)
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private static function addExternalResource($application, $prepend, $path, $type = "script") {
|
||||||
|
|
||||||
|
if ($type === "style") {
|
||||||
|
if (!in_array($path, self::$styles)) {
|
||||||
|
if ($prepend === true) {
|
||||||
|
array_unshift ( self::$styles, $path );
|
||||||
|
} else {
|
||||||
|
self::$styles[] = $path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} elseif ($type === "script") {
|
||||||
|
if (!in_array($path, self::$scripts)) {
|
||||||
|
if ($prepend === true) {
|
||||||
|
array_unshift ( self::$scripts, $path );
|
||||||
|
} else {
|
||||||
|
self::$scripts [] = $path;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue