-
+ D7236E98253DDDD33D7A6D779D4BDB6649575F81DF5F9F761C283179B63B6EFCAACE5B1B4CB6A05B7E4EB5E76D718383FC57C3649D0D374000CE09F0A0336FA4mp-wp/wp-admin/js/widgets.js(0 . 0)(1 . 150)
51586 jQuery(function($) {
51587 $('.noscript-action').remove();
51588
51589 var reminded = false;
51590 var lameWidgetReminder = function() {
51591 if ( reminded )
51592 return;
51593 window.onbeforeunload = function () { return widgetsL10n.lamerReminder };
51594 $('h2:first').after( '<div class="updated"><p>' + widgetsL10n.lameReminder + '</p></div>' );
51595 $('#current-widgets .submit input[name=save-widgets]').css( 'background-color', '#ffffe0' ).click( function() {
51596 window.onbeforeunload = null;
51597 } );
51598 reminded = true;
51599 };
51600
51601 var increment = 1;
51602
51603 // Open or close widget control form
51604 var toggleWidget = function( li, disableFields ) {
51605 var width = li.find('input.widget-width').val();
51606
51607 // it seems IE chokes on these animations because of the positioning/floating
51608 var widgetAnim = $.browser.msie ? function() {
51609 var t = $(this);
51610 if ( t.is(':visible') ) {
51611 if ( disableFields ) { t.find( ':input:enabled' ).not( '[name="widget-id[]"], [name*="[submit]"]' ).attr( 'disabled', 'disabled' ); }
51612 li.css( 'marginLeft', 0 );
51613 t.siblings('div').children('h4').children('a').text( widgetsL10n.edit );
51614 } else {
51615 t.find( ':disabled' ).attr( 'disabled', '' ); // always enable on open
51616 if ( width > 250 )
51617 li.css( 'marginLeft', ( width - 250 ) * -1 );
51618 t.siblings('div').children('h4').children('a').text( widgetsL10n.cancel );
51619 }
51620 t.toggle();
51621 } : function() {
51622 var t = $(this);
51623
51624 if ( t.is(':visible') ) {
51625 if ( disableFields ) { t.find( ':input:enabled' ).not( '[name="widget-id[]"], [name*="[submit]"]' ).attr( 'disabled', 'disabled' ); }
51626 if ( width > 250 )
51627 li.animate( { marginLeft: 0 } );
51628 t.siblings('div').children('h4').children('a').text( widgetsL10n.edit );
51629 } else {
51630 t.find( ':disabled' ).attr( 'disabled', '' ); // always enable on open
51631 if ( width > 250 )
51632 li.animate( { marginLeft: ( width - 250 ) * -1 } );
51633 t.siblings('div').children('h4').children('a').text( widgetsL10n.cancel );
51634 }
51635 t.animate( { height: 'toggle' } );
51636 };
51637
51638 return li.children('div.widget-control').each( widgetAnim ).end();
51639 };
51640
51641 // onclick for edit/cancel links
51642 var editClick = function() {
51643 var q = wpAjax.unserialize( this.href );
51644 // if link is in available widgets list, make sure it points to the current sidebar
51645 if ( ( q.sidebar && q.sidebar == $('#sidebar').val() ) || q.add ) {
51646 var w = q.edit || q.add;
51647 toggleWidget( $('#current-sidebar .widget-control-list input[@name^="widget-id"][@value=' + w + ']').parents('li:first'), false ).blur();
51648 return false;
51649 } else if ( q.sidebar ) { // otherwise, redirect to correct page
51650 return true;
51651 }
51652
51653 // If link is in current widgets list, just open the form
51654 toggleWidget( $(this).parents('li:first'), true ).blur();
51655 return false;
51656 };
51657
51658 // onclick for add links
51659 var addClick = function() {
51660 var oldLi = $(this).parents('li:first').find('ul.widget-control-info li');
51661 var newLi = oldLi.clone();
51662
51663 if ( newLi.html().match( /%i%/ ) ) {
51664 // supplid form is a template, replace %i% by unique id
51665 var i = $('#generated-time').val() + increment.toString();
51666 increment++;
51667 newLi.html( newLi.html().replace( /%i%/g, i ) );
51668 } else {
51669 $(this).text( widgetsL10n.edit ).unbind().click( editClick );
51670 // save form content in textarea so we don't have any conflicting HTML ids
51671 oldLi.html( '<textarea>' + oldLi.html() + '</textarea>' );
51672 }
51673
51674 // add event handlers
51675 addWidgetControls( newLi );
51676
51677 // add widget to sidebar sortable
51678 widgetSortable.append( newLi ).SortableAddItem( newLi[0] );
51679
51680 // increment widget counter
51681 var n = parseInt( $('#widget-count').text(), 10 ) + 1;
51682 $('#widget-count').text( n.toString() )
51683
51684 lameWidgetReminder();
51685 return false;
51686 };
51687
51688 // add event handlers to all links found in context
51689 var addWidgetControls = function( context ) {
51690 if ( !context )
51691 context = document;
51692
51693 $('a.widget-control-edit', context).click( editClick );
51694
51695 // onclick for save links
51696 $('a.widget-control-save', context).click( function() {
51697 lameWidgetReminder();
51698 toggleWidget( $(this).parents('li:first'), false ).blur()
51699 return false;
51700 } );
51701
51702 // onclick for remove links
51703 $('a.widget-control-remove', context).click( function() {
51704 var w = $(this).parents('li:first').find('input[@name^="widget-id"]').val();
51705 $(this).parents('li:first').remove();
51706 var t = $('#widget-list ul#widget-control-info-' + w + ' textarea');
51707 t.parent().html( t.text() ).parents('li.widget-list-item:first').children( 'h4' ).children('a.widget-action')
51708 .show().text( widgetsL10n.add ).unbind().click( addClick );
51709 var n = parseInt( $('#widget-count').text(), 10 ) - 1;
51710 $('#widget-count').text( n.toString() )
51711 return false;
51712 } );
51713 }
51714
51715 addWidgetControls();
51716
51717 $('a.widget-control-add').click( addClick );
51718
51719 var widgetSortable;
51720 var widgetSortableInit = function() {
51721 try { // a hack to make sortables work in jQuery 1.2+ and IE7
51722 $('#current-sidebar .widget-control-list').SortableDestroy();
51723 } catch(e) {}
51724 widgetSortable = $('#current-sidebar .widget-control-list').Sortable( {
51725 accept: 'widget-sortable',
51726 helperclass: 'sorthelper',
51727 handle: 'h4.widget-title',
51728 onStop: widgetSortableInit
51729 } );
51730 }
51731
51732 // initialize sortable
51733 widgetSortableInit();
51734
51735 });