Commit 44c2c1f6 authored by Matthieu Le Corre's avatar Matthieu Le Corre
Browse files

ajout de l affichage du HEADER.md

parent 8248023a
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
<namespace>ReadMeMd</namespace> <namespace>ReadMeMd</namespace>
<bugs>https://gitlab.univ-nantes.fr</bugs> <bugs>https://gitlab.univ-nantes.fr</bugs>
<dependencies> <dependencies>
<nextcloud min-version="12" max-version="14"/> <nextcloud min-version="12" max-version="15"/>
</dependencies> </dependencies>
<types> <types>
<filesystem/> <filesystem/>
......
...@@ -14,6 +14,5 @@ ...@@ -14,6 +14,5 @@
padding: 2em ; padding: 2em ;
border-bottom: 1px solid silver ; border-bottom: 1px solid silver ;
margin-bottom: 1em ; margin-bottom: 1em ;
background-color: #c6d6390f ;
} }
...@@ -8,15 +8,15 @@ OCA.ReadmeMD = {}; ...@@ -8,15 +8,15 @@ OCA.ReadmeMD = {};
*/ */
OCA.ReadmeMD.App = { OCA.ReadmeMD.App = {
/** /**
* Holds the MD container and content * Holds the MDs objects
*/ */
container: null, header: null,
content: null, readme: null,
/** /**
* Setup on page load * Setup on page load
*/ */
initialize: function (container) { initialize: function (header,readme) {
// Don't load if not in the files app // Don't load if not in the files app
if (!$('#content.app-files').length) { if (!$('#content.app-files').length) {
return; return;
...@@ -35,8 +35,11 @@ OCA.ReadmeMD.App = { ...@@ -35,8 +35,11 @@ OCA.ReadmeMD.App = {
$("#filestable").on('updated',this.checkMD); $("#filestable").on('updated',this.checkMD);
// container creation // container creation
this.container = container; this.header = header;
this.createContainer() ; this.readme = readme;
this.createContainer(this.header) ;
this.createContainer(this.readme) ;
}, },
...@@ -45,13 +48,21 @@ OCA.ReadmeMD.App = { ...@@ -45,13 +48,21 @@ OCA.ReadmeMD.App = {
* check MD handler * check MD handler
*/ */
checkMD: function() { checkMD: function() {
OCA.ReadmeMD.container.addClass("hidden") ; OCA.ReadmeMD.header.container.addClass("hidden") ;
OCA.ReadmeMD.readme.container.addClass("hidden") ;
for (var filenum in OCA.Files.App.fileList.files) { for (var filenum in OCA.Files.App.fileList.files) {
if ( OCA.Files.App.fileList.files[filenum].name == "README.md") {
OCA.ReadmeMD.container.removeClass("hidden") ; if ( OCA.Files.App.fileList.files[filenum].name == OCA.ReadmeMD.header.filename ) {
OCA.ReadmeMD.fillContainer() ; OCA.ReadmeMD.header.container.removeClass("hidden") ;
OCA.ReadmeMD.fillContainer(OCA.ReadmeMD.header) ;
} ;
if ( OCA.Files.App.fileList.files[filenum].name == OCA.ReadmeMD.readme.filename ) {
OCA.ReadmeMD.readme.container.removeClass("hidden") ;
OCA.ReadmeMD.fillContainer(OCA.ReadmeMD.readme) ;
} ; } ;
} ; } ;
}, },
...@@ -59,49 +70,65 @@ OCA.ReadmeMD.App = { ...@@ -59,49 +70,65 @@ OCA.ReadmeMD.App = {
/** /**
* show contenair * show contenair
*/ */
createContainer: function() { createContainer: function(zone) {
$('#filestable').after(this.container) ;
if (zone.position == "before")
{ $('#filestable').before(zone.container) ; }
if (zone.position == "after")
{ $('#filestable').after(zone.container) ; }
}, },
/** /**
* fill contant * fill contant
*/ */
fillContainer: function() { fillContainer: function(zone) {
dir=OCA.Files.App.fileList._currentDirectory ; dir=OCA.Files.App.fileList._currentDirectory ;i
filename ="README.md" ;
if (zone.position === "before" ) {
$.get( $.get(
OC.generateUrl('/apps/files_texteditor/ajax/loadfile'), OC.generateUrl('/apps/files_texteditor/ajax/loadfile'),
{ {
filename: filename, filename: zone.filename,
dir: dir dir: dir
} }
).done(function(data) { ).done(function(data,textStatus,jqXHR) {
OCA.ReadmeMD.content=data.filecontents ; OCA.ReadmeMD.header.content=data.filecontents ;
OCA.ReadmeMD.renderMD() ; OCA.ReadmeMD.renderMD(OCA.ReadmeMD.header) ;
}) ; }) ;
};
if (zone.position === "after" ) {
$.get(
OC.generateUrl('/apps/files_texteditor/ajax/loadfile'),
{
filename: zone.filename,
dir: dir
}
).done(function(data,textStatus,jqXHR) {
OCA.ReadmeMD.readme.content=data.filecontents ;
OCA.ReadmeMD.renderMD(OCA.ReadmeMD.readme) ;
}) ;
};
}, },
/** /**
* Render Markdown * Render Markdown
**/ **/
renderMD: function() { renderMD: function(zone) {
OCA.ReadmeMD.container //cleanup old content
.addClass('icon-loading') zone.container.children().remove();
.children().remove();
//render MD
OCA.Files_Texteditor.previewPlugins["text/markdown"].renderer.renderText( OCA.Files_Texteditor.previewPlugins["text/markdown"].renderer.renderText(
OCA.ReadmeMD.content, zone.content,
OCA.ReadmeMD.container zone.container
).done(function(data) { ).done(function(data) {
$("#filestable > tfoot > tr").height("auto") ; $("#filestable > tfoot > tr").height("auto") ;
OCA.ReadmeMD.container.removeClass('icon-loading') ;
}); });
} }
}; };
...@@ -110,7 +137,21 @@ OCA.ReadmeMD.App = { ...@@ -110,7 +137,21 @@ OCA.ReadmeMD.App = {
OCA.ReadmeMD = OCA.ReadmeMD.App ; OCA.ReadmeMD = OCA.ReadmeMD.App ;
$(document).ready(function () { $(document).ready(function () {
OCA.ReadmeMD.initialize($('<div id="preview" class="hidden text-markdown readmemd"></div>') ); var header = {
container: $('<div id="headerMD" class="hidden text-markdown headermd"></div>'),
position : "before",
filename : "HEADER.md",
content : null
} ;
var footer = {
container: $('<div id="readmeMD" class="hidden text-markdown readmemd"></div>'),
position : "after",
filename : "README.md",
content : null
} ;
OCA.ReadmeMD.initialize(header,footer);
}); });
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment