|
1 // return an array with any duplicate, whitespace or values removed |
|
2 function array_unique_noempty(a) { |
|
3 var out = []; |
|
4 jQuery.each( a, function(key, val) { |
|
5 val = jQuery.trim(val); |
|
6 if ( val && jQuery.inArray(val, out) == -1 ) |
|
7 out.push(val); |
|
8 } ); |
|
9 return out; |
|
10 } |
|
11 |
|
12 function new_tag_remove_tag() { |
|
13 var id = jQuery( this ).attr( 'id' ), num = id.split('-check-num-')[1], taxbox = jQuery(this).parents('.tagsdiv'), current_tags = taxbox.find( '.the-tags' ).val().split(','), new_tags = []; |
|
14 delete current_tags[num]; |
|
15 |
|
16 jQuery.each( current_tags, function(key, val) { |
|
17 val = jQuery.trim(val); |
|
18 if ( val ) { |
|
19 new_tags.push(val); |
|
20 } |
|
21 }); |
|
22 |
|
23 taxbox.find('.the-tags').val( new_tags.join(',').replace(/\s*,+\s*/, ',').replace(/,+/, ',').replace(/,+\s+,+/, ',').replace(/,+\s*$/, '').replace(/^\s*,+/, '') ); |
|
24 |
|
25 tag_update_quickclicks(taxbox); |
|
26 return false; |
|
27 } |
|
28 |
|
29 function tag_update_quickclicks(taxbox) { |
|
30 if ( jQuery(taxbox).find('.the-tags').length == 0 ) |
|
31 return; |
|
32 |
|
33 var current_tags = jQuery(taxbox).find('.the-tags').val().split(','); |
|
34 jQuery(taxbox).find('.tagchecklist').empty(); |
|
35 shown = false; |
|
36 |
|
37 jQuery.each( current_tags, function( key, val ) { |
|
38 var txt, button_id; |
|
39 |
|
40 val = jQuery.trim(val); |
|
41 if ( !val.match(/^\s+$/) && '' != val ) { |
|
42 button_id = jQuery(taxbox).attr('id') + '-check-num-' + key; |
|
43 txt = '<span><a id="' + button_id + '" class="ntdelbutton">X</a> ' + val + '</span> '; |
|
44 jQuery(taxbox).find('.tagchecklist').append(txt); |
|
45 jQuery( '#' + button_id ).click( new_tag_remove_tag ); |
|
46 } |
|
47 }); |
|
48 if ( shown ) |
|
49 jQuery(taxbox).find('.tagchecklist').prepend('<strong>'+postL10n.tagsUsed+'</strong><br />'); |
|
50 } |
|
51 |
|
52 function tag_flush_to_text(id, a) { |
|
53 a = a || false; |
|
54 var taxbox, text, tags, newtags; |
|
55 |
|
56 taxbox = jQuery('#'+id); |
|
57 text = a ? jQuery(a).text() : taxbox.find('input.newtag').val(); |
|
58 |
|
59 // is the input box empty (i.e. showing the 'Add new tag' tip)? |
|
60 if ( taxbox.find('input.newtag').hasClass('form-input-tip') && ! a ) |
|
61 return false; |
|
62 |
|
63 tags = taxbox.find('.the-tags').val(); |
|
64 newtags = tags ? tags + ',' + text : text; |
|
65 |
|
66 // massage |
|
67 newtags = newtags.replace(/\s+,+\s*/g, ',').replace(/,+/g, ',').replace(/,+\s+,+/g, ',').replace(/,+\s*$/g, '').replace(/^\s*,+/g, ''); |
|
68 newtags = array_unique_noempty(newtags.split(',')).join(','); |
|
69 taxbox.find('.the-tags').val(newtags); |
|
70 tag_update_quickclicks(taxbox); |
|
71 |
|
72 if ( ! a ) |
|
73 taxbox.find('input.newtag').val('').focus(); |
|
74 |
|
75 return false; |
|
76 } |
|
77 |
|
78 function tag_save_on_publish() { |
|
79 jQuery('.tagsdiv').each( function(i) { |
|
80 if ( !jQuery(this).find('input.newtag').hasClass('form-input-tip') ) |
|
81 tag_flush_to_text(jQuery(this).parents('.tagsdiv').attr('id')); |
|
82 } ); |
|
83 } |
|
84 |
|
85 function tag_press_key( e ) { |
|
86 if ( 13 == e.which ) { |
|
87 tag_flush_to_text(jQuery(e.target).parents('.tagsdiv').attr('id')); |
|
88 return false; |
|
89 } |
|
90 }; |
|
91 |
|
92 function tag_init() { |
|
93 |
|
94 jQuery('.ajaxtag').show(); |
|
95 jQuery('.tagsdiv').each( function(i) { |
|
96 tag_update_quickclicks(this); |
|
97 } ); |
|
98 |
|
99 // add the quickadd form |
|
100 jQuery('.ajaxtag input.tagadd').click(function(){tag_flush_to_text(jQuery(this).parents('.tagsdiv').attr('id'));}); |
|
101 jQuery('.ajaxtag input.newtag').focus(function() { |
|
102 if ( !this.cleared ) { |
|
103 this.cleared = true; |
|
104 jQuery(this).val( '' ).removeClass( 'form-input-tip' ); |
|
105 } |
|
106 }); |
|
107 |
|
108 jQuery('.ajaxtag input.newtag').blur(function() { |
|
109 if ( this.value == '' ) { |
|
110 this.cleared = false; |
|
111 jQuery(this).val( postL10n.addTag ).addClass( 'form-input-tip' ); |
|
112 } |
|
113 }); |
|
114 |
|
115 // auto-save tags on post save/publish |
|
116 jQuery('#publish').click( tag_save_on_publish ); |
|
117 jQuery('#save-post').click( tag_save_on_publish ); |
|
118 |
|
119 // catch the enter key |
|
120 jQuery('.ajaxtag input.newtag').keypress( tag_press_key ); |
|
121 } |
|
122 |
|
123 var commentsBox, tagCloud; |
|
124 (function($){ |
|
125 |
|
126 commentsBox = { |
|
127 st : 0, |
|
128 |
|
129 get : function(total, num) { |
|
130 var st = this.st, data; |
|
131 if ( ! num ) |
|
132 num = 20; |
|
133 |
|
134 this.st += num; |
|
135 this.total = total; |
|
136 $('#commentsdiv img.waiting').show(); |
|
137 |
|
138 data = { |
|
139 'action' : 'get-comments', |
|
140 'mode' : 'single', |
|
141 '_ajax_nonce' : $('#add_comment_nonce').val(), |
|
142 'post_ID' : $('#post_ID').val(), |
|
143 'start' : st, |
|
144 'num' : num |
|
145 }; |
|
146 |
|
147 $.post(ajaxurl, data, |
|
148 function(r) { |
|
149 r = wpAjax.parseAjaxResponse(r); |
|
150 $('#commentsdiv .widefat').show(); |
|
151 $('#commentsdiv img.waiting').hide(); |
|
152 |
|
153 if ( 'object' == typeof r && r.responses[0] ) { |
|
154 $('#the-comment-list').append( r.responses[0].data ); |
|
155 |
|
156 theList = theExtraList = null; |
|
157 $("a[className*=':']").unbind(); |
|
158 setCommentsList(); |
|
159 |
|
160 if ( commentsBox.st > commentsBox.total ) |
|
161 $('#show-comments').hide(); |
|
162 else |
|
163 $('#show-comments').html(postL10n.showcomm); |
|
164 return; |
|
165 } else if ( 1 == r ) { |
|
166 $('#show-comments').parent().html(postL10n.endcomm); |
|
167 return; |
|
168 } |
|
169 |
|
170 $('#the-comment-list').append('<tr><td colspan="5">'+wpAjax.broken+'</td></tr>'); |
|
171 } |
|
172 ); |
|
173 |
|
174 return false; |
|
175 } |
|
176 }; |
|
177 |
|
178 tagCloud = { |
|
179 init : function() { |
|
180 $('.tagcloud-link').click(function(){ |
|
181 tagCloud.get($(this).attr('id')); |
|
182 $(this).unbind().click(function(){ |
|
183 $(this).siblings('.the-tagcloud').toggle(); |
|
184 return false; |
|
185 }); |
|
186 return false; |
|
187 }); |
|
188 }, |
|
189 |
|
190 get : function(id) { |
|
191 var tax = id.substr(id.indexOf('-')+1); |
|
192 |
|
193 $.post(ajaxurl, {'action':'get-tagcloud','tax':tax}, function(r, stat) { |
|
194 if ( 0 == r || 'success' != stat ) |
|
195 r = wpAjax.broken; |
|
196 |
|
197 r = $('<p id="tagcloud-'+tax+'" class="the-tagcloud">'+r+'</p>'); |
|
198 $('a', r).click(function(){ |
|
199 var id = $(this).parents('p').attr('id'); |
|
200 tag_flush_to_text(id.substr(id.indexOf('-')+1), this); |
|
201 return false; |
|
202 }); |
|
203 |
|
204 $('#'+id).after(r); |
|
205 }); |
|
206 } |
|
207 }; |
|
208 |
|
209 $(document).ready(function(){tagCloud.init();}); |
|
210 })(jQuery); |
|
211 |
|
212 jQuery(document).ready( function($) { |
|
213 var noSyncChecks = false, syncChecks, catAddAfter, stamp = $('#timestamp').html(), visibility = $('#post-visibility-display').html(), sticky = ''; |
|
214 |
|
215 // postboxes |
|
216 postboxes.add_postbox_toggles('post'); |
|
217 |
|
218 // Editable slugs |
|
219 make_slugedit_clickable(); |
|
220 |
|
221 // prepare the tag UI |
|
222 tag_init(); |
|
223 |
|
224 $('#title').blur( function() { |
|
225 if ( ($("#post_ID").val() > 0) || ($("#title").val().length == 0) ) |
|
226 return; |
|
227 |
|
228 if ( typeof(autosave) != 'undefined' ) |
|
229 autosave(); |
|
230 }); |
|
231 |
|
232 // auto-suggest stuff |
|
233 $('.newtag').each(function(){ |
|
234 var tax = $(this).parents('div.tagsdiv').attr('id'); |
|
235 $(this).suggest( 'admin-ajax.php?action=ajax-tag-search&tax='+tax, { delay: 500, minchars: 2, multiple: true, multipleSep: ", " } ); |
|
236 }); |
|
237 |
|
238 // category tabs |
|
239 $('#category-tabs a').click(function(){ |
|
240 var t = $(this).attr('href'); |
|
241 $(this).parent().addClass('tabs').siblings('li').removeClass('tabs'); |
|
242 $('.tabs-panel').hide(); |
|
243 $(t).show(); |
|
244 if ( '#categories-all' == t ) |
|
245 deleteUserSetting('cats'); |
|
246 else |
|
247 setUserSetting('cats','pop'); |
|
248 return false; |
|
249 }); |
|
250 if ( getUserSetting('cats') ) |
|
251 $('#category-tabs a[href="#categories-pop"]').click(); |
|
252 |
|
253 // Ajax Cat |
|
254 $('#newcat').one( 'focus', function() { $(this).val( '' ).removeClass( 'form-input-tip' ) } ); |
|
255 $('#category-add-sumbit').click(function(){$('#newcat').focus();}); |
|
256 |
|
257 syncChecks = function() { |
|
258 if ( noSyncChecks ) |
|
259 return; |
|
260 noSyncChecks = true; |
|
261 var th = jQuery(this), c = th.is(':checked'), id = th.val().toString(); |
|
262 $('#in-category-' + id + ', #in-popular-category-' + id).attr( 'checked', c ); |
|
263 noSyncChecks = false; |
|
264 }; |
|
265 |
|
266 popularCats = $('#categorychecklist-pop :checkbox').map( function() { return parseInt(jQuery(this).val(), 10); } ).get().join(','); |
|
267 catAddBefore = function( s ) { |
|
268 if ( !$('#newcat').val() ) |
|
269 return false; |
|
270 s.data += '&popular_ids=' + popularCats + '&' + jQuery( '#categorychecklist :checked' ).serialize(); |
|
271 return s; |
|
272 }; |
|
273 |
|
274 catAddAfter = function( r, s ) { |
|
275 var newCatParent = jQuery('#newcat_parent'), newCatParentOption = newCatParent.find( 'option[value="-1"]' ); |
|
276 $(s.what + ' response_data', r).each( function() { |
|
277 var t = $($(this).text()); |
|
278 t.find( 'label' ).each( function() { |
|
279 var th = $(this), val = th.find('input').val(), id = th.find('input')[0].id, name, o; |
|
280 $('#' + id).change( syncChecks ).change(); |
|
281 if ( newCatParent.find( 'option[value="' + val + '"]' ).size() ) |
|
282 return; |
|
283 name = $.trim( th.text() ); |
|
284 o = $( '<option value="' + parseInt( val, 10 ) + '"></option>' ).text( name ); |
|
285 newCatParent.prepend( o ); |
|
286 } ); |
|
287 newCatParentOption.attr( 'selected', 'selected' ); |
|
288 } ); |
|
289 }; |
|
290 |
|
291 $('#categorychecklist').wpList( { |
|
292 alt: '', |
|
293 response: 'category-ajax-response', |
|
294 addBefore: catAddBefore, |
|
295 addAfter: catAddAfter |
|
296 } ); |
|
297 |
|
298 $('#category-add-toggle').click( function() { |
|
299 $('#category-adder').toggleClass( 'wp-hidden-children' ); |
|
300 $('#category-tabs a[href="#categories-all"]').click(); |
|
301 return false; |
|
302 } ); |
|
303 |
|
304 $('.categorychecklist .popular-category :checkbox').change( syncChecks ).filter( ':checked' ).change(), sticky = ''; |
|
305 |
|
306 function updateVisibility() { |
|
307 if ( $('#post-visibility-select input:radio:checked').val() != 'public' ) { |
|
308 $('#sticky').attr('checked', false); |
|
309 $('#sticky-span').hide(); |
|
310 } else { |
|
311 $('#sticky-span').show(); |
|
312 } |
|
313 if ( $('#post-visibility-select input:radio:checked').val() != 'password' ) { |
|
314 $('#password-span').hide(); |
|
315 } else { |
|
316 $('#password-span').show(); |
|
317 } |
|
318 } |
|
319 |
|
320 function updateText() { |
|
321 var attemptedDate, originalDate, currentDate, publishOn; |
|
322 |
|
323 attemptedDate = new Date( $('#aa').val(), $('#mm').val() -1, $('#jj').val(), $('#hh').val(), $('#mn').val()); |
|
324 originalDate = new Date( $('#hidden_aa').val(), $('#hidden_mm').val() -1, $('#hidden_jj').val(), $('#hidden_hh').val(), $('#hidden_mn').val()); |
|
325 currentDate = new Date( $('#cur_aa').val(), $('#cur_mm').val() -1, $('#cur_jj').val(), $('#cur_hh').val(), $('#cur_mn').val()); |
|
326 if ( attemptedDate > currentDate && $('#original_post_status').val() != 'future' ) { |
|
327 publishOn = postL10n.publishOnFuture; |
|
328 $('#publish').val( postL10n.schedule ); |
|
329 } else if ( attemptedDate <= currentDate && $('#original_post_status').val() != 'publish' ) { |
|
330 publishOn = postL10n.publishOn; |
|
331 $('#publish').val( postL10n.publish ); |
|
332 } else { |
|
333 publishOn = postL10n.publishOnPast; |
|
334 $('#publish').val( postL10n.update ); |
|
335 } |
|
336 if ( originalDate.toUTCString() == attemptedDate.toUTCString() ) { //hack |
|
337 $('#timestamp').html(stamp); |
|
338 } else { |
|
339 $('#timestamp').html( |
|
340 publishOn + ' <b>' + |
|
341 $( '#mm option[value=' + $('#mm').val() + ']' ).text() + ' ' + |
|
342 $('#jj').val() + ', ' + |
|
343 $('#aa').val() + ' @ ' + |
|
344 $('#hh').val() + ':' + |
|
345 $('#mn').val() + '</b> ' |
|
346 ); |
|
347 } |
|
348 |
|
349 if ( $('#post-visibility-select input:radio:checked').val() == 'private' ) { |
|
350 $('#publish').val( postL10n.update ); |
|
351 if ( $('#post_status option[value=publish]').length == 0 ) { |
|
352 $('#post_status').append('<option value="publish">' + postL10n.privatelyPublished + '</option>'); |
|
353 } |
|
354 $('#post_status option[value=publish]').html( postL10n.privatelyPublished ); |
|
355 $('#post_status option[value=publish]').attr('selected', true); |
|
356 $('.edit-post-status').hide(); |
|
357 } else { |
|
358 if ( $('#original_post_status').val() == 'future' || $('#original_post_status').val() == 'draft' ) { |
|
359 if ( $('#post_status option[value=publish]').length != 0 ) { |
|
360 $('#post_status option[value=publish]').remove(); |
|
361 $('#post_status').val($('#hidden_post_status').val()); |
|
362 } |
|
363 } else { |
|
364 $('#post_status option[value=publish]').html( postL10n.published ); |
|
365 } |
|
366 $('.edit-post-status').show(); |
|
367 } |
|
368 $('#post-status-display').html($('#post_status :selected').text()); |
|
369 if ( $('#post_status :selected').val() == 'private' || $('#post_status :selected').val() == 'publish' ) { |
|
370 $('#save-post').hide(); |
|
371 } else { |
|
372 $('#save-post').show(); |
|
373 if ( $('#post_status :selected').val() == 'pending' ) { |
|
374 $('#save-post').show().val( postL10n.savePending ); |
|
375 } else { |
|
376 $('#save-post').show().val( postL10n.saveDraft ); |
|
377 } |
|
378 } |
|
379 } |
|
380 |
|
381 $('.edit-visibility').click(function () { |
|
382 if ($('#post-visibility-select').is(":hidden")) { |
|
383 updateVisibility(); |
|
384 $('#post-visibility-select').slideDown("normal"); |
|
385 $('.edit-visibility').hide(); |
|
386 } |
|
387 return false; |
|
388 }); |
|
389 |
|
390 $('.cancel-post-visibility').click(function () { |
|
391 $('#post-visibility-select').slideUp("normal"); |
|
392 $('#visibility-radio-' + $('#hidden-post-visibility').val()).attr('checked', true); |
|
393 $('#post_password').val($('#hidden_post_password').val()); |
|
394 $('#sticky').attr('checked', $('#hidden-post-sticky').attr('checked')); |
|
395 $('#post-visibility-display').html(visibility); |
|
396 $('.edit-visibility').show(); |
|
397 updateText(); |
|
398 return false; |
|
399 }); |
|
400 |
|
401 $('.save-post-visibility').click(function () { // crazyhorse - multiple ok cancels |
|
402 $('#post-visibility-select').slideUp("normal"); |
|
403 $('.edit-visibility').show(); |
|
404 updateText(); |
|
405 if ( $('#post-visibility-select input:radio:checked').val() != 'public' ) { |
|
406 $('#sticky').attr('checked', false); |
|
407 } |
|
408 |
|
409 if ( true == $('#sticky').attr('checked') ) { |
|
410 sticky = 'Sticky'; |
|
411 } else { |
|
412 sticky = ''; |
|
413 } |
|
414 |
|
415 $('#post-visibility-display').html( |
|
416 postL10n[$('#post-visibility-select input:radio:checked').val() + sticky] |
|
417 ); |
|
418 |
|
419 return false; |
|
420 }); |
|
421 |
|
422 $('#post-visibility-select input:radio').change(function() { |
|
423 updateVisibility(); |
|
424 }); |
|
425 |
|
426 $('.edit-timestamp').click(function () { |
|
427 if ($('#timestampdiv').is(":hidden")) { |
|
428 $('#timestampdiv').slideDown("normal"); |
|
429 $('.edit-timestamp').hide(); |
|
430 } |
|
431 |
|
432 return false; |
|
433 }); |
|
434 |
|
435 $('.cancel-timestamp').click(function() { |
|
436 $('#timestampdiv').slideUp("normal"); |
|
437 $('#mm').val($('#hidden_mm').val()); |
|
438 $('#jj').val($('#hidden_jj').val()); |
|
439 $('#aa').val($('#hidden_aa').val()); |
|
440 $('#hh').val($('#hidden_hh').val()); |
|
441 $('#mn').val($('#hidden_mn').val()); |
|
442 $('.edit-timestamp').show(); |
|
443 updateText(); |
|
444 return false; |
|
445 }); |
|
446 |
|
447 $('.save-timestamp').click(function () { // crazyhorse - multiple ok cancels |
|
448 $('#timestampdiv').slideUp("normal"); |
|
449 $('.edit-timestamp').show(); |
|
450 updateText(); |
|
451 |
|
452 return false; |
|
453 }); |
|
454 |
|
455 $('.edit-post-status').click(function() { |
|
456 if ($('#post-status-select').is(":hidden")) { |
|
457 $('#post-status-select').slideDown("normal"); |
|
458 $(this).hide(); |
|
459 } |
|
460 |
|
461 return false; |
|
462 }); |
|
463 |
|
464 $('.save-post-status').click(function() { |
|
465 $('#post-status-select').slideUp("normal"); |
|
466 $('.edit-post-status').show(); |
|
467 updateText(); |
|
468 return false; |
|
469 }); |
|
470 |
|
471 $('.cancel-post-status').click(function() { |
|
472 $('#post-status-select').slideUp("normal"); |
|
473 $('#post_status').val($('#hidden_post_status').val()); |
|
474 $('.edit-post-status').show(); |
|
475 updateText(); |
|
476 return false; |
|
477 }); |
|
478 |
|
479 // Custom Fields |
|
480 $('#the-list').wpList( { addAfter: function( xml, s ) { |
|
481 $('table#list-table').show(); |
|
482 if ( typeof( autosave_update_post_ID ) != 'undefined' ) { |
|
483 autosave_update_post_ID(s.parsed.responses[0].supplemental.postid); |
|
484 } |
|
485 }, addBefore: function( s ) { |
|
486 s.data += '&post_id=' + $('#post_ID').val(); |
|
487 return s; |
|
488 } |
|
489 }); |
|
490 }); |