<commit_before>var shiftHeld = false;
$(document).ready(function(){
  init_interface();
  init_flash_messages();
  init_delete_confirmations();
  init_sortable_menu();
  init_submit_continue();
  init_modal_dialogs();
  init_tooltips();
});

init_interface = function() {
  $('input:submit:not(.button)').addClass('button');

  $('.button, #editor_switch a').corner('6px');
  $('#editor_switch a').appendTo($('<span></span>').prependTo('#editor_switch').corner('6px'));
  $('#page_container, .wym_box').corner('5px bottom');
  $('.wym_box').corner('5px tr');
  $('.wym_iframe iframe').corner('2px');
  $('.form-actions:not(".form-actions-dialog")').corner('5px');
  $('#recent_activity li a, #recent_inquiries li a').each(function(i, a) {
    $(this).textTruncate({
      width: $(this).width()
      , tooltip: false
    });
  });

  // make sure that users can tab to wymeditor fields and add an overlay while loading.
  $('textarea.wymeditor').each(function() {
    textarea = $(this);
    /*overlay = $("<div class='wym_loading_overlay'>&nbsp;</div>")
              .css({'height': textarea.height(), 'width': textarea.width()});
    textarea.before(overlay);*/
    if ((instance = WYMeditor.INSTANCES[$(textarea.next('.wym_box').find('iframe').attr('id').split('_')).last().get(0)]) != null) {
      textarea.parent().next().find('input, textarea').keydown($.proxy(function(e) {
        shiftHeld = e.shiftKey;
        if (shiftHeld && e.keyCode == $.ui.keyCode.TAB) {
          this._iframe.contentWindow.focus();
          e.preventDefault();
        }
      }, instance)).keyup(function(e) {
        shiftHeld = false;
      });
      textarea.parent().prev().find('input, textarea').keydown($.proxy(function(e) {
        if (e.keyCode == $.ui.keyCode.TAB) {
          this._iframe.contentWindow.focus();
          e.preventDefault();
        }
      }, instance));
    }
  });

  // focus first field in an admin form.
  $('form input[type=text]:first').focus();

  // ensure that the menu isn't wider than the page_container or else it looks silly to round that corner.
  var last_item_offset = (last_item = $('#menu a:visible:last')).offset();
  if (last_item_offset && ((last_item_offset.left + last_item.outerWidth() - $('#menu').offset().left + 5) < $('#page_container').outerWidth())) {
    $("#page_container:not('.login #page_container')").corner('5px tr');
  }
}

init_delete_confirmations = function() {
  $('a.confirm-delete').click(function(e) {
    if (confirm("Are you sure you want to " + (t=($(this).attr('title') || $(this).attr('tooltip')))[0].toLowerCase() + t.substring(1) + "?"))
    {
      $("<form method='POST' action='" + $(this).attr('href') + "'></form>")
        .append("<input type='hidden' name='_method' value='delete' />")
        .append("<input type='hidden' name='authenticity_token' value='" + $('#admin_authenticity_token').val() + "'/>")
        .appendTo('body').submit();
    }
    e.preventDefault();
  });
}

init_flash_messages = function(){
  $('#flash').fadeIn(550);
  $('#flash_close').click(function(e) {
     $('#flash').fadeOut({duration: 330});
     e.preventDefault();
  });
  $('#flash.flash_message').prependTo('#records');
}

init_modal_dialogs = function(){
  $('a[href*="dialog=true"]').not('#dialog_container a').each(function(i, anchor)
  {
    $(anchor).click(function(e){
      iframe = $("<iframe id='dialog_iframe' src='" + $(this).attr('href') + "&amp;app_dialog=true" + "'></iframe>").corner('8px');
      iframe.dialog({
        title: $(anchor).attr('title') || $(anchor).attr('name') || $(anchor).html() || null
        , modal: true
        , resizable: false
        , autoOpen: true
        , width: (parseInt($(anchor.href.match("width=([0-9]*)")).last().get(0))||928)
        , height: (parseInt($(anchor.href.match("height=([0-9]*)")).last().get(0))||473)
        , open: onOpenDialog
        , close: onCloseDialog
      });
      if ($.browser.msie) {
        iframe.css({'margin':'-2px 2px 2px -2px'});
      }
      $(document.body).addClass('hide-overflow');
      e.preventDefault();
    });
  });
}

