2009-04-11 16:37:24 +02:00
|
|
|
|
|
|
|
var wpWidgets;
|
|
|
|
(function($) {
|
|
|
|
|
|
|
|
wpWidgets = {
|
|
|
|
init : function() {
|
2009-05-10 02:49:48 +02:00
|
|
|
var rem;
|
2009-05-03 07:27:13 +02:00
|
|
|
|
2009-06-02 01:31:34 +02:00
|
|
|
if ( $('body').hasClass('widgets_access') ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-04 03:19:10 +02:00
|
|
|
$('#widgets-right div.sidebar-name').click(function(){
|
2009-04-11 16:37:24 +02:00
|
|
|
var c = $(this).siblings('.widgets-sortables');
|
|
|
|
if ( c.is(':visible') ) {
|
2009-05-10 12:33:30 +02:00
|
|
|
c.sortable('disable');
|
2009-05-03 07:27:13 +02:00
|
|
|
$(this).parent().addClass('closed');
|
2009-01-02 16:08:58 +01:00
|
|
|
} else {
|
2009-05-03 07:27:13 +02:00
|
|
|
$(this).parent().removeClass('closed');
|
2009-05-10 12:33:30 +02:00
|
|
|
c.sortable('enable').sortable('refresh');
|
2009-01-02 16:08:58 +01:00
|
|
|
}
|
2009-04-11 16:37:24 +02:00
|
|
|
});
|
2009-05-22 18:13:05 +02:00
|
|
|
|
2009-05-04 03:19:10 +02:00
|
|
|
$('#widgets-left div.sidebar-name').click(function(){
|
2009-05-03 07:27:13 +02:00
|
|
|
if ( $(this).siblings('.widget-holder').is(':visible') ) {
|
|
|
|
$(this).parent().addClass('closed');
|
|
|
|
} else {
|
|
|
|
$(this).parent().removeClass('closed');
|
|
|
|
}
|
|
|
|
});
|
2009-05-22 18:13:05 +02:00
|
|
|
|
2009-05-10 02:49:48 +02:00
|
|
|
$('#widgets-right .widget, #wp_inactive_widgets .widget').each(function(){
|
|
|
|
wpWidgets.appendTitle(this);
|
|
|
|
});
|
2009-05-22 18:13:05 +02:00
|
|
|
|
2009-05-03 07:27:13 +02:00
|
|
|
this.addEvents();
|
2009-04-27 10:46:47 +02:00
|
|
|
$('.widget-error').parents('.widget').find('a.widget-action').click();
|
2009-04-11 16:37:24 +02:00
|
|
|
|
2009-05-24 17:46:09 +02:00
|
|
|
$('#available-widgets').droppable({
|
|
|
|
tolerance: 'pointer',
|
|
|
|
accept: function(o){
|
|
|
|
return $(o).parent().attr('id') != 'widget-list';
|
|
|
|
},
|
|
|
|
drop: function(e,ui) {
|
|
|
|
ui.draggable.addClass('deleting');
|
|
|
|
$('#removing-widget').hide().children('span').html('');
|
|
|
|
},
|
|
|
|
over: function(e,ui) {
|
|
|
|
ui.draggable.addClass('deleting');
|
|
|
|
$('.widget-placeholder').hide();
|
|
|
|
|
|
|
|
if ( ui.draggable.hasClass('ui-sortable-helper') )
|
|
|
|
$('#removing-widget').show().children('span').html( ui.draggable.find('.widget-title h4').html() );
|
|
|
|
},
|
|
|
|
out: function(e,ui) {
|
|
|
|
ui.draggable.removeClass('deleting');
|
|
|
|
$('.widget-placeholder').show();
|
|
|
|
$('#removing-widget').hide().children('span').html('');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#widget-list .widget').draggable({
|
2009-04-11 16:37:24 +02:00
|
|
|
connectToSortable: '.widgets-sortables',
|
|
|
|
handle: '.widget-title',
|
|
|
|
distance: 2,
|
|
|
|
helper: 'clone',
|
2009-04-13 03:17:59 +02:00
|
|
|
zIndex: 5,
|
2009-05-10 02:49:48 +02:00
|
|
|
containment: 'document',
|
2009-05-03 07:27:13 +02:00
|
|
|
start: function(e,ui) {
|
2009-04-11 16:37:24 +02:00
|
|
|
wpWidgets.fixWebkit(1);
|
2009-05-03 07:27:13 +02:00
|
|
|
ui.helper.find('.widget-description').hide();
|
2009-04-11 16:37:24 +02: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,
|
2009-05-10 02:49:48 +02:00
|
|
|
containment: 'document',
|
2009-04-11 16:37:24 +02:00
|
|
|
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) {
|
2009-05-24 17:46:09 +02:00
|
|
|
if ( ui.item.hasClass('ui-draggable') )
|
|
|
|
ui.item.draggable('destroy');
|
|
|
|
|
|
|
|
if ( ui.item.hasClass('deleting') ) {
|
2009-05-31 13:34:08 +02:00
|
|
|
wpWidgets.save( ui.item, 1, 0, 1 ); // delete widget
|
2009-05-24 17:46:09 +02:00
|
|
|
ui.item.remove();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-03 07:27:13 +02: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-05-24 17:46:09 +02:00
|
|
|
|
2009-04-13 03:17:59 +02:00
|
|
|
ui.item.css({'marginLeft':'','width':''});
|
2009-05-24 17:46:09 +02:00
|
|
|
wpWidgets.fixWebkit();
|
2009-04-13 18:20:58 +02:00
|
|
|
if ( add ) {
|
2009-04-11 16:37:24 +02:00
|
|
|
if ( 'multi' == add ) {
|
2009-05-07 23:58:45 +02: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 16:37:24 +02:00
|
|
|
n++;
|
2009-05-03 07:27:13 +02:00
|
|
|
$('div#' + id).find('input.multi_number').val(n);
|
2009-04-11 16:37:24 +02:00
|
|
|
} else if ( 'single' == add ) {
|
|
|
|
ui.item.attr( 'id', 'new-' + id );
|
2009-05-03 07:27:13 +02:00
|
|
|
rem = 'div#' + id;
|
2009-04-11 16:37:24 +02:00
|
|
|
}
|
|
|
|
wpWidgets.addEvents(ui.item);
|
2009-05-31 13:34:08 +02:00
|
|
|
wpWidgets.save( ui.item, 0, 0, 1 );
|
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-05-24 17:46:09 +02:00
|
|
|
return;
|
2009-04-11 16:37:24 +02:00
|
|
|
}
|
|
|
|
wpWidgets.saveOrder(sb);
|
|
|
|
},
|
|
|
|
receive: function(e,ui) {
|
|
|
|
if ( !$(this).is(':visible') )
|
|
|
|
$(this).sortable('cancel');
|
2009-01-02 16:08:58 +01:00
|
|
|
}
|
2009-05-10 12:33:30 +02:00
|
|
|
}).not(':visible').sortable('disable');
|
2009-05-10 02:49:48 +02:00
|
|
|
wpWidgets.resize();
|
2009-05-31 13:34:08 +02:00
|
|
|
wpWidgets.fixLabels();
|
2009-04-11 16:37:24 +02:00
|
|
|
},
|
2009-01-02 16:08:58 +01:00
|
|
|
|
2009-04-11 16:37:24 +02:00
|
|
|
saveOrder : function(sb) {
|
2009-05-24 17:46:09 +02:00
|
|
|
if ( sb )
|
|
|
|
$('#' + sb).parents('.widgets-holder-wrap').find('.ajax-feedback').css('visibility', 'visible');
|
2009-04-13 18:20:58 +02:00
|
|
|
|
|
|
|
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-05-03 07:27:13 +02:00
|
|
|
a['sidebars[' + $(this).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-05-24 17:46:09 +02:00
|
|
|
this.resize();
|
2009-04-13 18:20:58 +02:00
|
|
|
},
|
2009-04-13 03:17:59 +02:00
|
|
|
|
2009-05-31 13:34:08 +02:00
|
|
|
save : function(widget, del, animate, order) {
|
2009-05-24 17:46:09 +02:00
|
|
|
var sb = widget.parents('.widgets-sortables').attr('id'), data = widget.find('form').serialize(), a;
|
|
|
|
widget = $(widget);
|
2009-05-31 13:34:08 +02:00
|
|
|
widget.find('.ajax-feedback').css('visibility', 'visible');
|
2009-04-11 16:37:24 +02:00
|
|
|
|
2009-05-24 17:46:09 +02:00
|
|
|
a = {
|
2009-04-11 16:37:24 +02:00
|
|
|
action: 'save-widget',
|
|
|
|
savewidgets: $('#_wpnonce_widgets').val(),
|
|
|
|
sidebar: sb
|
|
|
|
};
|
|
|
|
|
|
|
|
if ( del )
|
|
|
|
a['delete_widget'] = 1;
|
|
|
|
|
2009-05-04 01:17:47 +02:00
|
|
|
data += '&' + $.param(a);
|
2009-04-11 16:37:24 +02:00
|
|
|
|
2009-05-04 01:17:47 +02:00
|
|
|
$.post( ajaxurl, data, function(r){
|
2009-05-24 17:46:09 +02:00
|
|
|
var id;
|
2009-05-10 02:49:48 +02:00
|
|
|
|
2009-04-11 16:37:24 +02:00
|
|
|
if ( del ) {
|
2009-05-10 02:49:48 +02:00
|
|
|
if ( !$('.widget_number', widget).val() ) {
|
|
|
|
id = $('.widget-id', widget).val();
|
2009-04-11 16:37:24 +02:00
|
|
|
$('#available-widgets .widget-id').each(function(){
|
|
|
|
if ( $(this).val() == id )
|
2009-05-03 07:27:13 +02:00
|
|
|
$(this).parents('.widget').show();
|
2009-04-11 16:37:24 +02:00
|
|
|
});
|
|
|
|
}
|
2009-05-24 17:46:09 +02:00
|
|
|
|
|
|
|
if ( animate ) {
|
|
|
|
order = 0;
|
|
|
|
widget.slideUp('fast', function(){
|
|
|
|
$(this).remove();
|
|
|
|
wpWidgets.saveOrder();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
widget.remove();
|
|
|
|
wpWidgets.resize();
|
|
|
|
}
|
2009-05-31 13:34:08 +02:00
|
|
|
} else {
|
|
|
|
$('.ajax-feedback').css('visibility', 'hidden');
|
|
|
|
if ( r && r.length > 2 ) {
|
|
|
|
$('.widget-content', widget).html(r);
|
2009-05-10 02:49:48 +02:00
|
|
|
wpWidgets.appendTitle(widget);
|
2009-05-31 13:34:08 +02:00
|
|
|
wpWidgets.fixLabels(widget);
|
|
|
|
}
|
2009-05-10 02:49:48 +02:00
|
|
|
}
|
2009-05-24 17:46:09 +02:00
|
|
|
if ( order )
|
|
|
|
wpWidgets.saveOrder();
|
2009-05-10 02:49:48 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
appendTitle : function(widget) {
|
|
|
|
$('input[type="text"]', widget).each(function(){
|
2009-05-16 02:32:04 +02:00
|
|
|
var title;
|
|
|
|
if ( this.id.indexOf('title') != -1 ) {
|
|
|
|
title = $(this).val().replace(/<[^<>]+>/g, '').replace(/</g, '<').replace(/>/g, '>');
|
2009-05-24 17:46:09 +02:00
|
|
|
if ( title )
|
|
|
|
$('.widget-title .in-widget-title', widget).html(': ' + title);
|
2009-05-10 02:49:48 +02:00
|
|
|
return false;
|
2009-04-11 16:37:24 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2009-05-10 02:49:48 +02: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 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
|
|
|
});
|
|
|
|
},
|
2009-05-31 13:34:08 +02:00
|
|
|
|
|
|
|
fixLabels : function(sc) {
|
|
|
|
sc = sc || document;
|
|
|
|
|
|
|
|
$('.widget-inside label', sc).each(function(){
|
|
|
|
var f = $(this).attr('for');
|
|
|
|
|
|
|
|
if ( f && f == $('input', this).attr('id') )
|
|
|
|
$(this).removeAttr('for');
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
close : function(widget) {
|
|
|
|
widget.find('.widget-inside').slideUp('fast', function(){
|
|
|
|
widget.css({'width':'','marginLeft':''});
|
|
|
|
});
|
|
|
|
},
|
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') ) {
|
2009-05-03 07:27:13 +02:00
|
|
|
if ( w > 250 && inside.parents('.widgets-sortables').length ) {
|
2009-04-13 03:17:59 +02:00
|
|
|
css['width'] = w + 30 + 'px';
|
|
|
|
if ( inside.parents('.widget-liquid-right').length )
|
2009-05-10 02:49:48 +02:00
|
|
|
css['marginLeft'] = 235 - w + 'px';
|
2009-04-13 18:20:58 +02:00
|
|
|
inside.parents('.widget').css(css);
|
2009-04-13 03:17:59 +02:00
|
|
|
}
|
2009-05-24 17:46:09 +02:00
|
|
|
inside.slideDown('fast');
|
2009-04-13 03:17:59 +02:00
|
|
|
} else {
|
2009-05-24 17:46:09 +02:00
|
|
|
inside.slideUp('fast', 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(){
|
2009-05-31 13:34:08 +02:00
|
|
|
wpWidgets.save( $(this).parents('.widget'), 0, 1, 0 );
|
2009-01-02 16:08:58 +01:00
|
|
|
return false;
|
2009-04-11 16:37:24 +02:00
|
|
|
});
|
|
|
|
$('.widget-control-remove', sc).click(function(){
|
2009-05-31 13:34:08 +02:00
|
|
|
wpWidgets.save( $(this).parents('.widget'), 1, 1, 0 );
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
$('.widget-control-close', sc).click(function(){
|
|
|
|
wpWidgets.close( $(this).parents('.widget') );
|
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);
|