Skip to content

Commit

Permalink
fix replace js, css and metatags; remove unused handler
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanbarlog committed Nov 7, 2017
1 parent 14d097b commit 2d14162
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 56 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,27 @@ var Table = function() {
};
```

#### You don't need necessarily use this function

You don't actually need to use this function if you would write your JavaScript in a following way:

```javascript
// additional.js
var App = {
additional: function () {
// some additional functionality
console.log('executing App.additional');
},
// more functions within App namespace
}
App.additional();
```

The `App.additional()` will be executed every time the browser downloads `additional.js` file - no matter if the request is being handled with or without Ajaxcom. You just need to make sure that you are adding the `<script src="additional.js"></script>` to your DOM via Ajaxcom where it is needed.

The AjaxcomBundle will add all scripts within `javascripts` block to your page automatically (they will be inserted after the last `<script>` within your code).

### `replaceClass()`

You can easily replace class in any DOM object you want by invoking `replaceClass()` with two arguments - first is CSS selector of your choice and second is class which you want to replace current one with.
Expand Down
53 changes: 0 additions & 53 deletions src/Handler/ModalWindow.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Handler/ReplaceJavaScripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function handle(Handler $ajax, string $view, array $parameters = []): Han

try {
$javaScripts = $this->renderBlock->render($view, 'javascripts', $parameters);
$ajax->container('script:last-of-type')->append($javaScripts);
$ajax->container('script:last-of-type')->insertAfter($javaScripts);
} catch (AjaxcomException $exception) {
// do nothing
} finally {
Expand Down
2 changes: 1 addition & 1 deletion src/Handler/ReplaceMetaTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function handle(Handler $ajax, string $view, array $parameters = []): Han

try {
$metaTags = $this->renderBlock->render($view, 'metatags', $parameters);
$ajax->container('meta:last-of-type')->append($metaTags);
$ajax->container('meta:last-of-type')->insertAfter($metaTags);
} catch (AjaxcomException $exception) {
// do nothing
} finally {
Expand Down
2 changes: 1 addition & 1 deletion src/Handler/ReplaceStyleSheets.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function handle(Handler $ajax, string $view, array $parameters = []): Han

try {
$styleSheets = $this->renderBlock->render($view, 'stylesheets', $parameters);
$ajax->container('style:last-of-type')->append($styleSheets);
$ajax->container('style:last-of-type')->insertAfter($styleSheets);
} catch (AjaxcomException $exception) {
// do nothing
} finally {
Expand Down
1 change: 1 addition & 0 deletions src/Service/Ajaxcom.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public function handle(string $view, array $parameters = []): JsonResponse
$ajax = $this->removeBlocks->handle($ajax);
$ajax = $this->addBlocks->handle($ajax, $view, $parameters);
$ajax = $this->replaceClass->handle($ajax);
$ajax = $this->replaceJavaScripts->handle($ajax, $view, $parameters);
$ajax = $this->callbacks->handle($ajax);
$ajax = $this->changeUrl->handle($ajax);

Expand Down

0 comments on commit 2d14162

Please sign in to comment.