init_sortable_menu = function(){
  var $menu = $('#menu');

  if($menu.length == 0){return}

  $menu.sortable({
    axis: 'x',
    cursor: 'crosshair',
    update: function(){
      var ser   = $menu.sortable('serialize', {key: 'menu[]'}),
          token = escape($('#admin_authenticity_token').val());

      $.get('/refinery/update_menu_positions?' + ser, {authenticity_token: token});
    }
  }).tabs();
  //Initial status disabled
  $menu.sortable('disable');

  $menu.find('#menu_reorder').click(function(e){
    e.preventDefault();
    $('#menu_reorder, #menu_reorder_done').toggle();
    $('#site_bar, #header >*:not(#header_content, #menu, script), #content').fadeTo(500, 0.65);
    $menu.find('.tab a').click(function(ev){
      ev.preventDefault();
    });

    $menu.sortable('enable');
  });

  $menu.find('#menu_reorder_done').click(function(e){
    e.preventDefault();
    $('#menu_reorder, #menu_reorder_done').toggle();
    $('#site_bar, #header >*:not(#header_content, #menu, script), #content').fadeTo(500, 1);
    $menu.find('.tab a').unbind('click');

    $menu.sortable('disable');
  });

  $menu.find('> a').corner('top 5px');
}

init_submit_continue = function(){
  $('#submit_continue_button').click(submit_and_continue);

  if ($('#continue_editing').length > 0) {
    $('#editor_switch a').click(function(e) {
      if (!confirm("Any changes you've made will be lost. Are you sure you want to continue without saving?")) {
        e.preventDefault();
      }
    });
  }
}

