mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-22 17:18:32 +01:00
Speed up jQuery based scripts, props Denis-de-Bernardy, see #10021
git-svn-id: http://svn.automattic.com/wordpress/trunk@11837 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
9eef5564d5
commit
491b68752b
@ -2,18 +2,20 @@ var showNotice, adminMenu, columns, validateForm;
|
||||
(function($){
|
||||
// sidebar admin menu
|
||||
adminMenu = {
|
||||
|
||||
init : function() {
|
||||
$('#adminmenu div.wp-menu-toggle').each( function() {
|
||||
if ( $(this).siblings('.wp-submenu').length )
|
||||
$(this).click(function(){ adminMenu.toggle( $(this).siblings('.wp-submenu') ); });
|
||||
var menu = $('#adminmenu');
|
||||
|
||||
$('.wp-menu-toggle', menu).each( function() {
|
||||
var t = $(this), sub = t.siblings('.wp-submenu');
|
||||
if ( sub.length )
|
||||
t.click(function(){ adminMenu.toggle( sub ); });
|
||||
else
|
||||
$(this).hide();
|
||||
t.hide();
|
||||
});
|
||||
|
||||
|
||||
this.favorites();
|
||||
|
||||
$('a.separator').click(function(){
|
||||
|
||||
$('.separator', menu).click(function(){
|
||||
if ( $('body').hasClass('folded') ) {
|
||||
adminMenu.fold(1);
|
||||
deleteUserSetting( 'mfold' );
|
||||
@ -24,27 +26,31 @@ adminMenu = {
|
||||
return false;
|
||||
});
|
||||
|
||||
if ( $('body').hasClass('folded') ) {
|
||||
if ( $('body').hasClass('folded') )
|
||||
this.fold();
|
||||
}
|
||||
|
||||
this.restoreMenuState();
|
||||
},
|
||||
|
||||
restoreMenuState : function() {
|
||||
$('#adminmenu li.wp-has-submenu').each(function(i, e) {
|
||||
$('li.wp-has-submenu', '#adminmenu').each(function(i, e) {
|
||||
var v = getUserSetting( 'm'+i );
|
||||
if ( $(e).hasClass('wp-has-current-submenu') ) return true; // leave the current parent open
|
||||
if ( $(e).hasClass('wp-has-current-submenu') )
|
||||
return true; // leave the current parent open
|
||||
|
||||
if ( 'o' == v ) $(e).addClass('wp-menu-open');
|
||||
else if ( 'c' == v ) $(e).removeClass('wp-menu-open');
|
||||
if ( 'o' == v )
|
||||
$(e).addClass('wp-menu-open');
|
||||
else if ( 'c' == v )
|
||||
$(e).removeClass('wp-menu-open');
|
||||
});
|
||||
},
|
||||
|
||||
toggle : function(el) {
|
||||
el['slideToggle'](150, function() {
|
||||
el.css('display','');
|
||||
}).parent().toggleClass( 'wp-menu-open' );
|
||||
|
||||
el['slideToggle'](150, function(){el.css('display','');}).parent().toggleClass( 'wp-menu-open' );
|
||||
|
||||
$('#adminmenu li.wp-has-submenu').each(function(i, e) {
|
||||
$('.wp-has-submenu', '#adminmenu').each(function(i, e) {
|
||||
var v = $(e).hasClass('wp-menu-open') ? 'o' : 'c';
|
||||
setUserSetting( 'm'+i, v );
|
||||
});
|
||||
@ -62,14 +68,14 @@ adminMenu = {
|
||||
over: function(e){
|
||||
var m, b, h, o, f;
|
||||
m = $(this).find('.wp-submenu');
|
||||
b = m.parent().offset().top + m.height() + 1; // Bottom offset of the menu
|
||||
b = $(this).offset().top + m.height() + 1; // Bottom offset of the menu
|
||||
h = $('#wpwrap').height(); // Height of the entire page
|
||||
o = 60 + b - h;
|
||||
f = $(window).height() + $('body').scrollTop() - 15; // The fold
|
||||
if (f < (b - o)) {
|
||||
f = $(window).height() + $(window).scrollTop() - 15; // The fold
|
||||
if ( f < (b - o) ) {
|
||||
o = b - f;
|
||||
}
|
||||
if (o > 1) {
|
||||
if ( o > 1 ) {
|
||||
m.css({'marginTop':'-'+o+'px'});
|
||||
} else if ( m.css('marginTop') ) {
|
||||
m.css({'marginTop':''});
|
||||
@ -86,27 +92,42 @@ adminMenu = {
|
||||
},
|
||||
|
||||
favorites : function() {
|
||||
$('#favorite-inside').width($('#favorite-actions').width()-4);
|
||||
$('#favorite-toggle, #favorite-inside').bind( 'mouseenter', function(){$('#favorite-inside').removeClass('slideUp').addClass('slideDown'); setTimeout(function(){if ( $('#favorite-inside').hasClass('slideDown') ) { $('#favorite-inside').slideDown(100); $('#favorite-first').addClass('slide-down'); }}, 200) } );
|
||||
|
||||
$('#favorite-toggle, #favorite-inside').bind( 'mouseleave', function(){$('#favorite-inside').removeClass('slideDown').addClass('slideUp'); setTimeout(function(){if ( $('#favorite-inside').hasClass('slideUp') ) { $('#favorite-inside').slideUp(100, function(){ $('#favorite-first').removeClass('slide-down'); } ); }}, 300) } );
|
||||
$('#favorite-inside').width( $('#favorite-actions').width() - 4 );
|
||||
$('#favorite-toggle, #favorite-inside').bind('mouseenter', function() {
|
||||
$('#favorite-inside').removeClass('slideUp').addClass('slideDown');
|
||||
setTimeout(function() {
|
||||
if ( $('#favorite-inside').hasClass('slideDown') ) {
|
||||
$('#favorite-inside').slideDown(100);
|
||||
$('#favorite-first').addClass('slide-down');
|
||||
}
|
||||
}, 200);
|
||||
}).bind('mouseleave', function() {
|
||||
$('#favorite-inside').removeClass('slideDown').addClass('slideUp');
|
||||
setTimeout(function() {
|
||||
if ( $('#favorite-inside').hasClass('slideUp') ) {
|
||||
$('#favorite-inside').slideUp(100, function() {
|
||||
$('#favorite-first').removeClass('slide-down');
|
||||
});
|
||||
}
|
||||
}, 300);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$(document).ready(function(){adminMenu.init();});
|
||||
$(document).ready(function(){ adminMenu.init(); });
|
||||
|
||||
// show/hide/save table columns
|
||||
columns = {
|
||||
init : function() {
|
||||
$('.hide-column-tog').click( function() {
|
||||
var column = $(this).val(), show = $(this).attr('checked');
|
||||
if ( show ) {
|
||||
$('.hide-column-tog', '#adv-settings').click( function() {
|
||||
var column = $(this).val();
|
||||
if ( $(this).attr('checked') )
|
||||
$('.column-' + column).show();
|
||||
} else {
|
||||
else
|
||||
$('.column-' + column).hide();
|
||||
}
|
||||
|
||||
columns.save_manage_columns_state();
|
||||
} );
|
||||
});
|
||||
},
|
||||
|
||||
save_manage_columns_state : function() {
|
||||
@ -148,17 +169,20 @@ jQuery(document).ready( function($) {
|
||||
var lastClicked = false, checks, first, last, checked;
|
||||
|
||||
// pulse
|
||||
$('.fade').animate( { backgroundColor: '#ffffe0' }, 300).animate( { backgroundColor: '#fffbcc' }, 300).animate( { backgroundColor: '#ffffe0' }, 300).animate( { backgroundColor: '#fffbcc' }, 300);
|
||||
$('div.fade').animate( { opacity: .5 }, 400)
|
||||
.animate( { opacity: 1 }, 400)
|
||||
.animate( { opacity: .5 }, 400)
|
||||
.animate( { opacity: 1 }, 400);
|
||||
|
||||
// Move .updated and .error alert boxes
|
||||
$('div.wrap h2 ~ div.updated, div.wrap h2 ~ div.error').addClass('below-h2');
|
||||
$('div.updated, div.error').not('.below-h2').insertAfter('div.wrap h2:first');
|
||||
$('div.wrap').children('h2:first').nextAll('div.updated, div.error').addClass('below-h2');
|
||||
$('div.updated, div.error').not('.below-h2').insertAfter( $('div.wrap').children('h2:first') );
|
||||
|
||||
// screen settings tab
|
||||
$('#show-settings-link').click(function () {
|
||||
if ( ! $('#screen-options-wrap').hasClass('screen-options-open') ) {
|
||||
if ( ! $('#screen-options-wrap').hasClass('screen-options-open') )
|
||||
$('#contextual-help-link-wrap').css('visibility', 'hidden');
|
||||
}
|
||||
|
||||
$('#screen-options-wrap').slideToggle('fast', function(){
|
||||
if ( $(this).hasClass('screen-options-open') ) {
|
||||
$('#show-settings-link').css({'backgroundImage':'url("images/screen-options-right.gif")'});
|
||||
@ -174,10 +198,10 @@ jQuery(document).ready( function($) {
|
||||
|
||||
// help tab
|
||||
$('#contextual-help-link').click(function () {
|
||||
if ( ! $('#contextual-help-wrap').hasClass('contextual-help-open') ) {
|
||||
if ( ! $('#contextual-help-wrap').hasClass('contextual-help-open') )
|
||||
$('#screen-options-link-wrap').css('visibility', 'hidden');
|
||||
}
|
||||
$('#contextual-help-wrap').slideToggle('fast', function(){
|
||||
|
||||
$('#contextual-help-wrap').slideToggle('fast', function() {
|
||||
if ( $(this).hasClass('contextual-help-open') ) {
|
||||
$('#contextual-help-link').css({'backgroundImage':'url("images/screen-options-right.gif")'});
|
||||
$('#screen-options-link-wrap').css('visibility', '');
|
||||
@ -189,20 +213,19 @@ jQuery(document).ready( function($) {
|
||||
});
|
||||
return false;
|
||||
});
|
||||
$('#contextual-help-link-wrap, #screen-options-link-wrap').show();
|
||||
|
||||
// check all checkboxes
|
||||
$( 'table:visible tbody .check-column :checkbox' ).click( function(e) {
|
||||
$('tbody').children().children('.check-column').find(':checkbox').click( function(e) {
|
||||
if ( 'undefined' == e.shiftKey ) { return true; }
|
||||
if ( e.shiftKey ) {
|
||||
if ( !lastClicked ) { return true; }
|
||||
checks = $( lastClicked ).parents( 'form:first' ).find( ':checkbox' );
|
||||
checks = $( lastClicked ).closest( 'form' ).find( ':checkbox' );
|
||||
first = checks.index( lastClicked );
|
||||
last = checks.index( this );
|
||||
checked = $(this).attr('checked');
|
||||
if ( 0 < first && 0 < last && first != last ) {
|
||||
checks.slice( first, last ).attr( 'checked', function(){
|
||||
if ( $(this).parents('tr').is(':visible') )
|
||||
if ( $(this).closest('tr').is(':visible') )
|
||||
return checked ? 'checked' : '';
|
||||
|
||||
return '';
|
||||
@ -211,13 +234,17 @@ jQuery(document).ready( function($) {
|
||||
}
|
||||
lastClicked = this;
|
||||
return true;
|
||||
} );
|
||||
$( 'thead :checkbox, tfoot :checkbox' ).click( function(e) {
|
||||
var c = $(this).attr('checked'), kbtoggle = 'undefined' == typeof toggleWithKeyboard ? false : toggleWithKeyboard, toggle = e.shiftKey || kbtoggle;
|
||||
});
|
||||
|
||||
|
||||
$(this).parents( 'form:first' ).find( 'table tbody:visible' ).find( '.check-column :checkbox' ).attr( 'checked', function() {
|
||||
if ( $(this).parents('tr').is(':hidden') )
|
||||
$('thead, tfoot').find(':checkbox').click( function(e) {
|
||||
var c = $(this).attr('checked'),
|
||||
kbtoggle = 'undefined' == typeof toggleWithKeyboard ? false : toggleWithKeyboard,
|
||||
toggle = e.shiftKey || kbtoggle;
|
||||
|
||||
$(this).closest( 'table' ).children( 'tbody' ).filter(':visible')
|
||||
.children().children('.check-column').find(':checkbox')
|
||||
.attr('checked', function() {
|
||||
if ( $(this).closest('tr').is(':hidden') )
|
||||
return '';
|
||||
if ( toggle )
|
||||
return $(this).attr( 'checked' ) ? '' : 'checked';
|
||||
@ -225,7 +252,10 @@ jQuery(document).ready( function($) {
|
||||
return 'checked';
|
||||
return '';
|
||||
});
|
||||
$(this).parents( 'form:first' ).find( 'table thead:visible, table tfoot:visible').find( '.check-column :checkbox' ).attr( 'checked', function() {
|
||||
|
||||
$(this).closest('table').children('thead, tfoot').filter(':visible')
|
||||
.children().children('.check-column').find(':checkbox')
|
||||
.attr('checked', function() {
|
||||
if ( toggle )
|
||||
return '';
|
||||
else if (c)
|
||||
@ -233,17 +263,16 @@ jQuery(document).ready( function($) {
|
||||
return '';
|
||||
});
|
||||
});
|
||||
|
||||
$('#default-password-nag-no').click( function() {
|
||||
setUserSetting('default_password_nag', 'hide');
|
||||
$('div.default-password-nag').hide();
|
||||
return false;
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
jQuery(document).ready( function($){
|
||||
var turboNag = $('.turbo-nag');
|
||||
var turboNag = $('span.turbo-nag', '#user_info');
|
||||
|
||||
if ( !turboNag.length || ('undefined' != typeof(google) && google.gears) )
|
||||
return;
|
||||
@ -260,5 +289,4 @@ jQuery(document).ready( function($){
|
||||
}
|
||||
|
||||
turboNag.show();
|
||||
|
||||
});
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,74 +1,83 @@
|
||||
|
||||
var wpWidgets;
|
||||
(function($) {
|
||||
|
||||
wpWidgets = {
|
||||
|
||||
init : function() {
|
||||
var rem;
|
||||
var rem, sidebars = $('div.widgets-sortables');
|
||||
|
||||
if ( $('body').hasClass('widgets_access') ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$('#widgets-right div.sidebar-name').click(function(){
|
||||
var c = $(this).siblings('.widgets-sortables');
|
||||
if ( c.is(':visible') ) {
|
||||
$('#widgets-right').children('.widgets-holder-wrap').children('.sidebar-name').click(function(){
|
||||
var c = $(this).siblings('.widgets-sortables'), p = $(this).parent();
|
||||
if ( !p.hasClass('closed') ) {
|
||||
c.sortable('disable');
|
||||
$(this).parent().addClass('closed');
|
||||
p.addClass('closed');
|
||||
} else {
|
||||
$(this).parent().removeClass('closed');
|
||||
p.removeClass('closed');
|
||||
c.sortable('enable').sortable('refresh');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('#widgets-left div.sidebar-name').click(function(){
|
||||
if ( $(this).siblings('.widget-holder').is(':visible') ) {
|
||||
$(this).parent().addClass('closed');
|
||||
$('#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' );
|
||||
});
|
||||
|
||||
$('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 );
|
||||
|
||||
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');
|
||||
} else {
|
||||
$(this).parent().removeClass('closed');
|
||||
inside.slideUp('fast', function() {
|
||||
widget.css({'width':'','marginLeft':''});
|
||||
});
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
$('#widgets-right .widget, #wp_inactive_widgets .widget').each(function(){
|
||||
$('input.widget-control-save').live('click', function(){
|
||||
wpWidgets.save( $(this).closest('div.widget'), 0, 1, 0 );
|
||||
return false;
|
||||
});
|
||||
|
||||
$('a.widget-control-remove').live('click', function(){
|
||||
wpWidgets.save( $(this).closest('div.widget'), 1, 1, 0 );
|
||||
return false;
|
||||
});
|
||||
|
||||
$('a.widget-control-close').live('click', function(){
|
||||
wpWidgets.close( $(this).closest('div.widget') );
|
||||
return false;
|
||||
});
|
||||
|
||||
sidebars.children('.widget').each(function() {
|
||||
wpWidgets.appendTitle(this);
|
||||
if ( $('p.widget-error', this).length )
|
||||
$('a.widget-action', this).click();
|
||||
});
|
||||
|
||||
this.addEvents();
|
||||
$('.widget-error').parents('.widget').find('a.widget-action').click();
|
||||
|
||||
$('#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({
|
||||
connectToSortable: '.widgets-sortables',
|
||||
handle: '.widget-title',
|
||||
$('#widget-list').children('.widget').draggable({
|
||||
connectToSortable: 'div.widgets-sortables',
|
||||
handle: '> .widget-top > .widget-title',
|
||||
distance: 2,
|
||||
helper: 'clone',
|
||||
zIndex: 5,
|
||||
containment: 'document',
|
||||
start: function(e,ui) {
|
||||
wpWidgets.fixWebkit(1);
|
||||
ui.helper.find('.widget-description').hide();
|
||||
ui.helper.find('div.widget-description').hide();
|
||||
},
|
||||
stop: function(e,ui) {
|
||||
if ( rem )
|
||||
@ -78,17 +87,17 @@ wpWidgets = {
|
||||
}
|
||||
});
|
||||
|
||||
$('.widgets-sortables').sortable({
|
||||
sidebars.sortable({
|
||||
placeholder: 'widget-placeholder',
|
||||
connectWith: '.widgets-sortables',
|
||||
items: '.widget',
|
||||
handle: '.widget-title',
|
||||
items: '> .widget',
|
||||
handle: '> .widget-top > .widget-title',
|
||||
connectWith: 'div.widgets-sortables',
|
||||
cursor: 'move',
|
||||
distance: 2,
|
||||
containment: 'document',
|
||||
start: function(e,ui) {
|
||||
wpWidgets.fixWebkit(1);
|
||||
ui.item.find('.widget-inside').hide();
|
||||
ui.item.children('.widget-inside').hide();
|
||||
ui.item.css({'marginLeft':'','width':''});
|
||||
},
|
||||
stop: function(e,ui) {
|
||||
@ -101,7 +110,10 @@ wpWidgets = {
|
||||
return;
|
||||
}
|
||||
|
||||
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');
|
||||
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');
|
||||
|
||||
ui.item.css({'marginLeft':'','width':''});
|
||||
wpWidgets.fixWebkit();
|
||||
@ -115,7 +127,6 @@ wpWidgets = {
|
||||
ui.item.attr( 'id', 'new-' + id );
|
||||
rem = 'div#' + id;
|
||||
}
|
||||
wpWidgets.addEvents(ui.item);
|
||||
wpWidgets.save( ui.item, 0, 0, 1 );
|
||||
ui.item.find('input.add_new').val('');
|
||||
ui.item.find('a.widget-action').click();
|
||||
@ -127,14 +138,36 @@ wpWidgets = {
|
||||
if ( !$(this).is(':visible') )
|
||||
$(this).sortable('cancel');
|
||||
}
|
||||
}).not(':visible').sortable('disable');
|
||||
wpWidgets.resize();
|
||||
wpWidgets.fixLabels();
|
||||
}).parent().filter('.closed').children('.widgets-sortables').sortable('disable');
|
||||
|
||||
$('#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('');
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
saveOrder : function(sb) {
|
||||
if ( sb )
|
||||
$('#' + sb).parents('.widgets-holder-wrap').find('.ajax-feedback').css('visibility', 'visible');
|
||||
$('#' + sb).closest('div.widgets-holder-wrap').find('img.ajax-feedback').css('visibility', 'visible');
|
||||
|
||||
var a = {
|
||||
action: 'widgets-order',
|
||||
@ -142,20 +175,21 @@ wpWidgets = {
|
||||
sidebars: []
|
||||
};
|
||||
|
||||
$('.widgets-sortables').each( function() {
|
||||
$('div.widgets-sortables').each( function() {
|
||||
a['sidebars[' + $(this).attr('id') + ']'] = $(this).sortable('toArray').join(',');
|
||||
});
|
||||
|
||||
$.post( ajaxurl, a, function() {
|
||||
$('.ajax-feedback').css('visibility', 'hidden');
|
||||
$('img.ajax-feedback').css('visibility', 'hidden');
|
||||
});
|
||||
|
||||
this.resize();
|
||||
},
|
||||
|
||||
save : function(widget, del, animate, order) {
|
||||
var sb = widget.parents('.widgets-sortables').attr('id'), data = widget.find('form').serialize(), a;
|
||||
var sb = widget.closest('div.widgets-sortables').attr('id'), data = widget.find('form').serialize(), a;
|
||||
widget = $(widget);
|
||||
widget.find('.ajax-feedback').css('visibility', 'visible');
|
||||
$('.ajax-feedback', widget).css('visibility', 'visible');
|
||||
|
||||
a = {
|
||||
action: 'save-widget',
|
||||
@ -172,11 +206,11 @@ wpWidgets = {
|
||||
var id;
|
||||
|
||||
if ( del ) {
|
||||
if ( !$('.widget_number', widget).val() ) {
|
||||
id = $('.widget-id', widget).val();
|
||||
$('#available-widgets .widget-id').each(function(){
|
||||
if ( !$('input.widget_number', widget).val() ) {
|
||||
id = $('input.widget-id', widget).val();
|
||||
$('#available-widgets').find('input.widget-id').each(function(){
|
||||
if ( $(this).val() == id )
|
||||
$(this).parents('.widget').show();
|
||||
$(this).closest('div.widget').show();
|
||||
});
|
||||
}
|
||||
|
||||
@ -193,7 +227,7 @@ wpWidgets = {
|
||||
} else {
|
||||
$('.ajax-feedback').css('visibility', 'hidden');
|
||||
if ( r && r.length > 2 ) {
|
||||
$('.widget-content', widget).html(r);
|
||||
$('div.widget-content', widget).html(r);
|
||||
wpWidgets.appendTitle(widget);
|
||||
wpWidgets.fixLabels(widget);
|
||||
}
|
||||
@ -204,20 +238,17 @@ wpWidgets = {
|
||||
},
|
||||
|
||||
appendTitle : function(widget) {
|
||||
$('input[type="text"]', widget).each(function(){
|
||||
var title;
|
||||
if ( this.id.indexOf('title') != -1 ) {
|
||||
title = $(this).val().replace(/<[^<>]+>/g, '').replace(/</g, '<').replace(/>/g, '>');
|
||||
if ( title )
|
||||
$('.widget-title .in-widget-title', widget).html(': ' + title);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
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);
|
||||
}
|
||||
},
|
||||
|
||||
resize : function() {
|
||||
$('.widgets-sortables').not('#wp_inactive_widgets').each(function(){
|
||||
var h = 50, H = $('.widget', this).length;
|
||||
$('div.widgets-sortables').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' );
|
||||
});
|
||||
@ -230,55 +261,22 @@ wpWidgets = {
|
||||
KhtmlUserSelect: n
|
||||
});
|
||||
},
|
||||
|
||||
fixLabels : function(sc) {
|
||||
sc = sc || document;
|
||||
|
||||
$('.widget-inside label', sc).each(function(){
|
||||
fixLabels : function(widget) {
|
||||
widget.children('.widget-inside').find('label').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':''});
|
||||
});
|
||||
},
|
||||
|
||||
addEvents : function(sc) {
|
||||
sc = sc || document;
|
||||
$('a.widget-action', sc).click(function(){
|
||||
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 > 250 && inside.parents('.widgets-sortables').length ) {
|
||||
css['width'] = w + 30 + 'px';
|
||||
if ( inside.parents('.widget-liquid-right').length )
|
||||
css['marginLeft'] = 235 - w + 'px';
|
||||
inside.parents('.widget').css(css);
|
||||
}
|
||||
inside.slideDown('fast');
|
||||
} else {
|
||||
inside.slideUp('fast', function(){ inside.parents('.widget').css({'width':'','marginLeft':''}); });
|
||||
}
|
||||
return false;
|
||||
});
|
||||
$('.widget-control-save', sc).click(function(){
|
||||
wpWidgets.save( $(this).parents('.widget'), 0, 1, 0 );
|
||||
return false;
|
||||
});
|
||||
$('.widget-control-remove', sc).click(function(){
|
||||
wpWidgets.save( $(this).parents('.widget'), 1, 1, 0 );
|
||||
return false;
|
||||
});
|
||||
$('.widget-control-close', sc).click(function(){
|
||||
wpWidgets.close( $(this).parents('.widget') );
|
||||
return false;
|
||||
close : function(widget) {
|
||||
widget.children('.widget-inside').slideUp('fast', function(){
|
||||
widget.css({'width':'','marginLeft':''});
|
||||
});
|
||||
}
|
||||
};
|
||||
$(document).ready(function(){wpWidgets.init();});
|
||||
|
||||
$(document).ready(function($){ wpWidgets.init(); });
|
||||
|
||||
})(jQuery);
|
||||
|
File diff suppressed because one or more lines are too long
@ -15,9 +15,19 @@ require_once(ABSPATH . 'wp-admin/includes/widgets.php');
|
||||
if ( ! current_user_can('switch_themes') )
|
||||
wp_die( __( 'Cheatin’ uh?' ));
|
||||
|
||||
wp_enqueue_script('admin-widgets');
|
||||
wp_admin_css( 'widgets' );
|
||||
|
||||
$widgets_access = get_user_setting( 'widgets_access' );
|
||||
if ( isset($_GET['widgets-access']) ) {
|
||||
$widgets_access = 'on' == $_GET['widgets-access'] ? 'on' : 'off';
|
||||
set_user_setting( 'widgets_access', $widgets_access );
|
||||
}
|
||||
|
||||
if ( 'on' == $widgets_access )
|
||||
add_filter( 'admin_body_class', create_function('', '{return " widgets_access ";}') );
|
||||
else
|
||||
wp_enqueue_script('admin-widgets');
|
||||
|
||||
do_action( 'sidebar_admin_setup' );
|
||||
|
||||
$title = __( 'Widgets' );
|
||||
@ -302,15 +312,6 @@ if ( isset($_GET['editwidget']) && $_GET['editwidget'] ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$widgets_access = get_user_setting( 'widgets_access' );
|
||||
if ( isset($_GET['widgets-access']) ) {
|
||||
$widgets_access = 'on' == $_GET['widgets-access'] ? 'on' : 'off';
|
||||
set_user_setting( 'widgets_access', $widgets_access );
|
||||
}
|
||||
|
||||
if ( 'on' == $widgets_access )
|
||||
add_filter( 'admin_body_class', create_function('', '{return " widgets_access ";}') );
|
||||
|
||||
$messages = array(
|
||||
__('Changes saved.')
|
||||
);
|
||||
|
@ -60,7 +60,7 @@ function wp_default_scripts( &$scripts ) {
|
||||
|
||||
$scripts->add( 'utils', "/wp-admin/js/utils$suffix.js", false, '20090102' );
|
||||
|
||||
$scripts->add( 'common', "/wp-admin/js/common$suffix.js", array('jquery', 'hoverIntent', 'utils'), '20090730' );
|
||||
$scripts->add( 'common', "/wp-admin/js/common$suffix.js", array('jquery', 'hoverIntent', 'utils'), '20090817' );
|
||||
$scripts->add_data( 'common', 'group', 1 );
|
||||
$scripts->localize( 'common', 'commonL10n', array(
|
||||
'warnDelete' => __("You are about to permanently delete the selected items.\n 'Cancel' to stop, 'OK' to delete."),
|
||||
@ -340,7 +340,7 @@ function wp_default_scripts( &$scripts ) {
|
||||
$scripts->add( 'media-upload', "/wp-admin/js/media-upload$suffix.js", array( 'thickbox' ), '20090114' );
|
||||
$scripts->add_data( 'media-upload', 'group', 1 );
|
||||
|
||||
$scripts->add( 'admin-widgets', "/wp-admin/js/widgets$suffix.js", array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable' ), '20090601' );
|
||||
$scripts->add( 'admin-widgets', "/wp-admin/js/widgets$suffix.js", array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable' ), '20090817' );
|
||||
$scripts->add_data( 'admin-widgets', 'group', 1 );
|
||||
|
||||
$scripts->add( 'word-count', "/wp-admin/js/word-count$suffix.js", array( 'jquery' ), '20090422' );
|
||||
|
Loading…
Reference in New Issue
Block a user