|
2 | 2 |
|
3 | 3 | namespace Bolt\Extension\cdowdy\betterthumbs;
|
4 | 4 |
|
5 |
| -use Bolt\Asset\Snippet\Snippet; |
6 |
| -use Bolt\Asset\Target; |
| 5 | +use Bolt\Asset\File\JavaScript; |
7 | 6 | use Bolt\Controller\Zone;
|
8 | 7 | use Bolt\Extension\cdowdy\betterthumbs\Controller\BetterThumbsBackendController;
|
9 | 8 | use Bolt\Extension\cdowdy\betterthumbs\Controller\BetterThumbsController;
|
|
16 | 15 | use Bolt\Version as Version;
|
17 | 16 | use League\Flysystem\Adapter\Local;
|
18 | 17 | use League\Flysystem\Filesystem;
|
19 |
| - |
20 | 18 | use Pimple as Container;
|
21 | 19 |
|
22 | 20 |
|
@@ -60,7 +58,7 @@ public function image( $sourceImage, $name = 'betterthumbs', array $options = []
|
60 | 58 | $app = $this->getContainer();
|
61 | 59 | $config = $this->getConfig();
|
62 | 60 |
|
63 |
| - $this->addAssets(); |
| 61 | +// $this->addAssets(); |
64 | 62 |
|
65 | 63 | $file = $this->filterEmptyImageArray( $sourceImage );
|
66 | 64 |
|
@@ -147,49 +145,44 @@ public function image( $sourceImage, $name = 'betterthumbs', array $options = []
|
147 | 145 | return new \Twig_Markup( $renderTemplate, 'UTF-8' );
|
148 | 146 | }
|
149 | 147 |
|
150 |
| - /** |
151 |
| - * You can't rely on bolts methods to insert javascript/css in the location you want. |
152 |
| - * So we have to hack around it. Use the Snippet Class with their location methods and insert |
153 |
| - * Picturefill into the head. Add a check to make sure the script isn't loaded more than once ($_scriptAdded) |
154 |
| - * and stop the insertion of the files multiple times because bolt's registerAssets method will blindly insert |
155 |
| - * the files on every page |
156 |
| - * |
157 |
| - */ |
158 | 148 |
|
159 |
| - protected function addAssets() |
160 |
| - { |
161 |
| - $app = $this->getContainer(); |
162 | 149 |
|
163 |
| - $config = $this->getConfig(); |
| 150 | + /** |
| 151 | + * @return array |
| 152 | + */ |
| 153 | + protected function registerAssets() |
| 154 | + { |
164 | 155 |
|
165 |
| - $pfill = $config['picturefill']; |
| 156 | + $config = $this->getConfig(); |
166 | 157 |
|
167 |
| - $extPath = $app['resources']->getUrl( 'extensions' ); |
| 158 | + $pfill = $config['picturefill']; |
168 | 159 |
|
169 |
| - $vendor = 'vendor/cdowdy/'; |
170 |
| - $extName = 'betterthumbs/'; |
171 | 160 |
|
172 |
| - $pictureFillJS = $extPath . $vendor . $extName . 'picturefill/' . $this->_currentPictureFill . '/picturefill.min.js'; |
173 |
| - $pictureFill = <<<PFILL |
174 |
| -<script src="{$pictureFillJS}" async defer></script> |
175 |
| -PFILL; |
176 |
| - $asset = new Snippet(); |
177 |
| - $asset->setCallback( $pictureFill ) |
178 |
| - ->setZone( ZONE::FRONTEND ) |
179 |
| - ->setLocation( Target::AFTER_HEAD_CSS ); |
| 161 | + $vendor = 'vendor/cdowdy/'; |
| 162 | + $extName = 'betterthumbs/'; |
180 | 163 |
|
| 164 | + $pictureFillJS = '/extensions/' . $vendor . $extName . 'picturefill/' . $this->_currentPictureFill . '/picturefill.min.js'; |
181 | 165 |
|
182 |
| - // add picturefill script only once for each time the extension is used |
183 |
| - if ( $pfill ) { |
184 |
| - if ( $this->_scriptAdded == false ) { |
185 |
| - $app['asset.queue.snippet']->add( $asset ); |
186 |
| - $this->_scriptAdded = true; |
187 |
| - } else { |
| 166 | + $asset = JavaScript::create() |
| 167 | + ->setFileName($pictureFillJS) |
| 168 | + ->setPriority(5) |
| 169 | + ->setAttributes(['defer', 'async']) |
| 170 | + ->setZone(Zone::FRONTEND); |
188 | 171 |
|
189 |
| - $this->_scriptAdded = true; |
190 |
| - } |
191 |
| - } |
192 |
| - } |
| 172 | + if ($pfill && $this->_scriptAdded == false) { |
| 173 | + |
| 174 | + $this->_scriptAdded = true; |
| 175 | + return [ |
| 176 | + $asset, |
| 177 | + ]; |
| 178 | + } else { |
| 179 | + |
| 180 | + $this->_scriptAdded = true; |
| 181 | + |
| 182 | + return null; |
| 183 | + } |
| 184 | + |
| 185 | + } |
193 | 186 |
|
194 | 187 | /**
|
195 | 188 | * @param $name
|
@@ -800,7 +793,7 @@ public function btSrc( $sourceImage, $name = 'betterthumbs', array $options = []
|
800 | 793 | $app = $this->getContainer();
|
801 | 794 | $config = $this->getConfig();
|
802 | 795 |
|
803 |
| - $this->addAssets(); |
| 796 | +// $this->addAssets(); |
804 | 797 |
|
805 | 798 |
|
806 | 799 | $configName = $this->getNamedConfig( $name );
|
|
0 commit comments