Skip to content

Commit

Permalink
Adds a per textfilter toolbar (markdown, textile, none).
Browse files Browse the repository at this point in the history
TODO:

* The markdown and textile links use html ones, too lazy.
* Change the toolbar when you change the filter (JS sucks).
* Rewrite the whole thing to make it less 2003 ish.
  • Loading branch information
Frédéric de Villamil committed Aug 30, 2013
1 parent d3e74c1 commit c802f0a
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 130 deletions.
4 changes: 2 additions & 2 deletions app/views/admin/content/_form.html.erb
Expand Up @@ -36,15 +36,15 @@

<div id="editor">
<div id='quicktags' style='<%= "display: none;" if current_user.editor == 'visual' %>'>
<script type="text/javascript">edToolbar('article_body_and_extended');</script>
<script type="text/javascript">edToolbar('article_body_and_extended', '<%= @article.text_filter %>');</script>
</div>

<div id ='visual_editor' <%= "style='display: none;'" if current_user.editor == 'simple'%> >
<%= ckeditor_textarea('article', 'body_and_extended', {:class => 'large', :height => '300px', :rows => '20'}) if current_user.editor == 'visual' %>
</div>

<div id='simple_editor' <%= "style='display: none;'" if current_user.editor == 'visual'%> >
<%= text_area('article', 'body_and_extended', {:class => 'input-block-level', :height => '300px'}) if current_user.editor == 'simple' %>
<%= text_area('article', 'body_and_extended', {:class => 'input-block-level', :height => '360px'}) if current_user.editor == 'simple' %>
<%= render 'admin/shared/macros' if current_user.editor == 'simple' %>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/feedback/article.html.erb
Expand Up @@ -50,7 +50,7 @@
<div class='control-group'>
<label for='comment_body' class='control-label'><%= _("Your comment") %></label>
<div class='controls'>
<script type="text/javascript">edToolbar('comment_body');</script>
<script type="text/javascript">edToolbar('comment_body', '<%= current_user.default_text_filter.name %>');</script>
<%= text_area 'comment', 'body', { :rows => '10', :class => 'span6'} %>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/views/admin/feedback/edit.html.erb
Expand Up @@ -28,8 +28,8 @@
<div class='control-group'>
<label for='comment_body' class='control-label'><%= _("Your comment") %></label>
<div class='controls'>
<script type="text/javascript">edToolbar('comment_body');</script>
<%= text_area 'comment', 'body', { :rows => '10', :class => 'large'} %>
<script type="text/javascript">edToolbar('comment_body', '<%= current_user.default_text_filter.name %>');</script>
<%= text_area 'comment', 'body', { :rows => '10', :class => 'input-block-level'} %>
</div>
</div>
<div class='form-actions'>
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/notes/new.html.erb
Expand Up @@ -5,7 +5,7 @@
<%= form_tag :action=>"edit", :id => @note.id do %>
<input type="hidden" name="status[text_filter]" id="status_textfilter" value="<%= current_user.text_filter_name %>" />
<div id='quicktags'>
<script type="text/javascript">//edToolbar('status_body');</script>
<script type="text/javascript">//edToolbar('status_body', '<%= current_user.default_text_filter.name %>');</script>
</div>
<%= text_area('note', 'body', {:class => 'input-block-level', :rows => '7', :placeholder => _("Compose new note")}) %>

Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/pages/_form.html.erb
Expand Up @@ -32,7 +32,7 @@

<div id='editor'>
<div id='quicktags' style='<%= "display: none;" if current_user.editor == 'visual' %>'>
<script type="text/javascript">edToolbar('page_body');</script>
<script type="text/javascript">edToolbar('page_body', '<%= @page.text_filter %>');</script>
</div>
<div id ='visual_editor' <%= "style='display: none;'" if current_user.editor == 'simple'%> >
<%= ckeditor_textarea('page', 'body', {:class => 'large', :height => '300px', :rows => '20'}) if current_user.editor == 'visual' %>
Expand Down
183 changes: 60 additions & 123 deletions public/javascripts/administration.js
Expand Up @@ -82,125 +82,55 @@ function edButton(id, display, tagStart, tagEnd, access, open) {
this.open = open; // set to -1 if tag does not need to be closed
}

edButtons.push(
new edButton(
'ed_bold'
,'b'
,'<strong>'
,'</strong>'
,'b'
)
);

edButtons.push(
new edButton(
'ed_italic'
,'i'
,'<em>'
,'</em>'
,'i'
)
);

edButtons.push(
new edButton(
'ed_link'
,'link'
,''
,'</a>'
,'a'
)
); // special case

edButtons.push(
new edButton(
'ed_img'
,'img'
,''
,''
,'m'
,-1
)
); // special case

edButtons.push(
new edButton(
'ed_ul'
,'ul'
,'<ul>\n'
,'</ul>\n\n'
,'u'
)
);

edButtons.push(
new edButton(
'ed_ol'
,'ol'
,'<ol>\n'
,'</ol>\n\n'
,'o'
)
);

edButtons.push(
new edButton(
'ed_li'
,'li'
,'\t<li>'
,'</li>\n'
,'l'
)
);

