[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
Registered User
Posts: 970
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars
Contact:

[RFC] Get rid of JavaScript in HTML code

Post by Arty » Tue Aug 13, 2013 9:00 am

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
Formerly known as CyberAlien.

Free phpBB styles | Premium responsive XenForo styles

User avatar
hanakin
Infrastructure Team
Infrastructure Team
Posts: 788
Joined: Sat Dec 25, 2010 9:02 pm
Contact:

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

Post by hanakin » Tue Aug 13, 2013 2:24 pm

100% +1 Billion


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

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

Post by brunoais » Tue Aug 13, 2013 4:38 pm

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
Registered User
Posts: 970
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars
Contact:

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

Post by Arty » Tue Aug 13, 2013 5:02 pm

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

Free phpBB styles | Premium responsive XenForo styles

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

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

Post by brunoais » Tue Aug 13, 2013 7:24 pm

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: 348
Joined: Fri Jul 08, 2011 9:43 pm

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

Post by JoshyPHP » Tue Aug 13, 2013 7:30 pm

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

User avatar
Arty
Registered User
Posts: 970
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars
Contact:

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

Post by Arty » Fri Aug 16, 2013 4:07 pm

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') }}"
Formerly known as CyberAlien.

Free phpBB styles | Premium responsive XenForo styles

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 » Sat Aug 17, 2013 3:41 am

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

User avatar
Arty
Registered User
Posts: 970
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars
Contact:

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

Post by Arty » Sat Aug 17, 2013 3:45 pm

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

Free phpBB styles | Premium responsive XenForo styles

Post Reply