| [ Index ] |
PHP Cross Reference of WordPress |
[Summary view] [Print] [Text view]
1 var wpWidgets; 2 (function($) { 3 4 wpWidgets = { 5 6 init : function() { 7 var rem, sidebars = $('div.widgets-sortables'), isRTL = !! ( 'undefined' != typeof isRtl && isRtl ), 8 margin = ( isRtl ? 'marginRight' : 'marginLeft' ), the_id; 9 10 $('#widgets-right').children('.widgets-holder-wrap').children('.sidebar-name').click(function(){ 11 var c = $(this).siblings('.widgets-sortables'), p = $(this).parent(); 12 if ( !p.hasClass('closed') ) { 13 c.sortable('disable'); 14 p.addClass('closed'); 15 } else { 16 p.removeClass('closed'); 17 c.sortable('enable').sortable('refresh'); 18 } 19 }); 20 21 $('#widgets-left').children('.widgets-holder-wrap').children('.sidebar-name').click(function() { 22 $(this).parent().toggleClass('closed'); 23 }); 24 25 sidebars.each(function(){ 26 if ( $(this).parent().hasClass('inactive') ) 27 return true; 28 29 var h = 50, H = $(this).children('.widget').length; 30 h = h + parseInt(H * 48, 10); 31 $(this).css( 'minHeight', h + 'px' ); 32 }); 33 34 $('a.widget-action').live('click', function(){ 35 var css = {}, widget = $(this).closest('div.widget'), inside = widget.children('.widget-inside'), w = parseInt( widget.find('input.widget-width').val(), 10 ); 36 37 if ( inside.is(':hidden') ) { 38 if ( w > 250 && inside.closest('div.widgets-sortables').length ) { 39 css['width'] = w + 30 + 'px'; 40 if ( inside.closest('div.widget-liquid-right').length ) 41 css[margin] = 235 - w + 'px'; 42 widget.css(css); 43 } 44 wpWidgets.fixLabels(widget); 45 inside.slideDown('fast'); 46 } else { 47 inside.slideUp('fast', function() { 48 widget.css({'width':'', margin:''}); 49 }); 50 } 51 return false; 52 }); 53 54 $('input.widget-control-save').live('click', function(){ 55 wpWidgets.save( $(this).closest('div.widget'), 0, 1, 0 ); 56 return false; 57 }); 58 59 $('a.widget-control-remove').live('click', function(){ 60 wpWidgets.save( $(this).closest('div.widget'), 1, 1, 0 ); 61 return false; 62 }); 63 64 $('a.widget-control-close').live('click', function(){ 65 wpWidgets.close( $(this).closest('div.widget') ); 66 return false; 67 }); 68 69 sidebars.children('.widget').each(function() { 70 wpWidgets.appendTitle(this); 71 if ( $('p.widget-error', this).length ) 72 $('a.widget-action', this).click(); 73 }); 74 75 $('#widget-list').children('.widget').draggable({ 76 connectToSortable: 'div.widgets-sortables', 77 handle: '> .widget-top > .widget-title', 78 distance: 2, 79 helper: 'clone', 80 zIndex: 5, 81 containment: 'document', 82 start: function(e,ui) { 83 ui.helper.find('div.widget-description').hide(); 84 the_id = this.id; 85 }, 86 stop: function(e,ui) { 87 if ( rem ) 88 $(rem).hide(); 89 90 rem = ''; 91 } 92 }); 93 94 sidebars.sortable({ 95 placeholder: 'widget-placeholder', 96 items: '> .widget', 97 handle: '> .widget-top > .widget-title', 98 cursor: 'move', 99 distance: 2, 100 containment: 'document', 101 start: function(e,ui) { 102 ui.item.children('.widget-inside').hide(); 103 ui.item.css({margin:'', 'width':''}); 104 }, 105 stop: function(e,ui) { 106 if ( ui.item.hasClass('ui-draggable') && ui.item.data('draggable') ) 107 ui.item.draggable('destroy'); 108 109 if ( ui.item.hasClass('deleting') ) { 110 wpWidgets.save( ui.item, 1, 0, 1 ); // delete widget 111 ui.item.remove(); 112 return; 113 } 114 115 var add = ui.item.find('input.add_new').val(), 116 n = ui.item.find('input.multi_number').val(), 117 id = the_id, 118 sb = $(this).attr('id'); 119 120 ui.item.css({margin:'', 'width':''}); 121 the_id = ''; 122 123 if ( add ) { 124 if ( 'multi' == add ) { 125 ui.item.html( ui.item.html().replace(/<[^<>]+>/g, function(m){ return m.replace(/__i__|%i%/g, n); }) ); 126 ui.item.attr( 'id', id.replace('__i__', n) ); 127 n++; 128 $('div#' + id).find('input.multi_number').val(n); 129 } else if ( 'single' == add ) { 130 ui.item.attr( 'id', 'new-' + id ); 131 rem = 'div#' + id; 132 } 133 wpWidgets.save( ui.item, 0, 0, 1 ); 134 ui.item.find('input.add_new').val(''); 135 ui.item.find('a.widget-action').click(); 136 return; 137 } 138 wpWidgets.saveOrder(sb); 139 }, 140 receive: function(e, ui) { 141 var sender = $(ui.sender); 142 143 if ( !$(this).is(':visible') || this.id.indexOf('orphaned_widgets') != -1 ) 144 sender.sortable('cancel'); 145 146 if ( sender.attr('id').indexOf('orphaned_widgets') != -1 && !sender.children('.widget').length ) { 147 sender.parents('.orphan-sidebar').slideUp(400, function(){ $(this).remove(); }); 148 } 149 } 150 }).sortable('option', 'connectWith', 'div.widgets-sortables').parent().filter('.closed').children('.widgets-sortables').sortable('disable'); 151 152 $('#available-widgets').droppable({ 153 tolerance: 'pointer', 154 accept: function(o){ 155 return $(o).parent().attr('id') != 'widget-list'; 156 }, 157 drop: function(e,ui) { 158 ui.draggable.addClass('deleting'); 159 $('#removing-widget').hide().children('span').html(''); 160 }, 161 over: function(e,ui) { 162 ui.draggable.addClass('deleting'); 163 $('div.widget-placeholder').hide(); 164 165 if ( ui.draggable.hasClass('ui-sortable-helper') ) 166 $('#removing-widget').show().children('span') 167 .html( ui.draggable.find('div.widget-title').children('h4').html() ); 168 }, 169 out: function(e,ui) { 170 ui.draggable.removeClass('deleting'); 171 $('div.widget-placeholder').show(); 172 $('#removing-widget').hide().children('span').html(''); 173 } 174 }); 175 }, 176 177 saveOrder : function(sb) { 178 if ( sb ) 179 $('#' + sb).closest('div.widgets-holder-wrap').find('img.ajax-feedback').css('visibility', 'visible'); 180 181 var a = { 182 action: 'widgets-order', 183 savewidgets: $('#_wpnonce_widgets').val(), 184 sidebars: [] 185 }; 186 187 $('div.widgets-sortables').each( function() { 188 if ( $(this).sortable ) 189 a['sidebars[' + $(this).attr('id') + ']'] = $(this).sortable('toArray').join(','); 190 }); 191 192 $.post( ajaxurl, a, function() { 193 $('img.ajax-feedback').css('visibility', 'hidden'); 194 }); 195 196 this.resize(); 197 }, 198 199 save : function(widget, del, animate, order) { 200 var sb = widget.closest('div.widgets-sortables').attr('id'), data = widget.find('form').serialize(), a; 201 widget = $(widget); 202 $('.ajax-feedback', widget).css('visibility', 'visible'); 203 204 a = { 205 action: 'save-widget', 206 savewidgets: $('#_wpnonce_widgets').val(), 207 sidebar: sb 208 }; 209 210 if ( del ) 211 a['delete_widget'] = 1; 212 213 data += '&' + $.param(a); 214 215 $.post( ajaxurl, data, function(r){ 216 var id; 217 218 if ( del ) { 219 if ( !$('input.widget_number', widget).val() ) { 220 id = $('input.widget-id', widget).val(); 221 $('#available-widgets').find('input.widget-id').each(function(){ 222 if ( $(this).val() == id ) 223 $(this).closest('div.widget').show(); 224 }); 225 } 226 227 if ( animate ) { 228 order = 0; 229 widget.slideUp('fast', function(){ 230 $(this).remove(); 231 wpWidgets.saveOrder(); 232 }); 233 } else { 234 widget.remove(); 235 wpWidgets.resize(); 236 } 237 } else { 238 $('.ajax-feedback').css('visibility', 'hidden'); 239 if ( r && r.length > 2 ) { 240 $('div.widget-content', widget).html(r); 241 wpWidgets.appendTitle(widget); 242 wpWidgets.fixLabels(widget); 243 } 244 } 245 if ( order ) 246 wpWidgets.saveOrder(); 247 }); 248 }, 249 250 appendTitle : function(widget) { 251 var title = $('input[id*="-title"]', widget).val() || ''; 252 253 if ( title ) 254 title = ': ' + title.replace(/<[^<>]+>/g, '').replace(/</g, '<').replace(/>/g, '>'); 255 256 $(widget).children('.widget-top').children('.widget-title').children() 257 .children('.in-widget-title').html(title); 258 259 }, 260 261 resize : function() { 262 $('div.widgets-sortables').each(function(){ 263 if ( $(this).parent().hasClass('inactive') ) 264 return true; 265 266 var h = 50, H = $(this).children('.widget').length; 267 h = h + parseInt(H * 48, 10); 268 $(this).css( 'minHeight', h + 'px' ); 269 }); 270 }, 271 272 fixLabels : function(widget) { 273 widget.children('.widget-inside').find('label').each(function(){ 274 var f = $(this).attr('for'); 275 if ( f && f == $('input', this).attr('id') ) 276 $(this).removeAttr('for'); 277 }); 278 }, 279 280 close : function(widget) { 281 widget.children('.widget-inside').slideUp('fast', function(){ 282 widget.css({'width':'', margin:''}); 283 }); 284 } 285 }; 286 287 $(document).ready(function($){ wpWidgets.init(); }); 288 289 })(jQuery);
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Fri May 25 03:56:23 2012 | Hosted by follow the white rabbit. |