WordPress.org

Make WordPress Core

Opened 9 years ago

Closed 8 years ago

#3824 closed task (blessed) (fixed)

Transition the Admin Area over to using jQuery

Reported by: jeresig Owned by:
Milestone: 2.5 Priority: normal
Severity: normal Version: 2.1.1
Component: Administration Keywords: jquery javascript admin hit-list
Focuses: Cc:

Description

As discussed with Matt, he would like to see the Admin area, in 2.2, using jQuery as the Javascript library running the frontend.

This is the ticket where we can discuss this issue and post possible patches. (An influx of jQuery developers are going to be coming here to help out with the transition.)

Attachments (12)

queue_interface.diff (41.7 KB) - added by ryan 9 years ago.
wp_enqueue_script() for interface
dashboard-users-01.diff (8.5 KB) - added by aercolino 9 years ago.
replaces jQuery to Prototype in pages: Dashboard; Users / Authors & Users - (based on trunk)
uploads.diff (9.5 KB) - added by filosofo 9 years ago.
jquery_admin_widgets.diff (13.7 KB) - added by filosofo 9 years ago.
autosave.js.diff (8.6 KB) - added by rmccue 8 years ago.
Use jQuery in autosave.js
autosave.js.2.diff (9.3 KB) - added by rmccue 8 years ago.
Convert autosave.js to use jQuery - Change settings in script-loader.php
autosave.js.3.diff (9.8 KB) - added by ryan 8 years ago.
Fix call to jQuery.post(), add id to _wpnonce, set post_ID name.
autosave.js.4.diff (9.9 KB) - added by ryan 8 years ago.
Fixes tag and category saves
autosave.js.5.diff (12.2 KB) - added by ryan 8 years ago.
Use schedule plugin
autosave.js.6.diff (22.0 KB) - added by ryan 8 years ago.
now with the scheduler file
autosave.js.7.diff (22.3 KB) - added by rmccue 8 years ago.
Should be final patch. Includes speed improvements and setting temp_ID
autosave.js.8.diff (22.9 KB) - added by rmccue 8 years ago.
Now includes fix for draft saving with 0 timestamp

Download all attachments as: .zip

Change History (61)

#1 @filosofo
9 years ago

Can someone outline the advantages of jQuery over Prototype/Scriptaculous, or point to a discussion or article Matt has referenced?

#2 @aercolino
9 years ago

how to install jquery/interface in wordpress 2.1 (admin)

wp-admin/index.php:

17a18
> wp_enqueue_script('interface');

wp-admin/page-new.php:

7a8
> wp_enqueue_script('interface');

wp-admin/page.php:

56a57
> 	wp_enqueue_script('interface');

wp-admin/post-new.php:

7a8
> wp_enqueue_script('interface');

wp-admin/post.php:

59a60
> 	wp_enqueue_script('interface');

wp-includes/script-loader.php:

32a33,34
> 		$this->add( 'jquery', '/wp-includes/js/jquery/jquery.js', false, '1.1.1');
> 		$this->add( 'interface', '/wp-includes/js/jquery/interface.js', array('jquery'), '1.1.1');

#3 @foolswisdom
9 years ago

aercolino, can you just attach any patches. Lots of code in line a ticket makes it harder to follow any discussion

#4 @ryan
9 years ago

[4904] adds the libs and updates the script loader.

#5 @aercolino
9 years ago

I forgot to mention that jQuery needs the noConflict mode enabled.

jQuery.noConflict();

I added it to the end of jquery.js, but a different location is possible I guess.

@ryan
9 years ago

wp_enqueue_script() for interface

#6 @ryan
9 years ago

Patch enqueues interface. I'll apply once we start moving code to jquery.

#7 @aercolino
9 years ago

ryan, I wonder why you put interface inside the draft block in the page.php file

#8 @ryan
9 years ago

Because we currently only use those things for autosave which is only loaded for drafts. We don't autosave published posts because the saves would show up publicly. If we expand use of jquery beyond autosave for page.php, we can move it outside the draft block.

#9 @aercolino
9 years ago

Here is a diff that replaces jQuery to Prototype in the Dashboard and Users / Authors & Users pages. I'm working on the 2.1 version. Please tell me wether this is unacceptable, I'll install 2.1.1...

This file replaces entirely what I posted earlier.
I've decided not to use the interface plugin, for now, so I've removed it.

