| 1 | <?php |
||
| 3 | class ChecIOExtension extends SiteTreeExtension |
||
| 4 | { |
||
| 5 | /** |
||
| 6 | * Loads the third party javascript during Controller->init() |
||
| 7 | */ |
||
| 8 | public function contentcontrollerInit() |
||
| 9 | { |
||
| 10 | if ($jsPath = ChecIOShortcode::config()->get('third-party-js')) { |
||
| 11 | Requirements::javascript($jsPath); |
||
| 12 | } |
||
| 13 | } |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Tries to fetch the inline chec.io JS from cache, failing which it gets it from the URL. |
||
| 17 | * Should your theme clear requirements, placing this before the closing body tag ensures |
||
| 18 | * that it always gets loaded. |
||
| 19 | * @return string |
||
| 20 | */ |
||
| 21 | public function getChecIOJs() |
||
| 22 | { |
||
| 23 | if ($jsPath = ChecIOShortcode::config()->get('third-party-js')) { |
||
| 24 | return sprintf('<script type="text/javascript" src="%s"></script>', $jsPath); |
||
| 25 | } |
||
| 26 | return ''; |
||
| 27 | } |
||
| 29 |