mirror of
				https://github.com/getgrav/grav.git
				synced 2025-10-31 02:15:55 +01:00 
			
		
		
		
	Refactored asset sorting logic
This commit is contained in:
		| @@ -1,6 +1,8 @@ | |||||||
| # v1.3.4 | # v1.3.4 | ||||||
| ## xx/xx/2017 | ## xx/xx/2017 | ||||||
|  |  | ||||||
|  | 1. [](#improved) | ||||||
|  |     * Refactored the Assets sorting logic | ||||||
| 1. [](#bugfix) | 1. [](#bugfix) | ||||||
|     * Fixed `Page::summary()` when using delimiter and multibyte UTF8 Characters [#1644](https://github.com/getgrav/grav/issues/1644) |     * Fixed `Page::summary()` when using delimiter and multibyte UTF8 Characters [#1644](https://github.com/getgrav/grav/issues/1644) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -508,25 +508,10 @@ class Assets | |||||||
|  |  | ||||||
|         // Sort array by priorities (larger priority first) |         // Sort array by priorities (larger priority first) | ||||||
|         if (Grav::instance()) { |         if (Grav::instance()) { | ||||||
|             uasort($this->css, function ($a, $b) { |             uasort($this->css, array($this, 'sortAssetsByPriorityThenOrder')); | ||||||
|                 if ($a['priority'] == $b['priority']) { |             uasort($this->inline_css, array($this, 'sortAssetsByPriorityThenOrder')); | ||||||
|                     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']; |  | ||||||
|             }); |  | ||||||
|         } |  | ||||||
|         $this->css = array_reverse($this->css); |  | ||||||
|         $this->inline_css = array_reverse($this->inline_css); |  | ||||||
|  |  | ||||||
|         $inlineGroup = array_key_exists('loading', $attributes) && $attributes['loading'] === 'inline'; |         $inlineGroup = array_key_exists('loading', $attributes) && $attributes['loading'] === 'inline'; | ||||||
|  |  | ||||||
|         $attributes = $this->attributes(array_merge(['type' => 'text/css', 'rel' => 'stylesheet'], $attributes)); |         $attributes = $this->attributes(array_merge(['type' => 'text/css', 'rel' => 'stylesheet'], $attributes)); | ||||||
| @@ -609,24 +594,8 @@ class Assets | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         // Sort array by priorities (larger priority first) |         // Sort array by priorities (larger priority first) | ||||||
|         uasort($this->js, function ($a, $b) { |         uasort($this->js, array($this, 'sortAssetsByPriorityThenOrder')); | ||||||
|             if ($a['priority'] == $b['priority']) { |         uasort($this->inline_js, array($this, 'sortAssetsByPriorityThenOrder')); | ||||||
|                 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); |  | ||||||
|  |  | ||||||
|         $inlineGroup = array_key_exists('loading', $attributes) && $attributes['loading'] === 'inline'; |         $inlineGroup = array_key_exists('loading', $attributes) && $attributes['loading'] === 'inline'; | ||||||
|  |  | ||||||
| @@ -1416,9 +1385,13 @@ class Assets | |||||||
|      * |      * | ||||||
|      * @return mixed |      * @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