edButtons.push(
new edButton(
'ed_block'
,'b-quote'
,'<blockquote>'
,'</blockquote>'
,'q'
)
);

edButtons.push(
new edButton(
'ed_del'
,'del'
,'<del>'
,'</del>'
)
);

edButtons.push(
new edButton(
'ed_code'
,'code'
,'<code>'
,'</code>'
,'c'
)
);

edButtons.push(
new edButton(
'ed_more'
,'more'
,'\n<!--more-->\n'
,''
,''
)
);

edButtons.push(
new edButton(
'ed_publifycode'
,'publify:code'
,''
,'\n</publify:code>\n\n'
,'publify:code'
)
);
function get_buttons(textfilter) {
switch (textfilter) {
case "textile":
edButtons.push(new edButton('ed_bold', 'b', '**', '**', 'b'));
edButtons.push(new edButton('ed_italic', 'i', '_', '_', 'i'));
edButtons.push(new edButton('ed_link', 'link', '', '</a>', 'a'));
edButtons.push(new edButton('ed_img', 'img', '!', '!', 'm' ,-1));
edButtons.push(new edButton('ed_li', 'li', '* ', '', 'l', -1));
edButtons.push(new edButton('ed_block', 'b-quote', '>', '', 'q', -1));
edButtons.push(new edButton('ed_del', 'del', '<del>', '</del>'));
edButtons.push(new edButton('ed_code', 'code', '@', '@', 'c'));
edButtons.push(new edButton('ed_more', 'more', '\n<!--more-->\n', '', ''));
edButtons.push(new edButton('ed_publifycode', 'publify:code', '', '\n</publify:code>\n\n', 'publify:code'));
break;

case "markdown":
case "markdown smartypants":
edButtons.push(new edButton('ed_bold', 'b', '**', '**', 'b'));
edButtons.push(new edButton('ed_italic', 'i', '_', '_', 'i'));
edButtons.push(new edButton('ed_link', 'link', '', '</a>', 'a'));
edButtons.push(new edButton('ed_img', 'img', '', '', 'm' ,-1));
edButtons.push(new edButton('ed_li', 'li', '* ', '', 'l', -1));
edButtons.push(new edButton('ed_ol', 'ol', '#', '', 'o', -1));
edButtons.push(new edButton('ed_block', 'b-quote', '>', '', 'q', -1));
edButtons.push(new edButton('ed_del', 'del', '<del>', '</del>'));
edButtons.push(new edButton('ed_code', 'code', '`', '`', 'c'));
edButtons.push(new edButton('ed_more', 'more', '\n<!--more-->\n', '', ''));
edButtons.push(new edButton('ed_publifycode', 'publify:code', '', '\n</publify:code>\n\n', 'publify:code'));
break;

default:
edButtons.push(new edButton('ed_bold', 'b', '<strong>', '</strong>', 'b'));
edButtons.push(new edButton('ed_italic', 'i', '<em>', '</em>', 'i'));
edButtons.push(new edButton('ed_link', 'link', '', '</a>', 'a'));
edButtons.push(new edButton('ed_img', 'img', '', '', 'm' ,-1));
edButtons.push(new edButton('ed_ul', 'ul', '<ul>\n', '</ul>\n\n', 'u'));
edButtons.push(new edButton('ed_ol', 'ol', '<ol>\n', '</ol>\n\n', 'o'));
edButtons.push(new edButton('ed_li', 'li', '\t<li>', '</li>\n', 'l'));
edButtons.push(new edButton('ed_block', 'b-quote', '<blockquote>', '</blockquote>', 'q'));
edButtons.push(new edButton('ed_del', 'del', '<del>', '</del>'));
edButtons.push(new edButton('ed_code', 'code', '<code>', '</code>', 'c'));
edButtons.push(new edButton('ed_more', 'more', '\n<!--more-->\n', '', ''));
edButtons.push(new edButton('ed_publifycode', 'publify:code', '', '\n</publify:code>\n\n', 'publify:code'));
break;
}


}


var extendedStart = edButtons.length;

Expand Down Expand Up @@ -330,11 +260,18 @@ function edSpell(which) {
}
}

function edToolbar(which) {
function edToolbar(which, textfilter) {
get_buttons(textfilter);

document.write('<div id="ed_toolbar_' + which + '" class="btn-toolbar"><div class="btn-group">');
for (i = 0; i < extendedStart; i++) {
edShowButton(which, edButtons[i], i);
}

for (i = extendedStart; i < edButtons.length; i++) {
edShowButton(which, edButtons[i], i);
}

if (edShowExtraCookie()) {
document.write(
'<input type="button" id="ed_close_' + which + '" class="btn" onclick="edCloseAllTags(\'' + which + '\');" value="Close Tags" />'
Expand All @@ -347,9 +284,9 @@ function edToolbar(which) {
+ '<input type="button" id="ed_spell_' + which + '" class="btn" onclick="edSpell(\'' + which + '\');" value="Dict" />'
);
}
for (i = extendedStart; i < edButtons.length; i++) {
edShowButton(which, edButtons[i], i);
}



// edShowLinks();
document.write('</div></div>');
edOpenTags[which] = new Array();
Expand Down

0 comments on commit c802f0a

Please sign in to comment.