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