Files to add (excluded from this diff):

wp-includes/js/jquery/jquery.js
wp-includes/js/jquery/jquery.form.js

The diff includes some short new file.
Replaced files are still in place.

#10 @markjaquith
9 years ago

aercolino,

As this will be going into trunk for 2.2, and not the 2.1.x branch, we'll need the patches to apply against /trunk/

jQuery has already been added to /trunk/ so your patch wouldn't need to add it... you'd just need to implement it.

#11 @aercolino
9 years ago

OK, I understand... I just installed a fresh trunk :-)

Could you please add the jquery.form.js file to trunk? It's the jQuery plugin I used in the last patch. (http://www.malsup.com/jquery/form/)

#12 @ryan
9 years ago

[4959] for jquery.form.js.

#13 @aercolino
9 years ago

The jQuery library in trunk is old (1.1.1).
Could you please install version 1.1.2? (http://jquery.com/)

jQuery is distributed in compressed and uncompressed format. It would be great if you could install both (maybe with same filenames?), so that if I find issues, I can debug them. The uncompressd one could be erased at deployment time, I guess.

Thanks.

@aercolino
9 years ago

replaces jQuery to Prototype in pages: Dashboard; Users / Authors & Users - (based on trunk)

#14 @aercolino
9 years ago

The patch works fine in IE7 and FF2, and is now based on trunk.
Please try different browsers.

For testers: remember that in the Users / Authors & Users page ajax (jQuery) is called only for adding users to non-empty roles. This is how it works in WordPress. So the first user with a given role will be processed without ajax, and any other with ajax.

#15 @ryan
9 years ago

[4963] updates to jQuery 1.1.2.

#16 @ryan
9 years ago

  • Cc mdawaffe added

#17 @mdawaffe
9 years ago

aercolino, this looks tremendously pleasant :) In fact, awesome.

My only suggestion is to abstract the ajax request sending stuff out of users-js and put it into a rewritten, jQuery based wp-ajax-js.php

Also, if you want to take a look at the list manipulation stuff, I'd be happy to collaborate or help out. I'd like to see if it's possible to

  1. get rid of all of WP's inline JS. There's a lot of stuff like onclick="deleteSomething(...)"
  2. have the listMan stuff all be markup based like
    <ul id='the-list' class='list-man-list'>
     <li id='item-1' class='list-man-list-item'> blah blah
       <a href="http://delete url" class='list-man-delete'>delete</a>
     </li>
    </ul>
    

I don't think we need to worry about backward compatibility with listMan, so no holds barred as far as I'm concerned.

#18 @aercolino
9 years ago

mdawaffe, thanks :-)

You're right, the code in users-js.php is mostly shareable. In fact I began to transform the Write page, and I'll try to use as much as possible of it. (abstraction by comparison)

List manipulation is (almost) straightforward in jQuery, so knowing that it's possible to simplify the markup is a big relief.

I posted an article on my blog about an alternative display of custom fields (based on jQuery). I was using a DL instead of a TABLE (or a UL). I think it's a flexible design for lists in general and particularly useful for custom fields.

I'd like you to have a look at it and see if you deem it too radical a change or not.

#19 @ryan
9 years ago

  • Keywords hit-list added

#20 @rob1n
9 years ago

  • Milestone changed from 2.2 to 2.3

@filosofo
9 years ago

#21 @filosofo
9 years ago

I've attached a patch (uploads.diff) that converts the image uploading stuff to jQuery from Prototype.

#22 @abischof
9 years ago

  • Cc abischof added

#23 @rob1n
9 years ago

(In [5580]) Move Dashboard's news to jQuery. see #3824

#24 @rob1n
9 years ago

(In [5629]) Move uploads JS to jQuery. Props filosofo. see #3824

#25 @filosofo
9 years ago

I've added a patch, jquery_admin_widgets.diff, which converts the admin widgets area to jQuery.

There were a couple of places in the old code where Javascript was doing the work of CSS (basically just clearing some floats), so I took that out and used CSS instead.

Also in the old code was some dead code in which someone had apparently thought about making the dropzone lists all expand equally, but then didn't implement it (a line in resetDroppableHeights() gets the greatest number of widgets that any dropzone has, but never uses that info). I went ahead and made the dropzones expand equally vertically, because 1) someone seemingly meant to do this before and didn't 2) it looks better 3) under the old system if you had a really tall dropzone and a short dropzone, you had to go through shenanigans to drag a widget from the palette to the short dropzone.

