2009-04-11 10:37:24 -04:00
|
|
|
|
|
|
|
var wpWidgets;
|
|
|
|
(function($) {
|
|
|
|
|
|
|
|
wpWidgets = {
|
|
|
|
init : function() {
|
2009-05-09 20:49:48 -04:00
|
|
|
var rem;
|
2009-05-03 01:27:13 -04:00
|
|
|
|
2009-05-03 21:19:10 -04:00
|
|
|
$('#widgets-right div.sidebar-name').click(function(){
|
2009-04-11 10:37:24 -04:00
|
|
|
var c = $(this).siblings('.widgets-sortables');
|
|
|
|
if ( c.is(':visible') ) {
|
2009-05-10 06:33:30 -04:00
|
|
|
c.sortable('disable');
|
2009-05-03 01:27:13 -04:00
|
|
|
$(this).parent().addClass('closed');
|
2009-01-02 10:08:58 -05:00
|
|
|
} else {
|
2009-05-03 01:27:13 -04:00
|
|
|
$(this).parent().removeClass('closed');
|
2009-05-10 06:33:30 -04:00
|
|
|
c.sortable('enable').sortable('refresh');
|
2009-01-02 10:08:58 -05:00
|
|
|
}
|
2009-04-11 10:37:24 -04:00
|
|
|
});
|
2009-05-03 01:27:13 -04:00
|
|
|
|
2009-05-03 21:19:10 -04:00
|
|
|
$('#widgets-left div.sidebar-name').click(function(){
|
2009-05-03 01:27:13 -04:00
|
|
|
if ( $(this).siblings('.widget-holder').is(':visible') ) {
|
|
|
|
$(this).parent().addClass('closed');
|
|
|
|
} else {
|
|
|
|
$(this).parent().removeClass('closed');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2009-05-09 20:49:48 -04:00
|
|
|
$('#widgets-right .widget, #wp_inactive_widgets .widget').each(function(){
|
|
|
|
wpWidgets.appendTitle(this);
|
|
|
|
});
|
2009-05-03 01:27:13 -04:00
|
|
|
|
|
|
|
this.addEvents();
|
2009-04-27 04:46:47 -04:00
|
|
|
$('.widget-error').parents('.widget').find('a.widget-action').click();
|
2009-04-11 10:37:24 -04:00
|
|
|
|
|
|
|
$('#widget-list .widget').draggable({
|
|
|
|
connectToSortable: '.widgets-sortables',
|
|
|
|
handle: '.widget-title',
|
|
|
|
distance: 2,
|
|
|
|
helper: 'clone',
|
2009-04-12 21:17:59 -04:00
|
|
|
zIndex: 5,
|
2009-05-09 20:49:48 -04:00
|
|
|
containment: 'document',
|
2009-05-03 01:27:13 -04:00
|
|
|
start: function(e,ui) {
|
2009-04-11 10:37:24 -04:00
|
|
|
wpWidgets.fixWebkit(1);
|
2009-05-03 01:27:13 -04:00
|
|
|
ui.helper.find('.widget-description').hide();
|
2009-04-11 10:37:24 -04:00
|
|
|
},
|
|
|
|
stop: function(e,ui) {
|
|
|
|
if ( rem )
|
|
|
|
$(rem).hide();
|
|
|
|
rem = '';
|
|
|
|
wpWidgets.fixWebkit();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.widgets-sortables').sortable({
|
|
|
|
placeholder: 'widget-placeholder',
|
|
|
|
connectWith: '.widgets-sortables',
|
|
|
|
items: '.widget',
|
|
|
|
handle: '.widget-title',
|
|
|
|
cursor: 'move',
|
|
|
|
distance: 2,
|
|
|
|
opacity: 0.65,
|
2009-05-09 20:49:48 -04:00
|
|
|
containment: 'document',
|
2009-04-11 10:37:24 -04:00
|
|
|
start: function(e,ui) {
|
|
|
|
wpWidgets.fixWebkit(1);
|
2009-04-12 21:17:59 -04:00
|
|
|
ui.item.find('.widget-inside').hide();
|
|
|
|
ui.item.css({'marginLeft':'','width':''});
|
2009-04-11 10:37:24 -04:00
|
|
|
},
|
|
|
|
stop: function(e,ui) {
|
2009-05-03 01:27:13 -04:00
|
|
|
var add = ui.item.find('input.add_new').val(), n = ui.item.find('input.multi_number').val(), id = ui.item.attr('id'), sb = $(this).attr('id');
|
2009-04-12 21:17:59 -04:00
|
|
|
ui.item.css({'marginLeft':'','width':''});
|
2009-04-13 12:20:58 -04:00
|
|
|
if ( add ) {
|
2009-04-11 10:37:24 -04:00
|
|
|
if ( 'multi' == add ) {
|
2009-05-07 17:58:45 -04:00
|
|
|
ui.item.html( ui.item.html().replace(/<[^<>]+>/g, function(m){ return m.replace(/__i__|%i%/g, n); }) );
|
|
|
|
ui.item.attr( 'id', id.replace(/__i__|%i%/g, n) );
|
2009-04-11 10:37:24 -04:00
|
|
|
n++;
|
2009-05-03 01:27:13 -04:00
|
|
|
$('div#' + id).find('input.multi_number').val(n);
|
2009-04-11 10:37:24 -04:00
|
|
|
} else if ( 'single' == add ) {
|
|
|
|
ui.item.attr( 'id', 'new-' + id );
|
2009-05-03 01:27:13 -04:00
|
|
|
rem = 'div#' + id;
|
2009-04-11 10:37:24 -04:00
|
|
|
}
|
|
|
|
wpWidgets.addEvents(ui.item);
|
2009-05-04 15:33:54 -04:00
|
|
|
wpWidgets.save( ui.item.find('form').serialize(), sb, 0, 0 );
|
2009-04-11 10:37:24 -04:00
|
|
|
ui.item.find('input.add_new').val('');
|
2009-04-13 12:20:58 -04:00
|
|
|
ui.item.find('a.widget-action').click();
|
2009-04-11 10:37:24 -04:00
|
|
|
}
|
|
|
|
wpWidgets.saveOrder(sb);
|
2009-05-09 20:49:48 -04:00
|
|
|
wpWidgets.resize();
|
2009-04-11 10:37:24 -04:00
|
|
|
wpWidgets.fixWebkit();
|
|
|
|
},
|
|
|
|
receive: function(e,ui) {
|
|
|
|
if ( !$(this).is(':visible') )
|
|
|
|
$(this).sortable('cancel');
|
2009-01-02 10:08:58 -05:00
|
|
|
}
|
2009-05-10 06:33:30 -04:00
|
|
|
}).not(':visible').sortable('disable');
|
2009-05-09 20:49:48 -04:00
|
|
|
wpWidgets.resize();
|
2009-04-11 10:37:24 -04:00
|
|
|
},
|
2009-01-02 10:08:58 -05:00
|
|
|
|
2009-04-11 10:37:24 -04:00
|
|
|
saveOrder : function(sb) {
|
2009-05-03 01:27:13 -04:00
|
|
|
$('#' + sb).parents('.widgets-holder-wrap').find('.ajax-feedback').css('visibility', 'visible');
|
2009-04-13 12:20:58 -04:00
|
|
|
|
|
|
|
var a = {
|
2009-04-11 10:37:24 -04:00
|
|
|
action: 'widgets-order',
|
2009-04-13 12:20:58 -04:00
|
|
|
savewidgets: $('#_wpnonce_widgets').val(),
|
|
|
|
sidebars: []
|
2009-04-11 10:37:24 -04:00
|
|
|
};
|
2009-04-13 12:20:58 -04:00
|
|
|
|
2009-04-11 10:37:24 -04:00
|
|
|
$('.widgets-sortables').each( function() {
|
2009-05-03 01:27:13 -04:00
|
|
|
a['sidebars[' + $(this).attr('id') + ']'] = $(this).sortable('toArray').join(',');
|
2009-04-11 10:37:24 -04:00
|
|
|
});
|
2009-04-13 12:20:58 -04:00
|
|
|
|
|
|
|
$.post( ajaxurl, a, function() {
|
2009-04-11 10:37:24 -04:00
|
|
|
$('.ajax-feedback').css('visibility', 'hidden');
|
|
|
|
});
|
2009-04-13 12:20:58 -04:00
|
|
|
},
|
2009-04-12 21:17:59 -04:00
|
|
|
|
2009-04-13 12:20:58 -04:00
|
|
|
save : function(data, sb, del, t) {
|
2009-05-03 01:27:13 -04:00
|
|
|
$('#' + sb).parents('.widgets-holder-wrap').find('.ajax-feedback').css('visibility', 'visible');
|
2009-04-11 10:37:24 -04:00
|
|
|
|
2009-04-13 12:20:58 -04:00
|
|
|
var a = {
|
2009-04-11 10:37:24 -04:00
|
|
|
action: 'save-widget',
|
|
|
|
savewidgets: $('#_wpnonce_widgets').val(),
|
|
|
|
sidebar: sb
|
|
|
|
};
|
|
|
|
|
|
|
|
if ( del )
|
|
|
|
a['delete_widget'] = 1;
|
|
|
|
|
2009-05-03 19:17:47 -04:00
|
|
|
data += '&' + $.param(a);
|
2009-04-11 10:37:24 -04:00
|
|
|
|
2009-05-03 19:17:47 -04:00
|
|
|
$.post( ajaxurl, data, function(r){
|
2009-05-09 20:49:48 -04:00
|
|
|
var id, widget;
|
2009-04-11 10:37:24 -04:00
|
|
|
$('.ajax-feedback').css('visibility', 'hidden');
|
|
|
|
if ( !t )
|
|
|
|
return;
|
|
|
|
|
2009-05-09 20:49:48 -04:00
|
|
|
widget = $(t).parents('.widget');
|
|
|
|
|
2009-04-11 10:37:24 -04:00
|
|
|
if ( del ) {
|
2009-05-09 20:49:48 -04:00
|
|
|
widget.slideUp('normal', function(){
|
|
|
|
$(this).remove();
|
|
|
|
wpWidgets.resize();
|
|
|
|
});
|
|
|
|
if ( !$('.widget_number', widget).val() ) {
|
|
|
|
id = $('.widget-id', widget).val();
|
2009-04-11 10:37:24 -04:00
|
|
|
$('#available-widgets .widget-id').each(function(){
|
|
|
|
if ( $(this).val() == id )
|
2009-05-03 01:27:13 -04:00
|
|
|
$(this).parents('.widget').show();
|
2009-04-11 10:37:24 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
2009-05-09 20:49:48 -04:00
|
|
|
$(t).parents('.widget-inside').slideUp('normal', function(){
|
|
|
|
widget.css({'width':'','marginLeft':''});
|
|
|
|
wpWidgets.appendTitle(widget);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
appendTitle : function(widget) {
|
|
|
|
$('input[type="text"]', widget).each(function(){
|
|
|
|
if ( this.id.indexOf('title') != -1 && $(this).val() ) {
|
|
|
|
$('.widget-title .in-widget-title', widget).html(': ' + $(this).val());
|
|
|
|
return false;
|
2009-04-11 10:37:24 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2009-05-09 20:49:48 -04:00
|
|
|
resize : function() {
|
|
|
|
$('.widgets-sortables').not('#wp_inactive_widgets').each(function(){
|
|
|
|
var h = 50, H = $('.widget', this).length;
|
|
|
|
h = h + parseInt(H * 48, 10);
|
|
|
|
$(this).css( 'minHeight', h + 'px' );
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2009-04-11 10:37:24 -04:00
|
|
|
fixWebkit : function(n) {
|
|
|
|
n = n ? 'none' : '';
|
|
|
|
$('body').css({
|
2009-04-12 21:17:59 -04:00
|
|
|
WebkitUserSelect: n,
|
|
|
|
KhtmlUserSelect: n
|
2009-04-11 10:37:24 -04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
addEvents : function(sc) {
|
|
|
|
sc = sc || document;
|
|
|
|
$('a.widget-action', sc).click(function(){
|
2009-04-12 21:17:59 -04:00
|
|
|
var w = parseInt( $(this).parents('.widget').find('.widget-width').val(), 10 ), css = {}, inside = $(this).parents('.widget-top').siblings('.widget-inside');
|
|
|
|
if ( inside.is(':hidden') ) {
|
2009-05-03 01:27:13 -04:00
|
|
|
if ( w > 250 && inside.parents('.widgets-sortables').length ) {
|
2009-04-12 21:17:59 -04:00
|
|
|
css['width'] = w + 30 + 'px';
|
|
|
|
if ( inside.parents('.widget-liquid-right').length )
|
2009-05-09 20:49:48 -04:00
|
|
|
css['marginLeft'] = 235 - w + 'px';
|
2009-04-13 12:20:58 -04:00
|
|
|
inside.parents('.widget').css(css);
|
2009-04-12 21:17:59 -04:00
|
|
|
}
|
2009-04-13 12:20:58 -04:00
|
|
|
inside.slideDown('normal');
|
2009-04-12 21:17:59 -04:00
|
|
|
} else {
|
2009-04-13 12:20:58 -04:00
|
|
|
inside.slideUp('normal', function(){ inside.parents('.widget').css({'width':'','marginLeft':''}); });
|
2009-04-12 21:17:59 -04:00
|
|
|
}
|
2009-04-11 10:37:24 -04:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
$('.widget-control-save', sc).click(function(){
|
2009-05-03 19:17:47 -04:00
|
|
|
wpWidgets.save( $(this).parents('form').serialize(), $(this).parents('.widgets-sortables').attr('id'), 0, this );
|
2009-01-02 10:08:58 -05:00
|
|
|
return false;
|
2009-04-11 10:37:24 -04:00
|
|
|
});
|
|
|
|
$('.widget-control-remove', sc).click(function(){
|
2009-05-03 19:17:47 -04:00
|
|
|
wpWidgets.save( $(this).parents('form').serialize(), $(this).parents('.widgets-sortables').attr('id'), 1, this );
|
2009-01-02 10:08:58 -05:00
|
|
|
return false;
|
2009-04-11 10:37:24 -04:00
|
|
|
});
|
2009-01-02 10:08:58 -05:00
|
|
|
}
|
|
|
|
|
2009-04-11 10:37:24 -04:00
|
|
|
};
|
2009-04-13 12:20:58 -04:00
|
|
|
$(document).ready(function(){wpWidgets.init();});
|
2009-01-02 10:08:58 -05:00
|
|
|
|
2009-04-11 10:37:24 -04:00
|
|
|
})(jQuery);
|