mirror of
https://github.com/getgrav/grav.git
synced 2025-10-28 08:56:07 +01:00
Refactored asset sorting logic
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
# v1.3.4
|
||||
## xx/xx/2017
|
||||
|
||||
1. [](#improved)
|
||||
* Refactored the Assets sorting logic
|
||||
1. [](#bugfix)
|
||||
* Fixed `Page::summary()` when using delimiter and multibyte UTF8 Characters [#1644](https://github.com/getgrav/grav/issues/1644)
|
||||
|
||||
|
||||
@@ -508,24 +508,9 @@ class Assets
|
||||
|
||||
// Sort array by priorities (larger priority first)
|
||||
if (Grav::instance()) {
|
||||
uasort($this->css, function ($a, $b) {
|
||||
if ($a['priority'] == $b['priority']) {
|
||||
return $b['order'] - $a['order'];
|
||||
}
|
||||
|
||||
return $a['priority'] - $b['priority'];
|
||||
});
|
||||
|
||||
uasort($this->inline_css, function ($a, $b) {
|
||||
if ($a['priority'] == $b['priority']) {
|
||||
return $b['order'] - $a['order'];
|
||||
}
|
||||
|
||||
return $a['priority'] - $b['priority'];
|
||||
});
|
||||
uasort($this->css, array($this, 'sortAssetsByPriorityThenOrder'));
|
||||
uasort($this->inline_css, array($this, 'sortAssetsByPriorityThenOrder'));
|
||||
}
|
||||
$this->css = array_reverse($this->css);
|
||||
$this->inline_css = array_reverse($this->inline_css);
|
||||
|
||||
$inlineGroup = array_key_exists('loading', $attributes) && $attributes['loading'] === 'inline';
|
||||
|
||||
@@ -609,24 +594,8 @@ class Assets
|
||||
}
|
||||
|
||||
// Sort array by priorities (larger priority first)
|
||||
uasort($this->js, function ($a, $b) {
|
||||
if ($a['priority'] == $b['priority']) {
|
||||
return $b['order'] - $a['order'];
|
||||
}
|
||||
|
||||
return $a['priority'] - $b['priority'];
|
||||
});
|
||||
|
||||
uasort($this->inline_js, function ($a, $b) {
|
||||
if ($a['priority'] == $b['priority']) {
|
||||
return $b['order'] - $a['order'];
|
||||
}
|
||||
|
||||
return $a['priority'] - $b['priority'];
|
||||
});
|
||||
|
||||
$this->js = array_reverse($this->js);
|
||||
$this->inline_js = array_reverse($this->inline_js);
|
||||
uasort($this->js, array($this, 'sortAssetsByPriorityThenOrder'));
|
||||
uasort($this->inline_js, array($this, 'sortAssetsByPriorityThenOrder'));
|
||||
|
||||
$inlineGroup = array_key_exists('loading', $attributes) && $attributes['loading'] === 'inline';
|
||||
|
||||
@@ -1416,9 +1385,13 @@ class Assets
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function priorityCompare($a, $b)
|
||||
protected function sortAssetsByPriorityThenOrder($a, $b)
|
||||
{
|
||||
return $a ['priority'] - $b ['priority'];
|
||||
if ($a['priority'] == $b['priority']) {
|
||||
return $a['order'] - $b['order'];
|
||||
}
|
||||
|
||||
return $b['priority'] - $a['priority'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user