I've tested it successfully with the following browsers:

Firefox 2.0.0.6 in Windows and Linux

IE 6 & IE 7

Safari 3.0.3 for Windows

Opera 9.23 for Windows

Konqueror 3.5.6

#26 @filosofo
9 years ago

  • Cc filosofo added

#27 @andy
9 years ago

Nice work on the widgets, filosofo! It is much more responsive than the Scriptaculous version.

#28 @ryan
9 years ago

Yes, smoother and faster. One difference I note is that you can't reorder the Available Widgets list. You can only drop to the front of the list. I kinda like it this way, but it is different behavior.

#29 @ryan
9 years ago

(In [5934]) jquery for widgets admin. Props filosofo. see #3824

#30 @ryan
9 years ago

  • Milestone changed from 2.3 to 2.4 (next)

#31 @rmccue
8 years ago

I'm not exactly sure why, but it appears that it's not working. Can someone help me out here please? I've spent hours trying to find out why. I think it's because of the nonces, but there was no code previously to add it to the request parameters.

@rmccue
8 years ago

Use jQuery in autosave.js

#32 @rmccue
8 years ago

Hmm, it appears that the only difference between the 2 is that Prototype/SACK is that the original (using SACK) sends $_POSTrndval?. Is this used anywhere?

#33 @rmccue
8 years ago

Oops, I mean $POST['rndval']

@rmccue
8 years ago

Convert autosave.js to use jQuery - Change settings in script-loader.php

#34 @rmccue
8 years ago

  • Cc rmccue added

#35 @rmccue
8 years ago

Hmm, seems it is saving, but drafts are disappearing/aren't displayed on the write page. My bad.

#36 @rmccue
8 years ago

I still can't seem to work out why. Anyone care to look?

#37 @ryan
8 years ago

The call to jQuery.post() wasn't quite right, so the new nonce wasn't being generated. There's still a problem with post_ID, _wpnonce, and hiddenaction not being updated. I don't see them in the AYS POST data.

#38 @ryan
8 years ago

Adding an ID to _wpnonce fixes the nonce. The problem with the post ID is that the field has an ID of post_ID but a name of temp_ID. We're updating the element with an ID of post_ID, which is actually the temp_ID field. I think the old code inserted a new field with the name post_ID.

@ryan
8 years ago

Fix call to jQuery.post(), add id to _wpnonce, set post_ID name.

#39 follow-up: @ryan
8 years ago

Setting the name instead of id for #post_ID fixed that last issue I was having. Working well now. Next we need to get rid of PeriodicalExecuter so that we can really lose the prototype dependency.

#40 in reply to: ↑ 39 @filosofo
8 years ago

Replying to ryan:

Setting the name instead of id for #post_ID fixed that last issue I was having. Working well now. Next we need to get rid of PeriodicalExecuter so that we can really lose the prototype dependency.

I've based stuff on timer for this kind of thing.

#41 follow-up: @ryan
8 years ago

Would we need to add a currentlyExecuting flag to that?

#42 @ryan
8 years ago

Tags and cats aren't being saved. The reference to tags_input should be tags-input. Not sure what's up with categories, but catslist ends up empty.

@ryan
8 years ago

Fixes tag and category saves

#43 @rmccue
8 years ago

Categories were being saved for me before; I know, because I spent a fair bit of time getting them working.

#44 in reply to: ↑ 41 @rmccue
8 years ago

Replying to ryan:

Would we need to add a currentlyExecuting flag to that?

It looks like we can just set it to false in the callback.

#46 @ryan
8 years ago

The cat list was always empty for me until I switched to each().

@ryan
8 years ago

Use schedule plugin

#47 @ryan
8 years ago

Latest patch uses the schedule plugin for jQuery and drops the last prototype dependency for post and page editing.

@ryan
8 years ago

now with the scheduler file

@rmccue
8 years ago

Should be final patch. Includes speed improvements and setting temp_ID

@rmccue
8 years ago

Now includes fix for draft saving with 0 timestamp

#48 @ryan
8 years ago

(In [6546]) Port autosave to jquery. Props rmccue. see #3824

#49 @ryan
8 years ago

  • Resolution set to fixed
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.