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.
Comment | File | Size | Author |
---|---|---|---|
#12 | drupal-1574484-12.patch | 3.36 KB | tim.plunkett |
#9 | drupal-1574484-9.patch | 6.23 KB | tim.plunkett |
#8 | core-js-selectors-authorize-8.patch | 2.56 KB | nod_ |
#4 | drupal-1574484-2.patch | 2.27 KB | tim.plunkett |
core-js-selectors-authorize.patch | 1.43 KB | nod_ | |
Comments
Comment #1
nod_Comment #2
sunWhy 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".
1) Only anonymous functions, i.e., literal "function" functions as in
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.
Comment #3
nod_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.
Comment #4
tim.plunkettThe 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.
Comment #5
tim.plunkettOh, 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
Comment #6
sun0) 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.
Comment #7
nod_That's awesome :) makes things simpler.
Shouldn't this be using #states by the way?
Comment #8
nod_using #states API
(edit) that takes care or 0,1,2 :)
Comment #9
tim.plunkettHow's this for a JS cleanup?
Comment #10
sunAwesome, thanks!
This totally looks backportable to me.
Comment #11
catchLovely.
Committed/pushed to 8.x, seems worth a try for backport.
Comment #12
tim.plunkettThe diffstat is smaller here because CommonJavaScriptTestCase doesn't exist in D7, so nothing else references authorize.js directly.
Comment #13
sunCommonJavaScriptTestCase 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.
Comment #14
nod_tag
Comment #15
nod_We don't backport cleanup JS patches. No automated testing and not enough manpower.
This one was pretty nice though :)
Comment #17
Kiphaas7 CreditAttribution: Kiphaas7 commentedscrewed up. Ignore this.
Comment #18
Manuel Garcia CreditAttribution: Manuel Garcia commentedComment #19
xjmRemoving tag per #15.