diff --git a/readme.md b/readme.md
index 50a98af..52f195e 100644
--- a/readme.md
+++ b/readme.md
@@ -33,7 +33,6 @@ For Laravel users, there is a service provider you can make use of to automatica
];
```
-
When this provider is booted, you'll gain access to a helpful `JavaScript` facade, which you may use in your controllers.
```php
@@ -83,7 +82,7 @@ php artisan vendor:publish
php artisan vendor:publish --provider="Laracasts\Utilities\JavaScript\JavaScriptServiceProvider"
```
-This will add a new configuration file to: `config/javascript.php`.
+This will add a new configuration file to: `config/javascript.php`
```php
{{$js}}
+```
+
#### bind_js_vars_to_this_view
You need to update this file to specify which view you want your new JavaScript variables to be prepended to. Typically, your footer is a good place for this.
@@ -129,16 +134,19 @@ By default, all JavaScript vars will be nested under the global `window` object.
then you'll access all JavaScript variables, like so:
```js
-MyNewNamespace.varName
+MyNewNamespace.varName;
```
#### Note
+
Run this artisan command after changing the view path.
+
```
php artisan config:clear
```
### Symfony2
+
To use this component in Symfony2 applications you can try [this bundle](https://github.com/holyspecter/HospectPhpVarsToJsBundle), built on top of PHP-Vars-To-Js-Transformer.
### Without Laravel
diff --git a/src/JavaScriptServiceProvider.php b/src/JavaScriptServiceProvider.php
index a186fd7..5628221 100644
--- a/src/JavaScriptServiceProvider.php
+++ b/src/JavaScriptServiceProvider.php
@@ -34,9 +34,12 @@ public function register()
public function boot()
{
$this->publishes([
- __DIR__ . '/config/javascript.php' => config_path('javascript.php')
+ __DIR__ . '/config/javascript.php' => config_path('javascript.php'),
+ __DIR__ . '/views' => base_path('resources/views/vendor/utilities')
]);
+ $this->loadViewsFrom(__DIR__ . '/views', 'utilities');
+
if (class_exists('Illuminate\Foundation\AliasLoader')) {
AliasLoader::getInstance()->alias(
'JavaScript',
diff --git a/src/LaravelViewBinder.php b/src/LaravelViewBinder.php
index 6a2b5ec..bd6af7b 100644
--- a/src/LaravelViewBinder.php
+++ b/src/LaravelViewBinder.php
@@ -3,6 +3,7 @@
namespace Laracasts\Utilities\JavaScript;
use Illuminate\Contracts\Events\Dispatcher;
+use Illuminate\View\View;
class LaravelViewBinder implements ViewBinder
{
@@ -39,9 +40,11 @@ public function __construct(Dispatcher $event, $views)
*/
public function bind($js)
{
+
foreach ($this->views as $view) {
$this->event->listen("composing: {$view}", function () use ($js) {
- echo "";
+ $utilities = view("utilities::javascript", ['js' => $js]);
+ echo $utilities->render();
});
}
}
diff --git a/src/views/javascript.blade.php b/src/views/javascript.blade.php
new file mode 100644
index 0000000..2e89274
--- /dev/null
+++ b/src/views/javascript.blade.php
@@ -0,0 +1 @@
+
\ No newline at end of file