diff --git a/codepot/src/codepot/views/code_folder.php b/codepot/src/codepot/views/code_folder.php index e58352c5..deee742b 100644 --- a/codepot/src/codepot/views/code_folder.php +++ b/codepot/src/codepot/views/code_folder.php @@ -198,37 +198,6 @@ function show_loc_by_file_graph (response) $("#code_folder_loc_by_file_spin" ).removeClass ("fa-cog fa-spin"); } -function showdown_render_wiki (inputid, outputid) -{ - var sd = new showdown.Converter ({ - omitExtraWLInCodeBlocks: false, - noHeaderId: true, - prefixHeaderId: false, - parseImgDimensions: true, - headerLevelStart: 1, - simplifiedAutoLink: false, - literalMidWordUnderscores: false, - strikethrough: true, - tables: true, - tablesHeaderId: false, - ghCodeBlocks: true, - tasklists: true - }); - - function decodeEntities(str) - { - return str.replace(/&/g, '&'). - replace(/</g, '<'). - replace(/>/g, '>'). - replace(/"/g, '"'); - } - - var input = document.getElementById(inputid); - var output = document.getElementById(outputid); - - output.innerHTML = sd.makeHtml(decodeEntities(input.innerHTML)); -} - function render_readme() { 0 && substr_compare($readme_file, '.md', -3) === 0): ?> - showdown_render_wiki ("code_folder_readme_text", "code_folder_readme"); + showdown_render_wiki ( + "code_folder_readme_text", + "code_folder_readme", + codepot_merge_path("", "/wiki/show/id?>/"), + codepot_merge_path("", "/wiki/attachment0/id?>/") + ); prettyPrint(); } diff --git a/codepot/src/codepot/views/file_home.php b/codepot/src/codepot/views/file_home.php index 9879f0db..edfbccfb 100644 --- a/codepot/src/codepot/views/file_home.php +++ b/codepot/src/codepot/views/file_home.php @@ -41,13 +41,14 @@ function show_alert (outputMsg, titleMsg) }); } -function render_wiki(input_text) +function preview_new_description(input_text) { creole_render_wiki_with_input_text ( input_text, "file_home_new_description_preview", "/wiki/show/id?>/", - "/wiki/attachment0/id?>/" + "/wiki/attachment0/id?>/", + true // raw ); prettyPrint (); @@ -113,7 +114,7 @@ $(function () { $("#file_home_new_description_tabs").tabs (); $("#file_home_new_description_tabs").bind ('tabsshow', function (event, ui) { - if (ui.index == 2) render_wiki ($("#file_home_new_description").val()); + if (ui.index == 2) preview_new_description ($("#file_home_new_description").val()); }); $('#file_home_new_form_div').dialog ( diff --git a/codepot/src/codepot/views/file_show.php b/codepot/src/codepot/views/file_show.php index 63bd7f0e..5658624a 100644 --- a/codepot/src/codepot/views/file_show.php +++ b/codepot/src/codepot/views/file_show.php @@ -66,7 +66,8 @@ function preview_edit_description (input_text) input_text, "file_show_edit_description_preview", "", - "/" + "/", + true // raw ); prettyPrint (); diff --git a/codepot/src/codepot/views/issue_home.php b/codepot/src/codepot/views/issue_home.php index 0aa039b1..1917d04d 100644 --- a/codepot/src/codepot/views/issue_home.php +++ b/codepot/src/codepot/views/issue_home.php @@ -67,7 +67,8 @@ function preview_new_description(input_text) input_text, "issue_home_new_description_preview", "", - "" + "", + true ); prettyPrint (); diff --git a/codepot/src/codepot/views/issue_show.php b/codepot/src/codepot/views/issue_show.php index 636afaf7..af8f2ac3 100644 --- a/codepot/src/codepot/views/issue_show.php +++ b/codepot/src/codepot/views/issue_show.php @@ -177,7 +177,8 @@ function preview_edit_description (input_text) input_text, "issue_show_edit_description_preview", "", - "/" + "/", + true // raw ); prettyPrint (); @@ -1142,7 +1143,8 @@ function preview_issue_change_comment(input_text) input_text, "issue_change_comment_preview", "", - "" + "", + true ); prettyPrint (); diff --git a/codepot/src/codepot/views/project_edit.php b/codepot/src/codepot/views/project_edit.php index 842843f2..ceccb8db 100644 --- a/codepot/src/codepot/views/project_edit.php +++ b/codepot/src/codepot/views/project_edit.php @@ -23,22 +23,23 @@ + @@ -45,23 +46,79 @@ function show_alert (outputMsg, titleMsg) }); } -function resize_editor() +var previewing_text = false; + +function resize_text_editor() { - var editor = $("#wiki_edit_text_area"); - editor.height(0); // to prevent from continuous growing. it seems to affect footer placement when not set to 0. + var editor_container = $("#wiki_edit_result"); - var titleband = $("#wiki_edit_title_band"); - var files = $("#wiki_edit_files"); - var footer = $("#codepot_footer"); + if (previewing_text) + { + editor_container.height('auto'); + } + else + { + var editor = $("#wiki_edit_text_area"); + var titleband = $("wiki_edit_titleband"); + var footer = $("#codepot_footer"); - var ioff = titleband.offset(); - var foff = footer.offset(); + editor_container.height(0); + var coff = editor_container.offset(); + var foff = footer.offset(); - ioff.top += titleband.outerHeight() + files.outerHeight() + 10; + var editor_height = foff.top - coff.top - 10; + editor_container.innerHeight (editor_height); + editor.innerHeight (editor_height); + editor.innerWidth (titleband.innerWidth()); + } +} - editor.offset (ioff); - editor.innerHeight (foff.top - ioff.top - 5); - editor.innerWidth (titleband.innerWidth()); + +function preview_text (input_text) +{ + if (previewing_text) + { + // switch to editing mode + previewing_text = false; + $("#wiki_edit_text_preview").empty(); + $("#wiki_edit_text_area").show(); + $("#wiki_edit_text_show").hide(); + $("#wiki_edit_preview_button").button("option", "label", "lang->line('Preview'); ?>"); + } + else + { + // switch to preview mode + previewing_text = true; + + $("#wiki_edit_text_preview").show(); + $("#wiki_edit_text_area").hide(); + $("#wiki_edit_preview_button").button("option", "label", "lang->line('Edit'); ?>"); + + if ($('#wiki_edit_doctype').val() == 'M') + { + showdown_render_wiki_with_input_text ( + input_text, + "wiki_edit_text_preview", + "/wiki/show/id?>/", + "/wiki/attachment0/id?>/", + true // raw + ); + } + else + { + creole_render_wiki_with_input_text ( + input_text, + "wiki_edit_text_preview", + "/wiki/show/id?>/", + "/wiki/attachment0/id?>/", + true // raw + ); + } + + prettyPrint (); + } + + resize_text_editor (); } var populated_file_obj_for_adding = []; @@ -102,7 +159,7 @@ function populate_selected_files_for_adding () } populated_file_max_for_adding = f_no; - resize_editor (); + resize_text_editor (); } function cancel_out_add_file (no) @@ -110,7 +167,7 @@ function cancel_out_add_file (no) $('#wiki_edit_add_file_row_' + no).remove (); populated_file_obj_for_adding[no] = null; - resize_editor (); + resize_text_editor (); } function kill_file (no) @@ -130,7 +187,7 @@ function kill_file (no) } } - resize_editor (); + resize_text_editor (); } @@ -217,7 +274,7 @@ $(function () { $('#wiki_edit_files').accordion({ collapsible: true, heightStyle: "content", - activate: function() { resize_editor(); } + activate: function() { resize_text_editor(); } }); $('#wiki_edit_add_files_button').button().click (function () { @@ -234,7 +291,7 @@ $(function () { $("#wiki_edit_preview_button").button().click (function() { - // TODO: + preview_text ($('#wiki_edit_text_area').val()); return false; }); $("#wiki_edit_save_button").button().click (function() { @@ -330,7 +387,7 @@ $(function () { { show_alert ('
NOT SUPPORTED', "lang->line('Error')?>"); } - + return false; }); @@ -351,8 +408,8 @@ $(function () { // return null; // this line caused firefox to show the default message. }); - $(window).resize(resize_editor); - resize_editor (); + $(window).resize(resize_text_editor); + resize_text_editor (); }); @@ -444,10 +501,8 @@ $this->load->view ( -