author | ymh <ymh.work@gmail.com> |
Mon, 08 Sep 2025 19:44:41 +0200 | |
changeset 23 | 417f20492bf7 |
parent 22 | 8c2e4d02f4ef |
permissions | -rw-r--r-- |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1 |
/** |
9 | 2 |
* @file Contains all dynamic functionality needed on post and term pages. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3 |
* |
9 | 4 |
* @output wp-admin/js/post.js |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5 |
*/ |
0 | 6 |
|
16 | 7 |
/* global ajaxurl, wpAjax, postboxes, pagenow, tinymce, alert, deleteUserSetting, ClipboardJS */ |
9 | 8 |
/* global theList:true, theExtraList:true, getUserSetting, setUserSetting, commentReply, commentsBox */ |
9 |
/* global WPSetThumbnailHTML, wptitlehint */ |
|
10 |
||
16 | 11 |
// Backward compatibility: prevent fatal errors. |
9 | 12 |
window.makeSlugeditClickable = window.editPermalink = function(){}; |
0 | 13 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
14 |
// Make sure the wp object exists. |
5 | 15 |
window.wp = window.wp || {}; |
0 | 16 |
|
5 | 17 |
( function( $ ) { |
16 | 18 |
var titleHasFocus = false, |
19 |
__ = wp.i18n.__; |
|
0 | 20 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
21 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
22 |
* Control loading of comments on the post and term edit pages. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
23 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
24 |
* @type {{st: number, get: commentsBox.get, load: commentsBox.load}} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
25 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
26 |
* @namespace commentsBox |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
27 |
*/ |
9 | 28 |
window.commentsBox = { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
29 |
// Comment offset to use when fetching new comments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
30 |
st : 0, |
0 | 31 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
32 |
/** |
16 | 33 |
* Fetch comments using Ajax and display them in the box. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
34 |
* |
9 | 35 |
* @memberof commentsBox |
36 |
* |
|
16 | 37 |
* @param {number} total Total number of comments for this post. |
38 |
* @param {number} num Optional. Number of comments to fetch, defaults to 20. |
|
39 |
* @return {boolean} Always returns false. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
40 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
41 |
get : function(total, num) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
42 |
var st = this.st, data; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
43 |
if ( ! num ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
44 |
num = 20; |
0 | 45 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
46 |
this.st += num; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
47 |
this.total = total; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
48 |
$( '#commentsdiv .spinner' ).addClass( 'is-active' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
49 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
50 |
data = { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
51 |
'action' : 'get-comments', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
52 |
'mode' : 'single', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
53 |
'_ajax_nonce' : $('#add_comment_nonce').val(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
54 |
'p' : $('#post_ID').val(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
55 |
'start' : st, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
56 |
'number' : num |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
57 |
}; |
0 | 58 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
59 |
$.post( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
60 |
ajaxurl, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
61 |
data, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
62 |
function(r) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
63 |
r = wpAjax.parseAjaxResponse(r); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
64 |
$('#commentsdiv .widefat').show(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
65 |
$( '#commentsdiv .spinner' ).removeClass( 'is-active' ); |
0 | 66 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
67 |
if ( 'object' == typeof r && r.responses[0] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
68 |
$('#the-comment-list').append( r.responses[0].data ); |
0 | 69 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
70 |
theList = theExtraList = null; |
18 | 71 |
$( 'a[className*=\':\']' ).off(); |
0 | 72 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
73 |
// If the offset is over the total number of comments we cannot fetch any more, so hide the button. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
74 |
if ( commentsBox.st > commentsBox.total ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
75 |
$('#show-comments').hide(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
76 |
else |
16 | 77 |
$('#show-comments').show().children('a').text( __( 'Show more comments' ) ); |
0 | 78 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
79 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
80 |
} else if ( 1 == r ) { |
16 | 81 |
$('#show-comments').text( __( 'No more comments found.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
82 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
83 |
} |
0 | 84 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
85 |
$('#the-comment-list').append('<tr><td colspan="2">'+wpAjax.broken+'</td></tr>'); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
86 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
87 |
); |
0 | 88 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
89 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
90 |
}, |
0 | 91 |
|
7
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 |
* Load the next batch of comments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
94 |
* |
16 | 95 |
* @memberof commentsBox |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
96 |
* |
16 | 97 |
* @param {number} total Total number of comments to load. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
98 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
99 |
load: function(total){ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
100 |
this.st = jQuery('#the-comment-list tr.comment:visible').length; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
101 |
this.get(total); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
102 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
103 |
}; |
0 | 104 |
|
7
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 |
* Overwrite the content of the Featured Image postbox |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
107 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
108 |
* @param {string} html New HTML to be displayed in the content area of the postbox. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
109 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
110 |
* @global |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
111 |
*/ |
9 | 112 |
window.WPSetThumbnailHTML = function(html){ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
113 |
$('.inside', '#postimagediv').html(html); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
114 |
}; |
0 | 115 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
116 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
117 |
* Set the Image ID of the Featured Image |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
118 |
* |
16 | 119 |
* @param {number} id The post_id of the image to use as Featured Image. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
120 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
121 |
* @global |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
122 |
*/ |
9 | 123 |
window.WPSetThumbnailID = function(id){ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
124 |
var field = $('input[value="_thumbnail_id"]', '#list-table'); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
125 |
if ( field.length > 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
126 |
$('#meta\\[' + field.attr('id').match(/[0-9]+/) + '\\]\\[value\\]').text(id); |
0 | 127 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
128 |
}; |
0 | 129 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
130 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
131 |
* Remove the Featured Image |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
132 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
133 |
* @param {string} nonce Nonce to use in the request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
134 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
135 |
* @global |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
136 |
*/ |
9 | 137 |
window.WPRemoveThumbnail = function(nonce){ |
19 | 138 |
$.post( |
139 |
ajaxurl, { |
|
140 |
action: 'set-post-thumbnail', |
|
141 |
post_id: $( '#post_ID' ).val(), |
|
142 |
thumbnail_id: -1, |
|
143 |
_ajax_nonce: nonce, |
|
144 |
cookie: encodeURIComponent( document.cookie ) |
|
145 |
}, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
146 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
147 |
* Handle server response |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
148 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
149 |
* @param {string} str Response, will be '0' when an error occurred otherwise contains link to add Featured Image. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
150 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
151 |
function(str){ |
19 | 152 |
if ( str == '0' ) { |
153 |
alert( __( 'Could not set that as the thumbnail image. Try a different attachment.' ) ); |
|
154 |
} else { |
|
155 |
WPSetThumbnailHTML(str); |
|
156 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
157 |
} |
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 |
}; |
0 | 160 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
161 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
162 |
* Heartbeat locks. |
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 |
* Used to lock editing of an object by only one user at a time. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
165 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
166 |
* When the user does not send a heartbeat in a heartbeat-time |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
167 |
* the user is no longer editing and another user can start editing. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
168 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
169 |
$(document).on( 'heartbeat-send.refresh-lock', function( e, data ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
170 |
var lock = $('#active_post_lock').val(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
171 |
post_id = $('#post_ID').val(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
172 |
send = {}; |
0 | 173 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
174 |
if ( ! post_id || ! $('#post-lock-dialog').length ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
175 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
176 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
177 |
send.post_id = post_id; |
0 | 178 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
179 |
if ( lock ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
180 |
send.lock = lock; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
181 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
182 |
data['wp-refresh-post-lock'] = send; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
183 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
184 |
}).on( 'heartbeat-tick.refresh-lock', function( e, data ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
185 |
// Post locks: update the lock string or show the dialog if somebody has taken over editing. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
186 |
var received, wrap, avatar; |
0 | 187 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
188 |
if ( data['wp-refresh-post-lock'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
189 |
received = data['wp-refresh-post-lock']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
190 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
191 |
if ( received.lock_error ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
192 |
// Show "editing taken over" message. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
193 |
wrap = $('#post-lock-dialog'); |
0 | 194 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
195 |
if ( wrap.length && ! wrap.is(':visible') ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
196 |
if ( wp.autosave ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
197 |
// Save the latest changes and disable. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
198 |
$(document).one( 'heartbeat-tick', function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
199 |
wp.autosave.server.suspend(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
200 |
wrap.removeClass('saving').addClass('saved'); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
201 |
$(window).off( 'beforeunload.edit-post' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
202 |
}); |
0 | 203 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
204 |
wrap.addClass('saving'); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
205 |
wp.autosave.server.triggerSave(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
206 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
207 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
208 |
if ( received.lock_error.avatar_src ) { |
16 | 209 |
avatar = $( '<img />', { |
210 |
'class': 'avatar avatar-64 photo', |
|
211 |
width: 64, |
|
212 |
height: 64, |
|
213 |
alt: '', |
|
214 |
src: received.lock_error.avatar_src, |
|
19 | 215 |
srcset: received.lock_error.avatar_src_2x ? |
216 |
received.lock_error.avatar_src_2x + ' 2x' : |
|
217 |
undefined |
|
16 | 218 |
} ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
219 |
wrap.find('div.post-locked-avatar').empty().append( avatar ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
220 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
221 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
222 |
wrap.show().find('.currently-editing').text( received.lock_error.text ); |
18 | 223 |
wrap.find('.wp-tab-first').trigger( 'focus' ); |
0 | 224 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
225 |
} else if ( received.new_lock ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
226 |
$('#active_post_lock').val( received.new_lock ); |
0 | 227 |
} |
228 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
229 |
}).on( 'before-autosave.update-post-slug', function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
230 |
titleHasFocus = document.activeElement && document.activeElement.id === 'title'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
231 |
}).on( 'after-autosave.update-post-slug', function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
232 |
|
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 |
* Create slug area only if not already there |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
235 |
* and the title field was not focused (user was not typing a title) when autosave ran. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
236 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
237 |
if ( ! $('#edit-slug-box > *').length && ! titleHasFocus ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
238 |
$.post( ajaxurl, { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
239 |
action: 'sample-permalink', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
240 |
post_id: $('#post_ID').val(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
241 |
new_title: $('#title').val(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
242 |
samplepermalinknonce: $('#samplepermalinknonce').val() |
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 |
function( data ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
245 |
if ( data != '-1' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
246 |
$('#edit-slug-box').html(data); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
247 |
} |
5 | 248 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
249 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
250 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
251 |
}); |
0 | 252 |
|
253 |
}(jQuery)); |
|
254 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
255 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
256 |
* Heartbeat refresh nonces. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
257 |
*/ |
0 | 258 |
(function($) { |
259 |
var check, timeout; |
|
260 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
261 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
262 |
* Only allow to check for nonce refresh every 30 seconds. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
263 |
*/ |
0 | 264 |
function schedule() { |
265 |
check = false; |
|
266 |
window.clearTimeout( timeout ); |
|
267 |
timeout = window.setTimeout( function(){ check = true; }, 300000 ); |
|
268 |
} |
|
269 |
||
18 | 270 |
$( function() { |
271 |
schedule(); |
|
272 |
}).on( 'heartbeat-send.wp-refresh-nonces', function( e, data ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
273 |
var post_id, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
274 |
$authCheck = $('#wp-auth-check-wrap'); |
0 | 275 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
276 |
if ( check || ( $authCheck.length && ! $authCheck.hasClass( 'hidden' ) ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
277 |
if ( ( post_id = $('#post_ID').val() ) && $('#_wpnonce').val() ) { |
0 | 278 |
data['wp-refresh-post-nonces'] = { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
279 |
post_id: post_id |
0 | 280 |
}; |
281 |
} |
|
282 |
} |
|
283 |
}).on( 'heartbeat-tick.wp-refresh-nonces', function( e, data ) { |
|
284 |
var nonces = data['wp-refresh-post-nonces']; |
|
285 |
||
286 |
if ( nonces ) { |
|
287 |
schedule(); |
|
288 |
||
289 |
if ( nonces.replace ) { |
|
290 |
$.each( nonces.replace, function( selector, value ) { |
|
291 |
$( '#' + selector ).val( value ); |
|
292 |
}); |
|
293 |
} |
|
294 |
||
295 |
if ( nonces.heartbeatNonce ) |
|
296 |
window.heartbeatSettings.nonce = nonces.heartbeatNonce; |
|
297 |
} |
|
298 |
}); |
|
299 |
}(jQuery)); |
|
300 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
301 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
302 |
* All post and postbox controls and functionality. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
303 |
*/ |
18 | 304 |
jQuery( function($) { |
5 | 305 |
var stamp, visibility, $submitButtons, updateVisibility, updateText, |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
306 |
$textarea = $('#content'), |
5 | 307 |
$document = $(document), |
308 |
postId = $('#post_ID').val() || 0, |
|
309 |
$submitpost = $('#submitpost'), |
|
310 |
releaseLock = true, |
|
311 |
$postVisibilitySelect = $('#post-visibility-select'), |
|
312 |
$timestampdiv = $('#timestampdiv'), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
313 |
$postStatusSelect = $('#post-status-select'), |
16 | 314 |
isMac = window.navigator.platform ? window.navigator.platform.indexOf( 'Mac' ) !== -1 : false, |
315 |
copyAttachmentURLClipboard = new ClipboardJS( '.copy-attachment-url.edit-media' ), |
|
316 |
copyAttachmentURLSuccessTimeout, |
|
317 |
__ = wp.i18n.__, _x = wp.i18n._x; |
|
0 | 318 |
|
319 |
postboxes.add_postbox_toggles(pagenow); |
|
320 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
321 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
322 |
* Clear the window name. Otherwise if this is a former preview window where the user navigated to edit another post, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
323 |
* and the first post is still being edited, clicking Preview there will use this window to show the preview. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
324 |
*/ |
5 | 325 |
window.name = ''; |
326 |
||
0 | 327 |
// Post locks: contain focus inside the dialog. If the dialog is shown, focus the first item. |
328 |
$('#post-lock-dialog .notification-dialog').on( 'keydown', function(e) { |
|
16 | 329 |
// Don't do anything when [Tab] is pressed. |
0 | 330 |
if ( e.which != 9 ) |
331 |
return; |
|
332 |
||
333 |
var target = $(e.target); |
|
334 |
||
16 | 335 |
// [Shift] + [Tab] on first tab cycles back to last tab. |
0 | 336 |
if ( target.hasClass('wp-tab-first') && e.shiftKey ) { |
18 | 337 |
$(this).find('.wp-tab-last').trigger( 'focus' ); |
0 | 338 |
e.preventDefault(); |
16 | 339 |
// [Tab] on last tab cycles back to first tab. |
0 | 340 |
} else if ( target.hasClass('wp-tab-last') && ! e.shiftKey ) { |
18 | 341 |
$(this).find('.wp-tab-first').trigger( 'focus' ); |
0 | 342 |
e.preventDefault(); |
343 |
} |
|
18 | 344 |
}).filter(':visible').find('.wp-tab-first').trigger( 'focus' ); |
0 | 345 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
346 |
// Set the heartbeat interval to 10 seconds if post lock dialogs are enabled. |
5 | 347 |
if ( wp.heartbeat && $('#post-lock-dialog').length ) { |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
348 |
wp.heartbeat.interval( 10 ); |
5 | 349 |
} |
350 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
351 |
// The form is being submitted by the user. |
5 | 352 |
$submitButtons = $submitpost.find( ':submit, a.submitdelete, #post-preview' ).on( 'click.edit-post', function( event ) { |
353 |
var $button = $(this); |
|
354 |
||
355 |
if ( $button.hasClass('disabled') ) { |
|
356 |
event.preventDefault(); |
|
357 |
return; |
|
358 |
} |
|
359 |
||
360 |
if ( $button.hasClass('submitdelete') || $button.is( '#post-preview' ) ) { |
|
361 |
return; |
|
362 |
} |
|
363 |
||
364 |
// The form submission can be blocked from JS or by using HTML 5.0 validation on some fields. |
|
365 |
// Run this only on an actual 'submit'. |
|
366 |
$('form#post').off( 'submit.edit-post' ).on( 'submit.edit-post', function( event ) { |
|
367 |
if ( event.isDefaultPrevented() ) { |
|
368 |
return; |
|
369 |
} |
|
370 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
371 |
// Stop auto save. |
5 | 372 |
if ( wp.autosave ) { |
373 |
wp.autosave.server.suspend(); |
|
374 |
} |
|
375 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
376 |
if ( typeof commentReply !== 'undefined' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
377 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
378 |
* Warn the user they have an unsaved comment before submitting |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
379 |
* the post data for update. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
380 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
381 |
if ( ! commentReply.discardCommentChanges() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
382 |
return false; |
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
385 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
386 |
* Close the comment edit/reply form if open to stop the form |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
387 |
* action from interfering with the post's form action. |
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 |
commentReply.close(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
390 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
391 |
|
5 | 392 |
releaseLock = false; |
393 |
$(window).off( 'beforeunload.edit-post' ); |
|
394 |
||
395 |
$submitButtons.addClass( 'disabled' ); |
|
396 |
||
397 |
if ( $button.attr('id') === 'publish' ) { |
|
398 |
$submitpost.find( '#major-publishing-actions .spinner' ).addClass( 'is-active' ); |
|
399 |
} else { |
|
400 |
$submitpost.find( '#minor-publishing .spinner' ).addClass( 'is-active' ); |
|
401 |
} |
|
402 |
}); |
|
403 |
}); |
|
404 |
||
16 | 405 |
// Submit the form saving a draft or an autosave, and show a preview in a new tab. |
5 | 406 |
$('#post-preview').on( 'click.post-preview', function( event ) { |
407 |
var $this = $(this), |
|
408 |
$form = $('form#post'), |
|
409 |
$previewField = $('input#wp-preview'), |
|
410 |
target = $this.attr('target') || 'wp-preview', |
|
411 |
ua = navigator.userAgent.toLowerCase(); |
|
412 |
||
413 |
event.preventDefault(); |
|
414 |
||
415 |
if ( $this.hasClass('disabled') ) { |
|
416 |
return; |
|
417 |
} |
|
418 |
||
419 |
if ( wp.autosave ) { |
|
420 |
wp.autosave.server.tempBlockSave(); |
|
421 |
} |
|
422 |
||
423 |
$previewField.val('dopreview'); |
|
18 | 424 |
$form.attr( 'target', target ).trigger( 'submit' ).attr( 'target', '' ); |
5 | 425 |
|
426 |
// Workaround for WebKit bug preventing a form submitting twice to the same action. |
|
427 |
// https://bugs.webkit.org/show_bug.cgi?id=28633 |
|
428 |
if ( ua.indexOf('safari') !== -1 && ua.indexOf('chrome') === -1 ) { |
|
429 |
$form.attr( 'action', function( index, value ) { |
|
430 |
return value + '?t=' + ( new Date() ).getTime(); |
|
431 |
}); |
|
432 |
} |
|
433 |
||
434 |
$previewField.val(''); |
|
435 |
}); |
|
436 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
437 |
// Auto save new posts after a title is typed. |
5 | 438 |
if ( $( '#auto_draft' ).val() ) { |
18 | 439 |
$( '#title' ).on( 'blur', function() { |
5 | 440 |
var cancel; |
441 |
||
442 |
if ( ! this.value || $('#edit-slug-box > *').length ) { |
|
443 |
return; |
|
444 |
} |
|
445 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
446 |
// Cancel the auto save when the blur was triggered by the user submitting the form. |
5 | 447 |
$('form#post').one( 'submit', function() { |
448 |
cancel = true; |
|
449 |
}); |
|
450 |
||
451 |
window.setTimeout( function() { |
|
452 |
if ( ! cancel && wp.autosave ) { |
|
453 |
wp.autosave.server.triggerSave(); |
|
454 |
} |
|
455 |
}, 200 ); |
|
456 |
}); |
|
457 |
} |
|
458 |
||
459 |
$document.on( 'autosave-disable-buttons.edit-post', function() { |
|
460 |
$submitButtons.addClass( 'disabled' ); |
|
461 |
}).on( 'autosave-enable-buttons.edit-post', function() { |
|
462 |
if ( ! wp.heartbeat || ! wp.heartbeat.hasConnectionError() ) { |
|
463 |
$submitButtons.removeClass( 'disabled' ); |
|
464 |
} |
|
465 |
}).on( 'before-autosave.edit-post', function() { |
|
16 | 466 |
$( '.autosave-message' ).text( __( 'Saving Draft…' ) ); |
5 | 467 |
}).on( 'after-autosave.edit-post', function( event, data ) { |
468 |
$( '.autosave-message' ).text( data.message ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
469 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
470 |
if ( $( document.body ).hasClass( 'post-new-php' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
471 |
$( '.submitbox .submitdelete' ).show(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
472 |
} |
5 | 473 |
}); |
474 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
475 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
476 |
* When the user is trying to load another page, or reloads current page |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
477 |
* show a confirmation dialog when there are unsaved changes. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
478 |
*/ |
18 | 479 |
$( window ).on( 'beforeunload.edit-post', function( event ) { |
480 |
var editor = window.tinymce && window.tinymce.get( 'content' ); |
|
481 |
var changed = false; |
|
5 | 482 |
|
18 | 483 |
if ( wp.autosave ) { |
484 |
changed = wp.autosave.server.postChanged(); |
|
485 |
} else if ( editor ) { |
|
486 |
changed = ( ! editor.isHidden() && editor.isDirty() ); |
|
487 |
} |
|
5 | 488 |
|
18 | 489 |
if ( changed ) { |
490 |
event.preventDefault(); |
|
491 |
// The return string is needed for browser compat. |
|
492 |
// See https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event. |
|
16 | 493 |
return __( 'The changes you made will be lost if you navigate away from this page.' ); |
5 | 494 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
495 |
}).on( 'pagehide.edit-post', function( event ) { |
5 | 496 |
if ( ! releaseLock ) { |
497 |
return; |
|
498 |
} |
|
499 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
500 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
501 |
* Unload is triggered (by hand) on removing the Thickbox iframe. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
502 |
* Make sure we process only the main document unload. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
503 |
*/ |
5 | 504 |
if ( event.target && event.target.nodeName != '#document' ) { |
505 |
return; |
|
506 |
} |
|
507 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
508 |
var postID = $('#post_ID').val(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
509 |
var postLock = $('#active_post_lock').val(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
510 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
511 |
if ( ! postID || ! postLock ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
512 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
513 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
514 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
515 |
var data = { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
516 |
action: 'wp-remove-post-lock', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
517 |
_wpnonce: $('#_wpnonce').val(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
518 |
post_ID: postID, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
519 |
active_post_lock: postLock |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
520 |
}; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
521 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
522 |
if ( window.FormData && window.navigator.sendBeacon ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
523 |
var formData = new window.FormData(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
524 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
525 |
$.each( data, function( key, value ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
526 |
formData.append( key, value ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
527 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
528 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
529 |
if ( window.navigator.sendBeacon( ajaxurl, formData ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
530 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
531 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
532 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
533 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
534 |
// Fall back to a synchronous POST request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
535 |
// See https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
536 |
$.post({ |
5 | 537 |
async: false, |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
538 |
data: data, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
539 |
url: ajaxurl |
5 | 540 |
}); |
541 |
}); |
|
542 |
||
16 | 543 |
// Multiple taxonomies. |
0 | 544 |
if ( $('#tagsdiv-post_tag').length ) { |
5 | 545 |
window.tagBox && window.tagBox.init(); |
0 | 546 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
547 |
$('.meta-box-sortables').children('div.postbox').each(function(){ |
0 | 548 |
if ( this.id.indexOf('tagsdiv-') === 0 ) { |
5 | 549 |
window.tagBox && window.tagBox.init(); |
0 | 550 |
return false; |
551 |
} |
|
552 |
}); |
|
553 |
} |
|
554 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
555 |
// Handle categories. |
0 | 556 |
$('.categorydiv').each( function(){ |
557 |
var this_id = $(this).attr('id'), catAddBefore, catAddAfter, taxonomyParts, taxonomy, settingName; |
|
558 |
||
559 |
taxonomyParts = this_id.split('-'); |
|
560 |
taxonomyParts.shift(); |
|
561 |
taxonomy = taxonomyParts.join('-'); |
|
562 |
settingName = taxonomy + '_tab'; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
563 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
564 |
if ( taxonomy == 'category' ) { |
0 | 565 |
settingName = 'cats'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
566 |
} |
0 | 567 |
|
16 | 568 |
// @todo Move to jQuery 1.3+, support for multiple hierarchical taxonomies, see wp-lists.js. |
18 | 569 |
$('a', '#' + taxonomy + '-tabs').on( 'click', function( e ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
570 |
e.preventDefault(); |
0 | 571 |
var t = $(this).attr('href'); |
572 |
$(this).parent().addClass('tabs').siblings('li').removeClass('tabs'); |
|
573 |
$('#' + taxonomy + '-tabs').siblings('.tabs-panel').hide(); |
|
574 |
$(t).show(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
575 |
if ( '#' + taxonomy + '-all' == t ) { |
5 | 576 |
deleteUserSetting( settingName ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
577 |
} else { |
5 | 578 |
setUserSetting( settingName, 'pop' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
579 |
} |
0 | 580 |
}); |
581 |
||
5 | 582 |
if ( getUserSetting( settingName ) ) |
18 | 583 |
$('a[href="#' + taxonomy + '-pop"]', '#' + taxonomy + '-tabs').trigger( 'click' ); |
0 | 584 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
585 |
// Add category button controls. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
586 |
$('#new' + taxonomy).one( 'focus', function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
587 |
$( this ).val( '' ).removeClass( 'form-input-tip' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
588 |
}); |
0 | 589 |
|
16 | 590 |
// On [Enter] submit the taxonomy. |
18 | 591 |
$('#new' + taxonomy).on( 'keypress', function(event){ |
0 | 592 |
if( 13 === event.keyCode ) { |
593 |
event.preventDefault(); |
|
18 | 594 |
$('#' + taxonomy + '-add-submit').trigger( 'click' ); |
0 | 595 |
} |
596 |
}); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
597 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
598 |
// After submitting a new taxonomy, re-focus the input field. |
18 | 599 |
$('#' + taxonomy + '-add-submit').on( 'click', function() { |
600 |
$('#new' + taxonomy).trigger( 'focus' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
601 |
}); |
0 | 602 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
603 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
604 |
* Before adding a new taxonomy, disable submit button. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
605 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
606 |
* @param {Object} s Taxonomy object which will be added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
607 |
* |
16 | 608 |
* @return {Object} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
609 |
*/ |
0 | 610 |
catAddBefore = function( s ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
611 |
if ( !$('#new'+taxonomy).val() ) { |
0 | 612 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
613 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
614 |
|
0 | 615 |
s.data += '&' + $( ':checked', '#'+taxonomy+'checklist' ).serialize(); |
616 |
$( '#' + taxonomy + '-add-submit' ).prop( 'disabled', true ); |
|
617 |
return s; |
|
618 |
}; |
|
619 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
620 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
621 |
* Re-enable submit button after a taxonomy has been added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
622 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
623 |
* Re-enable submit button. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
624 |
* If the taxonomy has a parent place the taxonomy underneath the parent. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
625 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
626 |
* @param {Object} r Response. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
627 |
* @param {Object} s Taxonomy data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
628 |
* |
16 | 629 |
* @return {void} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
630 |
*/ |
0 | 631 |
catAddAfter = function( r, s ) { |
632 |
var sup, drop = $('#new'+taxonomy+'_parent'); |
|
633 |
||
634 |
$( '#' + taxonomy + '-add-submit' ).prop( 'disabled', false ); |
|
635 |
if ( 'undefined' != s.parsed.responses[0] && (sup = s.parsed.responses[0].supplemental.newcat_parent) ) { |
|
636 |
drop.before(sup); |
|
637 |
drop.remove(); |
|
638 |
} |
|
639 |
}; |
|
640 |
||
641 |
$('#' + taxonomy + 'checklist').wpList({ |
|
642 |
alt: '', |
|
643 |
response: taxonomy + '-ajax-response', |
|
644 |
addBefore: catAddBefore, |
|
645 |
addAfter: catAddAfter |
|
646 |
}); |
|
647 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
648 |
// Add new taxonomy button toggles input form visibility. |
18 | 649 |
$('#' + taxonomy + '-add-toggle').on( 'click', function( e ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
650 |
e.preventDefault(); |
0 | 651 |
$('#' + taxonomy + '-adder').toggleClass( 'wp-hidden-children' ); |
18 | 652 |
$('a[href="#' + taxonomy + '-all"]', '#' + taxonomy + '-tabs').trigger( 'click' ); |
653 |
$('#new'+taxonomy).trigger( 'focus' ); |
|
0 | 654 |
}); |
655 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
656 |
// Sync checked items between "All {taxonomy}" and "Most used" lists. |
19 | 657 |
$('#' + taxonomy + 'checklist, #' + taxonomy + 'checklist-pop').on( |
658 |
'click', |
|
659 |
'li.popular-category > label input[type="checkbox"]', |
|
660 |
function() { |
|
661 |
var t = $(this), c = t.is(':checked'), id = t.val(); |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
662 |
if ( id && t.parents('#taxonomy-'+taxonomy).length ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
663 |
$('input#in-' + taxonomy + '-' + id + ', input[id^="in-' + taxonomy + '-' + id + '-"]').prop('checked', c); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
664 |
$('input#in-popular-' + taxonomy + '-' + id).prop('checked', c); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
665 |
} |
19 | 666 |
} |
667 |
); |
|
0 | 668 |
|
16 | 669 |
}); // End cats. |
0 | 670 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
671 |
// Custom Fields postbox. |
0 | 672 |
if ( $('#postcustom').length ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
673 |
$( '#the-list' ).wpList( { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
674 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
675 |
* Add current post_ID to request to fetch custom fields |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
676 |
* |
9 | 677 |
* @ignore |
678 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
679 |
* @param {Object} s Request object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
680 |
* |
16 | 681 |
* @return {Object} Data modified with post_ID attached. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
682 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
683 |
addBefore: function( s ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
684 |
s.data += '&post_id=' + $('#post_ID').val(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
685 |
return s; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
686 |
}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
687 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
688 |
* Show the listing of custom fields after fetching. |
9 | 689 |
* |
690 |
* @ignore |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
691 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
692 |
addAfter: function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
693 |
$('table#list-table').show(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
694 |
} |
0 | 695 |
}); |
696 |
} |
|
697 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
698 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
699 |
* Publish Post box (#submitdiv) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
700 |
*/ |
0 | 701 |
if ( $('#submitdiv').length ) { |
702 |
stamp = $('#timestamp').html(); |
|
703 |
visibility = $('#post-visibility-display').html(); |
|
704 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
705 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
706 |
* When the visibility of a post changes sub-options should be shown or hidden. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
707 |
* |
9 | 708 |
* @ignore |
709 |
* |
|
16 | 710 |
* @return {void} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
711 |
*/ |
5 | 712 |
updateVisibility = function() { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
713 |
// Show sticky for public posts. |
5 | 714 |
if ( $postVisibilitySelect.find('input:radio:checked').val() != 'public' ) { |
0 | 715 |
$('#sticky').prop('checked', false); |
716 |
$('#sticky-span').hide(); |
|
717 |
} else { |
|
718 |
$('#sticky-span').show(); |
|
719 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
720 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
721 |
// Show password input field for password protected post. |
5 | 722 |
if ( $postVisibilitySelect.find('input:radio:checked').val() != 'password' ) { |
0 | 723 |
$('#password-span').hide(); |
724 |
} else { |
|
725 |
$('#password-span').show(); |
|
726 |
} |
|
5 | 727 |
}; |
0 | 728 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
729 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
730 |
* Make sure all labels represent the current settings. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
731 |
* |
9 | 732 |
* @ignore |
733 |
* |
|
16 | 734 |
* @return {boolean} False when an invalid timestamp has been selected, otherwise True. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
735 |
*/ |
5 | 736 |
updateText = function() { |
0 | 737 |
|
5 | 738 |
if ( ! $timestampdiv.length ) |
0 | 739 |
return true; |
740 |
||
741 |
var attemptedDate, originalDate, currentDate, publishOn, postStatus = $('#post_status'), |
|
742 |
optPublish = $('option[value="publish"]', postStatus), aa = $('#aa').val(), |
|
743 |
mm = $('#mm').val(), jj = $('#jj').val(), hh = $('#hh').val(), mn = $('#mn').val(); |
|
744 |
||
745 |
attemptedDate = new Date( aa, mm - 1, jj, hh, mn ); |
|
19 | 746 |
originalDate = new Date( |
747 |
$('#hidden_aa').val(), |
|
748 |
$('#hidden_mm').val() -1, |
|
749 |
$('#hidden_jj').val(), |
|
750 |
$('#hidden_hh').val(), |
|
751 |
$('#hidden_mn').val() |
|
752 |
); |
|
753 |
currentDate = new Date( |
|
754 |
$('#cur_aa').val(), |
|
755 |
$('#cur_mm').val() -1, |
|
756 |
$('#cur_jj').val(), |
|
757 |
$('#cur_hh').val(), |
|
758 |
$('#cur_mn').val() |
|
759 |
); |
|
0 | 760 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
761 |
// Catch unexpected date problems. |
19 | 762 |
if ( |
763 |
attemptedDate.getFullYear() != aa || |
|
764 |
(1 + attemptedDate.getMonth()) != mm || |
|
765 |
attemptedDate.getDate() != jj || |
|
766 |
attemptedDate.getMinutes() != mn |
|
767 |
) { |
|
5 | 768 |
$timestampdiv.find('.timestamp-wrap').addClass('form-invalid'); |
0 | 769 |
return false; |
770 |
} else { |
|
5 | 771 |
$timestampdiv.find('.timestamp-wrap').removeClass('form-invalid'); |
0 | 772 |
} |
773 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
774 |
// Determine what the publish should be depending on the date and post status. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
775 |
if ( attemptedDate > currentDate ) { |
16 | 776 |
publishOn = __( 'Schedule for:' ); |
777 |
$('#publish').val( _x( 'Schedule', 'post action/button label' ) ); |
|
0 | 778 |
} else if ( attemptedDate <= currentDate && $('#original_post_status').val() != 'publish' ) { |
16 | 779 |
publishOn = __( 'Publish on:' ); |
780 |
$('#publish').val( __( 'Publish' ) ); |
|
0 | 781 |
} else { |
16 | 782 |
publishOn = __( 'Published on:' ); |
783 |
$('#publish').val( __( 'Update' ) ); |
|
0 | 784 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
785 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
786 |
// If the date is the same, set it to trigger update events. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
787 |
if ( originalDate.toUTCString() == attemptedDate.toUTCString() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
788 |
// Re-set to the current value. |
0 | 789 |
$('#timestamp').html(stamp); |
790 |
} else { |
|
791 |
$('#timestamp').html( |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
792 |
'\n' + publishOn + ' <b>' + |
16 | 793 |
// translators: 1: Month, 2: Day, 3: Year, 4: Hour, 5: Minute. |
794 |
__( '%1$s %2$s, %3$s at %4$s:%5$s' ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
795 |
.replace( '%1$s', $( 'option[value="' + mm + '"]', '#mm' ).attr( 'data-text' ) ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
796 |
.replace( '%2$s', parseInt( jj, 10 ) ) |
0 | 797 |
.replace( '%3$s', aa ) |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
798 |
.replace( '%4$s', ( '00' + hh ).slice( -2 ) ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
799 |
.replace( '%5$s', ( '00' + mn ).slice( -2 ) ) + |
5 | 800 |
'</b> ' |
0 | 801 |
); |
802 |
} |
|
803 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
804 |
// Add "privately published" to post status when applies. |
5 | 805 |
if ( $postVisibilitySelect.find('input:radio:checked').val() == 'private' ) { |
16 | 806 |
$('#publish').val( __( 'Update' ) ); |
5 | 807 |
if ( 0 === optPublish.length ) { |
16 | 808 |
postStatus.append('<option value="publish">' + __( 'Privately Published' ) + '</option>'); |
0 | 809 |
} else { |
16 | 810 |
optPublish.html( __( 'Privately Published' ) ); |
0 | 811 |
} |
812 |
$('option[value="publish"]', postStatus).prop('selected', true); |
|
5 | 813 |
$('#misc-publishing-actions .edit-post-status').hide(); |
0 | 814 |
} else { |
815 |
if ( $('#original_post_status').val() == 'future' || $('#original_post_status').val() == 'draft' ) { |
|
816 |
if ( optPublish.length ) { |
|
817 |
optPublish.remove(); |
|
818 |
postStatus.val($('#hidden_post_status').val()); |
|
819 |
} |
|
820 |
} else { |
|
16 | 821 |
optPublish.html( __( 'Published' ) ); |
0 | 822 |
} |
823 |
if ( postStatus.is(':hidden') ) |
|
5 | 824 |
$('#misc-publishing-actions .edit-post-status').show(); |
0 | 825 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
826 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
827 |
// Update "Status:" to currently selected status. |
9 | 828 |
$('#post-status-display').text( |
16 | 829 |
// Remove any potential tags from post status text. |
830 |
wp.sanitize.stripTagsAndEncodeText( $('option:selected', postStatus).text() ) |
|
9 | 831 |
); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
832 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
833 |
// Show or hide the "Save Draft" button. |
19 | 834 |
if ( |
835 |
$('option:selected', postStatus).val() == 'private' || |
|
836 |
$('option:selected', postStatus).val() == 'publish' |
|
837 |
) { |
|
0 | 838 |
$('#save-post').hide(); |
839 |
} else { |
|
840 |
$('#save-post').show(); |
|
841 |
if ( $('option:selected', postStatus).val() == 'pending' ) { |
|
16 | 842 |
$('#save-post').show().val( __( 'Save as Pending' ) ); |
0 | 843 |
} else { |
16 | 844 |
$('#save-post').show().val( __( 'Save Draft' ) ); |
0 | 845 |
} |
846 |
} |
|
847 |
return true; |
|
5 | 848 |
}; |
0 | 849 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
850 |
// Show the visibility options and hide the toggle button when opened. |
18 | 851 |
$( '#visibility .edit-visibility').on( 'click', function( e ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
852 |
e.preventDefault(); |
5 | 853 |
if ( $postVisibilitySelect.is(':hidden') ) { |
0 | 854 |
updateVisibility(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
855 |
$postVisibilitySelect.slideDown( 'fast', function() { |
18 | 856 |
$postVisibilitySelect.find( 'input[type="radio"]' ).first().trigger( 'focus' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
857 |
} ); |
0 | 858 |
$(this).hide(); |
859 |
} |
|
860 |
}); |
|
861 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
862 |
// Cancel visibility selection area and hide it from view. |
18 | 863 |
$postVisibilitySelect.find('.cancel-post-visibility').on( 'click', function( event ) { |
5 | 864 |
$postVisibilitySelect.slideUp('fast'); |
0 | 865 |
$('#visibility-radio-' + $('#hidden-post-visibility').val()).prop('checked', true); |
866 |
$('#post_password').val($('#hidden-post-password').val()); |
|
867 |
$('#sticky').prop('checked', $('#hidden-post-sticky').prop('checked')); |
|
868 |
$('#post-visibility-display').html(visibility); |
|
18 | 869 |
$('#visibility .edit-visibility').show().trigger( 'focus' ); |
0 | 870 |
updateText(); |
5 | 871 |
event.preventDefault(); |
0 | 872 |
}); |
873 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
874 |
// Set the selected visibility as current. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
875 |
$postVisibilitySelect.find('.save-post-visibility').on( 'click', function( event ) { // Crazyhorse branch - multiple OK cancels. |
16 | 876 |
var visibilityLabel = '', selectedVisibility = $postVisibilitySelect.find('input:radio:checked').val(); |
877 |
||
5 | 878 |
$postVisibilitySelect.slideUp('fast'); |
18 | 879 |
$('#visibility .edit-visibility').show().trigger( 'focus' ); |
0 | 880 |
updateText(); |
881 |
||
16 | 882 |
if ( 'public' !== selectedVisibility ) { |
0 | 883 |
$('#sticky').prop('checked', false); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
884 |
} |
0 | 885 |
|
16 | 886 |
switch ( selectedVisibility ) { |
887 |
case 'public': |
|
888 |
visibilityLabel = $( '#sticky' ).prop( 'checked' ) ? __( 'Public, Sticky' ) : __( 'Public' ); |
|
889 |
break; |
|
890 |
case 'private': |
|
891 |
visibilityLabel = __( 'Private' ); |
|
892 |
break; |
|
893 |
case 'password': |
|
894 |
visibilityLabel = __( 'Password Protected' ); |
|
895 |
break; |
|
0 | 896 |
} |
897 |
||
16 | 898 |
$('#post-visibility-display').text( visibilityLabel ); |
5 | 899 |
event.preventDefault(); |
0 | 900 |
}); |
901 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
902 |
// When the selection changes, update labels. |
18 | 903 |
$postVisibilitySelect.find('input:radio').on( 'change', function() { |
0 | 904 |
updateVisibility(); |
905 |
}); |
|
906 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
907 |
// Edit publish time click. |
18 | 908 |
$timestampdiv.siblings('a.edit-timestamp').on( 'click', function( event ) { |
5 | 909 |
if ( $timestampdiv.is( ':hidden' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
910 |
$timestampdiv.slideDown( 'fast', function() { |
18 | 911 |
$( 'input, select', $timestampdiv.find( '.timestamp-wrap' ) ).first().trigger( 'focus' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
912 |
} ); |
0 | 913 |
$(this).hide(); |
914 |
} |
|
5 | 915 |
event.preventDefault(); |
0 | 916 |
}); |
917 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
918 |
// Cancel editing the publish time and hide the settings. |
18 | 919 |
$timestampdiv.find('.cancel-timestamp').on( 'click', function( event ) { |
920 |
$timestampdiv.slideUp('fast').siblings('a.edit-timestamp').show().trigger( 'focus' ); |
|
0 | 921 |
$('#mm').val($('#hidden_mm').val()); |
922 |
$('#jj').val($('#hidden_jj').val()); |
|
923 |
$('#aa').val($('#hidden_aa').val()); |
|
924 |
$('#hh').val($('#hidden_hh').val()); |
|
925 |
$('#mn').val($('#hidden_mn').val()); |
|
926 |
updateText(); |
|
5 | 927 |
event.preventDefault(); |
0 | 928 |
}); |
929 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
930 |
// Save the changed timestamp. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
931 |
$timestampdiv.find('.save-timestamp').on( 'click', function( event ) { // Crazyhorse branch - multiple OK cancels. |
0 | 932 |
if ( updateText() ) { |
5 | 933 |
$timestampdiv.slideUp('fast'); |
18 | 934 |
$timestampdiv.siblings('a.edit-timestamp').show().trigger( 'focus' ); |
0 | 935 |
} |
5 | 936 |
event.preventDefault(); |
0 | 937 |
}); |
938 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
939 |
// Cancel submit when an invalid timestamp has been selected. |
5 | 940 |
$('#post').on( 'submit', function( event ) { |
0 | 941 |
if ( ! updateText() ) { |
5 | 942 |
event.preventDefault(); |
943 |
$timestampdiv.show(); |
|
944 |
||
945 |
if ( wp.autosave ) { |
|
946 |
wp.autosave.enableButtons(); |
|
947 |
} |
|
948 |
||
949 |
$( '#publishing-action .spinner' ).removeClass( 'is-active' ); |
|
0 | 950 |
} |
951 |
}); |
|
952 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
953 |
// Post Status edit click. |
18 | 954 |
$postStatusSelect.siblings('a.edit-post-status').on( 'click', function( event ) { |
5 | 955 |
if ( $postStatusSelect.is( ':hidden' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
956 |
$postStatusSelect.slideDown( 'fast', function() { |
18 | 957 |
$postStatusSelect.find('select').trigger( 'focus' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
958 |
} ); |
0 | 959 |
$(this).hide(); |
960 |
} |
|
5 | 961 |
event.preventDefault(); |
0 | 962 |
}); |
963 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
964 |
// Save the Post Status changes and hide the options. |
18 | 965 |
$postStatusSelect.find('.save-post-status').on( 'click', function( event ) { |
966 |
$postStatusSelect.slideUp( 'fast' ).siblings( 'a.edit-post-status' ).show().trigger( 'focus' ); |
|
0 | 967 |
updateText(); |
5 | 968 |
event.preventDefault(); |
0 | 969 |
}); |
970 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
971 |
// Cancel Post Status editing and hide the options. |
18 | 972 |
$postStatusSelect.find('.cancel-post-status').on( 'click', function( event ) { |
973 |
$postStatusSelect.slideUp( 'fast' ).siblings( 'a.edit-post-status' ).show().trigger( 'focus' ); |
|
5 | 974 |
$('#post_status').val( $('#hidden_post_status').val() ); |
0 | 975 |
updateText(); |
5 | 976 |
event.preventDefault(); |
0 | 977 |
}); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
978 |
} |
0 | 979 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
980 |
/** |
9 | 981 |
* Handle the editing of the post_name. Create the required HTML elements and |
16 | 982 |
* update the changes via Ajax. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
983 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
984 |
* @global |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
985 |
* |
16 | 986 |
* @return {void} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
987 |
*/ |
5 | 988 |
function editPermalink() { |
19 | 989 |
var i, slug_value, slug_label, |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
990 |
$el, revert_e, |
5 | 991 |
c = 0, |
992 |
real_slug = $('#post_name'), |
|
993 |
revert_slug = real_slug.val(), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
994 |
permalink = $( '#sample-permalink' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
995 |
permalinkOrig = permalink.html(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
996 |
permalinkInner = $( '#sample-permalink a' ).html(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
997 |
buttons = $('#edit-slug-buttons'), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
998 |
buttonsOrig = buttons.html(), |
5 | 999 |
full = $('#editable-post-name-full'); |
0 | 1000 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1001 |
// Deal with Twemoji in the post-name. |
5 | 1002 |
full.find( 'img' ).replaceWith( function() { return this.alt; } ); |
1003 |
full = full.html(); |
|
1004 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1005 |
permalink.html( permalinkInner ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1006 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1007 |
// Save current content to revert to when cancelling. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1008 |
$el = $( '#editable-post-name' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1009 |
revert_e = $el.html(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1010 |
|
19 | 1011 |
buttons.html( |
1012 |
'<button type="button" class="save button button-small">' + __( 'OK' ) + '</button> ' + |
|
1013 |
'<button type="button" class="cancel button-link">' + __( 'Cancel' ) + '</button>' |
|
1014 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1015 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1016 |
// Save permalink changes. |
18 | 1017 |
buttons.children( '.save' ).on( 'click', function() { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1018 |
var new_slug = $el.children( 'input' ).val(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1019 |
|
5 | 1020 |
if ( new_slug == $('#editable-post-name-full').text() ) { |
18 | 1021 |
buttons.children('.cancel').trigger( 'click' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1022 |
return; |
0 | 1023 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1024 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1025 |
$.post( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1026 |
ajaxurl, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1027 |
{ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1028 |
action: 'sample-permalink', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1029 |
post_id: postId, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1030 |
new_slug: new_slug, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1031 |
new_title: $('#title').val(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1032 |
samplepermalinknonce: $('#samplepermalinknonce').val() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1033 |
}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1034 |
function(data) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1035 |
var box = $('#edit-slug-box'); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1036 |
box.html(data); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1037 |
if (box.hasClass('hidden')) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1038 |
box.fadeIn('fast', function () { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1039 |
box.removeClass('hidden'); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1040 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1041 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1042 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1043 |
buttons.html(buttonsOrig); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1044 |
permalink.html(permalinkOrig); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1045 |
real_slug.val(new_slug); |
18 | 1046 |
$( '.edit-slug' ).trigger( 'focus' ); |
16 | 1047 |
wp.a11y.speak( __( 'Permalink saved' ) ); |
5 | 1048 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1049 |
); |
5 | 1050 |
}); |
1051 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1052 |
// Cancel editing of permalink. |
18 | 1053 |
buttons.children( '.cancel' ).on( 'click', function() { |
5 | 1054 |
$('#view-post-btn').show(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1055 |
$el.html(revert_e); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1056 |
buttons.html(buttonsOrig); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1057 |
permalink.html(permalinkOrig); |
5 | 1058 |
real_slug.val(revert_slug); |
18 | 1059 |
$( '.edit-slug' ).trigger( 'focus' ); |
5 | 1060 |
}); |
1061 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1062 |
// If more than 1/4th of 'full' is '%', make it empty. |
5 | 1063 |
for ( i = 0; i < full.length; ++i ) { |
1064 |
if ( '%' == full.charAt(i) ) |
|
1065 |
c++; |
|
0 | 1066 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1067 |
slug_value = ( c > full.length / 4 ) ? '' : full; |
19 | 1068 |
slug_label = __( 'URL Slug' ); |
0 | 1069 |
|
19 | 1070 |
$el.html( |
1071 |
'<label for="new-post-slug" class="screen-reader-text">' + slug_label + '</label>' + |
|
1072 |
'<input type="text" id="new-post-slug" value="' + slug_value + '" autocomplete="off" spellcheck="false" />' |
|
1073 |
).children( 'input' ).on( 'keydown', function( e ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1074 |
var key = e.which; |
16 | 1075 |
// On [Enter], just save the new slug, don't save the post. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1076 |
if ( 13 === key ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1077 |
e.preventDefault(); |
18 | 1078 |
buttons.children( '.save' ).trigger( 'click' ); |
5 | 1079 |
} |
16 | 1080 |
// On [Esc] cancel the editing. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1081 |
if ( 27 === key ) { |
18 | 1082 |
buttons.children( '.cancel' ).trigger( 'click' ); |
5 | 1083 |
} |
18 | 1084 |
} ).on( 'keyup', function() { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1085 |
real_slug.val( this.value ); |
18 | 1086 |
}).trigger( 'focus' ); |
5 | 1087 |
} |
1088 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1089 |
$( '#titlediv' ).on( 'click', '.edit-slug', function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1090 |
editPermalink(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1091 |
}); |
0 | 1092 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1093 |
/** |
9 | 1094 |
* Adds screen reader text to the title label when needed. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1095 |
* |
9 | 1096 |
* Use the 'screen-reader-text' class to emulate a placeholder attribute |
1097 |
* and hide the label when entering a value. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1098 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1099 |
* @param {string} id Optional. HTML ID to add the screen reader helper text to. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1100 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1101 |
* @global |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1102 |
* |
16 | 1103 |
* @return {void} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1104 |
*/ |
9 | 1105 |
window.wptitlehint = function( id ) { |
0 | 1106 |
id = id || 'title'; |
1107 |
||
9 | 1108 |
var title = $( '#' + id ), titleprompt = $( '#' + id + '-prompt-text' ); |
0 | 1109 |
|
9 | 1110 |
if ( '' === title.val() ) { |
1111 |
titleprompt.removeClass( 'screen-reader-text' ); |
|
1112 |
} |
|
0 | 1113 |
|
9 | 1114 |
title.on( 'input', function() { |
1115 |
if ( '' === this.value ) { |
|
1116 |
titleprompt.removeClass( 'screen-reader-text' ); |
|
1117 |
return; |
|
1118 |
} |
|
1119 |
||
1120 |
titleprompt.addClass( 'screen-reader-text' ); |
|
1121 |
} ); |
|
5 | 1122 |
}; |
0 | 1123 |
|
1124 |
wptitlehint(); |
|
1125 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1126 |
// Resize the WYSIWYG and plain text editors. |
5 | 1127 |
( function() { |
1128 |
var editor, offset, mce, |
|
1129 |
$handle = $('#post-status-info'), |
|
1130 |
$postdivrich = $('#postdivrich'); |
|
0 | 1131 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1132 |
// If there are no textareas or we are on a touch device, we can't do anything. |
5 | 1133 |
if ( ! $textarea.length || 'ontouchstart' in window ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1134 |
// Hide the resize handle. |
5 | 1135 |
$('#content-resize-handle').hide(); |
1136 |
return; |
|
0 | 1137 |
} |
1138 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1139 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1140 |
* Handle drag event. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1141 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1142 |
* @param {Object} event Event containing details about the drag. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1143 |
*/ |
5 | 1144 |
function dragging( event ) { |
1145 |
if ( $postdivrich.hasClass( 'wp-editor-expand' ) ) { |
|
0 | 1146 |
return; |
5 | 1147 |
} |
0 | 1148 |
|
5 | 1149 |
if ( mce ) { |
1150 |
editor.theme.resizeTo( null, offset + event.pageY ); |
|
1151 |
} else { |
|
1152 |
$textarea.height( Math.max( 50, offset + event.pageY ) ); |
|
1153 |
} |
|
0 | 1154 |
|
5 | 1155 |
event.preventDefault(); |
1156 |
} |
|
0 | 1157 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1158 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1159 |
* When the dragging stopped make sure we return focus and do a confidence check on the height. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1160 |
*/ |
5 | 1161 |
function endDrag() { |
1162 |
var height, toolbarHeight; |
|
0 | 1163 |
|
5 | 1164 |
if ( $postdivrich.hasClass( 'wp-editor-expand' ) ) { |
1165 |
return; |
|
0 | 1166 |
} |
1167 |
||
5 | 1168 |
if ( mce ) { |
1169 |
editor.focus(); |
|
1170 |
toolbarHeight = parseInt( $( '#wp-content-editor-container .mce-toolbar-grp' ).height(), 10 ); |
|
0 | 1171 |
|
5 | 1172 |
if ( toolbarHeight < 10 || toolbarHeight > 200 ) { |
1173 |
toolbarHeight = 30; |
|
1174 |
} |
|
0 | 1175 |
|
5 | 1176 |
height = parseInt( $('#content_ifr').css('height'), 10 ) + toolbarHeight - 28; |
1177 |
} else { |
|
18 | 1178 |
$textarea.trigger( 'focus' ); |
5 | 1179 |
height = parseInt( $textarea.css('height'), 10 ); |
1180 |
} |
|
0 | 1181 |
|
5 | 1182 |
$document.off( '.wp-editor-resize' ); |
1183 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1184 |
// Confidence check: normalize height to stay within acceptable ranges. |
5 | 1185 |
if ( height && height > 50 && height < 5000 ) { |
1186 |
setUserSetting( 'ed_size', height ); |
|
1187 |
} |
|
1188 |
} |
|
0 | 1189 |
|
5 | 1190 |
$handle.on( 'mousedown.wp-editor-resize', function( event ) { |
1191 |
if ( typeof tinymce !== 'undefined' ) { |
|
1192 |
editor = tinymce.get('content'); |
|
1193 |
} |
|
0 | 1194 |
|
5 | 1195 |
if ( editor && ! editor.isHidden() ) { |
1196 |
mce = true; |
|
1197 |
offset = $('#content_ifr').height() - event.pageY; |
|
1198 |
} else { |
|
1199 |
mce = false; |
|
1200 |
offset = $textarea.height() - event.pageY; |
|
18 | 1201 |
$textarea.trigger( 'blur' ); |
5 | 1202 |
} |
0 | 1203 |
|
5 | 1204 |
$document.on( 'mousemove.wp-editor-resize', dragging ) |
1205 |
.on( 'mouseup.wp-editor-resize mouseleave.wp-editor-resize', endDrag ); |
|
0 | 1206 |
|
5 | 1207 |
event.preventDefault(); |
1208 |
}).on( 'mouseup.wp-editor-resize', endDrag ); |
|
1209 |
})(); |
|
1210 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1211 |
// TinyMCE specific handling of Post Format changes to reflect in the editor. |
5 | 1212 |
if ( typeof tinymce !== 'undefined' ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1213 |
// When changing post formats, change the editor body class. |
5 | 1214 |
$( '#post-formats-select input.post-format' ).on( 'change.set-editor-class', function() { |
0 | 1215 |
var editor, body, format = this.id; |
1216 |
||
5 | 1217 |
if ( format && $( this ).prop( 'checked' ) && ( editor = tinymce.get( 'content' ) ) ) { |
1218 |
body = editor.getBody(); |
|
1219 |
body.className = body.className.replace( /\bpost-format-[^ ]+/, '' ); |
|
1220 |
editor.dom.addClass( body, format == 'post-format-0' ? 'post-format-standard' : format ); |
|
1221 |
$( document ).trigger( 'editor-classchange' ); |
|
0 | 1222 |
} |
1223 |
}); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1224 |
|
16 | 1225 |
// When changing page template, change the editor body class. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1226 |
$( '#page_template' ).on( 'change.set-editor-class', function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1227 |
var editor, body, pageTemplate = $( this ).val() || ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1228 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1229 |
pageTemplate = pageTemplate.substr( pageTemplate.lastIndexOf( '/' ) + 1, pageTemplate.length ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1230 |
.replace( /\.php$/, '' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1231 |
.replace( /\./g, '-' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1232 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1233 |
if ( pageTemplate && ( editor = tinymce.get( 'content' ) ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1234 |
body = editor.getBody(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1235 |
body.className = body.className.replace( /\bpage-template-[^ ]+/, '' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1236 |
editor.dom.addClass( body, 'page-template-' + pageTemplate ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1237 |
$( document ).trigger( 'editor-classchange' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1238 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1239 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1240 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1241 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1242 |
|
16 | 1243 |
// Save on pressing [Ctrl]/[Command] + [S] in the Text editor. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1244 |
$textarea.on( 'keydown.wp-autosave', function( event ) { |
16 | 1245 |
// Key [S] has code 83. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1246 |
if ( event.which === 83 ) { |
19 | 1247 |
if ( |
1248 |
event.shiftKey || |
|
1249 |
event.altKey || |
|
1250 |
( isMac && ( ! event.metaKey || event.ctrlKey ) ) || |
|
1251 |
( ! isMac && ! event.ctrlKey ) |
|
1252 |
) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1253 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1254 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1255 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1256 |
wp.autosave && wp.autosave.server.triggerSave(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1257 |
event.preventDefault(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1258 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1259 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1260 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1261 |
// If the last status was auto-draft and the save is triggered, edit the current URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1262 |
if ( $( '#original_post_status' ).val() === 'auto-draft' && window.history.replaceState ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1263 |
var location; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1264 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1265 |
$( '#publish' ).on( 'click', function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1266 |
location = window.location.href; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1267 |
location += ( location.indexOf( '?' ) !== -1 ) ? '&' : '?'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1268 |
location += 'wp-post-new-reload=true'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1269 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1270 |
window.history.replaceState( null, null, location ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1271 |
}); |
0 | 1272 |
} |
16 | 1273 |
|
1274 |
/** |
|
1275 |
* Copies the attachment URL in the Edit Media page to the clipboard. |
|
1276 |
* |
|
1277 |
* @since 5.5.0 |
|
1278 |
* |
|
1279 |
* @param {MouseEvent} event A click event. |
|
1280 |
* |
|
1281 |
* @return {void} |
|
1282 |
*/ |
|
1283 |
copyAttachmentURLClipboard.on( 'success', function( event ) { |
|
1284 |
var triggerElement = $( event.trigger ), |
|
1285 |
successElement = $( '.success', triggerElement.closest( '.copy-to-clipboard-container' ) ); |
|
1286 |
||
1287 |
// Clear the selection and move focus back to the trigger. |
|
1288 |
event.clearSelection(); |
|
1289 |
||
1290 |
// Show success visual feedback. |
|
1291 |
clearTimeout( copyAttachmentURLSuccessTimeout ); |
|
1292 |
successElement.removeClass( 'hidden' ); |
|
1293 |
||
1294 |
// Hide success visual feedback after 3 seconds since last success. |
|
1295 |
copyAttachmentURLSuccessTimeout = setTimeout( function() { |
|
1296 |
successElement.addClass( 'hidden' ); |
|
1297 |
}, 3000 ); |
|
1298 |
||
1299 |
// Handle success audible feedback. |
|
1300 |
wp.a11y.speak( __( 'The file URL has been copied to your clipboard' ) ); |
|
1301 |
} ); |
|
1302 |
} ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1303 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1304 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1305 |
* TinyMCE word count display |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1306 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1307 |
( function( $, counter ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1308 |
$( function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1309 |
var $content = $( '#content' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1310 |
$count = $( '#wp-word-count' ).find( '.word-count' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1311 |
prevCount = 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1312 |
contentEditor; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1313 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1314 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1315 |
* Get the word count from TinyMCE and display it |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1316 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1317 |
function update() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1318 |
var text, count; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1319 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1320 |
if ( ! contentEditor || contentEditor.isHidden() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1321 |
text = $content.val(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1322 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1323 |
text = contentEditor.getContent( { format: 'raw' } ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1324 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1325 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1326 |
count = counter.count( text ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1327 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1328 |
if ( count !== prevCount ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1329 |
$count.text( count ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1330 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1331 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1332 |
prevCount = count; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1333 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1334 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1335 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1336 |
* Bind the word count update triggers. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1337 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1338 |
* When a node change in the main TinyMCE editor has been triggered. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1339 |
* When a key has been released in the plain text content editor. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1340 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1341 |
$( document ).on( 'tinymce-editor-init', function( event, editor ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1342 |
if ( editor.id !== 'content' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1343 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1344 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1345 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1346 |
contentEditor = editor; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1347 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1348 |
editor.on( 'nodechange keyup', _.debounce( update, 1000 ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1349 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1350 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1351 |
$content.on( 'input keyup', _.debounce( update, 1000 ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1352 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1353 |
update(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1354 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1355 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1356 |
} )( jQuery, new wp.utils.WordCounter() ); |