| @@ -1,323 +1,299 @@ | ||
| 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 | - //Apertura/chiusura aree nella colonna destra (ce n'è solo una in questo caso!) | |
| 11 | - $('#widgets-right').children('.widgets-holder-wrap').children('.sidebar-name').click(function(){ | |
| 12 | - var t = $(this); | |
| 13 | - var c = t.siblings('.widgets-sortables'), p = t.parent(); | |
| 14 | - if ( !p.hasClass('closed') ) { | |
| 15 | - c.sortable('disable'); | |
| 16 | - p.addClass('closed'); | |
| 17 | - } else { | |
| 18 | - p.removeClass('closed'); | |
| 19 | - c.sortable('enable').sortable('refresh'); | |
| 20 | - } | |
| 21 | - }); | |
| 22 | - | |
| 23 | - //Apertura/chiusura aree nella colonna sinistra (ce n'è solo una in questo caso!) | |
| 24 | - $('#widgets-left').children('.widgets-holder-wrap').children('.sidebar-name').click(function() { | |
| 25 | - $(this).siblings('.widget-holder').parent().toggleClass('closed'); | |
| 26 | - }); | |
| 27 | - | |
| 28 | - //Altezza sidebars | |
| 29 | - /* | |
| 30 | - sidebars.not('#wp_inactive_widgets').each(function(){ | |
| 31 | - var t = $(this); | |
| 32 | - var h = 50, H = t.children('.widget').length; | |
| 33 | - h = h + parseInt(H * 48, 10); | |
| 34 | - t.css( 'minHeight', h + 'px' ); | |
| 35 | - }); | |
| 36 | - */ | |
| 37 | - | |
| 38 | - //Evento per widget-action (aggiunto in modalità "live") | |
| 39 | - $('a.widget-action').live('click', function(){ | |
| 40 | - var css = {}, widget = $(this).closest('div.widget'), inside = widget.children('.widget-inside'), w = parseInt( widget.find('input.widget-width').val(), 10 ); | |
| 41 | - | |
| 42 | - if ( inside.is(':hidden') ) { | |
| 43 | - if ( w > 250 && inside.closest('div.widgets-sortables').length ) { | |
| 44 | - css['width'] = w + 30 + 'px'; | |
| 45 | - if ( inside.closest('div.widget-liquid-right').length ) | |
| 46 | - css[margin] = 235 - w + 'px'; | |
| 47 | - widget.css(css); | |
| 48 | - } | |
| 49 | - wpWidgets.fixLabels(widget); | |
| 50 | - inside.slideDown('fast'); | |
| 51 | - } else { | |
| 52 | - inside.slideUp('fast', function() { | |
| 53 | - widget.css({'width':'', margin:''}); | |
| 54 | - }); | |
| 55 | - } | |
| 56 | - return false; | |
| 57 | - }); | |
| 58 | - | |
| 59 | - //Click sul bottone di salvataggio | |
| 60 | - $('input.widget-control-save').live('click', function(){ | |
| 61 | - wpWidgets.save( $(this).closest('div.widget'), 0, 1, 0 ); | |
| 62 | - return false; | |
| 63 | - }); | |
| 64 | - | |
| 65 | - //Click sul bottone di rimozione | |
| 66 | - $('a.widget-control-remove').live('click', function(){ | |
| 67 | - wpWidgets.save( $(this).closest('div.widget'), 1, 1, 0 ); | |
| 68 | - return false; | |
| 69 | - }); | |
| 70 | - | |
| 71 | - //Click sul bottone di chiusura | |
| 72 | - $('a.widget-control-close').live('click', function(){ | |
| 73 | - wpWidgets.close( $(this).closest('div.widget') ); | |
| 74 | - return false; | |
| 75 | - }); | |
| 76 | - | |
| 77 | - //Impostazione titolo e apertura widget se c'è un errore | |
| 78 | - sidebars.children('.widget').each(function() { | |
| 79 | - wpWidgets.appendTitle(this); | |
| 80 | - if ( $('p.widget-error', this).length ) | |
| 81 | - $('a.widget-action', this).click(); | |
| 82 | - }); | |
| 83 | - | |
| 84 | - //Trascinabilità dei widget nella lista | |
| 85 | - $('#widget-list').children('.widget').draggable({ | |
| 86 | - connectToSortable: 'div.widgets-sortables', | |
| 87 | - handle: '> .widget-top > .widget-title', | |
| 88 | - distance: 2, | |
| 89 | - helper: 'clone', | |
| 90 | - zIndex: 5, | |
| 91 | - containment: 'document', | |
| 92 | - start: function(e,ui) { | |
| 93 | - wpWidgets.fixWebkit(1); | |
| 94 | - ui.helper.find('div.widget-description').hide(); | |
| 95 | - the_id = this.id; | |
| 96 | - }, | |
| 97 | - stop: function(e,ui) { | |
| 98 | - if ( rem ) | |
| 99 | - $(rem).hide(); | |
| 100 | - rem = ''; | |
| 101 | - wpWidgets.fixWebkit(); | |
| 102 | - } | |
| 103 | - }); | |
| 104 | - | |
| 105 | - //Ordinabilità dei widget | |
| 106 | - sidebars.sortable({ | |
| 107 | - placeholder: 'widget-placeholder', | |
| 108 | - items: '> .widget', | |
| 109 | - handle: '> .widget-top > .widget-title', | |
| 110 | - cursor: 'move', | |
| 111 | - distance: 2, | |
| 112 | - containment: 'document', | |
| 113 | - start: function(e,ui) { | |
| 114 | - wpWidgets.fixWebkit(1); | |
| 115 | - ui.item.children('.widget-inside').hide(); | |
| 116 | - ui.item.css({margin:'', 'width':''}); | |
| 117 | - }, | |
| 118 | - stop: function(e,ui) { | |
| 119 | - if ( ui.item.hasClass('ui-draggable') && ui.item.data('draggable') ) | |
| 120 | - ui.item.draggable('destroy'); | |
| 121 | - | |
| 122 | - if ( ui.item.hasClass('deleting') ) { | |
| 123 | - wpWidgets.save( ui.item, 1, 0, 1 ); // delete widget | |
| 124 | - ui.item.remove(); | |
| 125 | - return; | |
| 126 | - } | |
| 127 | - | |
| 128 | - var add = ui.item.find('input.add_new').val(), | |
| 129 | - n = ui.item.find('input.multi_number').val(), | |
| 130 | - id = the_id, | |
| 131 | - sb = $(this).attr('id'); | |
| 132 | - | |
| 133 | - ui.item.css({margin:'', 'width':''}); | |
| 134 | - the_id = ''; | |
| 135 | - | |
| 136 | - wpWidgets.fixWebkit(); | |
| 137 | - if ( add ) { | |
| 138 | - if ( 'multi' == add ) { | |
| 139 | - ui.item.html( ui.item.html().replace(/<[^<>]+>/g, function(m){ return m.replace(/__i__|%i%/g, n); }) ); | |
| 140 | - ui.item.attr( 'id', id.replace(/__i__|%i%/g, n) ); | |
| 141 | - n++; | |
| 142 | - $('div#' + id).find('input.multi_number').val(n); | |
| 143 | - } else if ( 'single' == add ) { | |
| 144 | - ui.item.attr( 'id', 'new-' + id ); | |
| 145 | - rem = 'div#' + id; | |
| 146 | - } | |
| 147 | - wpWidgets.save( ui.item, 0, 0, 1 ); | |
| 148 | - ui.item.find('input.add_new').val(''); | |
| 149 | - ui.item.find('a.widget-action').click(); | |
| 150 | - return; | |
| 151 | - } | |
| 152 | - wpWidgets.saveOrder(sb); | |
| 153 | - }, | |
| 154 | - receive: function(e,ui) { | |
| 155 | - var t = $(this); | |
| 156 | - if ( !t.is(':visible') ) { | |
| 157 | - t.sortable('cancel'); | |
| 158 | - } | |
| 159 | - } | |
| 160 | - }).sortable('option', 'connectWith', 'div.widgets-sortables').parent().filter('.closed').children('.widgets-sortables').sortable('disable'); | |
| 161 | - | |
| 162 | - //Droppabilità dei widget disponibili | |
| 163 | - $('#available-widgets').droppable({ | |
| 164 | - tolerance: 'pointer', | |
| 165 | - accept: function(o){ | |
| 166 | - return $(o).parent().attr('id') != 'widget-list'; | |
| 167 | - }, | |
| 168 | - drop: function(e,ui) { | |
| 169 | - ui.draggable.addClass('deleting'); | |
| 170 | - $('#removing-widget').hide().children('span').html(''); | |
| 171 | - }, | |
| 172 | - over: function(e,ui) { | |
| 173 | - ui.draggable.addClass('deleting'); | |
| 174 | - $('div.widget-placeholder').hide(); | |
| 175 | - | |
| 176 | - if ( ui.draggable.hasClass('ui-sortable-helper') ) | |
| 177 | - $('#removing-widget').show().children('span') | |
| 178 | - .html( ui.draggable.find('div.widget-title').children('h4').html() ); | |
| 179 | - }, | |
| 180 | - out: function(e,ui) { | |
| 181 | - ui.draggable.removeClass('deleting'); | |
| 182 | - $('div.widget-placeholder').show(); | |
| 183 | - $('#removing-widget').hide().children('span').html(''); | |
| 184 | - } | |
| 185 | - }); | |
| 186 | - | |
| 187 | - var holders = $('#widgets-left .widget-holder, #widgets-right .widgets-sortables'); | |
| 188 | - holders.wrap('<div class="accua-form-widget-scroll-wrapper"></div>'); | |
| 189 | - | |
| 190 | - $('.accua-form-widget-scroll-wrapper').each(function(){ | |
| 191 | - var t = $(this); | |
| 192 | - t.css({'height': t.height()}); | |
| 193 | - t.resizable({handles: 's'}); | |
| 194 | - }); | |
| 195 | - }, | |
| 196 | - | |
| 197 | - //Salvataggio ordine | |
| 198 | - saveOrder : function(sb) { | |
| 199 | - if ( sb ) | |
| 200 | - $('#' + sb).closest('div.widgets-holder-wrap').find('img.ajax-feedback').css('visibility', 'visible'); | |
| 201 | - | |
| 202 | - var a = { | |
| 203 | - action: 'accua-form-fields-order', | |
| 204 | - savewidgets: $('#_wpnonce_widgets').val(), | |
| 205 | - sidebars: [] | |
| 206 | - }; | |
| 207 | - | |
| 208 | - $('div.widgets-sortables').each( function() { | |
| 209 | - var t = $(this); | |
| 210 | - if ( t.sortable ) { | |
| 211 | - a['sidebars[' + t.attr('id') + ']'] = t.sortable('toArray').join(','); | |
| 212 | - } | |
| 213 | - }); | |
| 214 | - | |
| 215 | - $.post( ajaxurl, a, function() { | |
| 216 | - $('img.ajax-feedback').css('visibility', 'hidden'); | |
| 217 | - }); | |
| 218 | - | |
| 219 | - this.resize(); | |
| 220 | - }, | |
| 221 | - | |
| 222 | - //Salvataggio stato widget | |
| 223 | - save : function(widget, del, animate, order) { | |
| 224 | - var sb = widget.closest('div.widgets-sortables').attr('id'), data = widget.find('form').serialize(), a; | |
| 225 | - widget = $(widget); | |
| 226 | - $('.ajax-feedback', widget).css('visibility', 'visible'); | |
| 227 | - | |
| 228 | - a = { | |
| 229 | - action: 'accua-save-form-field', | |
| 230 | - savewidgets: $('#_wpnonce_widgets').val(), | |
| 231 | - sidebar: sb | |
| 232 | - }; | |
| 233 | - | |
| 234 | - if ( del ) | |
| 235 | - a['delete_widget'] = 1; | |
| 236 | - | |
| 237 | - data += '&' + $.param(a); | |
| 238 | - | |
| 239 | - $.post( ajaxurl, data, function(r){ | |
| 240 | - var id; | |
| 241 | - | |
| 242 | - if ( del ) { | |
| 243 | - if ( !$('input.widget_number', widget).val() ) { | |
| 244 | - id = $('input.widget-id', widget).val(); | |
| 245 | - $('#available-widgets').find('input.widget-id').each(function(){ | |
| 246 | - if ( $(this).val() == id ) | |
| 247 | - $(this).closest('div.widget').show(); | |
| 248 | - }); | |
| 249 | - } | |
| 250 | - | |
| 251 | - if ( animate ) { | |
| 252 | - order = 0; | |
| 253 | - widget.slideUp('fast', function(){ | |
| 254 | - $(this).remove(); | |
| 255 | - wpWidgets.saveOrder(); | |
| 256 | - }); | |
| 257 | - } else { | |
| 258 | - widget.remove(); | |
| 259 | - wpWidgets.resize(); | |
| 260 | - } | |
| 261 | - } else { | |
| 262 | - $('.ajax-feedback').css('visibility', 'hidden'); | |
| 263 | - if ( r && r.length > 2 ) { | |
| 264 | - $('div.widget-content', widget).html(r); | |
| 265 | - wpWidgets.appendTitle(widget); | |
| 266 | - wpWidgets.fixLabels(widget); | |
| 267 | - } | |
| 268 | - } | |
| 269 | - if ( order ) | |
| 270 | - wpWidgets.saveOrder(); | |
| 271 | - }); | |
| 272 | - }, | |
| 273 | - | |
| 274 | - //Aggiunta titolo | |
| 275 | - appendTitle : function(widget) { | |
| 276 | - var title = $('input[id*="-title"]', widget); | |
| 277 | - if ( title = title.val() ) { | |
| 278 | - title = title.replace(/<[^<>]+>/g, '').replace(/</g, '<').replace(/>/g, '>'); | |
| 279 | - $(widget).children('.widget-top').children('.widget-title').children() | |
| 280 | - .children('.in-widget-title').html(': ' + title); | |
| 281 | - } | |
| 282 | - }, | |
| 283 | - | |
| 284 | - resize : function() { | |
| 285 | - /* | |
| 286 | - $('div.widgets-sortables').not('#wp_inactive_widgets').each(function(){ | |
| 287 | - var t = $(this); | |
| 288 | - var h = 50, H = t.children('.widget').length; | |
| 289 | - h = h + parseInt(H * 48, 10); | |
| 290 | - t.css( 'minHeight', h + 'px' ); | |
| 291 | - }); | |
| 292 | - */ | |
| 293 | - }, | |
| 294 | - | |
| 295 | - fixWebkit : function(n) { | |
| 296 | - n = n ? 'none' : ''; | |
| 297 | - $('body').css({ | |
| 298 | - WebkitUserSelect: n, | |
| 299 | - KhtmlUserSelect: n | |
| 300 | - }); | |
| 301 | - }, | |
| 302 | - | |
| 303 | - fixLabels : function(widget) { | |
| 304 | - widget.children('.widget-inside').find('label').each(function(){ | |
| 305 | - var t = $(this); | |
| 306 | - var f = t.attr('for'); | |
| 307 | - if ( f && f == $('input', this).attr('id') ) { | |
| 308 | - t.removeAttr('for'); | |
| 309 | - } | |
| 310 | - }); | |
| 311 | - }, | |
| 312 | - | |
| 313 | - //Chiusura widget | |
| 314 | - close : function(widget) { | |
| 315 | - widget.children('.widget-inside').slideUp('fast', function(){ | |
| 316 | - widget.css({'width':'', margin:''}); | |
| 317 | - }); | |
| 318 | - } | |
| 319 | -}; | |
| 320 | - | |
| 321 | -$(document).ready(function($){ wpWidgets.init(); }); | |
| 322 | - | |
| 323 | -})(jQuery); | |
| 1 | +var accuaWidgets = {}; | |
| 2 | +(function($) { | |
| 3 | + | |
| 4 | +accuaWidgets = { | |
| 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 | + //Evento per widget-action (aggiunto in modalità "live") | |
| 11 | + // $('a.widget-action').live('click', function(){ | |
| 12 | + $(document).on('click', 'a.widget-action', function(){ | |
| 13 | + var css = {}, widget = $(this).closest('div.widget'), inside = widget.children('.widget-inside'), w = parseInt( widget.find('input.widget-width').val(), 10 ); | |
| 14 | + | |
| 15 | + if ( inside.is(':hidden') ) { | |
| 16 | + if ( w > 250 && inside.closest('div.widgets-sortables').length ) { | |
| 17 | + css['width'] = w + 30 + 'px'; | |
| 18 | + if ( inside.closest('div.widget-liquid-right').length ) | |
| 19 | + css[margin] = 235 - w + 'px'; | |
| 20 | + widget.css(css); | |
| 21 | + } | |
| 22 | + accuaWidgets.fixLabels(widget); | |
| 23 | + inside.slideDown('fast'); | |
| 24 | + } else { | |
| 25 | + inside.slideUp('fast', function() { | |
| 26 | + widget.css({'width':'', margin:''}); | |
| 27 | + }); | |
| 28 | + } | |
| 29 | + return false; | |
| 30 | + }); | |
| 31 | + | |
| 32 | + //Click sul bottone di salvataggio | |
| 33 | + // $('input.widget-control-save').live('click', function(){ | |
| 34 | + $(document).on('click', 'input.widget-control-save', function(){ | |
| 35 | + accuaWidgets.save( $(this).closest('div.widget'), 0, 1, 0 ); | |
| 36 | + return false; | |
| 37 | + }); | |
| 38 | + | |
| 39 | + //Click sul bottone di rimozione | |
| 40 | + //$('a.widget-control-remove').live('click', function(){ | |
| 41 | + $(document).on('click', 'a.widget-control-remove', function(){ | |
| 42 | + accuaWidgets.save( $(this).closest('div.widget'), 1, 1, 0 ); | |
| 43 | + return false; | |
| 44 | + }); | |
| 45 | + | |
| 46 | + //Click sul bottone di chiusura | |
| 47 | + //$('a.widget-control-close').live('click', function(){ | |
| 48 | + $(document).on('click', 'a.widget-control-close', function(){ | |
| 49 | + accuaWidgets.close( $(this).closest('div.widget') ); | |
| 50 | + return false; | |
| 51 | + }); | |
| 52 | + | |
| 53 | + //Impostazione titolo e apertura widget se c'è un errore | |
| 54 | + sidebars.children('.widget').each(function() { | |
| 55 | + accuaWidgets.appendTitle(this); | |
| 56 | + if ( $('p.widget-error', this).length ) | |
| 57 | + $('a.widget-action', this).click(); | |
| 58 | + }); | |
| 59 | + | |
| 60 | + //Trascinabilità dei widget nella lista | |
| 61 | + $('#widget-list').children('.widget').draggable({ | |
| 62 | + connectToSortable: 'div.widgets-sortables', | |
| 63 | + handle: '> .widget-top > .widget-title', | |
| 64 | + distance: 2, | |
| 65 | + helper: 'clone', | |
| 66 | + zIndex: 5, | |
| 67 | + containment: 'document', | |
| 68 | + start: function(e,ui) { | |
| 69 | + accuaWidgets.fixWebkit(1); | |
| 70 | + ui.helper.find('div.widget-description').hide(); | |
| 71 | + the_id = this.id; | |
| 72 | + }, | |
| 73 | + stop: function(e,ui) { | |
| 74 | + if ( rem ) | |
| 75 | + $(rem).hide(); | |
| 76 | + rem = ''; | |
| 77 | + accuaWidgets.fixWebkit(); | |
| 78 | + } | |
| 79 | + }); | |
| 80 | + | |
| 81 | + //Ordinabilità dei widget | |
| 82 | + sidebars.sortable({ | |
| 83 | + placeholder: 'widget-placeholder', | |
| 84 | + items: '> .widget', | |
| 85 | + handle: '> .widget-top > .widget-title', | |
| 86 | + cursor: 'move', | |
| 87 | + distance: 2, | |
| 88 | + containment: 'document', | |
| 89 | + start: function(e,ui) { | |
| 90 | + accuaWidgets.fixWebkit(1); | |
| 91 | + ui.item.children('.widget-inside').hide(); | |
| 92 | + ui.item.css({margin:'', 'width':''}); | |
| 93 | + }, | |
| 94 | + stop: function(e,ui) { | |
| 95 | + if ( ui.item.hasClass('ui-draggable') && ui.item.data('draggable') ) | |
| 96 | + ui.item.draggable('destroy'); | |
| 97 | + | |
| 98 | + if ( ui.item.hasClass('deleting') ) { | |
| 99 | + accuaWidgets.save( ui.item, 1, 0, 1 ); // delete widget | |
| 100 | + ui.item.remove(); | |
| 101 | + return; | |
| 102 | + } | |
| 103 | + | |
| 104 | + var add = ui.item.find('input.add_new').val(), | |
| 105 | + n = ui.item.find('input.multi_number').val(), | |
| 106 | + id = the_id, | |
| 107 | + sb = $(this).attr('id'); | |
| 108 | + | |
| 109 | + ui.item.css({margin:'', 'width':''}); | |
| 110 | + the_id = ''; | |
| 111 | + | |
| 112 | + accuaWidgets.fixWebkit(); | |
| 113 | + if ( add ) { | |
| 114 | + if ( 'multi' == add ) { | |
| 115 | + ui.item.html( ui.item.html().replace(/<[^<>]+>/g, function(m){ return m.replace(/__i__|%i%/g, n); }) ); | |
| 116 | + ui.item.attr( 'id', id.replace(/__i__|%i%/g, n) ); | |
| 117 | + n++; | |
| 118 | + $('div#' + id).find('input.multi_number').val(n); | |
| 119 | + } else if ( 'single' == add ) { | |
| 120 | + ui.item.attr( 'id', 'new-' + id ); | |
| 121 | + rem = 'div#' + id; | |
| 122 | + } | |
| 123 | + accuaWidgets.save( ui.item, 0, 0, 1 ); | |
| 124 | + ui.item.find('input.add_new').val(''); | |
| 125 | + ui.item.find('a.widget-action').click(); | |
| 126 | + return; | |
| 127 | + } | |
| 128 | + accuaWidgets.saveOrder(sb); | |
| 129 | + }, | |
| 130 | + receive: function(e,ui) { | |
| 131 | + var t = $(this); | |
| 132 | + if ( !t.is(':visible') ) { | |
| 133 | + t.sortable('cancel'); | |
| 134 | + } | |
| 135 | + } | |
| 136 | + }).sortable('option', 'connectWith', 'div.widgets-sortables').parent().filter('.closed').children('.widgets-sortables').sortable('disable'); | |
| 137 | + | |
| 138 | + //Droppabilità dei widget disponibili | |
| 139 | + $('#available-widgets').droppable({ | |
| 140 | + tolerance: 'pointer', | |
| 141 | + accept: function(o){ | |
| 142 | + return $(o).parent().attr('id') != 'widget-list'; | |
| 143 | + }, | |
| 144 | + drop: function(e,ui) { | |
| 145 | + ui.draggable.addClass('deleting'); | |
| 146 | + $('#removing-widget').hide().children('span').html(''); | |
| 147 | + }, | |
| 148 | + over: function(e,ui) { | |
| 149 | + ui.draggable.addClass('deleting'); | |
| 150 | + $('div.widget-placeholder').hide(); | |
| 151 | + | |
| 152 | + if ( ui.draggable.hasClass('ui-sortable-helper') ) | |
| 153 | + $('#removing-widget').show().children('span') | |
| 154 | + .html( ui.draggable.find('div.widget-title').children('h4').html() ); | |
| 155 | + }, | |
| 156 | + out: function(e,ui) { | |
| 157 | + ui.draggable.removeClass('deleting'); | |
| 158 | + $('div.widget-placeholder').show(); | |
| 159 | + $('#removing-widget').hide().children('span').html(''); | |
| 160 | + } | |
| 161 | + }); | |
| 162 | + | |
| 163 | + var holders = $('#widgets-left .widget-holder, #widgets-right .widgets-sortables'); | |
| 164 | + holders.wrap('<div class="accua-form-widget-scroll-wrapper"></div>'); | |
| 165 | + /* | |
| 166 | + $('.accua-form-widget-scroll-wrapper').each(function(){ | |
| 167 | + var t = $(this); | |
| 168 | + //t.css({'height': t.height()}); | |
| 169 | + t.resizable({handles: 's'}); | |
| 170 | + });*/ | |
| 171 | + }, | |
| 172 | + | |
| 173 | + //Salvataggio ordine | |
| 174 | + saveOrder : function(sb) { | |
| 175 | + if ( sb ) | |
| 176 | + $('#' + sb).closest('div.widgets-holder-wrap').find('img.ajax-feedback').css('visibility', 'visible'); | |
| 177 | + | |
| 178 | + var a = { | |
| 179 | + action: 'accua-form-fields-order', | |
| 180 | + _nonce_edit_form: $('#_nonce_edit_form').val(), | |
| 181 | + sidebars: [] | |
| 182 | + }; | |
| 183 | + | |
| 184 | + $('div.widgets-sortables').each( function() { | |
| 185 | + var t = $(this); | |
| 186 | + if ( t.sortable ) { | |
| 187 | + a['sidebars[' + t.attr('id') + ']'] = t.sortable('toArray').join(','); | |
| 188 | + } | |
| 189 | + }); | |
| 190 | + | |
| 191 | + $.post( ajaxurl, a, function() { | |
| 192 | + $('img.ajax-feedback').css('visibility', 'hidden'); | |
| 193 | + }); | |
| 194 | + | |
| 195 | + this.resize(); | |
| 196 | + }, | |
| 197 | + | |
| 198 | + //Salvataggio stato widget | |
| 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: 'accua-save-form-field', | |
| 206 | + _nonce_edit_form: $('#_nonce_edit_form').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 | + accuaWidgets.saveOrder(); | |
| 232 | + }); | |
| 233 | + } else { | |
| 234 | + widget.remove(); | |
| 235 | + accuaWidgets.resize(); | |
| 236 | + } | |
| 237 | + } else { | |
| 238 | + $('.ajax-feedback').css('visibility', 'hidden'); | |
| 239 | + if ( r && r.length > 2 ) { | |
| 240 | + $('div.widget-content', widget).html(r); | |
| 241 | + accuaWidgets.appendTitle(widget); | |
| 242 | + accuaWidgets.fixLabels(widget); | |
| 243 | + } | |
| 244 | + } | |
| 245 | + if ( order ) | |
| 246 | + accuaWidgets.saveOrder(); | |
| 247 | + }); | |
| 248 | + }, | |
| 249 | + | |
| 250 | + //Aggiunta titolo | |
| 251 | + appendTitle : function(widget) { | |
| 252 | + var title = $('input[id*="-title"]', widget); | |
| 253 | + if ( title = title.val() ) { | |
| 254 | + title = title.replace(/<[^<>]+>/g, '').replace(/</g, '<').replace(/>/g, '>'); | |
| 255 | + $(widget).children('.widget-top').children('.widget-title').children() | |
| 256 | + .children('.in-widget-title').html(': ' + title); | |
| 257 | + } | |
| 258 | + }, | |
| 259 | + | |
| 260 | + resize : function() { | |
| 261 | + /* | |
| 262 | + $('div.widgets-sortables').not('#wp_inactive_widgets').each(function(){ | |
| 263 | + var t = $(this); | |
| 264 | + var h = 50, H = t.children('.widget').length; | |
| 265 | + h = h + parseInt(H * 48, 10); | |
| 266 | + t.css( 'minHeight', h + 'px' ); | |
| 267 | + }); | |
| 268 | + */ | |
| 269 | + }, | |
| 270 | + | |
| 271 | + fixWebkit : function(n) { | |
| 272 | + n = n ? 'none' : ''; | |
| 273 | + $('body').css({ | |
| 274 | + WebkitUserSelect: n, | |
| 275 | + KhtmlUserSelect: n | |
| 276 | + }); | |
| 277 | + }, | |
| 278 | + | |
| 279 | + fixLabels : function(widget) { | |
| 280 | + widget.children('.widget-inside').find('label').each(function(){ | |
| 281 | + var t = $(this); | |
| 282 | + var f = t.attr('for'); | |
| 283 | + if ( f && f == $('input', this).attr('id') ) { | |
| 284 | + t.removeAttr('for'); | |
| 285 | + } | |
| 286 | + }); | |
| 287 | + }, | |
| 288 | + | |
| 289 | + //Chiusura widget | |
| 290 | + close : function(widget) { | |
| 291 | + widget.children('.widget-inside').slideUp('fast', function(){ | |
| 292 | + widget.css({'width':'', margin:''}); | |
| 293 | + }); | |
| 294 | + } | |
| 295 | +}; | |
| 296 | + | |
| 297 | +$(document).ready(function($){ accuaWidgets.init(); }); | |
| 298 | + | |
| 299 | +})(jQuery); | |