]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Refs #3091 rewrote the js and css register functions to require a name
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sat, 12 Mar 2011 20:08:44 +0000 (20:08 +0000)
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sat, 12 Mar 2011 20:08:44 +0000 (20:08 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@8668 36083f99-b078-4883-b0ff-0f9b5a30f544

15 files changed:
engine/lib/admin.php
engine/lib/elgglib.php
engine/lib/views.php
engine/tests/api/helpers.php
mod/blog/lib/blog.php
mod/notifications/index.php
mod/notifications/views/default/notifications/subscriptions/forminternals.php
mod/pages/start.php
mod/tinymce/views/default/tinymce/init.php
mod/zaudio/views/default/zaudio/audioplayer.php
views/default/admin/plugins/advanced.php
views/default/input/autocomplete.php
views/default/input/friendspicker.php
views/default/input/userpicker.php
views/default/page/components/list.php

index e788e30569fe40f33434f6ae8af85e97e8cbb82c..4e0c4f68149dc61169f4478b96d0f40b0b80a425 100644 (file)
@@ -282,7 +282,7 @@ function elgg_admin_add_plugin_settings_menu() {
 function admin_pagesetup() {
        if (elgg_in_context('admin')) {
                $url = elgg_get_simplecache_url('css', 'admin');
-               elgg_register_css($url, 'admin');
+               elgg_register_css('elgg.admin', $url);
                elgg_unregister_css('elgg');
 
                // setup footer menu
@@ -327,9 +327,9 @@ function admin_settings_page_handler($page) {
 
        elgg_unregister_css('elgg');
        $url = elgg_get_simplecache_url('js', 'admin');
-       elgg_register_js($url, 'admin');
+       elgg_register_js('elgg.admin', $url);
 
-       elgg_register_js('vendors/jquery/jquery.jeditable.mini.js', 'jquery.jeditable');
+       elgg_register_js('jquery.jeditable', 'vendors/jquery/jquery.jeditable.mini.js');
 
        // default to dashboard
        if (!isset($page[0]) || empty($page[0])) {
index bc272fbd7a4754e131bba859678c1a9a716ccb18..7b21f7dfc2b74c34d37c8167958a85a85f2125d4 100644 (file)
@@ -163,47 +163,55 @@ function forward($location = "", $reason = 'system') {
  * JavaScript from a view that may be called more than once. It also handles
  * more than one plugin adding the same JavaScript.
  *
- * Plugin authors are encouraged to use the $id variable. jQuery plugins
- * often have filenames such as jquery.rating.js. In that case, the id
- * would be "jquery.rating". It is recommended to not use version numbers
- * in the id.
+ * jQuery plugins often have filenames such as jquery.rating.js. A best practice
+ * is to base $name on the filename: "jquery.rating". It is recommended to not
+ * use version numbers in the name.
  *
  * The JavaScript files can be local to the server or remote (such as
  * Google's CDN).
  *
+ * @param string $name     An identifier for the JavaScript library
  * @param string $url      URL of the JavaScript file
- * @param string $id       An identifier of the JavaScript library
  * @param string $location Page location: head or footer. (default: head)
+ * @param int    $priority Priority of the CSS file (lower numbers load earlier)
+ *
  * @return bool
+ * @since 1.8.0
  */
-function elgg_register_js($url, $id = '', $location = 'head') {
-       return elgg_register_external_file('javascript', $url, $id, $location);
+function elgg_register_js($name, $url, $location = 'head', $priority = 500) {
+       return elgg_register_external_file('js', $name, $url, $location, $priority);
 }
 
 /**
  * Register a CSS file for inclusion in the HTML head
  *
- * @param string $url URL of the CSS file
- * @param string $id  An identifier for the CSS file
+ * @param string $name     An identifier for the CSS file
+ * @param string $url      URL of the CSS file
+ * @param int    $priority Priority of the CSS file (lower numbers load earlier)
+ *
  * @return bool
+ * @since 1.8.0
  */
-function elgg_register_css($url, $id = '') {
-       return elgg_register_external_file('css', $url, $id, 'head');
+function elgg_register_css($name, $url, $priority = 500) {
+       return elgg_register_external_file('css', $name, $url, 'head', $priority);
 }
 
 /**
  * Core registration function for external files
  *
  * @param string $type     Type of external resource
+ * @param string $name     Identifier used as key
  * @param string $url      URL
- * @param string $id       Identifier used as key
  * @param string $location Location in the page to include the file
+ * @param int    $priority Loading priority of the file
+ *
  * @return bool
+ * @since 1.8.0
  */
-function elgg_register_external_file($type, $url, $id, $location) {
+function elgg_register_external_file($type, $name, $url, $location, $priority) {
        global $CONFIG;
 
-       if (empty($url)) {
+       if (empty($name) || empty($url)) {
                return false;
        }
 
@@ -221,13 +229,8 @@ function elgg_register_external_file($type, $url, $id, $location) {
                $CONFIG->externals[$type][$location] = array();
        }
 
-       if (!$id) {
-               $id = count($CONFIG->externals[$type][$location]);
-       } else {
-               $id = trim(strtolower($id));
-       }
-
-       $CONFIG->externals[$type][$location][$id] = elgg_normalize_url($url);
+       $name = trim(strtolower($name));
+       $CONFIG->externals[$type][$location][$name] = elgg_normalize_url($url);
 
        return true;
 }
@@ -235,36 +238,37 @@ function elgg_register_external_file($type, $url, $id, $location) {
 /**
  * Unregister a JavaScript file
  *
- * @param string $id       The identifier for the JavaScript library
- * @param string $url      Optional URL to search for if id is not specified
- * @param string $location Location in the page
+ * @param string $name The identifier for the JavaScript library
+ *
  * @return bool
+ * @since 1.8.0
  */
-function elgg_unregister_js($id = '', $url = '', $location = 'head') {
-       return elgg_unregister_external_file('javascript', $id, $url, $location);
+function elgg_unregister_js($name) {
+       return elgg_unregister_external_file('js', $name);
 }
 
 /**
- * Unregister an external file
+ * Unregister a CSS file
+ *
+ * @param string $name The identifier for the CSS file
  *
- * @param string $id  The identifier of the CSS file
- * @param string $url Optional URL to search for if id is not specified
  * @return bool
+ * @since 1.8.0
  */
-function elgg_unregister_css($id = '', $url = '') {
-       return elgg_unregister_external_file('css', $id, $url, 'head');
+function elgg_unregister_css($name) {
+       return elgg_unregister_external_file('css', $name);
 }
 
 /**
  * Unregister an external file
  *
- * @param string $type     Type of file: javascript or css
- * @param string $id       The identifier of the file
- * @param string $url      Optional URL to search for if the id is not specified
- * @param string $location Location in the page
+ * @param string $type Type of file: javascript or css
+ * @param string $name The identifier of the file
+ *
  * @return bool
+ * @since 1.8.0
  */
-function elgg_unregister_external_file($type, $id = '', $url = '', $location = 'head') {
+function elgg_unregister_external_file($type, $name) {
        global $CONFIG;
 
        if (!isset($CONFIG->externals)) {
@@ -275,20 +279,11 @@ function elgg_unregister_external_file($type, $id = '', $url = '', $location = '
                return false;
        }
 
-       if (!isset($CONFIG->externals[$type][$location])) {
-               return false;
-       }
-
-       if (array_key_exists($id, $CONFIG->externals[$type][$location])) {
-               unset($CONFIG->externals[$type][$location][$id]);
-               return true;
-       }
-
-       // was not registered with an id so do a search for the url
-       $key = array_search($url, $CONFIG->externals[$type][$location]);
-       if ($key) {
-               unset($CONFIG->externals[$type][$location][$key]);
-               return true;
+       foreach ($CONFIG->externals[$type] as $location => $files) {
+               if (array_key_exists($name, $CONFIG->externals[$type][$location])) {
+                       unset($CONFIG->externals[$type][$location][$name]);
+                       return true;
+               }
        }
 
        return false;
@@ -300,15 +295,17 @@ function elgg_unregister_external_file($type, $id = '', $url = '', $location = '
  * @param string $location 'head' or 'footer'
  *
  * @return array
+ * @since 1.8.0
  */
 function elgg_get_js($location = 'head') {
-       return elgg_get_external_file('javascript', $location);
+       return elgg_get_external_file('js', $location);
 }
 
 /**
  * Get the CSS URLs
  *
  * @return array
+ * @since 1.8.0
  */
 function elgg_get_css() {
        return elgg_get_external_file('css', 'head');
@@ -319,7 +316,9 @@ function elgg_get_css() {
  *
  * @param string $type     Type of resource
  * @param string $location Page location
+ *
  * @return array
+ * @since 1.8.0
  */
 function elgg_get_external_file($type, $location) {
        global $CONFIG;
@@ -1761,7 +1760,7 @@ function elgg_is_valid_options_for_batch_operation($options, $type) {
  * @return boolean
  */
 function elgg_walled_garden_index() {
-       elgg_register_css('/css/walled_garden.css');
+       elgg_register_css('elgg.walled_garden', '/css/walled_garden.css');
        $login = elgg_view('core/account/login_walled_garden');
 
        echo elgg_view_page('', $login, 'walled_garden');
index 15e8b179b20186244c53cd2fee648c0a879f61fc..3d126332ac2c0b0c234b4394d6fd9cc22442d65b 100644 (file)
@@ -926,14 +926,14 @@ function elgg_view_annotation(ElggAnnotation $annotation, $full = true, $bypass
  * @return string The rendered list of entities
  * @access private
  */
-function elgg_view_entity_list($entities, $vars, $offset = 0, $limit = 10, $full_view = true,
+function elgg_view_entity_list($entities, $vars = array(), $offset = 0, $limit = 10, $full_view = true,
 $list_type_toggle = true, $pagination = true) {
 
        if (!is_int($offset)) {
                $offset = (int)get_input('offset', 0);
        }
 
-       if (func_num_args() == 2) {
+       if (is_array($vars)) {
                // new function
                $defaults = array(
                        'items' => $entities,
@@ -1256,7 +1256,7 @@ function elgg_view_form($action, $form_vars = array(), $body_vars = array()) {
  * @since 1.8.0
  * @access private
  */
-function elgg_view_list_item($item, $full_view, array $vars = array()) {
+function elgg_view_list_item($item, array $vars = array()) {
 
        $full_view = elgg_extract('full_view', $vars, false);
 
@@ -1470,10 +1470,10 @@ function autoregister_views($view_base, $folder, $base_location_path, $viewtype)
  */
 function elgg_views_register_core_head_elements() {
        $url = elgg_get_simplecache_url('js', 'elgg');
-       elgg_register_js($url, 'elgg');
+       elgg_register_js('elgg', $url, 'head', 10);
 
        $url = elgg_get_simplecache_url('css', 'elgg');
-       elgg_register_css($url, 'elgg');
+       elgg_register_css('elgg', $url, 10);
 }
 
 /**
@@ -1492,9 +1492,9 @@ function elgg_views_boot() {
        elgg_register_simplecache_view('css/ie6');
        elgg_register_simplecache_view('js/elgg');
 
-       elgg_register_js("/vendors/jquery/jquery-1.5.min.js", 'jquery');
-       elgg_register_js("/vendors/jquery/jquery-ui-1.8.9.min.js", 'jquery-ui');
-       elgg_register_js("/vendors/jquery/jquery.form.js", 'jquery.form');
+       elgg_register_js('jquery', '/vendors/jquery/jquery-1.5.min.js', 'head', 1);
+       elgg_register_js('jquery-ui', '/vendors/jquery/jquery-ui-1.8.9.min.js', 'head', 2);
+       elgg_register_js('jquery.form', '/vendors/jquery/jquery.form.js');
 
        elgg_register_event_handler('ready', 'system', 'elgg_views_register_core_head_elements');
 
index 488fd8390c26d9168c65d8af86088114322ca3ef..b8cf96900b52eec0dec14535aafa0fc6461d39e5 100644 (file)
@@ -103,15 +103,10 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {
        public function testElggRegisterJS() {
                global $CONFIG;
 
-               // specify id
-               $result = elgg_register_js('//test1.com', 'key', 'footer');
+               // specify name
+               $result = elgg_register_js('key', '//test1.com', 'footer');
                $this->assertTrue($result);
-               $this->assertIdentical('//test1.com', $CONFIG->externals['javascript']['footer']['key']);
-
-               // let Elgg pick id
-               $result = elgg_register_js('//test2.com');
-               $this->assertTrue($result);
-               $this->assertIdentical('//test2.com', $CONFIG->externals['javascript']['head'][0]);
+               $this->assertIdentical('//test1.com', $CONFIG->externals['js']['footer']['key']);
 
                // send a bad url
                $result = elgg_register_js();
@@ -124,19 +119,10 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {
        public function testElggRegisterCSS() {
                global $CONFIG;
 
-               // specify id
-               $result = elgg_register_css('//test1.com', 'key');
+               // specify name
+               $result = elgg_register_css('key', '//test1.com');
                $this->assertTrue($result);
                $this->assertIdentical('//test1.com', $CONFIG->externals['css']['head']['key']);
-
-               // let Elgg pick id
-               $result = elgg_register_css('//test2.com');
-               $this->assertTrue($result);
-               $this->assertIdentical('//test2.com', $CONFIG->externals['css']['head'][1]);
-
-               // send a bad url
-               $result = elgg_register_js();
-               $this->assertFalse($result);
        }
 
        /**
@@ -147,23 +133,20 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {
 
                $urls = array('id1' => '//url1.com', 'id2' => '//url2.com', 'id3' => '//url3.com');
                foreach ($urls as $id => $url) {
-                       elgg_register_js($url, $id);
+                       elgg_register_js($id, $url);
                }
 
                $result = elgg_unregister_js('id1');
                $this->assertTrue($result);
-               $this->assertNULL($CONFIG->externals['javascript']['head']['id1']);
-
-               $result = elgg_unregister_js('', '//url2.com');
-               $this->assertTrue($result);
-               $this->assertNULL($CONFIG->externals['javascript']['head']['id2']);
+               $this->assertNULL($CONFIG->externals['js']['head']['id1']);
 
                $result = elgg_unregister_js('id1');
                $this->assertFalse($result);
                $result = elgg_unregister_js('', '//url2.com');
                $this->assertFalse($result);
 
-               $this->assertIdentical($urls['id3'], $CONFIG->externals['javascript']['head']['id3']);
+               $result = elgg_unregister_js('id2');
+               $this->assertIdentical($urls['id3'], $CONFIG->externals['js']['head']['id3']);
        }
 
        /**
@@ -172,7 +155,9 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {
        public function testElggGetJS() {
                global $CONFIG;
 
-               $urls = array('id1' => '//url1.com', 'id2' => '//url2.com', 'id3' => '//url3.com');
+               $base = trim(elgg_get_site_url(), "/");
+
+               $urls = array('id1' => "$base/id1", 'id2' => "$base/id2", 'id3' => "$base/id3");
                foreach ($urls as $id => $url) {
                        elgg_register_js($url, $id);
                }
index 81d06ca0ac00abc12ded7c948302b571ff384a64..94ab65da1d96a34f544dcf70a64bd94241825bab 100644 (file)
@@ -299,7 +299,7 @@ function blog_get_page_content_edit($page, $guid = 0, $revision = NULL) {
                        elgg_push_breadcrumb(elgg_echo('edit'));
                        
                        $blog_js = elgg_get_simplecache_url('js', 'blog/save_draft');
-                       elgg_register_js($blog_js, 'blog');
+                       elgg_register_js('elgg.blog', $blog_js);
 
                        $content = elgg_view_form('blog/save', $vars, $body_vars);
                        $sidebar = elgg_view('blog/sidebar/revisions', $vars);
@@ -320,7 +320,7 @@ function blog_get_page_content_edit($page, $guid = 0, $revision = NULL) {
                $content = elgg_view_form('blog/save', $vars, $body_vars);
                
                $blog_js = elgg_get_simplecache_url('js', 'blog/save_draft');
-               elgg_register_js($blog_js, 'blog');
+               elgg_register_js('elgg.blog', $blog_js);
        }
 
        $return['title'] = $title;
index f970dfc324569ce0c39d636240754129d32b3bf2..30ee1b74bc7b2896abe393e24d4c9421f9ac94d6 100644 (file)
@@ -14,7 +14,7 @@ gatekeeper();
 set_page_owner(elgg_get_logged_in_user_guid());
 
 $js_url = elgg_get_simplecache_url('js', 'friendsPickerv1');
-elgg_register_js($js_url, 'friendsPicker');
+elgg_register_js('friendsPicker', $js_url);
 
 // Set the context to settings
 elgg_set_context('settings');
index 9361948424155fbeb64a342cce7f512a3aa78f71..fac8c083c9f879c41360f89e377b09be4917514f 100644 (file)
@@ -3,8 +3,8 @@
  * Hacked up friends picker that needs to be replaced
  */
 
-elgg_register_js('js/lib/friends_picker.js', 'friendspicker', 'head');
-elgg_register_js('vendors/jquery/jquery.easing.1.3.packed.js', 'jquery.easing');
+elgg_register_js('elgg.friendspicker', 'js/lib/friends_picker.js');
+elgg_register_js('jquery.easing', 'vendors/jquery/jquery.easing.1.3.packed.js');
 
 ?>
 <div class="elgg-module elgg-module-info">
index 1c655bd072115bacf393c439d44a9be8c8977786..23c564da5287ac842dfb36ab84fd74364085d1fa 100644 (file)
@@ -101,9 +101,9 @@ function pages_page_handler($page) {
        
        // add the jquery treeview files for navigation
        $js_url = elgg_get_site_url() . 'mod/pages/vendors/jquery-treeview/jquery.treeview.min.js';
-       elgg_register_js($js_url, 'jquery-treeview');
+       elgg_register_js('jquery-treeview', $js_url);
        $css_url = elgg_get_site_url() . 'mod/pages/vendors/jquery-treeview/jquery.treeview.css';
-       elgg_register_css($css_url, 'jquery-treeview');
+       elgg_register_css('jquery-treeview', $css_url);
 
        if (!isset($page[0])) {
                $page[0] = 'all';
index 408aba094678c90cd9855395e577f0576af7589e..3fe08771c1b5c9bd7e82eca339cf1aaa4f389f32 100644 (file)
@@ -3,5 +3,5 @@
  * Initialize the TinyMCE script
  */
 
-elgg_register_js('mod/tinymce/vendor/tinymce/jscripts/tiny_mce/tiny_mce.js', 'tinymce');
-elgg_register_js(elgg_get_simplecache_url('js', 'tinymce'), 'elgg.tinymce');
\ No newline at end of file
+elgg_register_js('tinymce', 'mod/tinymce/vendor/tinymce/jscripts/tiny_mce/tiny_mce.js');
+elgg_register_js('elgg.tinymce', elgg_get_simplecache_url('js', 'tinymce'));
\ No newline at end of file
index 2708f4cec33737585160a03512e722007e99c3d2..6898506a6099729bb8cbcbc909b1f424cd84cc58 100644 (file)
@@ -5,7 +5,7 @@
  */
 
 $js_url = elgg_get_site_url() . 'mod/zaudio/audioplayer/audio-player.js';
-elgg_register_js($js_url, 'zaudio');
+elgg_register_js('elgg.zaudio', $js_url);
 
 $swf_url = elgg_get_site_url() . 'mod/zaudio/audioplayer/player.swf';
 $mp3_url = elgg_get_site_url() . "mod/file/download.php?file_guid={$vars['file_guid']}";
index 49e31d9c1887d6c6855cd002919860de27f27b77..e78dbe2f1d3e5c7e4db853a34e3feea9831093bf 100644 (file)
@@ -85,7 +85,10 @@ $buttons .= $category_form;
 <div id="elgg-plugin-list">
 <?php
 
-       echo elgg_view_entity_list($installed_plugins, 0, 0, 0, true, false, false); 
+$options = array(
+
+);
+echo elgg_view_entity_list($installed_plugins, 0, 0, 0, true, false, false); 
 
 ?>
 </div>
\ No newline at end of file
index 61f33861190d3f369f9a0c73d9f3246b3b2700e2..212333141830fff3e2832081b3841da3d01bec31 100644 (file)
@@ -29,7 +29,7 @@ $ac_url_params = http_build_query(array(
 unset($vars['match_on']);
 unset($vars['match_owner']);
 
-elgg_register_js('js/lib/autocomplete.js', 'autocomplete', 'head');
+elgg_register_js('elgg.autocomplete', 'js/lib/autocomplete.js');
 
 ?>
 
index 82ef3e3d776fe14e3781b7248be54411f5fce6ef..b5f347e0ca1c72855be3be93b6b923893a55613d 100644 (file)
@@ -11,8 +11,8 @@
  * @uses $vars['entities'] The array of ElggUser objects
  */
 
-elgg_register_js('js/lib/friends_picker.js', 'friendspicker', 'head');
-elgg_register_js('vendors/jquery/jquery.easing.1.3.packed.js', 'jquery.easing');
+elgg_register_js('elgg.friendspicker', 'js/lib/friends_picker.js');
+elgg_register_js('jquery.easing', 'vendors/jquery/jquery.easing.1.3.packed.js');
 
 
 $chararray = elgg_echo('friendspicker:chararray');
index 77a51f37c302683e6d3c94fbbb76c6da066af873..8280305b08297373d5bde5dcd6133a95afffe9fb 100644 (file)
@@ -18,7 +18,7 @@
  *
  */
 
-elgg_register_js('js/lib/userpicker.js', 'userpicker', 'head');
+elgg_register_js('elgg.userpicker', 'js/lib/userpicker.js');
 
 function user_picker_add_user($user_id) {
        $user = get_entity($user_id);
index ae951c89fdb39bc286647e3f8967e0a47c1e5f5d..5e8c8432dc9ee44e268d1d7d7d52605fe5a5bc8c 100644 (file)
@@ -25,6 +25,11 @@ $pagination = elgg_extract('pagination', $vars, true);
 $offset_key = elgg_extract('offset_key', $vars, 'offset');
 $position = elgg_extract('position', $vars, 'after');
 
+// @todo standardize on full - will require backward compatible code
+if (isset($vars['full_view'])) {
+       $vars['full'] = $vars['full_view'];
+}
+
 $list_class = 'elgg-list';
 if (isset($vars['list_class'])) {
        $list_class = "{$vars['list_class']} $list_class";