2009-04-11 16:37:24 +02:00
|
|
|
|
|
|
|
var wpWidgets;
|
|
|
|
(function($) {
|
|
|
|
|
|
|
|
wpWidgets = {
|
|
|
|
init : function() {
|
|
|
|
var rem;
|
|
|
|
$('h3.sidebar-name').click(function(){
|
|
|
|
var c = $(this).siblings('.widgets-sortables');
|
|
|
|
if ( c.is(':visible') ) {
|
|
|
|
c.hide().sortable('disable');
|
2009-01-02 16:08:58 +01:00
|
|
|
} else {
|
2009-04-11 16:37:24 +02:00
|
|
|
c.show().sortable('enable').sortable('refresh');
|
2009-01-02 16:08:58 +01:00
|
|
|
}
|
2009-04-11 16:37:24 +02:00
|
|
|
$(this).siblings('#widget-list').toggle();
|
|
|
|
});
|
|
|
|
this.addEvents();
|
|
|
|
|
|
|
|
$('#widget-list .widget').draggable({
|
|
|
|
connectToSortable: '.widgets-sortables',
|
|
|
|
handle: '.widget-title',
|
|
|
|
distance: 2,
|
|
|
|
helper: 'clone',
|
2009-04-13 03:17:59 +02:00
|
|
|
zIndex: 5,
|
2009-04-11 16:37:24 +02:00
|
|
|
start: function() {
|
|
|
|
wpWidgets.fixWebkit(1);
|
|
|
|
},
|
|
|
|
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,
|
|
|
|
start: function(e,ui) {
|
|
|
|
wpWidgets.fixWebkit(1);
|
2009-04-13 03:17:59 +02:00
|
|
|
ui.item.find('.widget-inside').hide();
|
|
|
|
ui.item.css({'marginLeft':'','width':''});
|
2009-04-11 16:37:24 +02:00
|
|
|
},
|
|
|
|
stop: function(e,ui) {
|
|
|
|
var add = ui.item.find('input.add_new').val(), n = ui.item.find('input.multi_number').val(), id = ui.item.attr('id'), sb = $(this).parent().attr('id');
|
2009-04-13 03:17:59 +02:00
|
|
|
ui.item.css({'marginLeft':'','width':''});
|
2009-04-11 16:37:24 +02:00
|
|
|
|
2009-04-13 18:20:58 +02:00
|
|
|
if ( add ) {
|
2009-04-11 16:37:24 +02:00
|
|
|
if ( 'multi' == add ) {
|
|
|
|
ui.item.html( ui.item.html().replace(/<[^<>]+>/g, function(m){ return m.replace(/__i__/g, n); }) );
|
|
|
|
ui.item.attr( 'id', id.replace(/__i__/g, n) );
|
|
|
|
n++;
|
|
|
|
$('li#' + id).find('input.multi_number').val(n);
|
|
|
|
} else if ( 'single' == add ) {
|
|
|
|
ui.item.attr( 'id', 'new-' + id );
|
|
|
|
rem = 'li#' + id;
|
|
|
|
}
|
|
|
|
wpWidgets.addEvents(ui.item);
|
2009-04-13 18:20:58 +02:00
|
|
|
wpWidgets.save( ui.item.find('form').serializeArray(), sb, 0, 0 );
|
2009-04-11 16:37:24 +02:00
|
|
|
ui.item.find('input.add_new').val('');
|
2009-04-13 18:20:58 +02:00
|
|
|
ui.item.find('a.widget-action').click();
|
2009-04-11 16:37:24 +02:00
|
|
|
}
|
|
|
|
wpWidgets.saveOrder(sb);
|
|
|
|
wpWidgets.fixWebkit();
|
|
|
|
},
|
|
|
|
receive: function(e,ui) {
|
|
|
|
if ( !$(this).is(':visible') )
|
|
|
|
$(this).sortable('cancel');
|
2009-01-02 16:08:58 +01:00
|
|
|
}
|
|
|
|
|
2009-04-11 16:37:24 +02:00
|
|
|
}).not(':visible').sortable('disable');
|
|
|
|
},
|
2009-01-02 16:08:58 +01:00
|
|
|
|
2009-04-11 16:37:24 +02:00
|
|
|
saveOrder : function(sb) {
|
2009-04-13 18:20:58 +02:00
|
|
|
$('#' + sb + ' .ajax-feedback').css('visibility', 'visible');
|
|
|
|
|
|
|
|
var a = {
|
2009-04-11 16:37:24 +02:00
|
|
|
action: 'widgets-order',
|
2009-04-13 18:20:58 +02:00
|
|
|
savewidgets: $('#_wpnonce_widgets').val(),
|
|
|
|
sidebars: []
|
2009-04-11 16:37:24 +02:00
|
|
|
};
|
2009-04-13 18:20:58 +02:00
|
|
|
|
2009-04-11 16:37:24 +02:00
|
|
|
$('.widgets-sortables').each( function() {
|
2009-04-13 18:20:58 +02:00
|
|
|
a['sidebars[' + $(this).parent().attr('id') + ']'] = $(this).sortable('toArray').join(',');
|
2009-04-11 16:37:24 +02:00
|
|
|
});
|
2009-04-13 18:20:58 +02:00
|
|
|
|
|
|
|
$.post( ajaxurl, a, function() {
|
2009-04-11 16:37:24 +02:00
|
|
|
$('.ajax-feedback').css('visibility', 'hidden');
|
|
|
|
});
|
2009-04-13 18:20:58 +02:00
|
|
|
},
|
2009-04-13 03:17:59 +02:00
|
|
|
|
2009-04-13 18:20:58 +02:00
|
|
|
save : function(data, sb, del, t) {
|
2009-04-11 16:37:24 +02:00
|
|
|
$('#' + sb + ' .ajax-feedback').css('visibility', 'visible');
|
|
|
|
|
2009-04-13 18:20:58 +02:00
|
|
|
var a = {
|
2009-04-11 16:37:24 +02:00
|
|
|
action: 'save-widget',
|
|
|
|
savewidgets: $('#_wpnonce_widgets').val(),
|
|
|
|
sidebar: sb
|
|
|
|
};
|
|
|
|
|
|
|
|
if ( del )
|
|
|
|
a['delete_widget'] = 1;
|
|
|
|
|
|
|
|
$.map(data, function(n,i){ a[n.name] = n.value; });
|
|
|
|
|
|
|
|
$.post( ajaxurl, a, function(r){
|
|
|
|
var id;
|
|
|
|
$('.ajax-feedback').css('visibility', 'hidden');
|
|
|
|
if ( !t )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( del ) {
|
2009-04-13 18:20:58 +02:00
|
|
|
$(t).parents('li.widget').slideUp('normal', function(){ $(this).remove(); });
|
2009-04-11 16:37:24 +02:00
|
|
|
if ( !a.widget_number ) {
|
|
|
|
id = a['widget-id'];
|
|
|
|
$('#available-widgets .widget-id').each(function(){
|
|
|
|
if ( $(this).val() == id )
|
|
|
|
$(this).parents('li.widget').show();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
2009-04-13 19:08:13 +02:00
|
|
|
$(t).parents('.widget-inside').slideUp('normal', function(){ $(this).parents('li.widget').css({'width':'','marginLeft':''}); });
|
2009-04-11 16:37:24 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
fixWebkit : function(n) {
|
|
|
|
n = n ? 'none' : '';
|
|
|
|
$('body').css({
|
2009-04-13 03:17:59 +02:00
|
|
|
WebkitUserSelect: n,
|
|
|
|
KhtmlUserSelect: n
|
2009-04-11 16:37:24 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
addEvents : function(sc) {
|
|
|
|
sc = sc || document;
|
|
|
|
$('a.widget-action', sc).click(function(){
|
2009-04-13 03:17:59 +02: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') ) {
|
|
|
|
if ( w > 270 && inside.parents('.widgets-sortables').length ) {
|
|
|
|
css['width'] = w + 30 + 'px';
|
|
|
|
if ( inside.parents('.widget-liquid-right').length )
|
|
|
|
css['marginLeft'] = 270 - w + 'px';
|
2009-04-13 18:20:58 +02:00
|
|
|
inside.parents('.widget').css(css);
|
2009-04-13 03:17:59 +02:00
|
|
|
}
|
2009-04-13 18:20:58 +02:00
|
|
|
inside.slideDown('normal');
|
2009-04-13 03:17:59 +02:00
|
|
|
} else {
|
2009-04-13 18:20:58 +02:00
|
|
|
inside.slideUp('normal', function(){ inside.parents('.widget').css({'width':'','marginLeft':''}); });
|
2009-04-13 03:17:59 +02:00
|
|
|
}
|
2009-04-11 16:37:24 +02:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
$('.widget-control-save', sc).click(function(){
|
|
|
|
wpWidgets.save( $(this).parents('form').serializeArray(), $(this).parents('.widgets-holder-wrap').attr('id'), 0, this );
|
2009-01-02 16:08:58 +01:00
|
|
|
return false;
|
2009-04-11 16:37:24 +02:00
|
|
|
});
|
|
|
|
$('.widget-control-remove', sc).click(function(){
|
|
|
|
wpWidgets.save( $(this).parents('form').serializeArray(), $(this).parents('.widgets-holder-wrap').attr('id'), 1, this );
|
2009-01-02 16:08:58 +01:00
|
|
|
return false;
|
2009-04-11 16:37:24 +02:00
|
|
|
});
|
2009-01-02 16:08:58 +01:00
|
|
|
}
|
|
|
|
|
2009-04-11 16:37:24 +02:00
|
|
|
};
|
2009-04-13 18:20:58 +02:00
|
|
|
$(document).ready(function(){wpWidgets.init();});
|
2009-01-02 16:08:58 +01:00
|
|
|
|
2009-04-11 16:37:24 +02:00
|
|
|
})(jQuery);
|