jQuery(function($) { $("#body-button").click(function(){ $(this).toggleClass('icon-add').toggleClass('icon-remove'); $('#article-body-field').slideToggle(); return false; }) $("#textile-quickref-show").click(function(){ $('#textile-quickref-hide').show(); $(this).hide(); $('#textile-quickref').slideToggle(); return false; }) $("#textile-quickref-hide").click(function(){ $('#textile-quickref-show').show(); $(this).hide(); $('#textile-quickref').slideToggle(); return false; }) var button_add = $('.text-editor-sidebar span.button-add').attr('data-value'); var button_zoom = $('.text-editor-sidebar span.button-zoom').attr('data-value'); var button_close = $('.text-editor-sidebar span.button-close').attr('data-value'); function add_to_text_button(extra_class) { if (!extra_class) { extra_class = '' } return '' + button_add + ''; } function close_button(extra_class) { if (!extra_class) { extra_class = '' } return '' + button_close + ''; } function zoom_button() { return '' + button_zoom + ''; } function list_items(items, selector, auto_add) { var html_for_items = ''; var images = []; var files = []; var errors = []; $.each(items, function(i, item) { if (item.error) { errors.push(item); return; } if (item.content_type && item.content_type.match(/^image/)) { images.push(item); } else { files.push(item); } }); $.each(images, function(i, item) { html_for_items += '
', '').replace('', ''); // old firefox
      var data = $.parseJSON(text);
      list_items(data, '#media-upload-results .items', true);
      if (data.length && data.length > 0) {
        $('#media-upload-results').slideDown();
      }
      $('#media-upload-box .header').toggleClass('icon-loading');
    }
  });
  $('#media-upload-more-files').click(function() {
    $('#media-upload-results').hide();
    $('#media-upload-form').show();
    return false;
  });
  function is_public_article() {
    return $("#article_published_true").attr('checked');
  }
  function show_hide_privacy_options() {
    var show_privacy_options = $("#article_published_false").attr('checked');
    var custom_privacy_option = $(".custom_privacy_option").parent("div");
    if( show_privacy_options ) {
      custom_privacy_option.show();
    } else {
      custom_privacy_option.hide();
    }
    show_hide_token_input();
  }
  function show_hide_token_input() {
    var display_token =  $(".custom_privacy_option:checked").length == 0;
    var token_field = $("#text-input-search-exception-users").parent("div");
    if( display_token && !is_public_article() ) {
      token_field.css('display', 'block');
    } else {
      token_field.css('display', 'none');
    }
  }
  if( $("#token-input-search-article-privacy-exceptions").length == 1 ) {
    show_hide_privacy_options();
    show_hide_token_input();
  }
  $(document).ready(function(){
    show_hide_privacy_options();
  });
  //Hide / Show the text area
  $("#article_published_false").click(show_hide_privacy_options);
  $("#article_published_true").click(show_hide_privacy_options);
  $(".custom_privacy_option").click(show_hide_token_input);
});