diff options
author | redmatrix <git@macgirvin.com> | 2016-06-11 15:23:13 -0700 |
---|---|---|
committer | redmatrix <git@macgirvin.com> | 2016-06-11 15:23:13 -0700 |
commit | 0e0a6f5f8d58061f727da94646a232d9ee5f4c67 (patch) | |
tree | 46026db46756a5403565abcc5cb0718632e39c70 | |
parent | 96cd63cf1a569c03575c0a04a6b29509f886e981 (diff) | |
download | volse-hubzilla-0e0a6f5f8d58061f727da94646a232d9ee5f4c67.tar.gz volse-hubzilla-0e0a6f5f8d58061f727da94646a232d9ee5f4c67.tar.bz2 volse-hubzilla-0e0a6f5f8d58061f727da94646a232d9ee5f4c67.zip |
Work supporting issue #411, add an optional priority (int) as a second arg to head_add_js to affect the load ordering, larger numbered priorities will be included after lower numbered ones. Default priority is 0.Note that we treat main.js differently and always add main.js to the page last, regardless of any other
ordering.
-rwxr-xr-x | include/plugin.php | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/include/plugin.php b/include/plugin.php index be4e92f03..94385550c 100755 --- a/include/plugin.php +++ b/include/plugin.php @@ -593,26 +593,38 @@ function script_path() { return $scheme . '://' . $hostname; } -function head_add_js($src) { - App::$js_sources[] = $src; +function head_add_js($src, $priority = 0) { + if(! is_array(App::$js_sources[$priority])) + App::$js_sources[$priority] = array(); + App::$js_sources[$priority][] = $src; } -function head_remove_js($src) { +function head_remove_js($src, $priority = 0) { - $index = array_search($src, App::$js_sources); + $index = array_search($src, App::$js_sources[$priority]); if($index !== false) - unset(App::$js_sources[$index]); + unset(App::$js_sources[$priority][$index]); } +// We should probably try to register main.js with a high priority, but currently we handle it +// separately and put it at the end of the html head block in case any other javascript is +// added outside the head_add_js construct. + function head_get_js() { + +logger('sources:' . print_r(App::$js_sources,true)); $str = ''; - $sources = App::$js_sources; - if(count($sources)) - foreach($sources as $source) { - if($source === 'main.js') - continue; - $str .= format_js_if_exists($source); + if(App::$js_sources) { + foreach(App::$js_sources as $sources) { + if(count($sources)) { + foreach($sources as $source) { + if($src === 'main.js') + continue; + $str .= format_js_if_exists($source); + } + } } + } return $str; } |