Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #25059

Re: Dynamic CSS adjustments (JavaScript)

From Joao Rodrigues <groups_jr-1@yahoo.com>
Newsgroups comp.lang.javascript
Subject Re: Dynamic CSS adjustments (JavaScript)
Date 2014-06-26 22:43 -0300
Organization Aioe.org NNTP Server
Message-ID <loii82$jmc$1@speranza.aioe.org> (permalink)
References <MPG.2e1662bf95bc0a299899c1@news.demon.co.uk> <XnsA358CD0D1F4FBeejj99@194.109.133.133> <MPG.2e16b6ce69e50e579899c2@news.demon.co.uk> <toggle-20140627012335@ram.dialup.fu-berlin.de> <53acbbf8$0$6612$9b4e6d93@newsspool4.arcor-online.net>

Show all headers | View raw


On 26/06/2014 21:34, Christoph Michael Becker wrote:
> Stefan Ram wrote:
<snip>

>>    Today, we want »non-obtrusive JavaScript«. That is, there
>>    should be as little JavaScript as possible within the HTML
>>    document. Rather, it is moved into a separate script file:
>
> This approach is not uncontroversial (even though I prefer it, when viable).

ACK. But "non-obtrusive" JavaScript != "as little JS as possible". I 
prefer the latter. And putting JavaScript and CSS in external files is a 
recommended practice, because these files are cached by the browser, 
reducing the number of HTTP requests and the size of the HTML document.

>
>> <!DOCTYPE HTML><html><head><meta charset="UTF-8">
>> <title>Main</title><link rel="stylesheet" href="main.css">
>> </head><body>
>>      ...
>>      <script type="application/javascript;version=1.8" src="main.js"></script>
>
> Is "application/javascript;version=1.8" standardized in any way?

In HTML5, we could use <script> only.

>
>>      </body></html>
>>
>>    Then, you can start your script when the DOM is ready
>>    (put this into »main.js«):
>>
>> document.addEventListener( "DOMContentLoaded", myinit, false );
>
> One should be aware that document.addEventListener() is not implemented
> by several ECMAScript implementations in widespread use, though.

Unless one needs to support the extreme cheapskates that still use 
Windows XP with IE8, one may use document.addEventListener() without 
worry, because it is widely supported (since IE 9).

>  I'm
> not sure about the DOMContentLoaded event, either.

See <http://caniuse.com/domcontentloaded>

>
>>    Here, »myinit« represents a function that you write in
>>    »main.js«, above that line.
>>
>> function myinit() { "use strict"; ... }
>>
>>    The toggle function:
>>
>> function toggleDone()
>> { let dones = document.getElementsByClassName( 'done' );
>
> AFAIK, "let" is a construct that might be adopted for ECMAScript 6, but
> if I'm not mistaken it is not widely implemented, yet.  It might be
> better to avoid it, and instead use the classic "var" (what shouldn't
> make a difference here).
>
>>    for( let x = 0; x < dones.length; ++x )
>>    dones[ x ].classList.toggle( 'hidden' ); }
>
> DOMElement.prototype.classList requires somewhat recent DOM support, too.
>

ACK.

-- 
Joao Rodrigues

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Dynamic CSS adjustments (JavaScript) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-06-26 20:09 +0200
  Re: Dynamic CSS adjustments (JavaScript) Philip Herlihy <bounceback@you.com> - 2014-06-27 00:02 +0100
    Re: Dynamic CSS adjustments (JavaScript) Christoph Michael Becker <cmbecker69@arcor.de> - 2014-06-27 02:34 +0200
      Re: Dynamic CSS adjustments (JavaScript) Joao Rodrigues <groups_jr-1@yahoo.com> - 2014-06-26 22:43 -0300
        JavaScript and CSS in external files???, was Re: Dynamic CSS adjustments (JavaScript) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-06-27 09:19 +0200
        Re: Dynamic CSS adjustments (JavaScript) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-06-27 10:22 +0200
          Re: Dynamic CSS adjustments (JavaScript) Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2014-06-27 17:23 -0300
            Re: Dynamic CSS adjustments (JavaScript) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-06-27 23:28 +0200
              Re: Dynamic CSS adjustments (JavaScript) Joao Rodrigues <groups_jr-1@yahoo.com> - 2014-06-27 23:45 -0300
                Re: Dynamic CSS adjustments (JavaScript) Tim Streater <timstreater@greenbee.net> - 2014-06-28 10:30 +0100
      Re: Dynamic CSS adjustments (JavaScript) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-06-27 10:19 +0200
    Re: Dynamic CSS adjustments (JavaScript) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-06-27 10:12 +0200
    Re: Dynamic CSS adjustments (JavaScript) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-06-27 10:16 +0200
    Re: Dynamic CSS adjustments (JavaScript) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-06-27 10:16 +0200
    Re: Dynamic CSS adjustments (JavaScript) Philip Herlihy <bounceback@you.com> - 2014-06-30 11:02 +0100
  Re: Dynamic CSS adjustments (JavaScript) BootNic <bootnic.bounce@gmail.com> - 2014-06-26 23:18 -0400
    Re: Dynamic CSS adjustments (JavaScript) Philip Herlihy <bounceback@you.com> - 2014-06-30 11:31 +0100
      Re: Dynamic CSS adjustments (JavaScript) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-06-30 13:37 +0200
        Re: Dynamic CSS adjustments (JavaScript) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-06-30 13:40 +0200
          Re: Dynamic CSS adjustments (JavaScript) Philip Herlihy <bounceback@you.com> - 2014-07-01 12:41 +0100
            Re: Dynamic CSS adjustments (JavaScript) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-07-01 14:28 +0200
              Re: Dynamic CSS adjustments (JavaScript) Philip Herlihy <bounceback@you.com> - 2014-07-01 15:52 +0100
                Re: Dynamic CSS adjustments (JavaScript) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-07-01 18:08 +0200
        Re: Dynamic CSS adjustments (JavaScript) Scott Sauyet <scott.sauyet@gmail.com> - 2014-06-30 06:22 -0700
          Re: Dynamic CSS adjustments (JavaScript) Denis McMahon <denismfmcmahon@gmail.com> - 2014-06-30 14:32 +0000
            Re: Dynamic CSS adjustments (JavaScript) Scott Sauyet <scott.sauyet@gmail.com> - 2014-06-30 13:16 -0700
              Re: Dynamic CSS adjustments (JavaScript) Denis McMahon <denismfmcmahon@gmail.com> - 2014-06-30 23:14 +0000
                Re: Dynamic CSS adjustments (JavaScript) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-07-01 09:02 +0200

csiph-web