From 69caadb5602b09bf4cb3514bf89de4292814bc00 Mon Sep 17 00:00:00 2001
From: Anton Timmermans <email@atimmer.com>
Date: Thu, 14 Jul 2016 16:40:31 +0200
Subject: [PATCH 1/3] Document src/wp-admin/js/inline-edit-tax.js
---
src/wp-admin/js/inline-edit-tax.js | 86 ++++++++++++++++++++++++++++++++++++--
1 file changed, 83 insertions(+), 3 deletions(-)
diff --git a/src/wp-admin/js/inline-edit-tax.js b/src/wp-admin/js/inline-edit-tax.js
index 3bbf4fb..49e3137 100644
a
|
b
|
|
1 | 1 | /* global inlineEditL10n, ajaxurl */ |
2 | 2 | window.wp = window.wp || {}; |
3 | 3 | |
| 4 | /** |
| 5 | * Consists of functions relevant to the inline taxonomy editor. |
| 6 | * |
| 7 | * @namespace inlineEditTax |
| 8 | * |
| 9 | * @property {string} type The type of inline edit we are currently on. |
| 10 | * @property {string} what The type property with a hash prefixed and a dash suffixed. |
| 11 | */ |
4 | 12 | var inlineEditTax; |
| 13 | |
5 | 14 | ( function( $, wp ) { |
| 15 | |
6 | 16 | inlineEditTax = { |
7 | 17 | |
| 18 | /** |
| 19 | * Initializes the inline taxonomy editor, adds event handlers to be able to quick edit. |
| 20 | * |
| 21 | * @this inlineEditTax |
| 22 | * @memberof inlineEditTax |
| 23 | */ |
8 | 24 | init : function() { |
9 | 25 | var t = this, row = $('#inline-edit'); |
10 | 26 | |
… |
… |
inlineEditTax = { |
16 | 32 | return false; |
17 | 33 | }); |
18 | 34 | |
19 | | // prepare the edit row |
| 35 | /* |
| 36 | * Prepare the edit row. |
| 37 | * |
| 38 | * @param {Object} e The keyup event that has been triggered. |
| 39 | */ |
20 | 40 | row.keyup( function( e ) { |
| 41 | // 27 = [escape] |
21 | 42 | if ( e.which === 27 ) { |
22 | 43 | return inlineEditTax.revert(); |
23 | 44 | } |
… |
… |
inlineEditTax = { |
26 | 47 | $( '.cancel', row ).click( function() { |
27 | 48 | return inlineEditTax.revert(); |
28 | 49 | }); |
| 50 | |
29 | 51 | $( '.save', row ).click( function() { |
30 | 52 | return inlineEditTax.save(this); |
31 | 53 | }); |
| 54 | |
32 | 55 | $( 'input, select', row ).keydown( function( e ) { |
| 56 | // 13 = [enter] |
33 | 57 | if ( e.which === 13 ) { |
34 | 58 | return inlineEditTax.save( this ); |
35 | 59 | } |
… |
… |
inlineEditTax = { |
40 | 64 | }); |
41 | 65 | }, |
42 | 66 | |
| 67 | /** |
| 68 | * Toggles the quick edit based on if it is currently shown or hidden. |
| 69 | * |
| 70 | * @this inlineEditTax |
| 71 | * @memberof inlineEditTax |
| 72 | * |
| 73 | * @param {HTMLElement} el An element within the table row or the table row itself that we want to quick edit. |
| 74 | */ |
43 | 75 | toggle : function(el) { |
44 | 76 | var t = this; |
| 77 | |
45 | 78 | $(t.what+t.getId(el)).css('display') === 'none' ? t.revert() : t.edit(el); |
46 | 79 | }, |
47 | 80 | |
| 81 | /** |
| 82 | * Shows the quick editor |
| 83 | * |
| 84 | * @this inlineEditTax |
| 85 | * @memberof inlineEditTax |
| 86 | * |
| 87 | * @param {string|HTMLElement} id The ID of the term we want to quick edit or an element within the table row or the |
| 88 | * table row itself. |
| 89 | * @returns {boolean} Always returns false. |
| 90 | */ |
48 | 91 | edit : function(id) { |
49 | 92 | var editRow, rowData, val, |
50 | 93 | t = this; |
51 | 94 | t.revert(); |
52 | 95 | |
| 96 | // Makes sure we can pass an HTMLElement as the ID. |
53 | 97 | if ( typeof(id) === 'object' ) { |
54 | 98 | id = t.getId(id); |
55 | 99 | } |
… |
… |
inlineEditTax = { |
75 | 119 | return false; |
76 | 120 | }, |
77 | 121 | |
| 122 | /** |
| 123 | * Saves the quick edit data to the server and replaces the table row with the HTML retrieved from the server. |
| 124 | * |
| 125 | * @this inlineEditTax |
| 126 | * @memberof inlineEditTax |
| 127 | * |
| 128 | * @param {string|HTMLElement} id The ID of the term we want to quick edit or an element within the table row or the |
| 129 | * table row itself. |
| 130 | * @returns {boolean} Always returns false. |
| 131 | */ |
78 | 132 | save : function(id) { |
79 | 133 | var params, fields, tax = $('input[name="taxonomy"]').val() || ''; |
80 | 134 | |
| 135 | // Makes sure we can pass an HTMLElement as the ID. |
81 | 136 | if( typeof(id) === 'object' ) { |
82 | 137 | id = this.getId(id); |
83 | 138 | } |
… |
… |
inlineEditTax = { |
94 | 149 | fields = $('#edit-'+id).find(':input').serialize(); |
95 | 150 | params = fields + '&' + $.param(params); |
96 | 151 | |
97 | | // make ajax request |
| 152 | // Do the ajax request to save the data to the server. |
98 | 153 | $.post( ajaxurl, params, |
| 154 | /** |
| 155 | * Handles the response from the server, replaces the table row with the response from the server. |
| 156 | * |
| 157 | * @param {string} r The string with which to replace the table row. |
| 158 | */ |
99 | 159 | function(r) { |
100 | 160 | var row, new_id, option_value, |
101 | 161 | $errorSpan = $( '#edit-' + id + ' .inline-edit-save .error' ); |
… |
… |
inlineEditTax = { |
137 | 197 | } |
138 | 198 | } |
139 | 199 | ); |
| 200 | |
140 | 201 | // Prevent submitting the form when pressing Enter on a focused field. |
141 | 202 | return false; |
142 | 203 | }, |
143 | 204 | |
| 205 | /** |
| 206 | * Closes the quick edit form. |
| 207 | * |
| 208 | * @this inlineEditTax |
| 209 | * @memberof inlineEditTax |
| 210 | */ |
144 | 211 | revert : function() { |
145 | 212 | var id = $('table.widefat tr.inline-editor').attr('id'); |
146 | 213 | |
… |
… |
inlineEditTax = { |
148 | 215 | $( 'table.widefat .spinner' ).removeClass( 'is-active' ); |
149 | 216 | $('#'+id).siblings('tr.hidden').addBack().remove(); |
150 | 217 | id = id.substr( id.lastIndexOf('-') + 1 ); |
| 218 | |
151 | 219 | // Show the taxonomy row and move focus back to the Quick Edit link. |
152 | 220 | $( this.what + id ).show().find( '.editinline' ).focus(); |
153 | 221 | } |
154 | 222 | }, |
155 | 223 | |
| 224 | /** |
| 225 | * Retrieves the ID of the term of the element inside the table row. |
| 226 | * |
| 227 | * @memberof inlineEditTax |
| 228 | * |
| 229 | * @param {HTMLElement} o An element within the table row or the table row itself. |
| 230 | * @returns {string} The ID of the term based on the element. |
| 231 | */ |
156 | 232 | getId : function(o) { |
157 | 233 | var id = o.tagName === 'TR' ? o.id : $(o).parents('tr').attr('id'), parts = id.split('-'); |
| 234 | |
158 | 235 | return parts[parts.length - 1]; |
159 | 236 | } |
160 | 237 | }; |
161 | 238 | |
162 | | $(document).ready(function(){inlineEditTax.init();}); |
| 239 | $(document).ready(function(){ |
| 240 | inlineEditTax.init(); |
| 241 | }); |
| 242 | |
163 | 243 | })( jQuery, window.wp ); |
From 243a2919ffd527b286b5f0bd45f5b97119b125ca Mon Sep 17 00:00:00 2001
From: Anton Timmermans <email@atimmer.com>
Date: Thu, 4 Aug 2016 16:28:33 +0200
Subject: [PATCH 2/3] Process feedback and follow WP guidelines
---
src/wp-admin/js/inline-edit-tax.js | 44 ++++++++++++++++++++++++++++++++------
1 file changed, 38 insertions(+), 6 deletions(-)
diff --git a/src/wp-admin/js/inline-edit-tax.js b/src/wp-admin/js/inline-edit-tax.js
index 49e3137..50fcaa8 100644
a
|
b
|
|
1 | 1 | /* global inlineEditL10n, ajaxurl */ |
| 2 | /** |
| 3 | * This file is used on the term overview page to power quick-editing terms. |
| 4 | */ |
| 5 | |
2 | 6 | window.wp = window.wp || {}; |
3 | 7 | |
4 | 8 | /** |
… |
… |
window.wp = window.wp || {}; |
7 | 11 | * @namespace inlineEditTax |
8 | 12 | * |
9 | 13 | * @property {string} type The type of inline edit we are currently on. |
10 | | * @property {string} what The type property with a hash prefixed and a dash suffixed. |
| 14 | * @property {string} what The type property with a hash prefixed and a dash |
| 15 | * suffixed. |
11 | 16 | */ |
12 | 17 | var inlineEditTax; |
13 | 18 | |
… |
… |
var inlineEditTax; |
16 | 21 | inlineEditTax = { |
17 | 22 | |
18 | 23 | /** |
19 | | * Initializes the inline taxonomy editor, adds event handlers to be able to quick edit. |
| 24 | * @summary Initializes the inline taxonomy editor. |
| 25 | * |
| 26 | * Adds event handlers to be able to quick edit. |
| 27 | * |
| 28 | * @since 2.7.0 |
20 | 29 | * |
21 | 30 | * @this inlineEditTax |
22 | 31 | * @memberof inlineEditTax |
| 32 | * @returns {void} |
23 | 33 | */ |
24 | 34 | init : function() { |
25 | 35 | var t = this, row = $('#inline-edit'); |
… |
… |
inlineEditTax = { |
33 | 43 | }); |
34 | 44 | |
35 | 45 | /* |
36 | | * Prepare the edit row. |
| 46 | * @summary Cancels inline editing when pressing escape inside the inline editor. |
37 | 47 | * |
38 | 48 | * @param {Object} e The keyup event that has been triggered. |
39 | 49 | */ |
… |
… |
inlineEditTax = { |
44 | 54 | } |
45 | 55 | }); |
46 | 56 | |
| 57 | /** |
| 58 | * @summary Cancels inline editing when clicking the cancel button. |
| 59 | */ |
47 | 60 | $( '.cancel', row ).click( function() { |
48 | 61 | return inlineEditTax.revert(); |
49 | 62 | }); |
50 | 63 | |
| 64 | /** |
| 65 | * @summary Saves the inline edits when clicking the save button. |
| 66 | */ |
51 | 67 | $( '.save', row ).click( function() { |
52 | 68 | return inlineEditTax.save(this); |
53 | 69 | }); |
54 | 70 | |
| 71 | /** |
| 72 | * @summary Saves the inline edits when pressing enter inside the inline editor. |
| 73 | */ |
55 | 74 | $( 'input, select', row ).keydown( function( e ) { |
56 | 75 | // 13 = [enter] |
57 | 76 | if ( e.which === 13 ) { |
… |
… |
inlineEditTax = { |
59 | 78 | } |
60 | 79 | }); |
61 | 80 | |
| 81 | /** |
| 82 | * @summary Saves the inline edits on submitting the inline edit form. |
| 83 | */ |
62 | 84 | $( '#posts-filter input[type="submit"]' ).mousedown( function() { |
63 | 85 | t.revert(); |
64 | 86 | }); |
… |
… |
inlineEditTax = { |
67 | 89 | /** |
68 | 90 | * Toggles the quick edit based on if it is currently shown or hidden. |
69 | 91 | * |
| 92 | * @since 2.7.0 |
| 93 | * |
70 | 94 | * @this inlineEditTax |
71 | 95 | * @memberof inlineEditTax |
72 | 96 | * |
73 | 97 | * @param {HTMLElement} el An element within the table row or the table row itself that we want to quick edit. |
| 98 | * @returns {void} |
74 | 99 | */ |
75 | 100 | toggle : function(el) { |
76 | 101 | var t = this; |
… |
… |
inlineEditTax = { |
81 | 106 | /** |
82 | 107 | * Shows the quick editor |
83 | 108 | * |
| 109 | * @since 2.7.0 |
| 110 | * |
84 | 111 | * @this inlineEditTax |
85 | 112 | * @memberof inlineEditTax |
86 | 113 | * |
… |
… |
inlineEditTax = { |
122 | 149 | /** |
123 | 150 | * Saves the quick edit data to the server and replaces the table row with the HTML retrieved from the server. |
124 | 151 | * |
| 152 | * @since 2.7.0 |
| 153 | * |
125 | 154 | * @this inlineEditTax |
126 | 155 | * @memberof inlineEditTax |
127 | 156 | * |
… |
… |
inlineEditTax = { |
205 | 234 | /** |
206 | 235 | * Closes the quick edit form. |
207 | 236 | * |
| 237 | * @since 2.7.0 |
| 238 | * |
208 | 239 | * @this inlineEditTax |
209 | 240 | * @memberof inlineEditTax |
| 241 | * @returns {void} |
210 | 242 | */ |
211 | 243 | revert : function() { |
212 | 244 | var id = $('table.widefat tr.inline-editor').attr('id'); |
… |
… |
inlineEditTax = { |
224 | 256 | /** |
225 | 257 | * Retrieves the ID of the term of the element inside the table row. |
226 | 258 | * |
| 259 | * @since 2.7.0 |
| 260 | * |
227 | 261 | * @memberof inlineEditTax |
228 | 262 | * |
229 | 263 | * @param {HTMLElement} o An element within the table row or the table row itself. |
… |
… |
inlineEditTax = { |
236 | 270 | } |
237 | 271 | }; |
238 | 272 | |
239 | | $(document).ready(function(){ |
240 | | inlineEditTax.init(); |
241 | | }); |
| 273 | $(document).ready(function(){inlineEditTax.init();}); |
242 | 274 | |
243 | 275 | })( jQuery, window.wp ); |
From 81e73e00e2d3500fa28386ce9f5a91c5b53aaa8f Mon Sep 17 00:00:00 2001
From: Anton Timmermans <email@atimmer.com>
Date: Thu, 4 Aug 2016 16:31:40 +0200
Subject: [PATCH 3/3] Adhere to the line limit
---
src/wp-admin/js/inline-edit-tax.js | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/src/wp-admin/js/inline-edit-tax.js b/src/wp-admin/js/inline-edit-tax.js
index 50fcaa8..daad73f 100644
a
|
b
|
inlineEditTax = { |
94 | 94 | * @this inlineEditTax |
95 | 95 | * @memberof inlineEditTax |
96 | 96 | * |
97 | | * @param {HTMLElement} el An element within the table row or the table row itself that we want to quick edit. |
| 97 | * @param {HTMLElement} el An element within the table row or the table row |
| 98 | * itself that we want to quick edit. |
98 | 99 | * @returns {void} |
99 | 100 | */ |
100 | 101 | toggle : function(el) { |
… |
… |
inlineEditTax = { |
111 | 112 | * @this inlineEditTax |
112 | 113 | * @memberof inlineEditTax |
113 | 114 | * |
114 | | * @param {string|HTMLElement} id The ID of the term we want to quick edit or an element within the table row or the |
| 115 | * @param {string|HTMLElement} id The ID of the term we want to quick edit or an |
| 116 | * element within the table row or the |
115 | 117 | * table row itself. |
116 | 118 | * @returns {boolean} Always returns false. |
117 | 119 | */ |
… |
… |
inlineEditTax = { |
147 | 149 | }, |
148 | 150 | |
149 | 151 | /** |
150 | | * Saves the quick edit data to the server and replaces the table row with the HTML retrieved from the server. |
| 152 | * @summary Saves the quick edit data. |
| 153 | * |
| 154 | * Saves the quick edit data to the server and replaces the table row with the |
| 155 | * HTML retrieved from the server. |
151 | 156 | * |
152 | 157 | * @since 2.7.0 |
153 | 158 | * |
154 | 159 | * @this inlineEditTax |
155 | 160 | * @memberof inlineEditTax |
156 | 161 | * |
157 | | * @param {string|HTMLElement} id The ID of the term we want to quick edit or an element within the table row or the |
| 162 | * @param {string|HTMLElement} id The ID of the term we want to quick edit or an |
| 163 | * element within the table row or the |
158 | 164 | * table row itself. |
159 | 165 | * @returns {boolean} Always returns false. |
160 | 166 | */ |
… |
… |
inlineEditTax = { |
181 | 187 | // Do the ajax request to save the data to the server. |
182 | 188 | $.post( ajaxurl, params, |
183 | 189 | /** |
184 | | * Handles the response from the server, replaces the table row with the response from the server. |
| 190 | * @summary Handles the response from the server. |
| 191 | * |
| 192 | * Handles the response from the server, replaces the table row with the response |
| 193 | * from the server. |
185 | 194 | * |
186 | 195 | * @param {string} r The string with which to replace the table row. |
187 | 196 | */ |
… |
… |
inlineEditTax = { |
217 | 226 | |
218 | 227 | } else { |
219 | 228 | $errorSpan.html( r ).show(); |
220 | | // Some error strings may contain HTML entities (e.g. `“`), let's use the HTML element's text. |
| 229 | /* |
| 230 | * Some error strings may contain HTML entities (e.g. `“`), let's use |
| 231 | * the HTML element's text. |
| 232 | */ |
221 | 233 | wp.a11y.speak( $errorSpan.text() ); |
222 | 234 | } |
223 | 235 | } else { |