web/wp-admin/js/dashboard.js
changeset 204 09a1c134465b
parent 194 32102edaa81b
equal deleted inserted replaced
203:f507feede89a 204:09a1c134465b
     1 var ajaxWidgets,ajaxPopulateWidgets,quickPressLoad;jQuery(document).ready(function(c){var d=c("#welcome-panel"),a=c("#wp_welcome_panel-hide"),b=function(e){c.post(ajaxurl,{action:"update-welcome-panel",visible:e,welcomepanelnonce:c("#welcomepanelnonce").val()})};if(d.hasClass("hidden")&&a.prop("checked")){d.removeClass("hidden")}c(".welcome-panel-close, .welcome-panel-dismiss a",d).click(function(f){f.preventDefault();d.addClass("hidden");b(0);c("#wp_welcome_panel-hide").prop("checked",false)});a.click(function(){d.toggleClass("hidden",!this.checked);b(this.checked?1:0)});ajaxWidgets=["dashboard_incoming_links","dashboard_primary","dashboard_secondary","dashboard_plugins"];ajaxPopulateWidgets=function(f){function e(g,k){var j,h=c("#"+k+" div.inside:visible").find(".widget-loading");if(h.length){j=h.parent();setTimeout(function(){j.load(ajaxurl+"?action=dashboard-widgets&widget="+k,"",function(){j.hide().slideDown("normal",function(){c(this).css("display","")})})},g*500)}}if(f){f=f.toString();if(c.inArray(f,ajaxWidgets)!=-1){e(0,f)}}else{c.each(ajaxWidgets,e)}};ajaxPopulateWidgets();postboxes.add_postbox_toggles(pagenow,{pbshow:ajaxPopulateWidgets});quickPressLoad=function(){var e=c("#quickpost-action"),f;f=c("#quick-press").submit(function(){c("#dashboard_quick_press #publishing-action img.waiting").css("visibility","visible");c('#quick-press .submit input[type="submit"], #quick-press .submit input[type="reset"]').prop("disabled",true);if("post"==e.val()){e.val("post-quickpress-publish")}c("#dashboard_quick_press div.inside").load(f.attr("action"),f.serializeArray(),function(){c("#dashboard_quick_press #publishing-action img.waiting").css("visibility","hidden");c('#quick-press .submit input[type="submit"], #quick-press .submit input[type="reset"]').prop("disabled",false);c("#dashboard_quick_press ul").next("p").remove();c("#dashboard_quick_press ul").find("li").each(function(){c("#dashboard_recent_drafts ul").prepend(this)}).end().remove();quickPressLoad()});return false});c("#publish").click(function(){e.val("post-quickpress-publish")})};quickPressLoad()});
     1 var ajaxWidgets, ajaxPopulateWidgets, quickPressLoad;
       
     2 
       
     3 jQuery(document).ready( function($) {
       
     4 	/* Dashboard Welcome Panel */
       
     5 	var welcomePanel = $('#welcome-panel'),
       
     6 		welcomePanelHide = $('#wp_welcome_panel-hide'),
       
     7 	 	updateWelcomePanel = function( visible ) {
       
     8 			$.post( ajaxurl, {
       
     9 				action: 'update-welcome-panel',
       
    10 				visible: visible,
       
    11 				welcomepanelnonce: $('#welcomepanelnonce').val()
       
    12 			});
       
    13 		};
       
    14 
       
    15 	if ( welcomePanel.hasClass('hidden') && welcomePanelHide.prop('checked') )
       
    16 		welcomePanel.removeClass('hidden');
       
    17 
       
    18 	$('.welcome-panel-close, .welcome-panel-dismiss a', welcomePanel).click( function(e) {
       
    19 		e.preventDefault();
       
    20 		welcomePanel.addClass('hidden');
       
    21 		updateWelcomePanel( 0 );
       
    22 		$('#wp_welcome_panel-hide').prop('checked', false);
       
    23 	});
       
    24 
       
    25 	welcomePanelHide.click( function() {
       
    26 		welcomePanel.toggleClass('hidden', ! this.checked );
       
    27 		updateWelcomePanel( this.checked ? 1 : 0 );
       
    28 	});
       
    29 
       
    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) {
       
    39 		function show(i, id) {
       
    40 			var p, e = $('#' + id + ' div.inside:visible').find('.widget-loading');
       
    41 			if ( e.length ) {
       
    42 				p = e.parent();
       
    43 				setTimeout( function(){
       
    44 					p.load( ajaxurl + '?action=dashboard-widgets&widget=' + id, '', function() {
       
    45 						p.hide().slideDown('normal', function(){
       
    46 							$(this).css('display', '');
       
    47 						});
       
    48 					});
       
    49 				}, i * 500 );
       
    50 			}
       
    51 		}
       
    52 
       
    53 		if ( el ) {
       
    54 			el = el.toString();
       
    55 			if ( $.inArray(el, ajaxWidgets) != -1 )
       
    56 				show(0, el);
       
    57 		} else {
       
    58 			$.each( ajaxWidgets, show );
       
    59 		}
       
    60 	};
       
    61 	ajaxPopulateWidgets();
       
    62 
       
    63 	postboxes.add_postbox_toggles(pagenow, { pbshow: ajaxPopulateWidgets } );
       
    64 
       
    65 	/* QuickPress */
       
    66 	quickPressLoad = function() {
       
    67 		var act = $('#quickpost-action'), t;
       
    68 		t = $('#quick-press').submit( function() {
       
    69 			$('#dashboard_quick_press #publishing-action .spinner').show();
       
    70 			$('#quick-press .submit input[type="submit"], #quick-press .submit input[type="reset"]').prop('disabled', true);
       
    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() {
       
    77 				$('#dashboard_quick_press #publishing-action .spinner').hide();
       
    78 				$('#quick-press .submit input[type="submit"], #quick-press .submit input[type="reset"]').prop('disabled', false);
       
    79 				$('#dashboard_quick_press ul').next('p').remove();
       
    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 		$('#title, #tags-input').each( function() {
       
    91 			var input = $(this), prompt = $('#' + this.id + '-prompt-text');
       
    92 
       
    93 			if ( '' === this.value )
       
    94 				prompt.removeClass('screen-reader-text');
       
    95 
       
    96 			prompt.click( function() {
       
    97 				$(this).addClass('screen-reader-text');
       
    98 				input.focus();
       
    99 			});
       
   100 
       
   101 			input.blur( function() {
       
   102 				if ( '' === this.value )
       
   103 					prompt.removeClass('screen-reader-text');
       
   104 			});
       
   105 
       
   106 			input.focus( function() {
       
   107 				prompt.addClass('screen-reader-text');
       
   108 			});
       
   109 		});
       
   110 
       
   111 		$('#quick-press').on( 'click focusin', function() {
       
   112 			wpActiveEditor = 'content';
       
   113 		});
       
   114 	};
       
   115 	quickPressLoad();
       
   116 
       
   117 } );