Sha256: 5b2e5d2b697ecfa25210dc6c8308608b4c21e84a5b64e5f63b1df62139a4b90b

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

$(document).ready(function() {
  var form = $('form.formtastic, form.simple_form');

  if (form.length > 0 && form.attr('id').match(/^(new_enki_post|edit_enki_post|new_enki_page|edit_enki_page)/)) {
    var dest = window.location.href;
    dest = dest.replace(/\/(new|\d+)$/, '');
    dest = dest + '/preview';

    var toggle_preview = function() {
      if ($('#preview').length === 0) {
        form.hide();
        form.after('<div id="preview"><h3>Your entry will be formatted like this:</h3><p>Use Ctrl+E to return to edit mode.</p><div class="content"><p>Please wait...</p></div></div>');

        jQuery.ajax({
          type: 'POST',
          data: form.serialize().replace(/&*_method=\w+&*/, ''),
          url: dest,
          dataType: 'html',
          error: function() {
            $('#preview .content').html('<p>Failed to generate preview. Toggle back to edit mode and check that all required fields are filled in and valid.</p>');
          },
          success: function(r) {
            $('#preview .content').html(r);
          }
        });
      }
      else {
        $('#preview').remove();
        form.show();
      }
    };

    $(document).keyup(function(e) {
      if (e.ctrlKey && (e.which == 69)) { // Works in recent Safari and FF, unsure about IE
        toggle_preview();
        e.preventDefault();
      }
    });
  }
});

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
enki-engine-0.0.5 app/assets/javascripts/admin/edit-preview.js