submit_and_continue = function(e, redirect_to) {
  // ensure wymeditors are up to date.
  if ($(this).hasClass('wymupdate')) {
    $.each(WYMeditor.INSTANCES, function(index, wym)
    {
      wym.update();
    });
  }

  $('#continue_editing').val(true);
  $('#flash').fadeOut(250)
<commit_msg>Provide a hook to disable the prompt for the continue editing dialogue on site bar switch to website.<commit_after>var shiftHeld = false;
$(document).ready(function(){
  init_interface();
  init_flash_messages();
  init_delete_confirmations();
  init_sortable_menu();
  init_submit_continue();
  init_modal_dialogs();
  init_tooltips();
});

init_interface = function() {
  $('input:submit:not(.button)').addClass('button');

  $('.button, #editor_switch a').corner('6px');
  $('#editor_switch a').appendTo($('<span></span>').prependTo('#editor_switch').corner('6px'));
  $('#page_container, .wym_box').corner('5px bottom');
  $('.wym_box').corner('5px tr');
  $('.wym_iframe iframe').corner('2px');
  $('.form-actions:not(".form-actions-dialog")').corner('5px');
  $('#recent_activity li a, #recent_inquiries li a').each(function(i, a) {
    $(this).textTruncate({
      width: $(this).width()
      , tooltip: false
    });
  });

  // make sure that users can tab to wymeditor fields and add an overlay while loading.
  $('textarea.wymeditor').each(function() {
    textarea = $(this);
    /*overlay = $("<div class='wym_loading_overlay'>&nbsp;</div>")
              .css({'height': textarea.height(), 'width': textarea.width()});
    textarea.before(overlay);*/
    if ((instance = WYMeditor.INSTANCES[$(textarea.next('.wym_box').find('iframe').attr('id').split('_')).last().get(0)]) != null) {
      textarea.parent().next().find('input, textarea').keydown($.proxy(function(e) {
        shiftHeld = e.shiftKey;
        if (shiftHeld && e.keyCode == $.ui.keyCode.TAB) {
          this._iframe.contentWindow.focus();
          e.preventDefault();
        }
      }, instance)).keyup(function(e) {
        shiftHeld = false;
      });
      textarea.parent().prev().find('input, textarea').keydown($.proxy(function(e) {
        if (e.keyCode == $.ui.keyCode.TAB) {
          this._iframe.contentWindow.focus();
          e.preventDefault();
        }
      }, instance));
    }
  });

  // focus first field in an admin form.
  $('form input[type=text]:first').focus();

  // ensure that the menu isn't wider than the page_container or else it looks silly to round that corner.
  var last_item_offset = (last_item = $('#menu a:visible:last')).offset();
  if (last_item_offset && ((last_item_offset.left + last_item.outerWidth() - $('#menu').offset().left + 5) < $('#page_container').outerWidth())) {
    $("#page_container:not('.login #page_container')").corner('5px tr');
  }
}

init_delete_confirmations = function() {
  $('a.confirm-delete').click(function(e) {
    if (confirm("Are you sure you want to " + (t=($(this).attr('title') || $(this).attr('tooltip')))[0].toLowerCase() + t.substring(1) + "?"))
    {
      $("<form method='POST' action='" + $(this).attr('href') + "'></form>")
        .append("<input type='hidden' name='_method' value='delete' />")
        .append("<input type='hidden' name='authenticity_token' value='" + $('#admin_authenticity_token').val() + "'/>")
        .appendTo('body').submit();
    }
    e.preventDefault();
  });
}

init_flash_messages = function(){
  $('#flash').fadeIn(550);
  $('#flash_close').click(function(e) {
     $('#flash').fadeOut({duration: 330});
     e.preventDefault();
  });
  $('#flash.flash_message').prependTo('#records');
}

init_modal_dialogs = function(){
  $('a[href*="dialog=true"]').not('#dialog_container a').each(function(i, anchor)
  {
    $(anchor).click(function(e){
      iframe = $("<iframe id='dialog_iframe' src='" + $(this).attr('href') + "&amp;app_dialog=true" + "'></iframe>").corner('8px');
      iframe.dialog({
        title: $(anchor).attr('title') || $(anchor).attr('name') || $(anchor).html() || null
        , modal: true
        , resizable: false
        , autoOpen: true
        , width: (parseInt($(anchor.href.match("width=([0-9]*)")).last().get(0))||928)
        , height: (parseInt($(anchor.href.match("height=([0-9]*)")).last().get(0))||473)
        , open: onOpenDialog
        , close: onCloseDialog
      });
      if ($.browser.msie) {
        iframe.css({'margin':'-2px 2px 2px -2px'});
      }
      $(document.body).addClass('hide-overflow');
      e.preventDefault();
    });
  });
}

init_sortable_menu = function(){
  var $menu = $('#menu');

  if($menu.length == 0){return}

  $menu.sortable({
    axis: 'x',
    cursor: 'crosshair',
    update: function(){
      var ser   = $menu.sortable('serialize', {key: 'menu[]'}),
          token = escape($('#admin_authenticity_token').val());

      $.get('/refinery/update_menu_positions?' + ser, {authenticity_token: token});
    }
  }).tabs();
  //Initial status disabled
  $menu.sortable('disable');

  $menu.find('#menu_reorder').click(function(e){
    e.preventDefault();
    $('#menu_reorder, #menu_reorder_done').toggle();
    $('#site_bar, #header >*:not(#header_content, #menu, script), #content').fadeTo(500, 0.65);
    $menu.find('.tab a').click(function(ev){
      ev.preventDefault();
    });

    $menu.sortable('enable');
  });

  $menu.find('#menu_reorder_done').click(function(e){
    e.preventDefault();
    $('#menu_reorder, #menu_reorder_done').toggle();
    $('#site_bar, #header >*:not(#header_content, #menu, script), #content').fadeTo(500, 1);
    $menu.find('.tab a').unbind('click');

    $menu.sortable('disable');
  });

  $menu.find('> a').corner('top 5px');
}

init_submit_continue = function(){
  $('#submit_continue_button').click(submit_and_continue);

  if ((continue_editing = $('#continue_editing')).length > 0 && continue_editing.attr('rel') != 'no-prompt') {
    $('#editor_switch a').click(function(e) {
      if (!confirm("Any changes you've made will be lost. Are you sure you want to continue without saving?")) {
        e.preventDefault();
      }
    });
  }
}

submit_and_continue = function(e, redirect_to) {
  // ensure wymeditors are up to date.
  if ($(this).hasClass('wymupdate')) {
    $.each(WYMeditor.INSTANCES, function(index, wym)
    {
      wym.update();
    });
  }

  $('#continue_editing').val(true);
  $('#flash').fadeOut(250)

{'fraction_non_alphanumeric': 0.22250167672702884, 'fraction_numerical': 0.008383635144198525, 'mean_word_length': 3.777332799359231, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2960421', 'n_tokens_mistral': 4038, 'n_tokens_neox': 3913, 'n_words': 650}