diff options
author | cash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2011-03-12 21:02:30 +0000 |
---|---|---|
committer | cash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2011-03-12 21:02:30 +0000 |
commit | 9b2c527e6cea1ce81293324f1783bc78225ada0f (patch) | |
tree | 8a9b1b1527d422e26d61430df6afcd46e5cf593b /engine | |
parent | d4cab20408bcfa394ca978a16e09e6fd84539350 (diff) | |
download | elgg-9b2c527e6cea1ce81293324f1783bc78225ada0f.tar.gz elgg-9b2c527e6cea1ce81293324f1783bc78225ada0f.tar.bz2 |
Refs #3091 registering js and css support priority though does not maintain registration order if items have equal priority
git-svn-id: http://code.elgg.org/elgg/trunk@8669 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine')
-rw-r--r-- | engine/lib/elgglib.php | 14 | ||||
-rw-r--r-- | engine/tests/api/helpers.php | 20 |
2 files changed, 22 insertions, 12 deletions
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 7b21f7dfc..93be114f2 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -208,7 +208,7 @@ function elgg_register_css($name, $url, $priority = 500) { * @return bool * @since 1.8.0 */ -function elgg_register_external_file($type, $name, $url, $location, $priority) { +function elgg_register_external_file($type, $name, $url, $location, $priority = 500) { global $CONFIG; if (empty($name) || empty($url)) { @@ -230,7 +230,12 @@ function elgg_register_external_file($type, $name, $url, $location, $priority) { } $name = trim(strtolower($name)); - $CONFIG->externals[$type][$location][$name] = elgg_normalize_url($url); + + $item = new stdClass(); + $item->url = elgg_normalize_url($url); + $item->priority = max((int)$priority, 0); + + $CONFIG->externals[$type][$location][$name] = $item; return true; } @@ -327,7 +332,10 @@ function elgg_get_external_file($type, $location) { isset($CONFIG->externals[$type]) && isset($CONFIG->externals[$type][$location])) { - return array_values($CONFIG->externals[$type][$location]); + $items = array_values($CONFIG->externals[$type][$location]); + usort($items, create_function('$a,$b','return $a->priority >= $b->priority;')); + array_walk($items, create_function('&$v,$k', '$v = $v->url;')); + return $items; } return array(); } diff --git a/engine/tests/api/helpers.php b/engine/tests/api/helpers.php index b8cf96900..b7057220b 100644 --- a/engine/tests/api/helpers.php +++ b/engine/tests/api/helpers.php @@ -104,9 +104,9 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest { global $CONFIG; // specify name - $result = elgg_register_js('key', '//test1.com', 'footer'); + $result = elgg_register_js('key', 'http://test1.com', 'footer'); $this->assertTrue($result); - $this->assertIdentical('//test1.com', $CONFIG->externals['js']['footer']['key']); + $this->assertIdentical('http://test1.com', $CONFIG->externals['js']['footer']['key']->url); // send a bad url $result = elgg_register_js(); @@ -120,9 +120,9 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest { global $CONFIG; // specify name - $result = elgg_register_css('key', '//test1.com'); + $result = elgg_register_css('key', 'http://test1.com'); $this->assertTrue($result); - $this->assertIdentical('//test1.com', $CONFIG->externals['css']['head']['key']); + $this->assertIdentical('http://test1.com', $CONFIG->externals['css']['head']['key']->url); } /** @@ -131,7 +131,9 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest { public function testElggUnregisterJS() { global $CONFIG; - $urls = array('id1' => '//url1.com', 'id2' => '//url2.com', 'id3' => '//url3.com'); + $base = trim(elgg_get_site_url(), "/"); + + $urls = array('id1' => "$base/urla", 'id2' => "$base/urlb", 'id3' => "$base/urlc"); foreach ($urls as $id => $url) { elgg_register_js($id, $url); } @@ -142,11 +144,11 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest { $result = elgg_unregister_js('id1'); $this->assertFalse($result); - $result = elgg_unregister_js('', '//url2.com'); + $result = elgg_unregister_js('', 'does_not_exist'); $this->assertFalse($result); $result = elgg_unregister_js('id2'); - $this->assertIdentical($urls['id3'], $CONFIG->externals['js']['head']['id3']); + $this->assertIdentical($urls['id3'], $CONFIG->externals['js']['head']['id3']->url); } /** @@ -157,9 +159,9 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest { $base = trim(elgg_get_site_url(), "/"); - $urls = array('id1' => "$base/id1", 'id2' => "$base/id2", 'id3' => "$base/id3"); + $urls = array('id1' => "$base/urla", 'id2' => "$base/urlb", 'id3' => "$base/urlc"); foreach ($urls as $id => $url) { - elgg_register_js($url, $id); + elgg_register_js($id, $url); } $js_urls = elgg_get_js('head'); |