Skip to content

Commit

Permalink
customized js asset (prevent double loading of js resources)
Browse files Browse the repository at this point in the history
updated README
  • Loading branch information
simialbi committed Oct 18, 2021
1 parent 0a742f1 commit 49b3d28
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 23 deletions.
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
[![License](https://poser.pugx.org/simialbi/yii2-widget-turbo/license?format=flat-square)](https://packagist.org/packages/simialbi/yii2-widget-turbo)
[![build](https://github.com/simialbi/yii2-widget-turbo/actions/workflows/build.yml/badge.svg)](https://github.com/simialbi/yii2-widget-turbo/actions/workflows/build.yml)

This repository is work in progress. The Frame widget can already be used.

## Resources
* [Yii Framework](https://www.yiiframework.com)
* [Hotwired turbo](https://turbo.hotwired.dev)

## Installation
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
Expand All @@ -28,6 +32,57 @@ to the `require` section of your `composer.json`.

## Example Usage

### Basic Frame
```php
<?php
Frame::begin([
'options' => [
'id' => 'example-frame'
]
]);
?>
<a href="/messages/expanded">
Show all expanded messages in this frame.
</a>

<form action="/messages">
Show response from this form within this frame.
</form>
<?php
Frame::end();
```

### Eager loaded frame
```php
<?php
Frame::begin([
'options' => [
'id' => 'example-frame',
'src' => Url::to(['/messages'])
]
]);
?>
Content will be replaced when /messages has been loaded.
<?php
Frame::end();
```

### Lazy loaded frame
```php
<?php
Frame::begin([
'options' => [
'id' => 'example-frame',
'src' => Url::to(['/messages'])
],
'lazyLoading' => true
]);
?>
Content will be replaced when the frame becomes visible and /messages has been loaded.
<?php
Frame::end();
```


## License

Expand Down
32 changes: 9 additions & 23 deletions src/assets/js/turbo.es2017-umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -1393,23 +1393,11 @@ Copyright © 2021 Basecamp, LLC
// console.log(newScriptElements);
// for await (let i = 0; i < newScriptElements.length; i++) {
for (const inertScriptElement of newScriptElements) {
// const inertScriptElement = newScriptElements[i];
// let render = true;
// if (inertScriptElement.src !== '') {
// for (const existingScripts of scripts) {
// if (existingScripts.src === inertScriptElement.src) {
// render = false;
// break;
// }
// }
// }
// if (render) {
if (inertScriptElement.src) {
window.externalScripts.push(this.include(inertScriptElement.src));
} else {
internalScripts.push(inertScriptElement);
}
// }
if (inertScriptElement.src) {
window.externalScripts.push(this.include(inertScriptElement.src));
} else {
internalScripts.push(inertScriptElement);
}
}

// console.log(window.externalScripts);
Expand Down Expand Up @@ -3323,7 +3311,7 @@ Copyright © 2021 Basecamp, LLC
this.scrollObserver = new ScrollObserver(this);
this.streamObserver = new StreamObserver(this);
this.frameRedirector = new FrameRedirector(document.documentElement);
this.drive = true;
this.drive = false;
this.enabled = true;
this.progressBarDelay = 500;
this.started = false;
Expand Down Expand Up @@ -4089,7 +4077,7 @@ Copyright © 2021 Basecamp, LLC
shouldInterceptNavigation(element, submitter)
{
const id = (submitter === null || submitter === void 0 ? void 0 : submitter.getAttribute('data-turbo-frame')) || element.getAttribute('data-turbo-frame') || this.element.getAttribute('target');
if (!this.enabled || id == '_top') {
if (!this.enabled || id === '_top') {
return false;
}
if (id) {
Expand All @@ -4101,10 +4089,8 @@ Copyright © 2021 Basecamp, LLC
if (!session.elementDriveEnabled(element)) {
return false;
}
if (submitter && !session.elementDriveEnabled(submitter)) {
return false;
}
return true;
return !(submitter && !session.elementDriveEnabled(submitter));

}
}

Expand Down

0 comments on commit 49b3d28

Please sign in to comment.