2021-01-01 12:08:59 +01:00
|
|
|
/*
|
|
|
|
* MarkDoc
|
|
|
|
* PHP MarkDown document manager
|
|
|
|
* Hordé Nicolas
|
|
|
|
* https://github.com/dahut87/MarkDoc
|
|
|
|
* Release under GPLv3.0 license
|
|
|
|
* Base on Pheditor "PHP file editor" By Hamid Samak Release under MIT license
|
|
|
|
*/
|
|
|
|
|
|
|
|
var external = RegExp('^((f|ht)tps?:)?//');
|
|
|
|
var javascript = RegExp('^javascript:');
|
|
|
|
var emoji;
|
|
|
|
$(function(){
|
|
|
|
$("#files").jstree({
|
|
|
|
themes: { responsive: true },
|
|
|
|
plugins: [ "types" ],
|
|
|
|
core:
|
|
|
|
{
|
|
|
|
strings:{ loading: "Chargement" },
|
|
|
|
check_callback: true,
|
|
|
|
data : {
|
|
|
|
type: "POST",
|
|
|
|
dataType: "json",
|
|
|
|
url : "/index.php",
|
|
|
|
data : function (node) {
|
|
|
|
return { 'action' : 'children' };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2021-01-02 12:46:21 +01:00
|
|
|
emoji = new EmojiConvertor();
|
|
|
|
$("#content").html(emoji.replace_colons($("#content").html()));
|
2021-01-01 12:08:59 +01:00
|
|
|
$("#editor").hide();
|
|
|
|
$("#image").hide();
|
|
|
|
$("#save").hide();
|
2021-01-02 12:46:21 +01:00
|
|
|
setTimeout(function(){ $("#forkongithub").fadeOut(1500); }, 5000);
|
|
|
|
$("#toc").tocify();
|
2021-01-01 12:08:59 +01:00
|
|
|
|
|
|
|
$("#files").on("select_node.jstree", function (e, nodes) {
|
|
|
|
file="/"+$("#files").jstree("get_path",nodes.node,"/").replace(/^.+?[/]/, '');
|
|
|
|
if ($("#files").jstree("is_leaf",nodes.node))
|
2021-01-02 12:46:21 +01:00
|
|
|
openlink(file+".md",false);
|
2021-01-01 12:08:59 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
$("input[name=submit]").click(function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
search($("#search").val());
|
|
|
|
});
|
|
|
|
|
|
|
|
majlink('head');
|
|
|
|
});
|
|
|
|
|
2021-01-02 12:46:21 +01:00
|
|
|
function openlink(dest,majtree)
|
2021-01-01 12:08:59 +01:00
|
|
|
{
|
|
|
|
$.ajax({
|
|
|
|
type: "POST",
|
|
|
|
url: "/index.php",
|
|
|
|
data: { action: "open", file: encodeURIComponent(dest) },
|
|
|
|
success: function(data){
|
2021-01-02 12:46:21 +01:00
|
|
|
$("#content").html(emoji.replace_colons(data));
|
2021-01-01 12:08:59 +01:00
|
|
|
Prism.highlightAll();
|
|
|
|
majlink('content');
|
|
|
|
$(window).scrollTop(0);
|
2021-01-02 12:46:21 +01:00
|
|
|
if (majtree) searchtree(dest);
|
2021-01-01 12:08:59 +01:00
|
|
|
},
|
|
|
|
error: function(XMLHttpRequest, textStatus, errorThrown) {
|
|
|
|
if (dest!="special/404.md")
|
2021-01-02 12:46:21 +01:00
|
|
|
openlink("special/404.md",false);
|
2021-01-01 12:08:59 +01:00
|
|
|
else
|
|
|
|
$("#content").html("<b>Erreur 404 sur erreur 404: pas de /special/404.md !");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function alertBox(message, className) {
|
|
|
|
$(".alert").removeClass("alert-success alert-warning alert-danger");
|
|
|
|
$(".alert").html(message).addClass("alert-" + className).fadeIn();
|
|
|
|
setTimeout(function(){
|
|
|
|
$(".alert").fadeOut();
|
|
|
|
}, 5000);
|
|
|
|
}
|
|
|
|
|
|
|
|
function majlink(context)
|
|
|
|
{
|
|
|
|
$('#'+context+' a').click(function(e) {
|
|
|
|
dest=$(this).attr('href');
|
|
|
|
if (!external.test(dest) && !javascript.test(dest))
|
|
|
|
{
|
|
|
|
e.preventDefault();
|
2021-01-02 12:46:21 +01:00
|
|
|
openlink(dest,true);
|
2021-01-01 12:08:59 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-01-02 12:46:21 +01:00
|
|
|
function searchtree(file)
|
|
|
|
{
|
|
|
|
var flag;
|
|
|
|
$("#files").jstree("deselect_all");
|
|
|
|
node=$("#files").jstree("get_node", "ul > li:first");
|
|
|
|
file.split('/').forEach(function (item) {
|
|
|
|
flag=false;
|
|
|
|
subnodes=$("#files").jstree("get_children_dom",node);
|
|
|
|
subnodes.each(function (i,subnode)
|
|
|
|
{
|
|
|
|
text=$("#files").jstree("get_text",subnode);
|
|
|
|
if ((text==item) || (text+".md"==item))
|
|
|
|
{
|
|
|
|
$("#files").jstree("open_node",subnode);
|
|
|
|
if ($("#files").jstree("is_leaf",subnode))
|
|
|
|
{
|
|
|
|
$("#files").jstree("select_node",subnode,true);
|
|
|
|
flag=false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
node=subnode;
|
|
|
|
flag=true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (!flag) return false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-01-01 12:08:59 +01:00
|
|
|
function search(arg)
|
|
|
|
{
|
|
|
|
$("#search").val(arg);
|
|
|
|
$.ajax({
|
|
|
|
type: "POST",
|
|
|
|
url: "/index.php",
|
|
|
|
data: { action: "search", search: encodeURIComponent(arg), type: "js" },
|
|
|
|
success: function(data){
|
2021-01-02 12:46:21 +01:00
|
|
|
$("#content").html(data);
|
2021-01-01 12:08:59 +01:00
|
|
|
Prism.highlightAll();
|
|
|
|
majlink('content');
|
|
|
|
$(window).scrollTop(0);
|
|
|
|
},
|
|
|
|
error: function(XMLHttpRequest, textStatus, errorThrown) {
|
|
|
|
if (dest!="special/404.md")
|
2021-01-02 12:46:21 +01:00
|
|
|
openlink("special/404.md",false);
|
2021-01-01 12:08:59 +01:00
|
|
|
else
|
|
|
|
$("#content").html("<b>Erreur 404 sur erreur 404: pas de /special/404.md !");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|