]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/js/page.js
Wordpress 2.7.1-scripts
[autoinstalls/wordpress.git] / wp-admin / js / page.js
1 jQuery(document).ready( function($) {
2         postboxes.add_postbox_toggles('page');
3         make_slugedit_clickable();
4
5         // close postboxes that should be closed
6         jQuery('.if-js-closed').removeClass('if-js-closed').addClass('closed');
7
8         jQuery('#title').blur( function() { if ( (jQuery("#post_ID").val() > 0) || (jQuery("#title").val().length == 0) ) return; autosave(); } );
9
10         var stamp = $('#timestamp').html();
11
12         var visibility = $('#post-visibility-display').html();
13
14         function updateVisibility() {
15                 if ( $('#post-visibility-select input:radio:checked').val() != 'public' ) {
16                         $('#sticky').attr('checked', false);
17                         $('#sticky-span').hide();
18                 } else {
19                         $('#sticky-span').show();
20                 }
21                 if ( $('#post-visibility-select input:radio:checked').val() != 'password' ) {
22                         $('#password-span').hide();
23                 } else {
24                         $('#password-span').show();
25                 }
26         }
27
28         function updateText() {
29                 var attemptedDate = new Date( $('#aa').val(), $('#mm').val() -1, $('#jj').val(), $('#hh').val(), $('#mn').val());
30                 var originalDate = new Date( $('#hidden_aa').val(), $('#hidden_mm').val() -1, $('#hidden_jj').val(), $('#hidden_hh').val(), $('#hidden_mn').val());
31                 var currentDate = new Date( $('#cur_aa').val(), $('#cur_mm').val() -1, $('#cur_jj').val(), $('#cur_hh').val(), $('#cur_mn').val());
32                 if ( attemptedDate > currentDate && $('#original_post_status').val() != 'future' ) {
33                         var publishOn = postL10n.publishOnFuture;
34                         $('#publish').val( postL10n.schedule );
35                 } else if ( attemptedDate <= currentDate && $('#original_post_status').val() != 'publish' ) {
36                         var publishOn = postL10n.publishOn;
37                         $('#publish').val( postL10n.publish );
38                 } else {
39                         var publishOn = postL10n.publishOnPast;
40                         $('#publish').val( postL10n.update );
41                 }
42                 if ( originalDate.toUTCString() == attemptedDate.toUTCString() ) { //hack
43                         $('#timestamp').html(stamp);
44                 } else {
45                         $('#timestamp').html(
46                                 publishOn + ' <b>' +
47                                 $( '#mm option[value=' + $('#mm').val() + ']' ).text() + ' ' +
48                                 $('#jj').val() + ', ' +
49                                 $('#aa').val() + ' @ ' +
50                                 $('#hh').val() + ':' +
51                                 $('#mn').val() + '</b> '
52                         );
53                 }
54
55                 if ( $('#post-visibility-select input:radio:checked').val() == 'private' ) {
56                         $('#publish').val( postL10n.update );
57                         if ( $('#post_status option[value=publish]').length == 0 ) {
58                                 $('#post_status').append('<option value="publish">' + postL10n.privatelyPublished + '</option>');
59                         }
60                         $('#post_status option[value=publish]').html( postL10n.privatelyPublished );
61                         $('#post_status option[value=publish]').attr('selected', true);
62                         $('.edit-post-status').hide();
63                 } else {
64                         if ( $('#original_post_status').val() == 'future' || $('#original_post_status').val() == 'draft' ) {
65                                 if ( $('#post_status option[value=publish]').length != 0 ) {
66                                         $('#post_status option[value=publish]').remove();
67                                         $('#post_status').val($('#hidden_post_status').val());
68                                 }
69                         } else {
70                                 $('#post_status option[value=publish]').html( postL10n.published );
71                         }
72                         $('.edit-post-status').show();
73                 }
74                 $('#post-status-display').html($('#post_status :selected').text());
75                 if ( $('#post_status :selected').val() == 'private' || $('#post_status :selected').val() == 'publish' ) {
76                         $('#save-post').hide();
77                 } else {
78                         $('#save-post').show();
79                         if ( $('#post_status :selected').val() == 'pending' ) {
80                                 $('#save-post').show().val( postL10n.savePending );
81                         } else {
82                                 $('#save-post').show().val( postL10n.saveDraft );
83                         }
84                 }
85         }
86
87         $('.edit-visibility').click(function () {
88                 if ($('#post-visibility-select').is(":hidden")) {
89                         updateVisibility();
90                         $('#post-visibility-select').slideDown("normal");
91                         $('.edit-visibility').hide();
92                 }
93                 return false;
94         });
95
96         $('.cancel-post-visibility').click(function () {
97                 $('#post-visibility-select').slideUp("normal");
98                 $('#visibility-radio-' + $('#hidden-post-visibility').val()).attr('checked', true);
99                 $('#post_password').val($('#hidden_post_password').val());
100                 $('#post-visibility-display').html(visibility);
101                 $('.edit-visibility').show();
102                 updateText();
103                 return false;
104         });
105
106         $('.save-post-visibility').click(function () { // crazyhorse - multiple ok cancels
107                 $('#post-visibility-select').slideUp("normal");
108                 $('.edit-visibility').show();
109                 updateText();
110
111                 $('#post-visibility-display').html(
112                         postL10n[$('#post-visibility-select input:radio:checked').val()]
113                 );
114
115                 return false;
116         });
117
118         $('#post-visibility-select input:radio').change(function() {
119                 updateVisibility();
120         });
121
122         $('.edit-timestamp').click(function () {
123                 if ($('#timestampdiv').is(":hidden")) {
124                         $('#timestampdiv').slideDown("normal");
125                         $('.edit-timestamp').hide();
126                 }
127
128                 return false;
129         });
130
131         $('.cancel-timestamp').click(function() {
132                 $('#timestampdiv').slideUp("normal");
133                 $('#mm').val($('#hidden_mm').val());
134                 $('#jj').val($('#hidden_jj').val());
135                 $('#aa').val($('#hidden_aa').val());
136                 $('#hh').val($('#hidden_hh').val());
137                 $('#mn').val($('#hidden_mn').val());
138                 $('.edit-timestamp').show();
139
140                 updateText();
141                 return false;
142         });
143
144         $('.save-timestamp').click(function () { // crazyhorse - multiple ok cancels
145                 $('#timestampdiv').slideUp("normal");
146                 $('.edit-timestamp').show();
147                 updateText();
148
149                 return false;
150         });
151
152         $('.edit-post-status').click(function() {
153                 if ($('#post-status-select').is(":hidden")) {
154                         $('#post-status-select').slideDown("normal");
155                         $(this).hide();
156                 }
157
158                 return false;
159         });
160
161         $('.save-post-status').click(function() {
162                 $('#post-status-select').slideUp("normal");
163                 $('.edit-post-status').show();
164                 updateText();
165                 return false;
166         });
167
168         $('.cancel-post-status').click(function() {
169                 $('#post-status-select').slideUp("normal");
170                 $('#post_status').val($('#hidden_post_status').val());
171                 $('.edit-post-status').show();
172
173                 updateText();
174                 return false;
175         });
176
177         // Custom Fields
178         jQuery('#the-list').wpList( { addAfter: function( xml, s ) {
179                 $('table#list-table').show();
180                 if ( jQuery.isFunction( autosave_update_post_ID ) ) {
181                         autosave_update_post_ID(s.parsed.responses[0].supplemental.postid);
182                 }
183         }, addBefore: function( s ) {
184                 s.data += '&post_id=' + jQuery('#post_ID').val();
185                 return s;
186         }
187         });
188
189         // preview
190         $('#post-preview').click(function(e){
191                 if ( 1 > $('#post_ID').val() && autosaveFirst ) {
192                         autosaveDelayPreview = true;
193                         autosave();
194                         return false;
195                 }
196
197                 $('input#wp-preview').val('dopreview');
198                 $('form#post').attr('target', 'wp-preview').submit().attr('target', '');
199                 $('input#wp-preview').val('');
200                 return false;
201         });
202 });