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 ( -
-
-
+
diff --git a/codepot/src/codepot/views/wiki_show.php b/codepot/src/codepot/views/wiki_show.php index 10291dbf..f00149b9 100644 --- a/codepot/src/codepot/views/wiki_show.php +++ b/codepot/src/codepot/views/wiki_show.php @@ -59,37 +59,6 @@ function show_alert (outputMsg, titleMsg) }); } -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_wiki() { var column_count = 'columns ?>'; @@ -108,7 +77,12 @@ function render_wiki() } doctype == 'M'): ?> - showdown_render_wiki ("wiki_show_wiki_text", "wiki_show_wiki"); + showdown_render_wiki ( + "wiki_show_wiki_text", + "wiki_show_wiki", + "/wiki/show/id?>/", + "/wiki/attachment/id?>//" + ); creole_render_wiki ( "wiki_show_wiki_text", diff --git a/codepot/src/css/common.css b/codepot/src/css/common.css index 71a8fa45..533fbe43 100644 --- a/codepot/src/css/common.css +++ b/codepot/src/css/common.css @@ -403,6 +403,8 @@ pre, code, tt { font-size: inherit; border: 0 none; padding: 0.2em 0.2em 0.2em 0.2em; + + width: 100%; } .content .mainarea .form_input_label { diff --git a/codepot/src/css/file.css b/codepot/src/css/file.css index 98816b03..6e97d10a 100644 --- a/codepot/src/css/file.css +++ b/codepot/src/css/file.css @@ -48,23 +48,28 @@ } /*----------------------------------------------- - * file home view - new file dialog + * file home/show view - new/edit file dialog *-----------------------------------------------*/ -#file_home_mainarea_new_description_tabs { +#file_home_new_description_tabs, +#file_show_edit_description_tabs { border: none !important; } -#file_home_mainarea_new_description_tabs .ui-tabs-panel { +#file_home_new_description_tabs .ui-tabs-panel, +#file_show_edit_description_tabs .ui-tabs-panel { padding: 0.2em 0em 0em 0em !important; } -#file_home_mainarea_new_description_tabs .ui-widget-header { + +#file_home_new_description_tabs .ui-widget-header, +#file_show_edit_description_tabs .ui-widget-header { border: none !important; background: none !important; padding: 0em !important; } -#file_home_mainarea_new_description_tabs .ui-tabs-nav { +#file_home_new_description_tabs .ui-tabs-nav, +#file_show_edit_description_tabs .ui-tabs-nav { padding: 0em !important; } @@ -77,33 +82,3 @@ border-bottom: 1px solid #fbd850 !important; } - -/*----------------------------------------------- - * file home show - edit file dialog - *-----------------------------------------------*/ -#file_show_edit_description_tabs { - border: none !important; -} - -#file_show_edit_description_tabs .ui-tabs-panel { - padding: 0.2em 0em 0em 0em !important; -} - -#file_show_edit_description_tabs .ui-widget-header { - border: none !important; - background: none !important; - padding: 0em !important; -} - -#file_show_edit_description_tabs .ui-tabs-nav { - padding: 0em !important; -} - -/* #file_show_edit_description_tabs .ui-tabs-nav li { */ -.ui-tabs .ui-tabs-nav li.ui-state-default { - border-bottom: 1px solid #cccccc !important; -} - -.ui-tabs .ui-tabs-nav li.ui-state-active { - border-bottom: 1px solid #fbd850 !important; -} diff --git a/codepot/src/js/creole.js b/codepot/src/js/creole.js index c3b80f4e..92b61ca2 100644 --- a/codepot/src/js/creole.js +++ b/codepot/src/js/creole.js @@ -558,20 +558,17 @@ Parse.Simple.Creole.prototype = new Parse.Simple.Base(); Parse.Simple.Creole.prototype.constructor = Parse.Simple.Creole; -function creole_render_wiki (inputid, outputid, linkbase, imgbase) +function creole_render_wiki_with_input_text (input_text, outputid, linkbase, imgbase, raw = false) { - function $(id) { return document.getElementById(id); } - function decodeEntities(str) { - return str.replace(/&/g, '&'). - replace(/</g, '<'). + return str.replace(/</g, '<'). replace(/>/g, '>'). - replace(/"/g, '"'); + replace(/"/g, '"'). + replace(/&/g, '&'); /* & replacement must be the last */ } - var input = $(inputid); - var output = $(outputid); + var output = document.getElementById(outputid); var creole = new Parse.Simple.Creole( { forIE: document.all, @@ -580,40 +577,19 @@ function creole_render_wiki (inputid, outputid, linkbase, imgbase) Wikipedia: 'http://en.wikipedia.org/wiki/' },*/ linkFormat: linkbase, - imgFormat: imgbase + imgFormat: imgbase } ); - var xinput = decodeEntities(input.innerHTML); + var xinput; + if (raw) xinput = input_text; + else xinput = decodeEntities(input_text); + output.innerHTML = ''; creole.parse (output, xinput); } -function creole_render_wiki_with_input_text (input_text, outputid, linkbase, imgbase) +function creole_render_wiki (inputid, outputid, linkbase, imgbase, raw = false) { - function $(id) { return document.getElementById(id); } - - function decodeEntities(str) - { - return str.replace(/&/g, '&'). - replace(/</g, '<'). - replace(/>/g, '>'). - replace(/"/g, '"'); - } - - //var input = $(inputid); - var output = $(outputid); - var creole = new Parse.Simple.Creole( - { - forIE: document.all, - /*interwiki: { - WikiCreole: 'http://www.wikicreole.org/wiki/', - Wikipedia: 'http://en.wikipedia.org/wiki/' - },*/ - linkFormat: linkbase, - imgFormat: imgbase - } ); - - var xinput = decodeEntities(input_text); - output.innerHTML = ''; - creole.parse (output, xinput); + var input = document.getElementById(inputid); + return creole_render_wiki_with_input_text (input.innerHTML, outputid, linkbase, imgbase, raw); } diff --git a/codepot/src/js/showdown.js b/codepot/src/js/showdown.js index deec9b3d..0fe20047 100644 --- a/codepot/src/js/showdown.js +++ b/codepot/src/js/showdown.js @@ -2508,3 +2508,42 @@ if (typeof module !== 'undefined' && module.exports) { }).call(this); //# sourceMappingURL=showdown.js.map + + +function showdown_render_wiki_with_input_text (input_text, outputid, linkbase, imgbase, raw = false) +{ + 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, '&'); + } + + if (raw) xinput = input_text; + else xinput = decodeEntities(input_text); + var output = document.getElementById(outputid); + + output.innerHTML = sd.makeHtml(xinput); +} + +function showdown_render_wiki (inputid, outputid, linkbase, imgbase, raw = false) +{ + var input = document.getElementById(inputid); + return showdown_render_wiki_with_input_text (input.innerHTML, outputid, linkbase, imgbase, raw); +}