author | Anthony Ly <anthonyly.com@gmail.com> |
Wed, 12 Dec 2012 18:57:40 -0800 | |
changeset 199 | 9ff3c84d7b27 |
parent 194 | 32102edaa81b |
permissions | -rw-r--r-- |
136 | 1 |
var ajaxWidgets, ajaxPopulateWidgets, quickPressLoad; |
2 |
||
3 |
jQuery(document).ready( function($) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4 |
/* Dashboard Welcome Panel */ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5 |
var welcomePanel = $('#welcome-panel'), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
6 |
welcomePanelHide = $('#wp_welcome_panel-hide'), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
7 |
updateWelcomePanel = function( visible ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
8 |
$.post( ajaxurl, { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
9 |
action: 'update-welcome-panel', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
10 |
visible: visible, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
11 |
welcomepanelnonce: $('#welcomepanelnonce').val() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
12 |
}); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
13 |
}; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
14 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
15 |
if ( welcomePanel.hasClass('hidden') && welcomePanelHide.prop('checked') ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
16 |
welcomePanel.removeClass('hidden'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
17 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
18 |
$('.welcome-panel-close, .welcome-panel-dismiss a', welcomePanel).click( function(e) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
19 |
e.preventDefault(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
20 |
welcomePanel.addClass('hidden'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
21 |
updateWelcomePanel( 0 ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
22 |
$('#wp_welcome_panel-hide').prop('checked', false); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
23 |
}); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
24 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
25 |
welcomePanelHide.click( function() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
26 |
welcomePanel.toggleClass('hidden', ! this.checked ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
27 |
updateWelcomePanel( this.checked ? 1 : 0 ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
28 |
}); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
29 |
|
136 | 30 |
// These widgets are sometimes populated via ajax |
31 |
ajaxWidgets = [ |
|
32 |
'dashboard_incoming_links', |
|
33 |
'dashboard_primary', |
|
34 |
'dashboard_secondary', |
|
35 |
'dashboard_plugins' |
|
36 |
]; |
|
37 |
||
38 |
ajaxPopulateWidgets = function(el) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
39 |
function show(i, id) { |
136 | 40 |
var p, e = $('#' + id + ' div.inside:visible').find('.widget-loading'); |
41 |
if ( e.length ) { |
|
42 |
p = e.parent(); |
|
43 |
setTimeout( function(){ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
44 |
p.load( ajaxurl + '?action=dashboard-widgets&widget=' + id, '', function() { |
136 | 45 |
p.hide().slideDown('normal', function(){ |
46 |
$(this).css('display', ''); |
|
47 |
}); |
|
48 |
}); |
|
49 |
}, i * 500 ); |
|
50 |
} |
|
51 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
52 |
|
136 | 53 |
if ( el ) { |
54 |
el = el.toString(); |
|
55 |
if ( $.inArray(el, ajaxWidgets) != -1 ) |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
56 |
show(0, el); |
136 | 57 |
} else { |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
58 |
$.each( ajaxWidgets, show ); |
136 | 59 |
} |
60 |
}; |
|
61 |
ajaxPopulateWidgets(); |
|
62 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
63 |
postboxes.add_postbox_toggles(pagenow, { pbshow: ajaxPopulateWidgets } ); |
136 | 64 |
|
65 |
/* QuickPress */ |
|
66 |
quickPressLoad = function() { |
|
67 |
var act = $('#quickpost-action'), t; |
|
68 |
t = $('#quick-press').submit( function() { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
69 |
$('#dashboard_quick_press #publishing-action img.waiting').css('visibility', 'visible'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
70 |
$('#quick-press .submit input[type="submit"], #quick-press .submit input[type="reset"]').prop('disabled', true); |
136 | 71 |
|
72 |
if ( 'post' == act.val() ) { |
|
73 |
act.val( 'post-quickpress-publish' ); |
|
74 |
} |
|
75 |
||
76 |
$('#dashboard_quick_press div.inside').load( t.attr( 'action' ), t.serializeArray(), function() { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
77 |
$('#dashboard_quick_press #publishing-action img.waiting').css('visibility', 'hidden'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
78 |
$('#quick-press .submit input[type="submit"], #quick-press .submit input[type="reset"]').prop('disabled', false); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
79 |
$('#dashboard_quick_press ul').next('p').remove(); |
136 | 80 |
$('#dashboard_quick_press ul').find('li').each( function() { |
81 |
$('#dashboard_recent_drafts ul').prepend( this ); |
|
82 |
} ).end().remove(); |
|
83 |
quickPressLoad(); |
|
84 |
} ); |
|
85 |
return false; |
|
86 |
} ); |
|
87 |
||
88 |
$('#publish').click( function() { act.val( 'post-quickpress-publish' ); } ); |
|
89 |
||
90 |
}; |
|
91 |
quickPressLoad(); |
|
92 |
||
93 |
} ); |