[RFC] Get rid of JavaScript in HTML code

These requests for comments/change have lead to an implemented feature that has been successfully merged into the 3.1/Ascraeus branch. Everything listed in this forum will be available in phpBB 3.1.
User avatar
Arty
Former Team Member
Posts: 985
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars
Contact:

[RFC] Get rid of JavaScript in HTML code

Post by Arty »

Current document structure in prosilver is like this:

Code: Select all

doctype
<head>
  <some meta tags />
  <script> some script </script>
</head>
<body>
   <some html code />
   <script> some more script on editor page </script>
   <some mode html code />
</body>
</html>
Why do we have those scripts instead of putting it in external .js file? Because it uses template variables to set text and other stuff.

I suggest to remove those scripts. Use data attributes for variables that rely on template data and external JavaScript for the rest.

For example, instead of

Code: Select all

<script> var jump_page = 'Enter the page number you wish to go to:'; </script>
it could be added to <body> tag

Code: Select all

<body data-lang-jump-page="Enter the page number you wish to go to:">
or element that triggers popup

Ticket: http://tracker.phpbb.com/browse/PHPBB3-11795
PR: https://github.com/phpbb/phpbb3/pull/1666

User avatar
hanakin
Front-End Dev Team Lead
Front-End Dev Team Lead
Posts: 917
Joined: Sat Dec 25, 2010 9:02 pm
Contact:

Re: [RFC] Get rid of JavaScript in HTML code

Post by hanakin »

100% +1 Billion
Donations welcome via Paypal Image


User avatar
brunoais
Registered User
Posts: 964
Joined: Fri Dec 18, 2009 3:55 pm

Re: [RFC] Get rid of JavaScript in HTML code

Post by brunoais »

how would new lines be handled?
Would you use "\n" there? But AFAIK that is not a new line, that's a literal "\n" just like you were writing a "\\n" I think that should be checked.

User avatar
Arty
Former Team Member
Posts: 985
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars
Contact:

Re: [RFC] Get rid of JavaScript in HTML code

Post by Arty »

I don't think new lines are used by any language variables that are used in JavaScript.

User avatar
brunoais
Registered User
Posts: 964
Joined: Fri Dec 18, 2009 3:55 pm

Re: [RFC] Get rid of JavaScript in HTML code

Post by brunoais »

Still, we need to prepare in case we start using them.

I still do prefer the javascript variables on the <head>, though.

User avatar
JoshyPHP
Registered User
Posts: 373
Joined: Fri Jul 08, 2011 9:43 pm

Re: [RFC] Get rid of JavaScript in HTML code

Post by JoshyPHP »

Twig can escape new lines in attributes, but I don't know how it works with phpBB's templating.

User avatar
Arty
Former Team Member
Posts: 985
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars
Contact:

Re: [RFC] Get rid of JavaScript in HTML code

Post by Arty »

JoshyPHP wrote:Twig can escape new lines in attributes, but I don't know how it works with phpBB's templating.
Good idea.

It works, but requires minor trickery because language variables aren't actual twig variables:

Code: Select all

{% set l_jump_page %}{L_JUMP_PAGE}{% endset %}
<a data-lang-jump-page="{{ l_jump_page|e('html_attr') }}"

User avatar
EXreaction
Registered User
Posts: 1555
Joined: Sat Sep 10, 2005 2:15 am

Re: [RFC] Get rid of JavaScript in HTML code

Post by EXreaction »

{L_JUMP_PAGE|e('html_attr')} should be the same

User avatar
Arty
Former Team Member
Posts: 985
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars
Contact:

Re: [RFC] Get rid of JavaScript in HTML code

Post by Arty »

EXreaction wrote:{L_JUMP_PAGE|e('html_attr')} should be the same
It works. nice :)

Post Reply