From b2f229344cfa03916e476edcde102dd5baf1435c Mon Sep 17 00:00:00 2001 From: Ove Eriksson Date: Sun, 2 Nov 2014 11:18:10 +0100 Subject: [PATCH] scripts from Cdn's Replace javascript frameworks or own scripts with versions from Cdn's --- elements/helper.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/elements/helper.php b/elements/helper.php index dcd6072..d23448f 100644 --- a/elements/helper.php +++ b/elements/helper.php @@ -74,4 +74,25 @@ function getIncludeFile() // not found RETURN false; } -} \ No newline at end of file + + /** + * Replace javascript frameworks or own scripts with versions from Cdn's + * renames an array key, only if it exists, keeping the order + * $array is the js array from the document object + * $url_oldjs = the original path + * $url_newjs = the path to a Cdn + * + * returns the changed array + */ + public static function replaceUrljs($array, $url_oldjs, $url_newjs) + { + $keys = array_keys($array); + $index = array_search($url_oldjs, $keys); + + if ($index !== false) { + $keys[$index] = $url_newjs; + $array = array_combine($keys, $array); + } + return $array; + } +}