Utilisateur:Dr Brains/BlocNote.js
/**<pre><nowiki>
* Simple todo list docked on the right side of the page to take rapid notes.
* The list is saved and survives over a browser restart.
* This script uses client side storage which is currently only
* available on Firefox 2, and will NOT work on other non gecko browsers (IE, Opera, ...)
* Some wiki syntax is rendered for :
* - links and templates (e.g. [[foo]] and ((bar)))
* - bold and italic text (e.g. ''foo'' and '''bar''')
* Author : Zelda for fr.wikipedia.org
*/
// Activation
var Haut = false;
var Bas = false;
var Gauche = true;
var Droite = false;
var Taille = 50; // Taille bloc-note (en %)
var TailleD = 15; // Taille déplié (en %)
var TexteVide1 ="Bloc-note vide. Cliquer pour éditer...";
var TexteVide2 ="Cliquer pour éditer.";
var Position = ((100-Taille)/2);
///////////////////////////////////////////////////////////////////////////////////// HAUT //////////////////////////////////////////////////////////////////////////////////
/**
* Creates and restore the todo list
*/
function initTodoListHaut() {
if (typeof globalStorage == "undefined") {
//alert("This todo list requires client side persistent storage features which are currently available on Firefox 2.0 only");
return;
}
// retrieve stored text
var textContentHaut = globalStorage[location.hostname].getItem("todo-list-Haut.content");
if (! textContentHaut) textContentHaut = "";
var todoListHaut = document.createElement("table");
todoListHaut.id = "todo-list-Haut";
todoListHaut.setAttribute("style", "width:" + Taille + "%; position:fixed; top:0; left:" + Position + "%; z-index:10; opacity:.9; background:white; border:1px solid grey; border-spacing:0; -moz-border-radius-bottomright: 5px; -moz-border-radius-bottomleft: 5px; border-top:none");
todoListHaut.innerHTML = '<tr>' +
'<td><div style="width:100%; height:100%; overflow:auto; border:none; white-space:pre; font-size:120%; padding:.2em" id="todo-list-content-Haut" onclick="editTodoListHaut()" title="' + TexteVide2 + '"></div><textarea style="width:99%; height:100%; overflow:auto; border:none" id="todo-list-edit-Haut" onchange="saveTodoListHaut()" onblur="renderTodoListHaut()">' + textContentHaut + '</textarea></td></tr>' +
'<tr><td style="font-variant:small-caps; height:0.3em;padding:0; text-align:center; border: 1px dashed grey;background:#EEEEEE; cursor:pointer;width:100%; line-height:200%" id="todo-list-bar-Haut"></td>' +
'</tr>';
document.body.appendChild(todoListHaut);
renderTodoListHaut();
var visibleHaut = sessionStorage.getItem("todo-list-Haut.visible");
if (visibleHaut == "true") {
showTodoListHaut();
} else {
hideTodoListHaut();
}
}
/**
* Show the todo list
*/
function showTodoListHaut() {
var todoListHaut = document.getElementById("todo-list-Haut");
var listContentHaut = document.getElementById("todo-list-content-Haut");
var todoListBarHaut = document.getElementById("todo-list-bar-Haut");
listContentHaut.parentNode.style.display = "";
todoListHaut.style.height=TailleD+"%";
todoListBarHaut.style.height="10%";
todoListBarHaut.onmouseover = hideTodoListHaut;
sessionStorage.setItem("todo-list-Haut.visible", "true");
}
/**
* Hide the todo list
*/
function hideTodoListHaut() {
var todoListHaut = document.getElementById("todo-list-Haut");
var listContentHaut = document.getElementById("todo-list-content-Haut");
var todoListBarHaut = document.getElementById("todo-list-bar-Haut");
listContentHaut.parentNode.style.display = "none";
todoListHaut.style.height="auto";
todoListBarHaut.style.height="auto";
todoListBarHaut.onmouseover = showTodoListHaut;
sessionStorage.setItem("todo-list-Haut.visible", "false");
}
/**
* Save the todo list (each time the content changes)
*/
function saveTodoListHaut() {
globalStorage[location.hostname].setItem("todo-list-Haut.content", document.getElementById("todo-list-edit-Haut").value);
}
/**
* Shows a textarea to edit the todo list
*/
function editTodoListHaut() {
var divHaut = document.getElementById("todo-list-content-Haut");
var textareaHaut = document.getElementById("todo-list-edit-Haut");
divHaut.innerHTML = textareaHaut.value;
divHaut.style.display = "none";
textareaHaut.style.display = "";
textareaHaut.focus();
}
/**
* Renders the todo list interpreting some wiki syntax (links, templates, bold, italic)
*/
function renderTodoListHaut() {
var divHaut = document.getElementById("todo-list-content-Haut");
var textareaHaut = document.getElementById("todo-list-edit-Haut");
var contentHaut = textareaHaut.value;
if (!contentHaut || contentHaut == "") {
contentHaut = "''" + TexteVide1 + "''";
}
// Escape HTML characters
contentHaut = contentHaut.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
// Render wiki links
contentHaut = contentHaut.replace(/\[\[:?([^\|\]]*)(?:\|([^\|\]]+))?\]\]/g, function(match, article, title, offset, s) {
return "<a href=\"" + mw.config.get('wgServer') + "/wiki/" + article + "\">[[" + ((title) ? title : article) + "]]</a>";
});
// Render wiki templates
contentHaut = contentHaut.replace(/\{\{([^\}\|]+)(\|[^\}]+)?\}\}/g, "<a href=\"" + mw.config.get('wgServer') + "/wiki/Template:$1\">(($1$2))</a>");
// Render bold
contentHaut = contentHaut.replace(/'''((?:[^']|'(?!''))+)'''/g, "<b>$1</b>");
// Render italic
contentHaut = contentHaut.replace(/''((?:[^']|'(?!'))+)''/g, "<i>$1</i>");
divHaut.innerHTML = contentHaut;
divHaut.style.display = "";
textareaHaut.style.display = "none";
}
if(Haut){addOnloadHook(initTodoListHaut);}
///////////////////////////////////////////////////////////////////////////////////// BAS ////////////////////////////////////////////////////////////////////////////////////
/**
* Creates and restore the todo list
*/
function initTodoListBas() {
if (typeof globalStorage == "undefined") {
//alert("This todo list requires client side persistent storage features which are currently available on Firefox 2.0 only");
return;
}
// retrieve stored text
var textContentBas = globalStorage[location.hostname].getItem("todo-list-Bas.content");
if (! textContentBas) textContentBas = "";
var todoListBas = document.createElement("table");
todoListBas.id = "todo-list-Bas";
todoListBas.setAttribute("style", "width:" + Taille + "%; position:fixed; bottom:0; left:" + Position + "%; z-index:10; opacity:.9; background:white; border:1px solid grey; border-spacing:0; -moz-border-radius-topright: 5px; -moz-border-radius-topleft: 5px; border-top:none");
todoListBas.innerHTML = '<tr>' +
'<td style="font-variant:small-caps; height:0.3em;padding:0; text-align:center; border: 1px dashed grey;background:#EEEEEE; cursor:pointer;width:100%; line-height:200%" id="todo-list-bar-Bas"></td>' +
'</tr>' +
'<tr>' +
'<td><div style="width:100%; height:100%; overflow:auto; border:none; white-space:pre; font-size:120%; padding:.2em" id="todo-list-content-Bas" onclick="editTodoListBas()" title="' + TexteVide2 + '"></div><textarea style="width:99%; height:100%; overflow:auto; border:none" id="todo-list-edit-Bas" onchange="saveTodoListBas()" onblur="renderTodoListBas()">' + textContentBas + '</textarea></td>' +
'</tr>';
document.body.appendChild(todoListBas);
renderTodoListBas();
var visibleBas = sessionStorage.getItem("todo-list-Bas.visible");
if (visibleBas == "true") {
showTodoListBas();
} else {
hideTodoListBas();
}
}
/**
* Show the todo list
*/
function showTodoListBas() {
var todoListBas = document.getElementById("todo-list-Bas");
var listContentBas = document.getElementById("todo-list-content-Bas");
var todoListBarBas = document.getElementById("todo-list-bar-Bas");
listContentBas.parentNode.style.display = "";
todoListBas.style.height=TailleD+"%";
todoListBarBas.style.height="10%";
todoListBarBas.onmouseover = hideTodoListBas;
sessionStorage.setItem("todo-list-Bas.visible", "true");
}
/**
* Hide the todo list
*/
function hideTodoListBas() {
var todoListBas = document.getElementById("todo-list-Bas");
var listContentBas = document.getElementById("todo-list-content-Bas");
var todoListBarBas = document.getElementById("todo-list-bar-Bas");
listContentBas.parentNode.style.display = "none";
todoListBas.style.height="auto";
todoListBarBas.style.height="auto";
todoListBarBas.onmouseover = showTodoListBas;
sessionStorage.setItem("todo-list-Bas.visible", "false");
}
/**
* Save the todo list (each time the content changes)
*/
function saveTodoListBas() {
globalStorage[location.hostname].setItem("todo-list-Bas.content", document.getElementById("todo-list-edit-Bas").value);
}
/**
* Shows a textarea to edit the todo list
*/
function editTodoListBas() {
var divBas = document.getElementById("todo-list-content-Bas");
var textareaBas = document.getElementById("todo-list-edit-Bas");
divBas.innerHTML = textareaBas.value;
divBas.style.display = "none";
textareaBas.style.display = "";
textareaBas.focus();
}
/**
* Renders the todo list interpreting some wiki syntax (links, templates, bold, italic)
*/
function renderTodoListBas() {
var divBas = document.getElementById("todo-list-content-Bas");
var textareaBas = document.getElementById("todo-list-edit-Bas");
var contentBas = textareaBas.value;
if (!contentBas || contentBas == "") {
contentBas = "''" + TexteVide1 + "''";
}
// Escape HTML characters
contentBas = contentBas.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
// Render wiki links
contentBas = contentBas.replace(/\[\[:?([^\|\]]*)(?:\|([^\|\]]+))?\]\]/g, function(match, article, title, offset, s) {
return "<a href=\"" + mw.config.get('wgServer') + "/wiki/" + article + "\">[[" + ((title) ? title : article) + "]]</a>";
});
// Render wiki templates
contentBas = contentBas.replace(/\{\{([^\}\|]+)(\|[^\}]+)?\}\}/g, "<a href=\"" + mw.config.get('wgServer') + "/wiki/Template:$1\">(($1$2))</a>");
// Render bold
contentBas = contentBas.replace(/'''((?:[^']|'(?!''))+)'''/g, "<b>$1</b>");
// Render italic
contentBas = contentBas.replace(/''((?:[^']|'(?!'))+)''/g, "<i>$1</i>");
divBas.innerHTML = contentBas;
divBas.style.display = "";
textareaBas.style.display = "none";
}
if(Bas){addOnloadHook(initTodoListBas);}
///////////////////////////////////////////////////////////////////////////////////// GAUCHE ///////////////////////////////////////////////////////////////////////////////////////
/**
* Creates and restore the todo list
*/
function initTodoListGauche() {
if (typeof globalStorage == "undefined") {
//alert("This todo list requires client side persistent storage features which are currently available on Firefox 2.0 only");
return;
}
// retrieve stored text
var textContentGauche = globalStorage[location.hostname].getItem("todo-list.contentGauche");
if (! textContentGauche) textContentGauche = "";
var todoListGauche = document.createElement("table");
todoListGauche.id = "todo-listGauche";
todoListGauche.setAttribute("style", "height:" + Taille + "%; position:fixed; bottom:" + Position + "%; left:0; z-index:10; opacity:.9; background:white; border:1px solid grey; border-spacing:0; -moz-border-radius-topright: 5px; -moz-border-radius-bottomright: 5px; border-left:none");
todoListGauche.innerHTML = '<tr>' +
'<td><div style="width:100%; height:100%; overflow:auto; border:none; white-space:pre; font-size:120%; padding:.2em" id="todo-list-contentGauche" onclick="editTodoListGauche()" title="' + TexteVide2 + '"></div><textarea style="width:100%; height:99%; overflow:auto; border:none" id="todo-list-editGauche" onchange="saveTodoListGauche()" onblur="renderTodoListGauche()">' + textContentGauche + '</textarea></td>' +
'<td style="font-variant:small-caps; width:0.3em;padding:0; text-align:center; border:1px dashed grey;background:#EEEEEE; cursor:pointer;height:100%; line-height:200%" id="todo-list-barGauche"></td>' +
'</tr>';
document.body.appendChild(todoListGauche);
renderTodoListGauche();
var visibleGauche = sessionStorage.getItem("todo-listGauche.visible");
if (visibleGauche == "true") {
showTodoListGauche();
} else {
hideTodoListGauche();
}
}
/**
* Show the todo list
*/
function showTodoListGauche() {
var todoListGauche = document.getElementById("todo-listGauche");
var listContentGauche = document.getElementById("todo-list-contentGauche");
var todoListBarGauche = document.getElementById("todo-list-barGauche");
listContentGauche.parentNode.style.display = "";
todoListGauche.style.width=TailleD+"%";
todoListBarGauche.style.width="5%";
todoListBarGauche.onmouseover = hideTodoListGauche;
sessionStorage.setItem("todo-listGauche.visible", "true");
}
/**
* Hide the todo list
*/
function hideTodoListGauche() {
var todoListGauche = document.getElementById("todo-listGauche");
var listContentGauche = document.getElementById("todo-list-contentGauche");
var todoListBarGauche = document.getElementById("todo-list-barGauche");
listContentGauche.parentNode.style.display = "none";
todoListGauche.style.width="auto";
todoListBarGauche.style.width="auto";
todoListBarGauche.onmouseover = showTodoListGauche;
sessionStorage.setItem("todo-listGauche.visible", "false");
}
/**
* Save the todo list (each time the content changes)
*/
function saveTodoListGauche() {
globalStorage[location.hostname].setItem("todo-listGauche.content", document.getElementById("todo-list-editGauche").value);
}
/**
* Shows a textarea to edit the todo list
*/
function editTodoListGauche() {
var div = document.getElementById("todo-list-contentGauche");
var textarea = document.getElementById("todo-list-editGauche");
div.innerHTML = textarea.value;
div.style.display = "none";
textarea.style.display = "";
textarea.focus();
}
/**
* Renders the todo list interpreting some wiki syntax (links, templates, bold, italic)
*/
function renderTodoListGauche() {
var div = document.getElementById("todo-list-contentGauche");
var textarea = document.getElementById("todo-list-editGauche");
var content = textarea.value;
if (!content || content == "") {
content = "''" + TexteVide1 + "''";
}
// Escape HTML characters
content = content.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
// Render wiki links
content = content.replace(/\[\[:?([^\|\]]*)(?:\|([^\|\]]+))?\]\]/g, function(match, article, title, offset, s) {
return "<a href=\"" + mw.config.get('wgServer') + "/wiki/" + article + "\">[[" + ((title) ? title : article) + "]]</a>";
});
// Render wiki templates
content = content.replace(/\{\{([^\}\|]+)(\|[^\}]+)?\}\}/g, "<a href=\"" + mw.config.get('wgServer') + "/wiki/Template:$1\">(($1$2))</a>");
// Render bold
content = content.replace(/'''((?:[^']|'(?!''))+)'''/g, "<b>$1</b>");
// Render italic
content = content.replace(/''((?:[^']|'(?!'))+)''/g, "<i>$1</i>");
div.innerHTML = content;
div.style.display = "";
textarea.style.display = "none";
}
if(Gauche){addOnloadHook(initTodoListGauche);}
///////////////////////////////////////////////////////////////////////////////////// DROITE //////////////////////////////////////////////////////////////////////////////////////
function initTodoListRight() {
if (typeof globalStorage == "undefined") {
//alert("This todo list requires client side persistent storage features which are currently available on Firefox 2.0 only");
return;
}
// retrieve stored text
var textContentRight = globalStorage[location.hostname].getItem("todo-list-Right.content");
if (! textContentRight) textContentRight = "";
var todoListRight = document.createElement("table");
todoListRight.id = "todo-list-Right";
todoListRight.setAttribute("style", "height:" + Taille + "%; position:fixed; bottom:" + Position + "%; right:0; z-index:10; opacity:.9; background:white; border:1px solid grey; border-spacing:0; -moz-border-radius-topleft: 5px; -moz-border-radius-bottomleft: 5px; border-right:none");
todoListRight.innerHTML = '<tr>' +
'<td style="font-variant:small-caps; width:0.3em;padding:0; text-align:center; border: 1px dashed grey;background:#EEEEEE; cursor:pointer;height:100%; line-height:200%" id="todo-list-bar-Right"></td>' +
'<td><div style="width:100%; height:100%; overflow:auto; border:none; white-space:pre; font-size:120%; padding:.2em" id="todo-list-content-Right" onclick="editTodoListRight()" title="' + TexteVide2 + '"></div><textarea style="width:100%; height:99%; overflow:auto; border:none" id="todo-list-edit-Right" onchange="saveTodoListRight()" onblur="renderTodoListRight()">' + textContentRight + '</textarea></td>' +
'</tr>';
document.body.appendChild(todoListRight);
renderTodoListRight();
var visibleRight = sessionStorage.getItem("todo-list-Right.visible");
if (visibleRight == "true") {
showTodoListRight();
} else {
hideTodoListRight();
}
}
/**
* Show the todo list
*/
function showTodoListRight() {
var todoListRight = document.getElementById("todo-list-Right");
var listContentRight = document.getElementById("todo-list-content-Right");
var todoListBarRight = document.getElementById("todo-list-bar-Right");
listContentRight.parentNode.style.display = "";
todoListRight.style.width=TailleD+"%";
todoListBarRight.style.width="5%";
todoListBarRight.onmouseover = hideTodoListRight;
sessionStorage.setItem("todo-list-Right.visible", "true");
}
/**
* Hide the todo list
*/
function hideTodoListRight() {
var todoListRight = document.getElementById("todo-list-Right");
var listContentRight = document.getElementById("todo-list-content-Right");
var todoListBarRight = document.getElementById("todo-list-bar-Right");
listContentRight.parentNode.style.display = "none";
todoListRight.style.width="auto";
todoListBarRight.style.width="auto";
todoListBarRight.onmouseover = showTodoListRight;
sessionStorage.setItem("todo-list-Right.visible", "false");
}
/**
* Save the todo list (each time the content changes)
*/
function saveTodoListRight() {
globalStorage[location.hostname].setItem("todo-list-Right.content", document.getElementById("todo-list-edit-Right").value);
}
/**
* Shows a textarea to edit the todo list
*/
function editTodoListRight() {
var divRight = document.getElementById("todo-list-content-Right");
var textareaRight = document.getElementById("todo-list-edit-Right");
divRight.innerHTML = textareaRight.value;
divRight.style.display = "none";
textareaRight.style.display = "";
textareaRight.focus();
}
/**
* Renders the todo list interpreting some wiki syntax (links, templates, bold, italic)
*/
function renderTodoListRight() {
var divRight = document.getElementById("todo-list-content-Right");
var textareaRight = document.getElementById("todo-list-edit-Right");
var contentRight = textareaRight.value;
if (!contentRight || contentRight == "") {
contentRight = "''" + TexteVide1 + "''";
}
// Escape HTML characters
contentRight = contentRight.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
// Render wiki links
contentRight = contentRight.replace(/\[\[:?([^\|\]]*)(?:\|([^\|\]]+))?\]\]/g, function(match, article, title, offset, s) {
return "<a href=\"" + mw.config.get('wgServer') + "/wiki/" + article + "\">[[" + ((title) ? title : article) + "]]</a>";
});
// Render wiki templates
contentRight = contentRight.replace(/\{\{([^\}\|]+)(\|[^\}]+)?\}\}/g, "<a href=\"" + mw.config.get('wgServer') + "/wiki/Template:$1\">(($1$2))</a>");
// Render bold
contentRight = contentRight.replace(/'''((?:[^']|'(?!''))+)'''/g, "<b>$1</b>");
// Render italic
contentRight = contentRight.replace(/''((?:[^']|'(?!'))+)''/g, "<i>$1</i>");
divRight.innerHTML = contentRight;
divRight.style.display = "";
textareaRight.style.display = "none";
}
if(Droite){addOnloadHook(initTodoListRight);}
//</nowiki></pre>
Text is available under the CC BY-SA 4.0 license; additional terms may apply.
Images, videos and audio are available under their respective licenses.