2007-02-13 10:25:05 +01:00
|
|
|
/*
|
|
|
|
* Based on Simon Willison's blockquotes.js
|
|
|
|
* http://simon.incutio.com/archive/2002/12/20/#blockquoteCitations
|
|
|
|
*/
|
|
|
|
function extractBlockquoteCitations() {
|
|
|
|
var quotes = document.getElementsByTagName('blockquote');
|
|
|
|
for (i = 0; i < quotes.length; i++) {
|
|
|
|
var cite = quotes[i].getAttribute('cite');
|
|
|
|
if (cite && cite != '') {
|
|
|
|
var newlink = document.createElement('a');
|
|
|
|
newlink.setAttribute('href', cite);
|
|
|
|
newlink.setAttribute('title', cite);
|
|
|
|
newlink.appendChild(document.createTextNode('#'));
|
|
|
|
var newspan = document.createElement('span');
|
|
|
|
newspan.setAttribute('class','blockquotesource');
|
|
|
|
newspan.appendChild(newlink);
|
|
|
|
quotes[i].lastChild.previousSibling.appendChild(newspan);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-10-17 23:26:17 +02:00
|
|
|
|
|
|
|
function fixRunIn() {
|
|
|
|
// work around lack of gecko support for display:run-in
|
|
|
|
var re = /^num_|\s+num_|^un_|\s+un_|proof/;
|
|
|
|
$$('div > h6').each(function(element) {
|
|
|
|
if(re.test($(element.parentNode).className)) {
|
|
|
|
var new_span = new Element('span').update(element.textContent);
|
|
|
|
new_span.addClassName('theorem_label');
|
|
|
|
var next_el = element.next().firstChild;
|
|
|
|
next_el.parentNode.insertBefore(new_span, next_el);
|
|
|
|
var period = new Element('span').update('. ');
|
|
|
|
next_el.parentNode.insertBefore(period, next_el);
|
|
|
|
element.remove();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// add tombstone to proof, since gecko doesn't support :last-child properly
|
|
|
|
$$('div.proof').each(function(element) {
|
|
|
|
var l = element.childElements().length -1;
|
|
|
|
var span = new Element('span').update('\u00a0\u00a0\u25ae');
|
|
|
|
element.childElements()[l].insert(span);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2009-11-06 21:32:45 +01:00
|
|
|
function mactionWorkarounds() {
|
|
|
|
$$('maction[actiontype="tooltip"]').each( function(mtool){
|
2009-11-08 09:27:38 +01:00
|
|
|
Element.writeAttribute(mtool, 'title',
|
|
|
|
Element.firstDescendant(mtool).nextSibling.firstChild.data);
|
|
|
|
});
|
2009-11-06 21:32:45 +01:00
|
|
|
$$('maction[actiontype="statusline"]').each( function(mstatus){
|
2009-11-08 09:27:38 +01:00
|
|
|
var v = Element.firstDescendant(mstatus).nextSibling.firstChild.data;
|
|
|
|
Event.observe(mstatus, 'mouseover', function(){window.status = v;});
|
|
|
|
Event.observe(mstatus, 'mouseout', function(){window.status = '';});
|
2009-11-06 21:32:45 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2010-01-29 06:37:10 +01:00
|
|
|
function addS5button(page_name) {
|
|
|
|
var f = $('MarkupHelp');
|
|
|
|
if (f) {
|
|
|
|
var s5button = new Element('input', {id:'S5button', type:'button', value: 'Make this page an S5 slideshow'});
|
|
|
|
f.insert({top: s5button});
|
|
|
|
Event.observe(s5button, 'click', function(){
|
|
|
|
var preamble = "author: " + document.getElementById('author').value +
|
|
|
|
"\ncompany: \ntitle: " + page_name +
|
|
|
|
"\nsubtitle: \nslide_theme: default\nslide_footer: \nslide_subfooter: " +
|
|
|
|
"\n\n:category: S5-slideshow\n\n" + page_name +
|
|
|
|
"\n==============\n\nMy First Slide\n-----------------\n\n";
|
|
|
|
var content = document.getElementById('content');
|
|
|
|
content.value = preamble + content.value;
|
|
|
|
document.getElementById('S5button').hide();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-06 04:36:35 +01:00
|
|
|
function setupSVGedit(path){
|
|
|
|
var f = $('MarkupHelp');
|
|
|
|
var selected;
|
|
|
|
var before;
|
|
|
|
var after;
|
|
|
|
// create a control button
|
|
|
|
if (f) {
|
|
|
|
var SVGeditButton = new Element('input', {id:'SVGeditButton', type:'button', value: 'Create an SVG graphic'});
|
|
|
|
f.insert({top: SVGeditButton});
|
|
|
|
SVGeditButton.disabled = true;
|
|
|
|
Event.observe(SVGeditButton, 'click', function(){
|
2010-03-15 17:13:22 +01:00
|
|
|
var editor = window.open(path + "?initStroke[width]=2", 'Edit SVG graphic', 'status=1,resizable=1,scrollbars=1');
|
2010-03-12 10:50:23 +01:00
|
|
|
editor.addEventListener("load", function() {
|
|
|
|
editor.svgEditor.setCustomHandlers({
|
|
|
|
'save': function(window,svg){
|
2010-04-02 06:56:21 +02:00
|
|
|
editor.svgEditor.setConfig({no_save_warning: true});
|
2010-03-12 10:50:23 +01:00
|
|
|
window.opener.postMessage(svg, window.location.protocol + '//' + window.location.host);
|
|
|
|
window.close();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
editor.svgEditor.randomizeIds();
|
|
|
|
if (selected) editor.svgEditor.loadFromString(selected);
|
|
|
|
}, true);
|
2010-02-06 08:44:41 +01:00
|
|
|
SVGeditButton.disabled = true;
|
|
|
|
SVGeditButton.value = 'Create SVG graphic';
|
2010-02-06 05:55:54 +01:00
|
|
|
editor.focus();
|
2010-02-06 04:36:35 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
var t = $('content');
|
|
|
|
|
|
|
|
var callback = function(){
|
|
|
|
// This is triggered by 'onmouseup' events
|
|
|
|
var sel = window.getSelection();
|
|
|
|
var a = sel.anchorOffset;
|
|
|
|
var f = sel.focusOffset;
|
|
|
|
// A bit of ugliness, because Gecko-based browsers
|
|
|
|
// don't support getSelection in textareas
|
|
|
|
if (t.selectionStart ) {
|
|
|
|
var begin = t.selectionStart;
|
|
|
|
var end = t.selectionEnd;
|
|
|
|
} else {
|
|
|
|
if( a < f) {
|
|
|
|
begin = a;
|
|
|
|
end = f;
|
|
|
|
} else {
|
|
|
|
begin = f;
|
|
|
|
end = a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// finally, slice up the textarea content into before, selected, & after pieces
|
|
|
|
before = t.value.slice(0, begin);
|
|
|
|
selected = t.value.slice(begin, end);
|
2010-02-17 14:29:15 +01:00
|
|
|
after = t.value.slice(end, t.value.length);
|
2010-02-06 04:36:35 +01:00
|
|
|
if (selected && selected != '') {
|
2010-03-07 01:28:51 +01:00
|
|
|
if ( selected.match(/^<svg(.|\n)*<\/svg>$/) && !selected.match(/<\/svg>(.|\n)/)) {
|
2010-02-06 04:36:35 +01:00
|
|
|
SVGeditButton.disabled = false;
|
|
|
|
SVGeditButton.value = 'Edit existing SVG graphic';
|
|
|
|
} else {
|
|
|
|
SVGeditButton.disabled = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SVGeditButton.disabled = false;
|
|
|
|
SVGeditButton.value = 'Create SVG graphic';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Event.observe(t, 'mouseup', callback );
|
|
|
|
var my_loc = window.location.protocol + '//' + window.location.host;
|
|
|
|
Event.observe(window, "message", function(event){
|
|
|
|
if(event.origin !== my_loc) { return;}
|
|
|
|
t.value = before + event.data + after;
|
2010-02-06 05:55:54 +01:00
|
|
|
t.focus();
|
2010-05-11 07:38:21 +02:00
|
|
|
selectRange(t, before.length, before.length+event.data.length);
|
2010-05-11 08:10:59 +02:00
|
|
|
callback();
|
2010-02-06 04:36:35 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2010-05-11 07:38:21 +02:00
|
|
|
function selectRange(elt, start, end) {
|
|
|
|
if (elt.setSelectionRange) {
|
|
|
|
elt.focus();
|
|
|
|
elt.setSelectionRange(start, end);
|
|
|
|
} else if (elt.createTextRange) {
|
|
|
|
var range = elt.createTextRange();
|
|
|
|
range.collapse(true);
|
|
|
|
range.moveEnd('character', end);
|
|
|
|
range.moveStart('character', start);
|
|
|
|
range.select();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-12 08:12:52 +01:00
|
|
|
function updateSize(elt, w, h) {
|
2009-12-10 23:57:05 +01:00
|
|
|
// adjust to the size of the user's browser area.
|
2009-12-12 08:12:52 +01:00
|
|
|
// w and h are the original, unadjusted, width and height per row/column
|
2009-12-10 23:57:05 +01:00
|
|
|
var parentheight = document.viewport.getHeight() - $('pageName').getHeight()
|
2009-12-12 22:28:05 +01:00
|
|
|
- $('editFormButtons').getHeight() - $('hidebutton').getHeight();
|
2009-12-12 08:12:52 +01:00
|
|
|
var parentwidth = $('Content').getWidth();
|
2009-12-10 23:57:05 +01:00
|
|
|
var f = $('MarkupHelp');
|
2009-12-12 22:28:05 +01:00
|
|
|
if (f.visible()) { parentwidth = parentwidth - f.getWidth() - 20 }
|
2009-12-13 05:37:38 +01:00
|
|
|
var changename = $('alter_title');
|
|
|
|
if (changename) {
|
|
|
|
parentheight = parentheight - changename.parentNode.getHeight()-2*h;
|
|
|
|
}
|
2009-12-12 22:28:05 +01:00
|
|
|
elt.writeAttribute({'cols': Math.floor(parentwidth/w) - 1,
|
2009-12-13 05:37:38 +01:00
|
|
|
'rows': Math.floor(parentheight/h) - 4 });
|
2009-12-10 23:57:05 +01:00
|
|
|
elt.setStyle({Width: parentwidth, Height: parentheight});
|
|
|
|
}
|
|
|
|
|
|
|
|
function resizeableTextarea() {
|
|
|
|
//make the textarea resize to fit available space
|
|
|
|
var f = $('MarkupHelp');
|
|
|
|
if (f) {
|
2009-12-12 22:28:05 +01:00
|
|
|
var hidebutton = new Element('input', {id:'hidebutton', type:'button', value: 'Hide markup help'});
|
2009-12-10 23:57:05 +01:00
|
|
|
f.insert({before: hidebutton});
|
|
|
|
}
|
|
|
|
$$('textarea#content').each( function(textarea) {
|
2009-12-12 08:12:52 +01:00
|
|
|
var w = textarea.getWidth()/textarea.getAttribute('cols');
|
|
|
|
var h = textarea.getStyle('lineHeight').replace(/(\d*)px/, "$1");
|
2009-12-13 05:37:38 +01:00
|
|
|
var changename = $('alter_title');
|
|
|
|
if (changename) {
|
|
|
|
Event.observe(changename.parentNode, 'change', function() {
|
|
|
|
updateSize(textarea, w, h);
|
|
|
|
});
|
|
|
|
}
|
2009-12-10 23:57:05 +01:00
|
|
|
Event.observe(hidebutton, 'click', function(){
|
|
|
|
if (f.visible()) {
|
|
|
|
f.hide();
|
|
|
|
hidebutton.writeAttribute({value: 'Show markup help'});
|
2009-12-12 08:12:52 +01:00
|
|
|
updateSize(textarea, w, h)
|
2009-12-10 23:57:05 +01:00
|
|
|
} else {
|
|
|
|
f.show();
|
|
|
|
hidebutton.writeAttribute({value: 'Hide markup help'});
|
2009-12-12 08:12:52 +01:00
|
|
|
updateSize(textarea, w, h)
|
2009-12-10 23:57:05 +01:00
|
|
|
}
|
|
|
|
});
|
2009-12-12 08:12:52 +01:00
|
|
|
Event.observe(window, 'resize', function(){ updateSize(textarea, w, h) });
|
|
|
|
updateSize(textarea, w, h);
|
2009-12-10 23:57:05 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2007-02-13 10:25:05 +01:00
|
|
|
window.onload = function (){
|
|
|
|
extractBlockquoteCitations();
|
2008-10-17 23:26:17 +02:00
|
|
|
fixRunIn();
|
2009-11-06 21:32:45 +01:00
|
|
|
mactionWorkarounds();
|
2009-12-10 23:57:05 +01:00
|
|
|
resizeableTextarea();
|
2007-02-13 10:25:05 +01:00
|
|
|
};
|