Skip to content

Comments

[4.0][RFC] Serialise inline scripts and inline styles#14240

Closed
dgrammatiko wants to merge 3 commits intojoomla:4.0-devfrom
dgrammatiko:serialise_tags
Closed

[4.0][RFC] Serialise inline scripts and inline styles#14240
dgrammatiko wants to merge 3 commits intojoomla:4.0-devfrom
dgrammatiko:serialise_tags

Conversation

@dgrammatiko
Copy link
Contributor

@dgrammatiko dgrammatiko commented Feb 24, 2017

Pull Request for Issue # .

Summary of Changes

  • Drop the separate arrays for inline scripts and styles
  • The data will be merged in the relative scrips and styleSheets arrays (can we remove the underscore???)
  • Make JHTML compatible with these changes

Testing Instructions

Apply patch and observe the produced head, inline scripts should be between script tags with src, same for the styles
Also the jQuery.noConflict(); should be inline and not a file...

Update to JHtml

for inline script:

JHtml::_('script', '', ['inline' => ‘content for inline script’]);

For inline style:

JHtml::_('stylesheet', '', ['inline' => ‘content for inline script’]);

Actual result

Check the structure of the head:
screen shot 2017-02-24 at 23 56 37

Documentation Changes Required

YUP!

@wilsonge @mbabker @yvesh

if ($noConflict)
{
JHtml::_('script', 'system/jquery-noconflict.min.js', array('version' => 'auto', 'relative' => true));
JHtml::_('script', '', [], ['content' => 'jQuery.noConflict();']);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not better to have that in the array params?

array('inline' => true) ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay you changed it again.. what's the difference to doing addScriptDeclaration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not a file, so we need to append the data in a <script> tag.

This is the less intrusive approach (I think for the function)

to
```php
JHtml::_('script', '', ['inline' => ‘content for inline script’]);
```
$this->_scripts = (isset($data['scripts']) && !empty($data['scripts'])) ? $data['scripts'] : $this->_scripts;
$this->_script = (isset($data['script']) && !empty($data['script'])) ? $data['script'] : $this->_script;
$this->styleSheets = (isset($data['styleSheets']) && !empty($data['styleSheets'])) ? $data['styleSheets'] : $this->styleSheets;
$this->scripts = (isset($data['scripts']) && !empty($data['scripts'])) ? $data['scripts'] : $this->scripts;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cs

* @since 11.1
*/
public $_script = array();
public $scripts = array();
Copy link
Member

@yvesh yvesh Feb 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of templates use $_script and $_style to unset things like jquery migrate. We need to deprecate these.. maybe we even make them protected and make getters / setters for them?

@rdeutz made a PR for removing values there btw.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, that's the reason I did this as an RFC. There is a B/C break here that needs to be justified

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can still use the vars

public $_script = array();

But there gonna be empty, so no clue if that will help. Also there is no $framework anymore due to Mootools removal...

}

$buffer .= '<link href="' . $src . '" rel="stylesheet"';
$buffer .= $src !== 'inlineStyles_' . $enumarateInlineStyles ? '<link href="' . $src . '" rel="stylesheet"' : '<style>';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have that in a jlayout? :-) There is sometimes the need to override something

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be careful about putting this stuff into layouts. At this point you are rendering the HTML for the <head> element. What are you really going to need to be able to override here that should be encouraged through the use of a layout over the existing onBeforeCompileHead event?

Copy link
Member

@yvesh yvesh Feb 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm let me make an example: The way it's rendered now is xhtml (hardcoded) .e.g <link .. />, maybe you want to use html5 (<link ..>) or looking into the future maybe your output is something totally different (xhtml2, html6, xslt, xdoc, pdf ..) which requires a different markup of the inclusion of css and script files.

We don't know what our users are going to do with Joomla, but we should give them the flexibility to override anything.. And try to not hardcode a single line of HTML output in PHP.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think @mbabker is right here, in the sense that this is the HTML head, so let's stick to the platform (w3c) and HTML5. @yvesh for the other examples you mentioned above I guess we need a pdf, xdoc etc render per se, or am I getting this wrong?

Copy link
Member

@yvesh yvesh Feb 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah use case is limited, but maybe there will be a new draft for a new cool html version coming in 2 years, which uses again a different markup.. i don't know i still like a bit flexibility here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the standard changes, we address it then. Any changes would more likely be with the allowed attributes versus changes to the actual markup, and we already allow attributes arrays so it shouldn't be a big deal.

As for the XDOC, PDF, etc. type outputs, use a renderer for those view formats as needed. This is a renderer specific to the HTML format. It might be a good base to copy down the road, there might be ways to move some stuff to a trait, but let's keep the scope in this class limited to its current design.

@wilsonge
Copy link
Contributor

Ok so what's the advantage of this? Like if I was building JDocument from scratch i would probably do something like this. But I don't see the advantage of changing the ordering that inline scripts/styles and files get loaded given how long it's been this way at this point

@dgrammatiko
Copy link
Contributor Author

dgrammatiko commented Feb 25, 2017

Two simple examples to point out how the system fails badly with its current architecture:
CSS
com_something, loads:

  • bootstrap.css: .btn { background-color: white;}
  • inline css: .btn { background-color: black;}
    mod_something loads mod.css with .btn { background-color: red;}

Expected colour red, actual black

JS
com_something, loads:

  • core.js Joomla.SubmitForm = function1
  • inline script Joomla.SubmitForm = function2
    mod_something loads mod.js with Joomla.SubmitForm = function3

Expected function3, actual function2

Both Css and JS need to be appended in the order they had been inserted... :)

@dgrammatiko
Copy link
Contributor Author

I guess this won't go anywhere, closing

@dgrammatiko dgrammatiko deleted the serialise_tags branch July 22, 2017 20:16
@dgrammatiko dgrammatiko restored the serialise_tags branch January 12, 2019 11:41
@dgrammatiko dgrammatiko reopened this Jan 12, 2019
@joomla-cms-bot joomla-cms-bot added the RFC Request for Comment label Jan 12, 2019
@dgrammatiko
Copy link
Contributor Author

@wilsonge @yvesh @mbabker can we reconsider this one, if I do it in a B/C way?
Reason: I'm trying to utilise type="module" nomodule in my apps but I need some inline polyfill for Safari 10.1 which is impossible to do right now without slipping out of the API...

@dgrammatiko
Copy link
Contributor Author

Closing, obviously Joomla 4 will be out of sync with the current Javascript and as people keep telling me I shouldn't run after unicorns (in this case js modules)...

@dgrammatiko dgrammatiko closed this Mar 9, 2019
@dgrammatiko dgrammatiko deleted the serialise_tags branch March 9, 2019 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RFC Request for Comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants