Comments (15)
yep. thanks :)
from phpagebuilder.
I see scripts are indeed removed on save. This might be something that GrapesJS is doing in the background, but I am not yet sure. Anyway, you can create a script.js
file in your block folder and this should work just fine.
from phpagebuilder.
I see scripts are indeed removed on save. This might be something that GrapesJS is doing in the background, but I am not yet sure. Anyway, you can create a
script.js
file in your block folder and this should work just fine.
Yes, script.js inside a block's folder did the trick
Regarding styles - I did patch vendor/hansschouten/phpagebuilder/src/Modules/GrapesJS/resources/views/grapesjs/config.php
'avoidInlineStyle' => true,
to
'avoidInlineStyle' => false,
and inline styles began to work. Could you please add this option to phpb_config? Or any other solution?
from phpagebuilder.
Just noticed - <styles>
block also lost
is style.css
should work in my block folder as a script.js
you mentioned before?
from phpagebuilder.
I see scripts are indeed removed on save. This might be something that GrapesJS is doing in the background, but I am not yet sure. Anyway, you can create a
script.js
file in your block folder and this should work just fine.
script.js inside the block' folder succesfully embedded in public state as this code
<script type="text/javascript" class="script2595779758">
document.getElementsByClassName("script2595779758")[0].addEventListener("run-script", function() {
let inPageBuilder = false;
let block = document.getElementsByClassName("script2595779758")[0].previousSibling;
let blockSelector = "." + block.className;
try {
const bacCarouselItems = document.querySelectorAll(".bac-carousel-item");
let itemNum = 1;
setInterval(() =>{
if(itemNum == bacCarouselItems.length) {
itemNum = 0;
bacCarouselItems.forEach(item => item === bacCarouselItems[itemNum] ? bacCarouselItems[itemNum].classList.add("active") : item.classList.remove("active"));
itemNum = 1;
} else {
bacCarouselItems.forEach(item => item === bacCarouselItems[itemNum] ? bacCarouselItems[itemNum].classList.add("active") : item.classList.remove("active"));
itemNum++;
}
}, 10000);
} catch {}
});
</script>
but run-script
never fired
any thoughts?
from phpagebuilder.
I did some patching again and it works
PHPageBuilder/src/Modules/GrapesJS/Block/BlockRenderer.php
Lines 163 to 175 in 0914081
protected function wrapScriptWithScopeAndContextData($script)
{
$scriptId = 'script' . rand(0, 10000000000);
$html = '<script type="text/javascript" class="' . $scriptId . '">'. PHP_EOL;
// $html .= 'let inPageBuilder = false;'. PHP_EOL;
$html .= 'let block'.$scriptId.' = document.getElementsByClassName("' . $scriptId . '")[0].previousSibling;'. PHP_EOL;
$html .= 'let blockSelector'.$scriptId.' = "." + block'.$scriptId.'.className;'. PHP_EOL;
$html .= 'var items = document.querySelectorAll(blockSelector'.$scriptId.');';
$html .= ' for (var i = 0, len = items.length; i < len; i++) {';
$html .= ' (function(){';
$html .= ' // START component code'. PHP_EOL;
$html .= $script;
$html .= ' // END component code'. PHP_EOL;
$html .= ' }.bind(items[i]))();';
$html .= ' }';
$html .= '</script>';
return $html;
}
sample code for block's scripts embedding got from here: https://grapesjs.com/docs/modules/Components-js.html#basic-scripts
from phpagebuilder.
The run scripts is fired if you add this to the very bottom of your layout files:
<script type="text/javascript">
document.querySelectorAll("script").forEach(function(scriptTag) {
scriptTag.dispatchEvent(new Event('run-script'));
});
</script>
from phpagebuilder.
The problem with the other approach is that you don't have access to any scripts that will be loaded at the end of your page body. By triggering these events, you do have access to them because now your block scripts are runned at the very end.
However, I like the binding trick to allow using this
. And you can always use a document.ready or something if needed. I will keep this in mind, but for now triggering the run-script
event should also work.
from phpagebuilder.
I had no idea yesterday about why run-script is missing. That's why I made this workaround. Thank you for keep in touch :)
One more edge case - I need the script to be inserted inside concrete div tag... How about this?
from phpagebuilder.
I need the script to be inserted inside concrete div tag
Done this by custom script.js in a block
var script = document.createElement("script");
var done = false;
script.src = 'https://external.js';
document.getElementsByClassName("address-map")[0].appendChild(script);
from phpagebuilder.
Ok, you are right. I should add that snippet to the readme or at least the boilerplate. Yes, you can add the script in specific locations that way. So everything is working now?
from phpagebuilder.
Regarding styles - I did patch
vendor/hansschouten/phpagebuilder/src/Modules/GrapesJS/resources/views/grapesjs/config.php
'avoidInlineStyle' => true,
to
'avoidInlineStyle' => false,
and inline styles began to work. Could you please add this option to phpb_config? Or any other solution?
this issue is left out of the discussion scope. consider please
from phpagebuilder.
You are right. However, I was using that setting before but it gave all kinds of issues with saving styles. This setting would save all inline style, but consider what happens if you are using an image slider or other blocks with advanced JS and then you open a page in the pagebuilder and click save. These plugins will add all kinds of style to your html and this would all be saved. And there were more issues as well.
Using inline style is a bad practice, please add the appropriate selectors to your html and refer to them in an external stylesheet.
from phpagebuilder.
moreover I have seen somewhere on GrapesJS's github that this option will be forced to true in future releases
from phpagebuilder.
Ok, thanks for the heads up. Once they would build websites as complex as my clients while still offering very easy component script notations, inline styling would definitely break when saving pages. Or scripts should be disabled in the pagebuilder, but that makes editing html inside tab components like here impossible. For my clients saving pages with extensive JS/CSS works fine without needing any inline styles. The problem of using inline styles is that JS packages would add styling into the DOM that should not be stored.
from phpagebuilder.
Related Issues (20)
- Important note: how to add static module which get data from database?
- How to clear blocks cache?
- Missing usage references with Framework Laminas
- SQLSTATE[42S22]: Column not found: 1054 Unknown column 'setting' in 'field list'
- Save as plain html in database
- I created a code editing plugin if you want to use it HOT 1
- How can I get Grapejs default block components inside my block HOT 3
- PHP 8.0+ HOT 1
- Index.php HOT 1
- error after installation HOT 1
- CKEditor 4 End of Life
- Pagebuilder is stuck on loading
- image options
- admin Not Found HOT 5
- need help with adjustments!!!
- Documentation guide incomplete
- Integration into Symfony
- PHP 8 HOT 1
- Creating multiple columns where the user can drag blocks in.
- Update my settings based on how many elements are inside the block
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phpagebuilder.