-jQuery(function($) {
- $('.noscript-action').remove();
-
- var increment = 1;
-
- // Open or close widget control form
- var toggleWidget = function( li, disableFields ) {
- var width = li.find('input.widget-width').val();
-
- // it seems IE chokes on these animations because of the positioning/floating
- var widgetAnim = $.browser.msie ? function() {
- var t = $(this);
- if ( t.is(':visible') ) {
- if ( disableFields ) { t.find( ':input:enabled' ).not( '[name="widget-id[]"], [name*="[submit]"]' ).attr( 'disabled', 'disabled' ); }
- li.css( 'marginLeft', 0 );
- t.siblings('h4').children('a').text( widgetsL10n.edit );
- } else {
- t.find( ':disabled' ).attr( 'disabled', '' ); // always enable on open
- if ( width > 250 )
- li.css( 'marginLeft', ( width - 250 ) * -1 );
- t.siblings('h4').children('a').text( widgetsL10n.cancel );
- }
- t.toggle();
- } : function() {
- var t = $(this);
-
- if ( t.is(':visible') ) {
- if ( disableFields ) { t.find( ':input:enabled' ).not( '[name="widget-id[]"], [name*="[submit]"]' ).attr( 'disabled', 'disabled' ); }
- if ( width > 250 )
- li.animate( { marginLeft: 0 } );
- t.siblings('h4').children('a').text( widgetsL10n.edit );
- } else {
- t.find( ':disabled' ).attr( 'disabled', '' ); // always enable on open
- if ( width > 250 )
- li.animate( { marginLeft: ( width - 250 ) * -1 } );
- t.siblings('h4').children('a').text( widgetsL10n.cancel );
- }
- t.animate( { height: 'toggle' } );
- };
-
- return li.children('div.widget-control').each( widgetAnim ).end();
- };
-
- // onclick for edit/cancel links
- var editClick = function() {
- var q = wpAjax.unserialize( this.href );
- // if link is in available widgets list, make sure it points to the current sidebar
- if ( ( q.sidebar && q.sidebar == $('#sidebar').val() ) || q.add ) {
- var w = q.edit || q.add;
- toggleWidget( $('#current-sidebar .widget-control-list input[@name^="widget-id"][@value=' + w + ']').parents('li:first'), false ).blur();
- return false;
- } else if ( q.sidebar ) { // otherwise, redirect to correct page
- return true;
- }
-
- // If link is in current widgets list, just open the form
- toggleWidget( $(this).parents('li:first'), true ).blur();
- return false;
- };
-
- // onclick for add links
- var addClick = function() {
- var oldLi = $(this).parents('li:first').find('ul.widget-control-info li');
- var newLi = oldLi.clone();
-
- if ( newLi.html().match( /%i%/ ) ) {
- // supplid form is a template, replace %i% by unique id
- var i = $('#generated-time').val() + increment.toString();
- increment++;
- newLi.html( newLi.html().replace( /%i%/g, i ) );
- } else {
- $(this).text( widgetsL10n.edit ).unbind().click( editClick );
- // save form content in textarea so we don't have any conflicting HTML ids
- oldLi.html( '<textarea>' + oldLi.html() + '</textarea>' );
- }
-
- // add event handlers
- addWidgetControls( newLi );
-
- // add widget to sidebar sortable
- widgetSortable.append( newLi ).SortableAddItem( newLi[0] );
-
- // increment widget counter
- var n = parseInt( $('#widget-count').text(), 10 ) + 1;
- $('#widget-count').text( n.toString() )
-
- return false;
- };
-
- // add event handlers to all links found in context
- var addWidgetControls = function( context ) {
- if ( !context )
- context = document;
-
- $('a.widget-control-edit', context).click( editClick );
-
- // onclick for save links
- $('a.widget-control-save', context).click( function() {
- toggleWidget( $(this).parents('li:first'), false ).blur()
- return false;
- } );
-
- // onclick for remove links
- $('a.widget-control-remove', context).click( function() {
- var w = $(this).parents('li:first').find('input[@name^="widget-id"]').val();
- $(this).parents('li:first').remove();
- var t = $('#widget-list ul#widget-control-info-' + w + ' textarea');
- t.parent().html( t.text() ).parents('li.widget-list-item:first').children( 'h4' ).children('a.widget-action')
- .show().text( widgetsL10n.add ).unbind().click( addClick );
- var n = parseInt( $('#widget-count').text(), 10 ) - 1;
- $('#widget-count').text( n.toString() )
- return false;
- } );
- }
-
- addWidgetControls();
-
- $('a.widget-control-add').click( addClick );
-
- var widgetSortable;
- var widgetSortableInit = function() {
- try { // a hack to make sortables work in jQuery 1.2+ and IE7
- $('#current-sidebar .widget-control-list').SortableDestroy();
- } catch(e) {}
- widgetSortable = $('#current-sidebar .widget-control-list').Sortable( {
- accept: 'widget-sortable',
- helperclass: 'sorthelper',
- handle: 'h4.widget-title',
- onStop: widgetSortableInit
- } );
- }
-
- // initialize sortable
- widgetSortableInit();
-
-});
+var wpWidgets;(function(a){wpWidgets={init:function(){var b;if(a("body").hasClass("widgets_access")){return}a("#widgets-right div.sidebar-name").click(function(){var d=a(this).siblings(".widgets-sortables");if(d.is(":visible")){d.sortable("disable");a(this).parent().addClass("closed")}else{a(this).parent().removeClass("closed");d.sortable("enable").sortable("refresh")}});a("#widgets-left div.sidebar-name").click(function(){if(a(this).siblings(".widget-holder").is(":visible")){a(this).parent().addClass("closed")}else{a(this).parent().removeClass("closed")}});a("#widgets-right .widget, #wp_inactive_widgets .widget").each(function(){wpWidgets.appendTitle(this)});this.addEvents();a(".widget-error").parents(".widget").find("a.widget-action").click();a("#available-widgets").droppable({tolerance:"pointer",accept:function(c){return a(c).parent().attr("id")!="widget-list"},drop:function(d,c){c.draggable.addClass("deleting");a("#removing-widget").hide().children("span").html("")},over:function(d,c){c.draggable.addClass("deleting");a(".widget-placeholder").hide();if(c.draggable.hasClass("ui-sortable-helper")){a("#removing-widget").show().children("span").html(c.draggable.find(".widget-title h4").html())}},out:function(d,c){c.draggable.removeClass("deleting");a(".widget-placeholder").show();a("#removing-widget").hide().children("span").html("")}});a("#widget-list .widget").draggable({connectToSortable:".widgets-sortables",handle:".widget-title",distance:2,helper:"clone",zIndex:5,containment:"document",start:function(d,c){wpWidgets.fixWebkit(1);c.helper.find(".widget-description").hide()},stop:function(d,c){if(b){a(b).hide()}b="";wpWidgets.fixWebkit()}});a(".widgets-sortables").sortable({placeholder:"widget-placeholder",connectWith:".widgets-sortables",items:".widget",handle:".widget-title",cursor:"move",distance:2,containment:"document",start:function(d,c){wpWidgets.fixWebkit(1);c.item.find(".widget-inside").hide();c.item.css({marginLeft:"",width:""})},stop:function(f,c){if(c.item.hasClass("ui-draggable")){c.item.draggable("destroy")}if(c.item.hasClass("deleting")){wpWidgets.save(c.item,1,0,1);c.item.remove();return}var d=c.item.find("input.add_new").val(),i=c.item.find("input.multi_number").val(),h=c.item.attr("id"),g=a(this).attr("id");c.item.css({marginLeft:"",width:""});wpWidgets.fixWebkit();if(d){if("multi"==d){c.item.html(c.item.html().replace(/<[^<>]+>/g,function(e){return e.replace(/__i__|%i%/g,i)}));c.item.attr("id",h.replace(/__i__|%i%/g,i));i++;a("div#"+h).find("input.multi_number").val(i)}else{if("single"==d){c.item.attr("id","new-"+h);b="div#"+h}}wpWidgets.addEvents(c.item);wpWidgets.save(c.item,0,0,1);c.item.find("input.add_new").val("");c.item.find("a.widget-action").click();return}wpWidgets.saveOrder(g)},receive:function(d,c){if(!a(this).is(":visible")){a(this).sortable("cancel")}}}).not(":visible").sortable("disable");wpWidgets.resize();wpWidgets.fixLabels()},saveOrder:function(c){if(c){a("#"+c).parents(".widgets-holder-wrap").find(".ajax-feedback").css("visibility","visible")}var b={action:"widgets-order",savewidgets:a("#_wpnonce_widgets").val(),sidebars:[]};a(".widgets-sortables").each(function(){b["sidebars["+a(this).attr("id")+"]"]=a(this).sortable("toArray").join(",")});a.post(ajaxurl,b,function(){a(".ajax-feedback").css("visibility","hidden")});this.resize()},save:function(g,d,e,b){var h=g.parents(".widgets-sortables").attr("id"),f=g.find("form").serialize(),c;g=a(g);g.find(".ajax-feedback").css("visibility","visible");c={action:"save-widget",savewidgets:a("#_wpnonce_widgets").val(),sidebar:h};if(d){c.delete_widget=1}f+="&"+a.param(c);a.post(ajaxurl,f,function(i){var j;if(d){if(!a(".widget_number",g).val()){j=a(".widget-id",g).val();a("#available-widgets .widget-id").each(function(){if(a(this).val()==j){a(this).parents(".widget").show()}})}if(e){b=0;g.slideUp("fast",function(){a(this).remove();wpWidgets.saveOrder()})}else{g.remove();wpWidgets.resize()}}else{a(".ajax-feedback").css("visibility","hidden");if(i&&i.length>2){a(".widget-content",g).html(i);wpWidgets.appendTitle(g);wpWidgets.fixLabels(g)}}if(b){wpWidgets.saveOrder()}})},appendTitle:function(b){a('input[type="text"]',b).each(function(){var c;if(this.id.indexOf("title")!=-1){c=a(this).val().replace(/<[^<>]+>/g,"").replace(/</g,"<").replace(/>/g,">");if(c){a(".widget-title .in-widget-title",b).html(": "+c)}return false}})},resize:function(){a(".widgets-sortables").not("#wp_inactive_widgets").each(function(){var c=50,b=a(".widget",this).length;c=c+parseInt(b*48,10);a(this).css("minHeight",c+"px")})},fixWebkit:function(b){b=b?"none":"";a("body").css({WebkitUserSelect:b,KhtmlUserSelect:b})},fixLabels:function(b){b=b||document;a(".widget-inside label",b).each(function(){var c=a(this).attr("for");if(c&&c==a("input",this).attr("id")){a(this).removeAttr("for")}})},close:function(b){b.find(".widget-inside").slideUp("fast",function(){b.css({width:"",marginLeft:""})})},addEvents:function(b){b=b||document;a("a.widget-action",b).click(function(){var d=parseInt(a(this).parents(".widget").find(".widget-width").val(),10),e={},c=a(this).parents(".widget-top").siblings(".widget-inside");if(c.is(":hidden")){if(d>250&&c.parents(".widgets-sortables").length){e.width=d+30+"px";if(c.parents(".widget-liquid-right").length){e.marginLeft=235-d+"px"}c.parents(".widget").css(e)}c.slideDown("fast")}else{c.slideUp("fast",function(){c.parents(".widget").css({width:"",marginLeft:""})})}return false});a(".widget-control-save",b).click(function(){wpWidgets.save(a(this).parents(".widget"),0,1,0);return false});a(".widget-control-remove",b).click(function(){wpWidgets.save(a(this).parents(".widget"),1,1,0);return false});a(".widget-control-close",b).click(function(){wpWidgets.close(a(this).parents(".widget"));return false})}};a(document).ready(function(){wpWidgets.init()})})(jQuery);
\ No newline at end of file