(function ($) { //create ajax commands to be used from the drupal ajax api Drupal.ajax.prototype.commands['getBlock'] = function(ajax, response, status) { var box = $(this).parents('.boxes-box'); data = response; $.ajax({ type: "GET", url: data.url, data: { 'boxes_delta': data.delta }, global: true, success: function(response, status) { if($('#boxes-box-form').dialog('isOpen')){ $('#boxes-box-form').dialog('close'); } $('.hasPopup').removeClass('hasPopup'); box.removeClass('boxes-box-editing').find('.box-editor').remove().end().find('.boxes-box-content').show(); ajax.success(response, status); }, error: Drupal.ajax.error, dataType: 'json' }); }; Drupal.ajax.prototype.commands['showBoxForm'] = function(ajax, response, status) { if(!$('#boxes-box-form').size() || !$('#boxes-box-form').dialog('isOpen')){ Drupal.ajax.prototype.commands.insert(ajax, response, status); $(response.selector).addClass('hasPopup'); $('#boxes-box-form') .dialog({ modal : true, close: function(e){ //handle someone closing the box without clicking any buttons if (Drupal.wysiwygDetach && $('.wysiwyg', this).val()) { var item = $('.wysiwyg', this)[0]; var params = Drupal.settings.wysiwyg.triggers[item.id]; Drupal.wysiwygDetach(this, params['format'+$(item).val()]) } $(response.selector).removeClass('hasPopup').html(Drupal.t('Loading...')); $('.boxes-ajax.use-ajax-submit.form-submit[value="Cancel"]').click(); $(this).dialog('destroy').remove(); }, open: function(ui, event){ $(this).siblings('.ui-dialog-titlebar').children('.ui-dialog-titlebar-close').click(function(e){ $('.boxes-ajax.use-ajax-submit.form-submit[value="Cancel"]').click(); }); }, width: Math.min($(window).width() * .75, 750), height: Math.min($(window).height() * .75, 750), title : Drupal.t('Edit Box') }); } else { //change the selector to just update the current form - in place (in the popup) response.selector = '#boxes-box-form'; Drupal.ajax.prototype.commands.insert(ajax, response, status); } }; Drupal.behaviors.boxes = { attach: function(context, settings) { $('div.boxes-box-controls a:not(.boxes-processed)') .addClass('boxes-processed') .click(function() { // If we are not using edit-in-place, bail. if (this.href.indexOf('/admin/structure/block/manage/boxes/') != -1) { return; } var box = $(this).parents('.boxes-box'); if (box.is('.boxes-box-editing')) { box.removeClass('boxes-box-editing').find('.box-editor').remove().end().find('.boxes-box-content').show(); } else { // Show editing form - the form itself gets loaded via ajax.. box.find('.boxes-box-content').hide().end().addClass('boxes-box-editing').prepend('