Make WordPress Core

Opened 7 years ago

Closed 6 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:


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

Download all attachments as: .zip

Change History (61)

comment:1 filosofo7 years ago

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

comment:2 aercolino7 years ago

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


> wp_enqueue_script('interface');


> wp_enqueue_script('interface');


> 	wp_enqueue_script('interface');


> wp_enqueue_script('interface');


> 	wp_enqueue_script('interface');


> 		$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');

comment:3 foolswisdom7 years ago

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

comment:4 ryan7 years ago

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

comment:5 aercolino7 years ago

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


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

ryan7 years ago

wp_enqueue_script() for interface

comment:6 ryan7 years ago

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

comment:7 aercolino7 years ago

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

comment:8 ryan7 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.

comment:9 aercolino7 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):


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

comment:10 markjaquith7 years ago


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.

comment:11 aercolino7 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/)

comment:12 ryan7 years ago

[4959] for jquery.form.js.

comment:13 aercolino7 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.


aercolino7 years ago

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

comment:14 aercolino7 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.

comment:15 ryan7 years ago

[4963] updates to jQuery 1.1.2.

comment:16 ryan7 years ago

  • Cc mdawaffe added

comment:17 mdawaffe7 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>

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

comment:18 aercolino7 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.

comment:19 ryan7 years ago

  • Keywords hit-list added

comment:20 rob1n7 years ago

  • Milestone changed from 2.2 to 2.3

filosofo7 years ago

comment:21 filosofo7 years ago

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

comment:22 abischof7 years ago

  • Cc abischof added

comment:23 rob1n7 years ago

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

comment:24 rob1n7 years ago

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

comment:25 filosofo7 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 in Windows and Linux

IE 6 & IE 7

Safari 3.0.3 for Windows

Opera 9.23 for Windows

Konqueror 3.5.6

comment:26 filosofo7 years ago

  • Cc filosofo added

comment:27 andy7 years ago

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

comment:28 ryan7 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.

comment:29 ryan7 years ago

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

comment:30 ryan7 years ago

  • Milestone changed from 2.3 to 2.4 (next)

comment:31 rmccue6 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.

rmccue6 years ago

Use jQuery in autosave.js

comment:32 rmccue6 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?

comment:33 rmccue6 years ago

Oops, I mean $POST['rndval']

rmccue6 years ago

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

comment:34 rmccue6 years ago

  • Cc rmccue added

comment:35 rmccue6 years ago

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

comment:36 rmccue6 years ago

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

comment:37 ryan6 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.

comment:38 ryan6 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.

ryan6 years ago

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

comment:39 follow-up: ryan6 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.

comment:40 in reply to: ↑ 39 filosofo6 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.

comment:41 follow-up: ryan6 years ago

Would we need to add a currentlyExecuting flag to that?

comment:42 ryan6 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.

ryan6 years ago

Fixes tag and category saves

comment:43 rmccue6 years ago

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

comment:44 in reply to: ↑ 41 rmccue6 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.

comment:46 ryan6 years ago

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

ryan6 years ago

Use schedule plugin

comment:47 ryan6 years ago

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

ryan6 years ago

now with the scheduler file

rmccue6 years ago

Should be final patch. Includes speed improvements and setting temp_ID

rmccue6 years ago

Now includes fix for draft saving with 0 timestamp

comment:48 ryan6 years ago

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

comment:49 ryan6 years ago

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