5
|
1 |
/* global pagenow, ajaxurl, postboxes, wpActiveEditor:true */ |
0
|
2 |
var ajaxWidgets, ajaxPopulateWidgets, quickPressLoad; |
|
3 |
|
|
4 |
jQuery(document).ready( function($) { |
5
|
5 |
var welcomePanel = $( '#welcome-panel' ), |
0
|
6 |
welcomePanelHide = $('#wp_welcome_panel-hide'), |
5
|
7 |
updateWelcomePanel; |
0
|
8 |
|
5
|
9 |
updateWelcomePanel = function( visible ) { |
|
10 |
$.post( ajaxurl, { |
|
11 |
action: 'update-welcome-panel', |
|
12 |
visible: visible, |
|
13 |
welcomepanelnonce: $( '#welcomepanelnonce' ).val() |
|
14 |
}); |
|
15 |
}; |
|
16 |
|
|
17 |
if ( welcomePanel.hasClass('hidden') && welcomePanelHide.prop('checked') ) { |
0
|
18 |
welcomePanel.removeClass('hidden'); |
5
|
19 |
} |
0
|
20 |
|
|
21 |
$('.welcome-panel-close, .welcome-panel-dismiss a', welcomePanel).click( function(e) { |
|
22 |
e.preventDefault(); |
|
23 |
welcomePanel.addClass('hidden'); |
|
24 |
updateWelcomePanel( 0 ); |
|
25 |
$('#wp_welcome_panel-hide').prop('checked', false); |
|
26 |
}); |
|
27 |
|
|
28 |
welcomePanelHide.click( function() { |
|
29 |
welcomePanel.toggleClass('hidden', ! this.checked ); |
|
30 |
updateWelcomePanel( this.checked ? 1 : 0 ); |
|
31 |
}); |
|
32 |
|
|
33 |
// These widgets are sometimes populated via ajax |
5
|
34 |
ajaxWidgets = ['dashboard_primary']; |
0
|
35 |
|
|
36 |
ajaxPopulateWidgets = function(el) { |
|
37 |
function show(i, id) { |
|
38 |
var p, e = $('#' + id + ' div.inside:visible').find('.widget-loading'); |
|
39 |
if ( e.length ) { |
|
40 |
p = e.parent(); |
|
41 |
setTimeout( function(){ |
5
|
42 |
p.load( ajaxurl + '?action=dashboard-widgets&widget=' + id + '&pagenow=' + pagenow, '', function() { |
0
|
43 |
p.hide().slideDown('normal', function(){ |
|
44 |
$(this).css('display', ''); |
|
45 |
}); |
|
46 |
}); |
|
47 |
}, i * 500 ); |
|
48 |
} |
|
49 |
} |
|
50 |
|
|
51 |
if ( el ) { |
|
52 |
el = el.toString(); |
5
|
53 |
if ( $.inArray(el, ajaxWidgets) !== -1 ) { |
0
|
54 |
show(0, el); |
5
|
55 |
} |
0
|
56 |
} else { |
|
57 |
$.each( ajaxWidgets, show ); |
|
58 |
} |
|
59 |
}; |
|
60 |
ajaxPopulateWidgets(); |
|
61 |
|
|
62 |
postboxes.add_postbox_toggles(pagenow, { pbshow: ajaxPopulateWidgets } ); |
|
63 |
|
|
64 |
/* QuickPress */ |
|
65 |
quickPressLoad = function() { |
|
66 |
var act = $('#quickpost-action'), t; |
5
|
67 |
|
|
68 |
$( '#quick-press .submit input[type="submit"], #quick-press .submit input[type="reset"]' ).prop( 'disabled' , false ); |
|
69 |
|
0
|
70 |
t = $('#quick-press').submit( function() { |
|
71 |
$('#dashboard_quick_press #publishing-action .spinner').show(); |
|
72 |
$('#quick-press .submit input[type="submit"], #quick-press .submit input[type="reset"]').prop('disabled', true); |
|
73 |
|
5
|
74 |
$.post( t.attr( 'action' ), t.serializeArray(), function( data ) { |
|
75 |
// Replace the form, and prepend the published post. |
|
76 |
$('#dashboard_quick_press .inside').html( data ); |
|
77 |
$('#quick-press').removeClass('initial-form'); |
|
78 |
quickPressLoad(); |
|
79 |
highlightLatestPost(); |
|
80 |
$('#title').focus(); |
|
81 |
}); |
|
82 |
|
|
83 |
function highlightLatestPost () { |
|
84 |
var latestPost = $('.drafts ul li').first(); |
|
85 |
latestPost.css('background', '#fffbe5'); |
|
86 |
setTimeout(function () { |
|
87 |
latestPost.css('background', 'none'); |
|
88 |
}, 1000); |
0
|
89 |
} |
|
90 |
|
|
91 |
return false; |
|
92 |
} ); |
|
93 |
|
|
94 |
$('#publish').click( function() { act.val( 'post-quickpress-publish' ); } ); |
|
95 |
|
5
|
96 |
$('#title, #tags-input, #content').each( function() { |
0
|
97 |
var input = $(this), prompt = $('#' + this.id + '-prompt-text'); |
|
98 |
|
5
|
99 |
if ( '' === this.value ) { |
0
|
100 |
prompt.removeClass('screen-reader-text'); |
5
|
101 |
} |
0
|
102 |
|
|
103 |
prompt.click( function() { |
|
104 |
$(this).addClass('screen-reader-text'); |
|
105 |
input.focus(); |
|
106 |
}); |
|
107 |
|
|
108 |
input.blur( function() { |
5
|
109 |
if ( '' === this.value ) { |
0
|
110 |
prompt.removeClass('screen-reader-text'); |
5
|
111 |
} |
0
|
112 |
}); |
|
113 |
|
|
114 |
input.focus( function() { |
|
115 |
prompt.addClass('screen-reader-text'); |
|
116 |
}); |
|
117 |
}); |
|
118 |
|
|
119 |
$('#quick-press').on( 'click focusin', function() { |
|
120 |
wpActiveEditor = 'content'; |
|
121 |
}); |
5
|
122 |
|
|
123 |
autoResizeTextarea(); |
0
|
124 |
}; |
|
125 |
quickPressLoad(); |
|
126 |
|
5
|
127 |
$( '.meta-box-sortables' ).sortable( 'option', 'containment', 'document' ); |
|
128 |
|
|
129 |
function autoResizeTextarea() { |
|
130 |
if ( document.documentMode && document.documentMode < 9 ) { |
|
131 |
return; |
|
132 |
} |
|
133 |
|
|
134 |
// Add a hidden div. We'll copy over the text from the textarea to measure its height. |
|
135 |
$('body').append( '<div class="quick-draft-textarea-clone" style="display: none;"></div>' ); |
|
136 |
|
|
137 |
var clone = $('.quick-draft-textarea-clone'), |
|
138 |
editor = $('#content'), |
|
139 |
editorHeight = editor.height(), |
|
140 |
// 100px roughly accounts for browser chrome and allows the |
|
141 |
// save draft button to show on-screen at the same time. |
|
142 |
editorMaxHeight = $(window).height() - 100; |
|
143 |
|
|
144 |
// Match up textarea and clone div as much as possible. |
|
145 |
// Padding cannot be reliably retrieved using shorthand in all browsers. |
|
146 |
clone.css({ |
|
147 |
'font-family': editor.css('font-family'), |
|
148 |
'font-size': editor.css('font-size'), |
|
149 |
'line-height': editor.css('line-height'), |
|
150 |
'padding-bottom': editor.css('paddingBottom'), |
|
151 |
'padding-left': editor.css('paddingLeft'), |
|
152 |
'padding-right': editor.css('paddingRight'), |
|
153 |
'padding-top': editor.css('paddingTop'), |
|
154 |
'white-space': 'pre-wrap', |
|
155 |
'word-wrap': 'break-word', |
|
156 |
'display': 'none' |
|
157 |
}); |
|
158 |
|
|
159 |
// propertychange is for IE < 9 |
|
160 |
editor.on('focus input propertychange', function() { |
|
161 |
var $this = $(this), |
|
162 |
// is to ensure that the height of a final trailing newline is included. |
|
163 |
textareaContent = $this.val() + ' ', |
|
164 |
// 2px is for border-top & border-bottom |
|
165 |
cloneHeight = clone.css('width', $this.css('width')).text(textareaContent).outerHeight() + 2; |
|
166 |
|
|
167 |
// Default to having scrollbars |
|
168 |
editor.css('overflow-y', 'auto'); |
|
169 |
|
|
170 |
// Only change the height if it has indeed changed and both heights are below the max. |
|
171 |
if ( cloneHeight === editorHeight || ( cloneHeight >= editorMaxHeight && editorHeight >= editorMaxHeight ) ) { |
|
172 |
return; |
|
173 |
} |
|
174 |
|
|
175 |
// Don't allow editor to exceed height of window. |
|
176 |
// This is also bound in CSS to a max-height of 1300px to be extra safe. |
|
177 |
if ( cloneHeight > editorMaxHeight ) { |
|
178 |
editorHeight = editorMaxHeight; |
|
179 |
} else { |
|
180 |
editorHeight = cloneHeight; |
|
181 |
} |
|
182 |
|
|
183 |
// No scrollbars as we change height, not for IE < 9 |
|
184 |
editor.css('overflow', 'hidden'); |
|
185 |
|
|
186 |
$this.css('height', editorHeight + 'px'); |
|
187 |
}); |
|
188 |
} |
|
189 |
|
0
|
190 |
} ); |