author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 17:39:30 +0200 | |
changeset 7 | cf61fcea0001 |
parent 5 | 5e2f62d02dcd |
child 9 | 177826044cd9 |
permissions | -rw-r--r-- |
5 | 1 |
/* global inlineEditL10n, ajaxurl, typenow */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3 |
* This file contains the functions needed for the inline editing of posts. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5 |
* @since 2.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6 |
*/ |
5 | 7 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8 |
window.wp = window.wp || {}; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
9 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
10 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
11 |
* Manages the quick edit and bulk edit windows for editing posts or pages. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
12 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
13 |
* @namespace |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
14 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
15 |
* @since 2.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
16 |
* @access public |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
17 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
18 |
* @type {Object} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
19 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
20 |
* @property {string} type The type of inline editor. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
21 |
* @property {string} what The prefix before the post id. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
22 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
23 |
*/ |
5 | 24 |
var inlineEditPost; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
25 |
( function( $, wp ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
26 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
27 |
inlineEditPost = { |
0 | 28 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
29 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
30 |
* @summary Initializes the inline and bulk post editor. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
31 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
32 |
* Binds event handlers to the escape key to close the inline editor |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
33 |
* and to the save and close buttons. Changes DOM to be ready for inline |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
34 |
* editing. Adds event handler to bulk edit. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
35 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
36 |
* @memberof inlineEditPost |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
37 |
* @since 2.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
38 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
39 |
* @returns {void} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
40 |
*/ |
0 | 41 |
init : function(){ |
42 |
var t = this, qeRow = $('#inline-edit'), bulkRow = $('#bulk-edit'); |
|
43 |
||
44 |
t.type = $('table.widefat').hasClass('pages') ? 'page' : 'post'; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
45 |
// Post id prefix. |
0 | 46 |
t.what = '#post-'; |
47 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
48 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
49 |
* @summary Bind escape key to revert the changes and close the quick editor. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
50 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
51 |
* @returns {boolean} The result of revert. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
52 |
*/ |
0 | 53 |
qeRow.keyup(function(e){ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
54 |
// Revert changes if escape key is pressed. |
5 | 55 |
if ( e.which === 27 ) { |
0 | 56 |
return inlineEditPost.revert(); |
5 | 57 |
} |
0 | 58 |
}); |
59 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
60 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
61 |
* @summary Bind escape key to revert the changes and close the bulk editor. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
62 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
63 |
* @returns {boolean} The result of revert. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
64 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
65 |
bulkRow.keyup(function(e){ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
66 |
// Revert changes if escape key is pressed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
67 |
if ( e.which === 27 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
68 |
return inlineEditPost.revert(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
69 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
70 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
71 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
72 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
73 |
* @summary Revert changes and close the quick editor if the cancel button is clicked. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
74 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
75 |
* @returns {boolean} The result of revert. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
76 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
77 |
$( '.cancel', qeRow ).click( function() { |
0 | 78 |
return inlineEditPost.revert(); |
79 |
}); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
80 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
81 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
82 |
* @summary Save changes in the quick editor if the save(named: update) button is clicked. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
83 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
84 |
* @returns {boolean} The result of save. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
85 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
86 |
$( '.save', qeRow ).click( function() { |
0 | 87 |
return inlineEditPost.save(this); |
88 |
}); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
89 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
90 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
91 |
* @summary If enter is pressed, and the target is not the cancel button, save the post. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
92 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
93 |
* @returns {boolean} The result of save. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
94 |
*/ |
0 | 95 |
$('td', qeRow).keydown(function(e){ |
5 | 96 |
if ( e.which === 13 && ! $( e.target ).hasClass( 'cancel' ) ) { |
0 | 97 |
return inlineEditPost.save(this); |
5 | 98 |
} |
0 | 99 |
}); |
100 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
101 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
102 |
* @summary Revert changes and close the bulk editor if the cancel button is clicked. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
103 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
104 |
* @returns {boolean} The result of revert. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
105 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
106 |
$( '.cancel', bulkRow ).click( function() { |
0 | 107 |
return inlineEditPost.revert(); |
108 |
}); |
|
109 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
110 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
111 |
* @summary Disables the password input field when the private post checkbox is checked. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
112 |
*/ |
0 | 113 |
$('#inline-edit .inline-edit-private input[value="private"]').click( function(){ |
114 |
var pw = $('input.inline-edit-password-input'); |
|
115 |
if ( $(this).prop('checked') ) { |
|
116 |
pw.val('').prop('disabled', true); |
|
117 |
} else { |
|
118 |
pw.prop('disabled', false); |
|
119 |
} |
|
120 |
}); |
|
121 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
122 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
123 |
* @summary Bind click event to the .editinline link which opens the quick editor. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
124 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
125 |
$('#the-list').on( 'click', 'a.editinline', function( e ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
126 |
e.preventDefault(); |
0 | 127 |
inlineEditPost.edit(this); |
128 |
}); |
|
129 |
||
5 | 130 |
$('#bulk-edit').find('fieldset:first').after( |
0 | 131 |
$('#inline-edit fieldset.inline-edit-categories').clone() |
132 |
).siblings( 'fieldset:last' ).prepend( |
|
133 |
$('#inline-edit label.inline-edit-tags').clone() |
|
134 |
); |
|
135 |
||
136 |
$('select[name="_status"] option[value="future"]', bulkRow).remove(); |
|
137 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
138 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
139 |
* @summary Adds onclick events to the apply buttons. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
140 |
*/ |
0 | 141 |
$('#doaction, #doaction2').click(function(e){ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
142 |
var n; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
143 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
144 |
t.whichBulkButtonId = $( this ).attr( 'id' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
145 |
n = t.whichBulkButtonId.substr( 2 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
146 |
|
5 | 147 |
if ( 'edit' === $( 'select[name="' + n + '"]' ).val() ) { |
0 | 148 |
e.preventDefault(); |
149 |
t.setBulk(); |
|
150 |
} else if ( $('form#posts-filter tr.inline-editor').length > 0 ) { |
|
151 |
t.revert(); |
|
152 |
} |
|
153 |
}); |
|
154 |
}, |
|
155 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
156 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
157 |
* @summary Toggles the quick edit window. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
158 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
159 |
* Hides the window when it's active and shows the window when inactive. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
160 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
161 |
* @memberof inlineEditPost |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
162 |
* @since 2.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
163 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
164 |
* @param {Object} el Element within a post table row. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
165 |
*/ |
0 | 166 |
toggle : function(el){ |
167 |
var t = this; |
|
5 | 168 |
$( t.what + t.getId( el ) ).css( 'display' ) === 'none' ? t.revert() : t.edit( el ); |
0 | 169 |
}, |
170 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
171 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
172 |
* @summary Creates the bulk editor row to edit multiple posts at once. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
173 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
174 |
* @memberof inlineEditPost |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
175 |
* @since 2.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
176 |
*/ |
0 | 177 |
setBulk : function(){ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
178 |
var te = '', type = this.type, c = true; |
0 | 179 |
this.revert(); |
180 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
181 |
$( '#bulk-edit td' ).attr( 'colspan', $( 'th:visible, td:visible', '.widefat:first thead' ).length ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
182 |
|
5 | 183 |
// Insert the editor at the top of the table with an empty row above to maintain zebra striping. |
184 |
$('table.widefat tbody').prepend( $('#bulk-edit') ).prepend('<tr class="hidden"></tr>'); |
|
0 | 185 |
$('#bulk-edit').addClass('inline-editor').show(); |
186 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
187 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
188 |
* @summary Create a HTML div with the title and a delete link(cross-icon) for each selected post. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
189 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
190 |
* Get the selected posts based on the checked checkboxes in the post table. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
191 |
* Create a HTML div with the title and a link(delete-icon) for each selected post. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
192 |
*/ |
5 | 193 |
$( 'tbody th.check-column input[type="checkbox"]' ).each( function() { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
194 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
195 |
// If the checkbox for a post is selected, add the post to the edit list. |
0 | 196 |
if ( $(this).prop('checked') ) { |
197 |
c = false; |
|
198 |
var id = $(this).val(), theTitle; |
|
199 |
theTitle = $('#inline_'+id+' .post_title').html() || inlineEditL10n.notitle; |
|
200 |
te += '<div id="ttle'+id+'"><a id="_'+id+'" class="ntdelbutton" title="'+inlineEditL10n.ntdeltitle+'">X</a>'+theTitle+'</div>'; |
|
201 |
} |
|
202 |
}); |
|
203 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
204 |
// If no checkboxes where checked, just hide the quick/bulk edit rows. |
5 | 205 |
if ( c ) { |
0 | 206 |
return this.revert(); |
5 | 207 |
} |
0 | 208 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
209 |
// Add onclick events to the delete-icons in the bulk editors the post title list. |
0 | 210 |
$('#bulk-titles').html(te); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
211 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
212 |
* @summary Binds on click events to the checkboxes before the posts in the table. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
213 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
214 |
* @listens click |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
215 |
*/ |
0 | 216 |
$('#bulk-titles a').click(function(){ |
217 |
var id = $(this).attr('id').substr(1); |
|
218 |
||
219 |
$('table.widefat input[value="' + id + '"]').prop('checked', false); |
|
220 |
$('#ttle'+id).remove(); |
|
221 |
}); |
|
222 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
223 |
// Enable auto-complete for tags when editing posts. |
5 | 224 |
if ( 'post' === type ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
225 |
$( 'tr.inline-editor textarea[data-wp-taxonomy]' ).each( function ( i, element ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
226 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
227 |
* While Quick Edit clones the form each time, Bulk Edit always re-uses |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
228 |
* the same form. Let's check if an autocomplete instance already exists. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
229 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
230 |
if ( $( element ).autocomplete( 'instance' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
231 |
// jQuery equivalent of `continue` within an `each()` loop. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
232 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
233 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
234 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
235 |
$( element ).wpTagsSuggest(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
236 |
} ); |
0 | 237 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
238 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
239 |
// Scrolls to the top of the table where the editor is rendered. |
0 | 240 |
$('html, body').animate( { scrollTop: 0 }, 'fast' ); |
241 |
}, |
|
242 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
243 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
244 |
* @summary Creates a quick edit window for the post that has been clicked. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
245 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
246 |
* @memberof inlineEditPost |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
247 |
* @since 2.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
248 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
249 |
* @param {number|Object} id The id of the clicked post or an element within a post |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
250 |
* table row. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
251 |
* @returns {boolean} Always returns false at the end of execution. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
252 |
*/ |
0 | 253 |
edit : function(id) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
254 |
var t = this, fields, editRow, rowData, status, pageOpt, pageLevel, nextPage, pageLoop = true, nextLevel, f, val, pw; |
0 | 255 |
t.revert(); |
256 |
||
5 | 257 |
if ( typeof(id) === 'object' ) { |
0 | 258 |
id = t.getId(id); |
5 | 259 |
} |
0 | 260 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
261 |
fields = ['post_title', 'post_name', 'post_author', '_status', 'jj', 'mm', 'aa', 'hh', 'mn', 'ss', 'post_password', 'post_format', 'menu_order', 'page_template']; |
5 | 262 |
if ( t.type === 'page' ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
263 |
fields.push('post_parent'); |
5 | 264 |
} |
0 | 265 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
266 |
// Add the new edit row with an extra blank row underneath to maintain zebra striping. |
0 | 267 |
editRow = $('#inline-edit').clone(true); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
268 |
$( 'td', editRow ).attr( 'colspan', $( 'th:visible, td:visible', '.widefat:first thead' ).length ); |
0 | 269 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
270 |
$(t.what+id).removeClass('is-expanded').hide().after(editRow).after('<tr class="hidden"></tr>'); |
0 | 271 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
272 |
// Populate fields in the quick edit window. |
0 | 273 |
rowData = $('#inline_'+id); |
274 |
if ( !$(':input[name="post_author"] option[value="' + $('.post_author', rowData).text() + '"]', editRow).val() ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
275 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
276 |
// The post author no longer has edit capabilities, so we need to add them to the list of authors. |
0 | 277 |
$(':input[name="post_author"]', editRow).prepend('<option value="' + $('.post_author', rowData).text() + '">' + $('#' + t.type + '-' + id + ' .author').text() + '</option>'); |
278 |
} |
|
5 | 279 |
if ( $( ':input[name="post_author"] option', editRow ).length === 1 ) { |
0 | 280 |
$('label.inline-edit-author', editRow).hide(); |
281 |
} |
|
282 |
||
283 |
for ( f = 0; f < fields.length; f++ ) { |
|
5 | 284 |
val = $('.'+fields[f], rowData); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
285 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
286 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
287 |
* @summary Replaces the image for a Twemoji(Twitter emoji) with it's alternate text. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
288 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
289 |
* @returns Alternate text from the image. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
290 |
*/ |
5 | 291 |
val.find( 'img' ).replaceWith( function() { return this.alt; } ); |
292 |
val = val.text(); |
|
293 |
$(':input[name="' + fields[f] + '"]', editRow).val( val ); |
|
0 | 294 |
} |
295 |
||
5 | 296 |
if ( $( '.comment_status', rowData ).text() === 'open' ) { |
297 |
$( 'input[name="comment_status"]', editRow ).prop( 'checked', true ); |
|
298 |
} |
|
299 |
if ( $( '.ping_status', rowData ).text() === 'open' ) { |
|
300 |
$( 'input[name="ping_status"]', editRow ).prop( 'checked', true ); |
|
301 |
} |
|
302 |
if ( $( '.sticky', rowData ).text() === 'sticky' ) { |
|
303 |
$( 'input[name="sticky"]', editRow ).prop( 'checked', true ); |
|
304 |
} |
|
0 | 305 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
306 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
307 |
* @summary Creates the select boxes for the categories. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
308 |
*/ |
0 | 309 |
$('.post_category', rowData).each(function(){ |
5 | 310 |
var taxname, |
311 |
term_ids = $(this).text(); |
|
0 | 312 |
|
313 |
if ( term_ids ) { |
|
314 |
taxname = $(this).attr('id').replace('_'+id, ''); |
|
315 |
$('ul.'+taxname+'-checklist :checkbox', editRow).val(term_ids.split(',')); |
|
316 |
} |
|
317 |
}); |
|
318 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
319 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
320 |
* @summary Gets all the taxonomies for live auto-fill suggestions. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
321 |
* When typing the name of a tag. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
322 |
*/ |
0 | 323 |
$('.tags_input', rowData).each(function(){ |
5 | 324 |
var terms = $(this), |
0 | 325 |
taxname = $(this).attr('id').replace('_' + id, ''), |
326 |
textarea = $('textarea.tax_input_' + taxname, editRow), |
|
327 |
comma = inlineEditL10n.comma; |
|
328 |
||
5 | 329 |
terms.find( 'img' ).replaceWith( function() { return this.alt; } ); |
330 |
terms = terms.text(); |
|
331 |
||
0 | 332 |
if ( terms ) { |
5 | 333 |
if ( ',' !== comma ) { |
0 | 334 |
terms = terms.replace(/,/g, comma); |
5 | 335 |
} |
0 | 336 |
textarea.val(terms); |
337 |
} |
|
338 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
339 |
textarea.wpTagsSuggest(); |
0 | 340 |
}); |
341 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
342 |
// Handle the post status. |
0 | 343 |
status = $('._status', rowData).text(); |
5 | 344 |
if ( 'future' !== status ) { |
0 | 345 |
$('select[name="_status"] option[value="future"]', editRow).remove(); |
5 | 346 |
} |
0 | 347 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
348 |
pw = $( '.inline-edit-password-input' ).prop( 'disabled', false ); |
5 | 349 |
if ( 'private' === status ) { |
350 |
$('input[name="keep_private"]', editRow).prop('checked', true); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
351 |
pw.val( '' ).prop( 'disabled', true ); |
0 | 352 |
} |
353 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
354 |
// Remove the current page and children from the parent dropdown. |
0 | 355 |
pageOpt = $('select[name="post_parent"] option[value="' + id + '"]', editRow); |
356 |
if ( pageOpt.length > 0 ) { |
|
357 |
pageLevel = pageOpt[0].className.split('-')[1]; |
|
358 |
nextPage = pageOpt; |
|
359 |
while ( pageLoop ) { |
|
360 |
nextPage = nextPage.next('option'); |
|
5 | 361 |
if ( nextPage.length === 0 ) { |
362 |
break; |
|
363 |
} |
|
364 |
||
0 | 365 |
nextLevel = nextPage[0].className.split('-')[1]; |
5 | 366 |
|
0 | 367 |
if ( nextLevel <= pageLevel ) { |
368 |
pageLoop = false; |
|
369 |
} else { |
|
370 |
nextPage.remove(); |
|
371 |
nextPage = pageOpt; |
|
372 |
} |
|
373 |
} |
|
374 |
pageOpt.remove(); |
|
375 |
} |
|
376 |
||
377 |
$(editRow).attr('id', 'edit-'+id).addClass('inline-editor').show(); |
|
378 |
$('.ptitle', editRow).focus(); |
|
379 |
||
380 |
return false; |
|
381 |
}, |
|
382 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
383 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
384 |
* @summary Saves the changes made in the quick edit window to the post. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
385 |
* AJAX saving is only for Quick Edit and not for bulk edit. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
386 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
387 |
* @since 2.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
388 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
389 |
* @param {int} id The id for the post that has been changed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
390 |
* @returns {boolean} false, so the form does not submit when pressing |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
391 |
* Enter on a focused field. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
392 |
*/ |
0 | 393 |
save : function(id) { |
394 |
var params, fields, page = $('.post_status_page').val() || ''; |
|
395 |
||
5 | 396 |
if ( typeof(id) === 'object' ) { |
0 | 397 |
id = this.getId(id); |
5 | 398 |
} |
0 | 399 |
|
5 | 400 |
$( 'table.widefat .spinner' ).addClass( 'is-active' ); |
0 | 401 |
|
402 |
params = { |
|
403 |
action: 'inline-save', |
|
404 |
post_type: typenow, |
|
405 |
post_ID: id, |
|
406 |
edit_date: 'true', |
|
407 |
post_status: page |
|
408 |
}; |
|
409 |
||
5 | 410 |
fields = $('#edit-'+id).find(':input').serialize(); |
0 | 411 |
params = fields + '&' + $.param(params); |
412 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
413 |
// Make ajax request. |
0 | 414 |
$.post( ajaxurl, params, |
415 |
function(r) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
416 |
var $errorNotice = $( '#edit-' + id + ' .inline-edit-save .notice-error' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
417 |
$error = $errorNotice.find( '.error' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
418 |
|
5 | 419 |
$( 'table.widefat .spinner' ).removeClass( 'is-active' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
420 |
$( '.ac_results' ).hide(); |
0 | 421 |
|
422 |
if (r) { |
|
5 | 423 |
if ( -1 !== r.indexOf( '<tr' ) ) { |
424 |
$(inlineEditPost.what+id).siblings('tr.hidden').addBack().remove(); |
|
0 | 425 |
$('#edit-'+id).before(r).remove(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
426 |
$( inlineEditPost.what + id ).hide().fadeIn( 400, function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
427 |
// Move focus back to the Quick Edit link. $( this ) is the row being animated. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
428 |
$( this ).find( '.editinline' ).focus(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
429 |
wp.a11y.speak( inlineEditL10n.saved ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
430 |
}); |
0 | 431 |
} else { |
432 |
r = r.replace( /<.[^<>]*?>/g, '' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
433 |
$errorNotice.removeClass( 'hidden' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
434 |
$error.html( r ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
435 |
wp.a11y.speak( $error.text() ); |
0 | 436 |
} |
437 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
438 |
$errorNotice.removeClass( 'hidden' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
439 |
$error.html( inlineEditL10n.error ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
440 |
wp.a11y.speak( inlineEditL10n.error ); |
0 | 441 |
} |
5 | 442 |
}, |
443 |
'html'); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
444 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
445 |
// Prevent submitting the form when pressing Enter on a focused field. |
0 | 446 |
return false; |
447 |
}, |
|
448 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
449 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
450 |
* @summary Hides and empties the Quick Edit and/or Bulk Edit windows. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
451 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
452 |
* @memberof inlineEditPost |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
453 |
* @since 2.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
454 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
455 |
* @returns {boolean} Always returns false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
456 |
*/ |
0 | 457 |
revert : function(){ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
458 |
var $tableWideFat = $( '.widefat' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
459 |
id = $( '.inline-editor', $tableWideFat ).attr( 'id' ); |
0 | 460 |
|
461 |
if ( id ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
462 |
$( '.spinner', $tableWideFat ).removeClass( 'is-active' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
463 |
$( '.ac_results' ).hide(); |
0 | 464 |
|
5 | 465 |
if ( 'bulk-edit' === id ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
466 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
467 |
// Hide the bulk editor. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
468 |
$( '#bulk-edit', $tableWideFat ).removeClass( 'inline-editor' ).hide().siblings( '.hidden' ).remove(); |
5 | 469 |
$('#bulk-titles').empty(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
470 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
471 |
// Store the empty bulk editor in a hidden element. |
0 | 472 |
$('#inlineedit').append( $('#bulk-edit') ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
473 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
474 |
// Move focus back to the Bulk Action button that was activated. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
475 |
$( '#' + inlineEditPost.whichBulkButtonId ).focus(); |
0 | 476 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
477 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
478 |
// Remove both the inline-editor and its hidden tr siblings. |
5 | 479 |
$('#'+id).siblings('tr.hidden').addBack().remove(); |
0 | 480 |
id = id.substr( id.lastIndexOf('-') + 1 ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
481 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
482 |
// Show the post row and move focus back to the Quick Edit link. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
483 |
$( this.what + id ).show().find( '.editinline' ).focus(); |
0 | 484 |
} |
485 |
} |
|
486 |
||
487 |
return false; |
|
488 |
}, |
|
489 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
490 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
491 |
* @summary Gets the id for a the post that you want to quick edit from the row |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
492 |
* in the quick edit table. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
493 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
494 |
* @memberof inlineEditPost |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
495 |
* @since 2.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
496 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
497 |
* @param {Object} o DOM row object to get the id for. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
498 |
* @returns {string} The post id extracted from the table row in the object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
499 |
*/ |
0 | 500 |
getId : function(o) { |
501 |
var id = $(o).closest('tr').attr('id'), |
|
502 |
parts = id.split('-'); |
|
503 |
return parts[parts.length - 1]; |
|
504 |
} |
|
505 |
}; |
|
506 |
||
507 |
$( document ).ready( function(){ inlineEditPost.init(); } ); |
|
508 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
509 |
// Show/hide locks on posts. |
0 | 510 |
$( document ).on( 'heartbeat-tick.wp-check-locked-posts', function( e, data ) { |
511 |
var locked = data['wp-check-locked-posts'] || {}; |
|
512 |
||
513 |
$('#the-list tr').each( function(i, el) { |
|
514 |
var key = el.id, row = $(el), lock_data, avatar; |
|
515 |
||
516 |
if ( locked.hasOwnProperty( key ) ) { |
|
517 |
if ( ! row.hasClass('wp-locked') ) { |
|
518 |
lock_data = locked[key]; |
|
519 |
row.find('.column-title .locked-text').text( lock_data.text ); |
|
520 |
row.find('.check-column checkbox').prop('checked', false); |
|
521 |
||
522 |
if ( lock_data.avatar_src ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
523 |
avatar = $( '<img class="avatar avatar-18 photo" width="18" height="18" alt="" />' ).attr( 'src', lock_data.avatar_src.replace( /&/g, '&' ) ); |
0 | 524 |
row.find('.column-title .locked-avatar').empty().append( avatar ); |
525 |
} |
|
526 |
row.addClass('wp-locked'); |
|
527 |
} |
|
528 |
} else if ( row.hasClass('wp-locked') ) { |
|
529 |
// Make room for the CSS animation |
|
530 |
row.removeClass('wp-locked').delay(1000).find('.locked-info span').empty(); |
|
531 |
} |
|
532 |
}); |
|
533 |
}).on( 'heartbeat-send.wp-check-locked-posts', function( e, data ) { |
|
534 |
var check = []; |
|
535 |
||
536 |
$('#the-list tr').each( function(i, el) { |
|
5 | 537 |
if ( el.id ) { |
0 | 538 |
check.push( el.id ); |
5 | 539 |
} |
0 | 540 |
}); |
541 |
||
5 | 542 |
if ( check.length ) { |
0 | 543 |
data['wp-check-locked-posts'] = check; |
5 | 544 |
} |
545 |
}).ready( function() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
546 |
|
5 | 547 |
// Set the heartbeat interval to 15 sec. |
548 |
if ( typeof wp !== 'undefined' && wp.heartbeat ) { |
|
549 |
wp.heartbeat.interval( 15 ); |
|
550 |
} |
|
0 | 551 |
}); |
552 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
553 |
})( jQuery, window.wp ); |