Selectors are not repeated.
Removed duplicated code.
Removed .length check, jQuery can deal with empty results gracefully.

I'm not quite sure how to get this file included so that I can test nothing broke. If you can tell me how to test that would be nice.

I'd like to remove the float thing and make js add/remove a class name, that'd be cleaner. I'm not sure we want the JS script to add a "no-float" class or remove a "float-left" class that would be added on the PHP side.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nod_’s picture

Title: Selector clean-up: authorize.js » Selectors clean-up: authorize.js
sun’s picture

+++ b/core/misc/authorize.js
@@ -10,15 +10,17 @@
+    var $filetransfer = $('.filetransfer');

Why are none of the selectors using $(context).find() ?

I realize that the old code did not either, but that looks like a straight bug to me, which we can fix within the scope of "cleaning up selectors".

+++ b/core/misc/authorize.js
@@ -10,15 +10,17 @@
+    function handleSettingsChange () {

1) Only anonymous functions, i.e., literal "function" functions as in

foo = function () {
  ...

should use a space between "function" and "()".

See http://drupal.org/node/172169

2) Whenever moving embedded behavior logic into dedicated functions, we should ideally add them in the public scope on the behavior object (next to attach and detach methods), so they can be overridden by contributed modules, if necessary.

nod_’s picture

From what I could see this script is used in some special page where the form is the only thing displayed and there is no ajax going on. Meaning context will always be document which mean a context find and this is the same. Since the selector is simple it'll be fast to match anyway.

1) doc is talking about function call, not function declaration. Like that it helps differentiate between a declaration and execution and it's coherent with the anonymous declaration.

2) I agree with that but we shouldn't go overboard either. In PHP classes we have protected things too. And i'm not sure it's worth for a 1 line method nobody cared about before.

tim.plunkett’s picture

Status: Needs work » Needs review
FileSize
2.27 KB

The authorize.js file wasn't ever loaded in D8, fixed that.

.connection-settings-update-filetransfer-default-wrapper has never been a valid CSS class in core.

As of the patch in #538660-107: Move update manager upgrade process into new authorize.php file (and make it actually work), there was a $form['connection_settings']['update_filetransfer_default'] and it had JS and CSS associated with it and its wrapper.

However, as of the massive rewrite in #538660-111: Move update manager upgrade process into new authorize.php file (and make it actually work), that form element was completely removed, but its CSS and JS were not.

So, we can remove that part and not worry about the floats.

I don't see what swapping an anonymous function for a named one gets us, when its only used once and it makes the code somewhat less readable, but I left that in for now.

tim.plunkett’s picture

Oh, by the way, to get to this page I enabled the system_test module and then went to http://example.com/system-test/authorize-init/system-test-auth

sun’s picture

0) Any "clean-up" effort primarily targets "consistency", and I thus think that we should fix bogus selectors that are not using context correctly. Mind you, many novice JS coders are simply looking "How does Drupal core do it?" and open an arbitrary .js file to use that as template for their own code.

1) I can see how the previous docs were unclear and confusing. The detail about anonymous function literals was located in a separate section of the standards page. I've cleaned that up now: http://drupal.org/node/172169

2) I'm fine with omitting the named function in this case.

nod_’s picture

That's awesome :) makes things simpler.

Shouldn't this be using #states by the way?

nod_’s picture

using #states API

(edit) that takes care or 0,1,2 :)

tim.plunkett’s picture

FileSize
6.23 KB

How's this for a JS cleanup?

sun’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs backport to D7

Awesome, thanks!

This totally looks backportable to me.

catch’s picture

Version: 8.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Lovely.

Committed/pushed to 8.x, seems worth a try for backport.

tim.plunkett’s picture

Status: Patch (to be ported) » Needs review
FileSize
3.36 KB

The diffstat is smaller here because CommonJavaScriptTestCase doesn't exist in D7, so nothing else references authorize.js directly.

sun’s picture

CommonJavaScriptTestCase is JavaScriptTestCase in D7. However, you're right in that it doesn't contain any references to authorize.js.

Backport looks good. Needs manual testing.

nod_’s picture

Issue tags: +Needs manual testing

tag

nod_’s picture

Version: 7.x-dev » 8.x-dev
Status: Needs review » Fixed

We don't backport cleanup JS patches. No automated testing and not enough manpower.

This one was pretty nice though :)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Kiphaas7’s picture

screwed up. Ignore this.

Manuel Garcia’s picture

Issue summary: View changes
Parent issue: » #1574470: Selectors clean-up
xjm’s picture

Issue tags: -Needs backport to D7

Removing tag per #15.