News for hackers. Stuff that matters.
Re:The Future of JQuery UI and JQuery Mobile by collinmanderson on Thursday December 21, 2017 @04:11PM (#15982795)
jQuery is still quite relevant and helpful. Despite the hype with newer libraries, jQuery is used on 73% of _all_ websites. https://w3techs.com/technologies/overview/javascript_library...

I often tell myself, ok, I'm going to just use vanilla JS for this one, but compared to jQuery, it's way too verbose. Try doing $('.my-elements').show() in vanilla js.

The problem is the jQuery foundation has become too bureaucratic, making contributions harder. Example: https://github.com/globalizejs/globalize/pull/703

Re:The Future of JQuery UI and JQuery Mobile by Lazare on Thursday December 21, 2017 @07:24PM (#15984197)
That github thread was maddening to read. They actually got a lawyer to chime in with their explanation for why the new CLA is needed, and then we got this nonsense:

> Among other changes, the updated CLA gives the Foundation the ability to re-license contributions under Apache 2.0.

But they already said:

> There is no need to get new signatures for old contributions

So they're not planning on getting all old contributions to be updated to the new CLA, but they think the new CLA will let them relicense the entire code base under Apache 2.0. That's not how that works! But it gets worse, because when challenged the lawyer quotes the updated CLA language:

> You understand and agree that the JS Foundation projects and your Contributions are public and that a record of the Contributions (including all metadata and personal information you submit with them) is maintained indefinitely and may be redistributed consistent with the JS Foundation’s policies and the requirements of the Apache v2.0 license where they are relevant.

"You [...] agree that [...] your Contributions are public and that a record of the Contributions (including all metadata and personal information you submit with them) [...] may be redistributed consistent with [...] the requirements of the Apache v2.0 license where they are relevant."

That's clearly saying that they may need to provide people with the record of your contribution in order to prove that, eg, the Apache v2.0 license is being complied with. It is not an agreement that your actual contribution is licensed (or can be relicensed) under the Apache v2.0 license.

This is just magical thinking. You can't just mumble the words "Apache 2.0" somewhere in the general neighborhood of a legal document and have it magically relicense years of contributions. You certainly can't make people agree that metadata about your contribution can be shared with some people, and then expect that to magically change the license under which the contribution itself exists.

Re:The Future of JQuery UI and JQuery Mobile by sideproject on Thursday December 21, 2017 @06:18PM (#15983823)
Just read through that issue thread on github. That makes me almost cry! Here's an awesome project (whether it's dated or not), and then there are all these people trying to make valid, good contributions, but for some reason (however valid they are) they have to go through all these red-tapes.

I don't know where to stand. One side, maybe you need all these red-tapes so that you don't get in any trouble. But this makes me feel like things are not going to progress and people will eventually turn away.

Haven't we already seen too many examples like this? Things start small, they get popular, people jump in to use, then things get political and it dies out.

Re:The Future of JQuery UI and JQuery Mobile by codazoda on Thursday December 21, 2017 @04:34PM (#15982990)
That's actually a good example. My gut feeling was simply to write the following.

document.getElementsByClassName("my-class")[0].style.display = 'block';

The PlainJS site mentions that it's not quite that simple and suggests writing your own show() and hide() functions if you're avoiding jQuery.

https://plainjs.com/javascript/effects/hide-or-show-an-eleme...

Re:The Future of JQuery UI and JQuery Mobile by taco_emoji on Thursday December 21, 2017 @05:06PM (#15983268)
It's like a corollary to Greenspun's Tenth Rule [0], in that anytime I try to do something in vanilla JS, I just end up poorly re-inventing half of JQuery just to do it.

[0] https://en.wikipedia.org/wiki/Greenspun%27s_tenth_rule

Re:The Future of JQuery UI and JQuery Mobile by franciscop on Thursday December 21, 2017 @07:12PM (#15984109)
I ended up reinventing most of jQuery: https://umbrellajs.com/

But it was fun and I learned a lot, so there is that.

Re:The Future of JQuery UI and JQuery Mobile by collinmanderson on Thursday December 21, 2017 @04:54PM (#15983146)
Right, and that still doesn't handle applying the action to all _all_ items of that class.

It would need to be something like this, though it still doesn't automatically handle inline vs block:

document.querySelectorAll('.my-elements').forEach(function(el){el.style.display = 'block'})

And apparently there are issues even with that: https://css-tricks.com/snippets/javascript/loop-queryselecto...

Re:The Future of JQuery UI and JQuery Mobile by kibibu on Thursday December 21, 2017 @09:07PM (#15984732)
Ok, I kinda got sniped on this. Here's a first pass at a micro lib to do it using Proxy object:

    const $ = (() => {
        function listProxy(arr) {
            return new Proxy(arr, {
                set: (t, p, v, r) => {
                    for(let x of t) {
                        x[p] = v;
                    }
                },
                get: (t, p, r) => {
                    if(t.length > 0 && t[0][p] instanceof Function) {
                        return (...args) => { Array.prototype.map.call(t, (x) => x[p](args)) };
                    } else {
                        return listProxy( Array.prototype.map.call(t, (x) => x[p]) );
                    }
                }
            })
        }

        return (sel, root) => {
            if(root === undefined) root = document;
            return listProxy(root.querySelectorAll(sel));
        }
    })();

    // use like this:
    $('.my-elements').className = 'Important'; 
    $('.my-elements').style.color = 'Red';     
    $('.my-elements').classList.add('Another');
demo: https://codepen.io/anon/pen/RxGgNR
Re:The Future of JQuery UI and JQuery Mobile by exizt88 on Thursday December 21, 2017 @04:59PM (#15983200)
For reference, this is how you do this in jQuery: $('.my-elements').show()
Re:The Future of JQuery UI and JQuery Mobile by bijection on Thursday December 21, 2017 @04:59PM (#15983196)
To make that work for all elements of that class, you could rewrite it as

  document.querySelectorAll('.myclass')
    .forEach(el => el.style.display = 'block')
The jQuery is still shorter, but the vanilla js is definitely manageable.
Re:The Future of JQuery UI and JQuery Mobile by tracker1 on Thursday December 21, 2017 @06:23PM (#15983865)

  Array.from(document.querySelectorAll('.myclass'))
    .forEach(el => el.style.display = 'block')
Re:The Future of JQuery UI and JQuery Mobile by collinmanderson on Thursday December 21, 2017 @07:13PM (#15984117)
Though ie11 doesn't have Array.from()
Re:The Future of JQuery UI and JQuery Mobile by bonesss on Friday December 22, 2017 @04:38AM (#15986310)
Hrmmm... maybe someone should make a library that would smooth over browser differences and provide a consistent element selection syntax? Call it JavascriptSelection, or jSelection?
Re:The Future of JQuery UI and JQuery Mobile by emergie on Friday December 22, 2017 @09:09AM (#15987497)
imho 'JavascriptQuery' or 'jQuery' sounds better, oh wait...
Re:The Future of JQuery UI and JQuery Mobile by tracker1 on Wednesday December 27, 2017 @05:13PM (#16018498)
I tend to polyfill older browsers, Array.from is a pretty small one. Sad thing is at a point where it's probably worth it to have 2-3 builds in place... 1 for legacy browsers, one for modern without modules, and one for modules/import/http2 support.

Just haven't taken the time... at least the main app I work on at work doesn't need to support IE11. Latest Edge,, Firefox, Safari and Chrome ... and Chrome is the primary target.

Re:The Future of JQuery UI and JQuery Mobile by no_gravity on Thursday December 21, 2017 @05:12PM (#15983321)
Unfortunately, querySelectorAll returns a NodeList, not an Array. So you cannot use forEach() on it.
Re:The Future of JQuery UI and JQuery Mobile by hawkice on Thursday December 21, 2017 @05:15PM (#15983347)
Re:The Future of JQuery UI and JQuery Mobile by collinmanderson on Thursday December 21, 2017 @05:16PM (#15983357)
It's a very recent addition. IE11 doesn't have it for sure.
Re:The Future of JQuery UI and JQuery Mobile by no_gravity on Thursday December 21, 2017 @05:18PM (#15983367)
Not in Edge though.
Re:The Future of JQuery UI and JQuery Mobile by hawkice on Thursday December 21, 2017 @05:24PM (#15983409)
The page I linked has a compatibility chart that says Edge 16 has it (no idea if that's a planned release, haven't ever used Edge).
Re:The Future of JQuery UI and JQuery Mobile by darepublic on Thursday December 21, 2017 @06:18PM (#15983819)
You can use Array.prototype.forEach.call(nodelist, fn), or Arrays.from(nodelist).forEach
Re:The Future of JQuery UI and JQuery Mobile by panzi on Thursday December 21, 2017 @11:24PM (#15985267)
I don't use Windows so I can't test it, but would this work as a polyfill?

    NodeList.prototype.forEach = Array.prototype.forEach;
In Chrome this even returns true:

    NodeList.prototype.forEach === Array.prototype.forEach
Re:The Future of JQuery UI and JQuery Mobile by emergie on Friday December 22, 2017 @09:12AM (#15987523)
Tested in IE11, document.documentMode===11

  Array.prototype.forEach.call(document.querySelectorAll('div'), console.log)
seams to work
Re:The Future of JQuery UI and JQuery Mobile by aplummer on Thursday December 21, 2017 @05:44PM (#15983558)
This comment is actually a fantastic example of why jQuery is so popular.

Missing:

Re:The Future of JQuery UI and JQuery Mobile by krapp on Friday December 22, 2017 @09:33AM (#15987679)
Unfortunately, document.getElementsByClassName isn't universally supported[0], so even if you wanted to do it that way, it still wouldn't be that easy. Never is.

[0]https://caniuse.com/#feat=getelementsbyclassname

Re:The Future of JQuery UI and JQuery Mobile by drinchev on Thursday December 21, 2017 @04:57PM (#15983169)
In this specific case jQuery's `show` is just giving you a shortcut to show/hide arbitrary elements.

Try doing this with CSS, please.

    <div class="element"></div>

    .element { display: block; }
    .element.is-hidden { display: none; }

    document.getElementsByClassName("element")[0].classList.add( "is-hidden" );
You should never ask yourself "How can I accomplish that without jQuery", but rather "What would be the best way to do it!"
Re:The Future of JQuery UI and JQuery Mobile by ibdf on Thursday December 21, 2017 @04:18PM (#15982851)
I think that number is inflated by CMSs such as WP early adoption of jquery. I have used jQuery extensively and I agree that's still relevant, but jQuery Mobile and UI never really took off.
Re:The Future of JQuery UI and JQuery Mobile by collinmanderson on Thursday December 21, 2017 @04:49PM (#15983107)
Yes, 28% of all websites use WordPress (over half of the 73%). It means a lot of WordPress theme developers use jQuery.

Yes, jQuery Mobile never really became a thing, but jQuery UI has some pretty useful widgets (autocomplete, date picker, sortable, etc.)

Re:The Future of JQuery UI and JQuery Mobile by invalidusernam3 on Thursday December 21, 2017 @04:59PM (#15983192)
The biggest benefit that I've found for jQuery (and a lot of JS libraries) over vanilla is browser compatibility. I generally don't have time to check compatibility of every mildly complex piece of JS I write. Using a library often solves that issue
Re:The Future of JQuery UI and JQuery Mobile by drinchev on Thursday December 21, 2017 @05:01PM (#15983217)
That was a relevant answer couple of years ago. These days you can achieve most with having a properly setup IDE-intellisense ( e.g. WebStorm ).
Re:The Future of JQuery UI and JQuery Mobile by taco_emoji on Thursday December 21, 2017 @05:09PM (#15983291)
Does that really solve the issue though? All the IDE can tell you is that some browser version doesn't support what you're doing, it doesn't write the polyfill for you.
Re:The Future of JQuery UI and JQuery Mobile by drinchev on Thursday December 21, 2017 @05:13PM (#15983327)
Most of the polyfills these days are pretty much syntax sugar & ES6 transpiling. If you do your code in non ES6 plain JS way, I'm quite sure the IDE will give you the benefits that you receive with jQuery.
Re:The Future of JQuery UI and JQuery Mobile by newfoundglory on Friday December 22, 2017 @12:35AM (#15985477)
By "these days" do you mean "needed to support the latest version of each major browser"?
Re:The Future of JQuery UI and JQuery Mobile by leeoniya on Thursday December 21, 2017 @04:42PM (#15983056)
whenever i feel the need for jquery these days, i typically reach for the much smaller, faster, ie11+ https://github.com/franciscop/umbrella
Re:The Future of JQuery UI and JQuery Mobile by saas_co_de on Thursday December 21, 2017 @05:23PM (#15983398)
nice. thanks. despite the plainjs appeal in practice i still find that using jquery is faster, easier, and safer.

the parts of it i want are very simple though. i can (and have) written my own replacements, but I don't want to throw my own one-off replacement into the projects I use, so having some kind of community library is much better.

Re:The Future of JQuery UI and JQuery Mobile by interfixus on Friday December 22, 2017 @12:20AM (#15985427)
From the author of the Picnic css framework. That bodes well for conciseness, documentation, and style.
Re:The Future of JQuery UI and JQuery Mobile by COil on Friday December 22, 2017 @04:16AM (#15986227)
Agree. And for quick prototyping it's also very useful.