[refs #616] some fixes and refactoring

This commit is contained in:
Alexander Machehin 2012-09-18 16:00:21 +06:00
parent a4c8e8eff8
commit a492367a17
10 changed files with 58 additions and 38 deletions

View File

@ -0,0 +1,28 @@
$(document).ready(function() {
var preview_url = $('#preview_url').val();
$('#md_tabs.nav.nav-tabs').each(function(i) { $(this).find('a:first').tab('show') });
$('#md_tabs a[data-toggle="tab"]').on('shown', function (e) {
if(e.relatedTarget) { var hash = e.relatedTarget.hash; }
else { var hash = e.currentTarget.hash; }
var el = $(hash+'_input');
var el_dup = $(hash+'_input_dup');
var preview = $(e.target.hash+' > .formatted.cm-s-default');
if(el.val() != el_dup.val() || preview.val() === '') {
el_dup.val(el.val());
$.ajax({
type: 'POST',
url: preview_url,
data: el_dup.serialize(),
success: function(data){
preview.html(data).find('code').each(function (code) {
CodeMirror.runMode(this.innerHTML.replace(/&/gi, '&'), this.className, this);
});
},
error: function(data){
alert('error'); // TODO remove
}
});
};
});
});

View File

@ -232,7 +232,9 @@ $(document).ready(function() {
form.fadeOut('slow');
$('#edit_issue_content').fadeIn('slow');
$('h3.issue_title').html(form.find('#issue_title').attr('value'));
$('.fulltext.view.issue_body').html(data);
$('.fulltext.view.issue_body').html(data).find('code').each(function (code) {
CodeMirror.runMode(this.innerHTML.replace(/&/gi, '&'), this.className, this);
});
},
error: function(data){
alert('error'); // TODO remove

View File

@ -1494,8 +1494,8 @@ table.tablesorter.platform-maintainers.static-search thead tr.search th input[ty
.md_and_cm {
overflow: auto;
min-height: 112px;
margin: 10px 0 10px;
padding: 5px;
border-radius: 4px 4px 4px 4px;
pre {
@ -1529,7 +1529,8 @@ table.tablesorter.platform-maintainers.static-search thead tr.search th input[ty
line-height: 5px;
}
#open-comment textarea {
#open-comment {
textarea {
background: none repeat scroll 0 0 #FFFFFF;
border: 1px solid #DEDEDE;
border-radius: 4px 4px 4px 4px;
@ -1540,7 +1541,12 @@ table.tablesorter.platform-maintainers.static-search thead tr.search th input[ty
width: 98%;
max-width: 98%;
margin: 10px 0 10px;
resize: both;
resize: vertical;
}
.tab-pane textarea {
min-height: 112px;
}
}
#open-comment > h3.tmargin0 {

View File

@ -54,7 +54,7 @@ class Projects::IssuesController < Projects::BaseController
render :partial => 'status', :status => (@issue.save ? 200 : 500)
elsif params[:issue]
status = @issue.update_attributes(params[:issue]) ? 200 : 500
render :inline => ActionController::Base.helpers.simple_format(params[:issue][:body]), :status => status
render :inline => view_context.markdown(@issue.body), :status => status
else
render :nothing => true, :status => 200
end

View File

@ -43,7 +43,7 @@ module ApplicationHelper
def markdown(text)
html_options = {filter_html: true, hard_wrap: true, with_toc_data: true}
options = {no_intraemphasis: true, tables: true, fenced_code_blocks: true, autolink: true, strikethrough: true, lax_html_blocks: true}
Redcarpet::Markdown.new(Redcarpet::Render::HTML.new(html_options), options).render(text).html_safe
@redcarpet ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML.new(html_options), options)
@redcarpet.render(text).html_safe
end
end

View File

@ -11,30 +11,3 @@
.tab-pane{:id => "#{id}_preview"}
.formatted.cm-s-default.md_and_cm{:style => 'background: #FFF'}
:javascript
$(document).ready(function() {
$('#md_tabs a:first').tab('show');
$('#md_tabs a[data-toggle="tab"]').on('shown', function (e) {
var hash = e.relatedTarget.hash;
var el = $(hash+'_input');
var el_dup = $(hash+'_input_dup');
var preview = $(e.target.hash+' > .formatted.cm-s-default');
if(el.val() != el_dup.val() || preview.val() === '') {
el_dup.val(el.val());
$.ajax({
type: 'POST',
url: '#{project_md_preview_path @project}',
data: el_dup.serialize(),
success: function(data){
preview.html(data).find('code').each(function (code) {
CodeMirror.runMode(this.innerHTML.replace(/&amp;/gi, '&'), this.className, this);
});
},
error: function(data){
alert('error'); // TODO remove
}
});
};
});
});

View File

@ -9,3 +9,5 @@
.inner
= form_for @comment, :url => project_commentable_comment_path(@project, @commentable, @comment), :html => {:class => :form} do |f|
= render "form", :f => f, :id => "edit_#{@comment.id}"
=hidden_field_tag :preview_url, project_md_preview_path(@project)

View File

@ -14,3 +14,6 @@
= render "projects/comments/list", :list => Comment.for_commit(@commit), :project => @project, :commentable => @commit
= render "projects/comments/add", :project => @project, :commentable => @commit if current_user
=hidden_field_tag :preview_url, project_md_preview_path(@project)

View File

@ -5,3 +5,5 @@
%h3.bpadding10= t("layout.issues.create_header")
= form_for :issue, :url => project_issues_path(@project), :html => { :class => 'form issue' } do |f|
= render "form", :f => f
=hidden_field_tag :preview_url, project_md_preview_path(@project)

View File

@ -20,10 +20,12 @@
- if can? :update, @issue
=link_to t('layout.edit'), '#', :id => 'edit_issue_content', :class => 'button'
=form_for :issue, :url => [@project, @issue], :method => :put, :html => { :class => 'edit_form issue', :style => 'display:none;' } do |f|
.leftlist= t('activerecord.attributes.issue.title') + ':'
.rightlist= f.text_field :title
.leftlist= t('activerecord.attributes.issue.body') + ':'
.rightlist= f.text_area :body
#open-comment.comment.view
%h3.tmargin0{:style => 'margin-bottom: 0;'}= t 'activerecord.attributes.issue.title'
.wrapper= f.text_area :title, :cols => 80, :rows => 1, :style => 'height: 16px; margin: 0 0 10px;'
#open-comment.comment.view
%h3.tmargin0= t 'activerecord.attributes.issue.body'
=render 'projects/comments/body', :f => f, :id => 'update'
.both
=f.submit t('layout.update'), :id => 'update_issue_content'
=link_to t('layout.issues.cancel_button'), '#', :id => 'cancel_edit_issue_content', :class => 'button'
@ -34,3 +36,5 @@
%br
= render "projects/comments/add", :project => @project, :commentable => @issue if current_user
=hidden_field_tag :preview_url, project_md_preview_path(@project)