2009-04-11 10:37:24 -04:00
|
|
|
var wpWidgets;
|
|
|
|
(function($) {
|
|
|
|
|
|
|
|
wpWidgets = {
|
2009-05-03 01:27:13 -04:00
|
|
|
|
2009-08-18 05:53:37 -04:00
|
|
|
init : function() {
|
|
|
|
var rem, sidebars = $('div.widgets-sortables');
|
2009-06-01 19:31:34 -04:00
|
|
|
|
2009-08-18 05:53:37 -04:00
|
|
|
$('#widgets-right').children('.widgets-holder-wrap').children('.sidebar-name').click(function(){
|
|
|
|
var c = $(this).siblings('.widgets-sortables'), p = $(this).parent();
|
|
|
|
if ( !p.hasClass('closed') ) {
|
2009-05-10 06:33:30 -04:00
|
|
|
c.sortable('disable');
|
2009-08-18 05:53:37 -04:00
|
|
|
p.addClass('closed');
|
2009-01-02 10:08:58 -05:00
|
|
|
} else {
|
2009-08-18 05:53:37 -04:00
|
|
|
p.removeClass('closed');
|
2009-05-10 06:33:30 -04:00
|
|
|
c.sortable('enable').sortable('refresh');
|
2009-01-02 10:08:58 -05:00
|
|
|
}
|
2009-08-18 05:53:37 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
$('#widgets-left').children('.widgets-holder-wrap').children('.sidebar-name').click(function() {
|
|
|
|
$(this).siblings('.widget-holder').parent().toggleClass('closed');
|
|
|
|
});
|
|
|
|
|
|
|
|
sidebars.not('#wp_inactive_widgets').each(function(){
|
|
|
|
var h = 50, H = $(this).children('.widget').length;
|
|
|
|
h = h + parseInt(H * 48, 10);
|
|
|
|
$(this).css( 'minHeight', h + 'px' );
|
|
|
|
});
|
2009-05-22 12:13:05 -04:00
|
|
|
|
2009-08-18 05:53:37 -04:00
|
|
|
$('a.widget-action').live('click', function(){
|
|
|
|
var css = {}, widget = $(this).closest('div.widget'), inside = widget.children('.widget-inside'), w = parseInt( widget.find('input.widget-width').val(), 10 );
|
2010-01-15 17:11:12 -05:00
|
|
|
|
2009-08-18 05:53:37 -04:00
|
|
|
if ( inside.is(':hidden') ) {
|
|
|
|
if ( w > 250 && inside.closest('div.widgets-sortables').length ) {
|
|
|
|
css['width'] = w + 30 + 'px';
|
|
|
|
if ( inside.closest('div.widget-liquid-right').length )
|
|
|
|
css['marginLeft'] = 235 - w + 'px';
|
|
|
|
widget.css(css);
|
|
|
|
}
|
|
|
|
wpWidgets.fixLabels(widget);
|
|
|
|
inside.slideDown('fast');
|
2009-05-03 01:27:13 -04:00
|
|
|
} else {
|
2009-08-18 05:53:37 -04:00
|
|
|
inside.slideUp('fast', function() {
|
|
|
|
widget.css({'width':'','marginLeft':''});
|
|
|
|
});
|
2009-05-03 01:27:13 -04:00
|
|
|
}
|
2009-08-18 05:53:37 -04:00
|
|
|
return false;
|
|
|
|
});
|
2009-05-22 12:13:05 -04:00
|
|
|
|
2009-08-18 05:53:37 -04:00
|
|
|
$('input.widget-control-save').live('click', function(){
|
|
|
|
wpWidgets.save( $(this).closest('div.widget'), 0, 1, 0 );
|
|
|
|
return false;
|
2009-05-09 20:49:48 -04:00
|
|
|
});
|
2009-05-22 12:13:05 -04:00
|
|
|
|
2009-08-18 05:53:37 -04:00
|
|
|
$('a.widget-control-remove').live('click', function(){
|
|
|
|
wpWidgets.save( $(this).closest('div.widget'), 1, 1, 0 );
|
|
|
|
return false;
|
|
|
|
});
|
2009-04-11 10:37:24 -04:00
|
|
|
|
2009-08-18 05:53:37 -04:00
|
|
|
$('a.widget-control-close').live('click', function(){
|
|
|
|
wpWidgets.close( $(this).closest('div.widget') );
|
|
|
|
return false;
|
|
|
|
});
|
2009-05-24 11:46:09 -04:00
|
|
|
|
2009-08-18 05:53:37 -04:00
|
|
|
sidebars.children('.widget').each(function() {
|
|
|
|
wpWidgets.appendTitle(this);
|
|
|
|
if ( $('p.widget-error', this).length )
|
|
|
|
$('a.widget-action', this).click();
|
2009-05-24 11:46:09 -04:00
|
|
|
});
|
|
|
|
|
2009-08-18 05:53:37 -04:00
|
|
|
$('#widget-list').children('.widget').draggable({
|
|
|
|
connectToSortable: 'div.widgets-sortables',
|
|
|
|
handle: '> .widget-top > .widget-title',
|
2009-04-11 10:37:24 -04:00
|
|
|
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-08-18 05:53:37 -04:00
|
|
|
ui.helper.find('div.widget-description').hide();
|
2009-04-11 10:37:24 -04:00
|
|
|
},
|
|
|
|
stop: function(e,ui) {
|
|
|
|
if ( rem )
|
|
|
|
$(rem).hide();
|
|
|
|
rem = '';
|
|
|
|
wpWidgets.fixWebkit();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2009-08-18 05:53:37 -04:00
|
|
|
sidebars.sortable({
|
2009-04-11 10:37:24 -04:00
|
|
|
placeholder: 'widget-placeholder',
|
2009-08-18 05:53:37 -04:00
|
|
|
items: '> .widget',
|
|
|
|
handle: '> .widget-top > .widget-title',
|
2009-04-11 10:37:24 -04:00
|
|
|
cursor: 'move',
|
|
|
|
distance: 2,
|
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-08-18 05:53:37 -04:00
|
|
|
ui.item.children('.widget-inside').hide();
|
2009-04-12 21:17:59 -04:00
|
|
|
ui.item.css({'marginLeft':'','width':''});
|
2009-04-11 10:37:24 -04:00
|
|
|
},
|
|
|
|
stop: function(e,ui) {
|
2009-05-24 11:46:09 -04:00
|
|
|
if ( ui.item.hasClass('ui-draggable') )
|
|
|
|
ui.item.draggable('destroy');
|
|
|
|
|
|
|
|
if ( ui.item.hasClass('deleting') ) {
|
2009-05-31 07:34:08 -04:00
|
|
|
wpWidgets.save( ui.item, 1, 0, 1 ); // delete widget
|
2009-05-24 11:46:09 -04:00
|
|
|
ui.item.remove();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-08-18 05:53:37 -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-05-24 11:46:09 -04:00
|
|
|
|
2009-04-12 21:17:59 -04:00
|
|
|
ui.item.css({'marginLeft':'','width':''});
|
2009-05-24 11:46:09 -04:00
|
|
|
wpWidgets.fixWebkit();
|
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
|
|
|
}
|
2009-05-31 07:34:08 -04:00
|
|
|
wpWidgets.save( ui.item, 0, 0, 1 );
|
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-05-24 11:46:09 -04:00
|
|
|
return;
|
2009-04-11 10:37:24 -04:00
|
|
|
}
|
|
|
|
wpWidgets.saveOrder(sb);
|
|
|
|
},
|
|
|
|
receive: function(e,ui) {
|
|
|
|
if ( !$(this).is(':visible') )
|
|
|
|
$(this).sortable('cancel');
|
2009-01-02 10:08:58 -05:00
|
|
|
}
|
2009-08-24 15:16:53 -04:00
|
|
|
}).sortable('option', 'connectWith', 'div.widgets-sortables').parent().filter('.closed').children('.widgets-sortables').sortable('disable');
|
2009-08-18 05:53:37 -04: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');
|
|
|
|
$('div.widget-placeholder').hide();
|
|
|
|
|
|
|
|
if ( ui.draggable.hasClass('ui-sortable-helper') )
|
|
|
|
$('#removing-widget').show().children('span')
|
|
|
|
.html( ui.draggable.find('div.widget-title').children('h4').html() );
|
|
|
|
},
|
|
|
|
out: function(e,ui) {
|
|
|
|
ui.draggable.removeClass('deleting');
|
|
|
|
$('div.widget-placeholder').show();
|
|
|
|
$('#removing-widget').hide().children('span').html('');
|
|
|
|
}
|
|
|
|
});
|
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-24 11:46:09 -04:00
|
|
|
if ( sb )
|
2009-08-18 05:53:37 -04:00
|
|
|
$('#' + sb).closest('div.widgets-holder-wrap').find('img.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-08-18 05:53:37 -04:00
|
|
|
$('div.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-08-18 05:53:37 -04:00
|
|
|
$('img.ajax-feedback').css('visibility', 'hidden');
|
2009-04-11 10:37:24 -04:00
|
|
|
});
|
2009-08-18 05:53:37 -04:00
|
|
|
|
2009-05-24 11:46:09 -04:00
|
|
|
this.resize();
|
2009-04-13 12:20:58 -04:00
|
|
|
},
|
2009-04-12 21:17:59 -04:00
|
|
|
|
2009-05-31 07:34:08 -04:00
|
|
|
save : function(widget, del, animate, order) {
|
2009-08-18 05:53:37 -04:00
|
|
|
var sb = widget.closest('div.widgets-sortables').attr('id'), data = widget.find('form').serialize(), a;
|
2009-05-24 11:46:09 -04:00
|
|
|
widget = $(widget);
|
2009-08-18 05:53:37 -04:00
|
|
|
$('.ajax-feedback', widget).css('visibility', 'visible');
|
2009-04-11 10:37:24 -04:00
|
|
|
|
2009-05-24 11:46:09 -04:00
|
|
|
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-24 11:46:09 -04:00
|
|
|
var id;
|
2009-05-09 20:49:48 -04:00
|
|
|
|
2009-04-11 10:37:24 -04:00
|
|
|
if ( del ) {
|
2009-08-18 05:53:37 -04:00
|
|
|
if ( !$('input.widget_number', widget).val() ) {
|
|
|
|
id = $('input.widget-id', widget).val();
|
|
|
|
$('#available-widgets').find('input.widget-id').each(function(){
|
2009-04-11 10:37:24 -04:00
|
|
|
if ( $(this).val() == id )
|
2009-08-18 05:53:37 -04:00
|
|
|
$(this).closest('div.widget').show();
|
2009-04-11 10:37:24 -04:00
|
|
|
});
|
|
|
|
}
|
2009-05-24 11:46:09 -04:00
|
|
|
|
|
|
|
if ( animate ) {
|
|
|
|
order = 0;
|
|
|
|
widget.slideUp('fast', function(){
|
|
|
|
$(this).remove();
|
|
|
|
wpWidgets.saveOrder();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
widget.remove();
|
|
|
|
wpWidgets.resize();
|
|
|
|
}
|
2009-05-31 07:34:08 -04:00
|
|
|
} else {
|
|
|
|
$('.ajax-feedback').css('visibility', 'hidden');
|
|
|
|
if ( r && r.length > 2 ) {
|
2009-08-18 05:53:37 -04:00
|
|
|
$('div.widget-content', widget).html(r);
|
2009-05-09 20:49:48 -04:00
|
|
|
wpWidgets.appendTitle(widget);
|
2009-05-31 07:34:08 -04:00
|
|
|
wpWidgets.fixLabels(widget);
|
|
|
|
}
|
2009-05-09 20:49:48 -04:00
|
|
|
}
|
2009-05-24 11:46:09 -04:00
|
|
|
if ( order )
|
|
|
|
wpWidgets.saveOrder();
|
2009-05-09 20:49:48 -04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
appendTitle : function(widget) {
|
2009-08-18 05:53:37 -04:00
|
|
|
var title = $('input[id*="-title"]', widget);
|
|
|
|
if ( title = title.val() ) {
|
|
|
|
title = title.replace(/<[^<>]+>/g, '').replace(/</g, '<').replace(/>/g, '>');
|
|
|
|
$(widget).children('.widget-top').children('.widget-title').children()
|
|
|
|
.children('.in-widget-title').html(': ' + title);
|
|
|
|
}
|
2009-04-11 10:37:24 -04:00
|
|
|
},
|
|
|
|
|
2009-05-09 20:49:48 -04:00
|
|
|
resize : function() {
|
2009-08-18 05:53:37 -04:00
|
|
|
$('div.widgets-sortables').not('#wp_inactive_widgets').each(function(){
|
|
|
|
var h = 50, H = $(this).children('.widget').length;
|
2009-05-09 20:49:48 -04:00
|
|
|
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
|
|
|
});
|
|
|
|
},
|
2009-05-31 07:34:08 -04:00
|
|
|
|
2009-08-18 05:53:37 -04:00
|
|
|
fixLabels : function(widget) {
|
|
|
|
widget.children('.widget-inside').find('label').each(function(){
|
2009-05-31 07:34:08 -04:00
|
|
|
var f = $(this).attr('for');
|
|
|
|
if ( f && f == $('input', this).attr('id') )
|
|
|
|
$(this).removeAttr('for');
|
|
|
|
});
|
|
|
|
},
|
2009-08-18 05:53:37 -04:00
|
|
|
|
2009-05-31 07:34:08 -04:00
|
|
|
close : function(widget) {
|
2009-08-18 05:53:37 -04:00
|
|
|
widget.children('.widget-inside').slideUp('fast', function(){
|
2009-05-31 07:34:08 -04:00
|
|
|
widget.css({'width':'','marginLeft':''});
|
|
|
|
});
|
2009-01-02 10:08:58 -05:00
|
|
|
}
|
2009-04-11 10:37:24 -04:00
|
|
|
};
|
2009-08-18 05:53:37 -04:00
|
|
|
|
|
|
|
$(document).ready(function($){ wpWidgets.init(); });
|
2009-01-02 10:08:58 -05:00
|
|
|
|
2009-04-11 10:37:24 -04:00
|
|
|
})(jQuery);
|