Участник:Hogart/monobook.js: различия между версиями
Перейти к навигации
Перейти к поиску
Содержимое удалено Содержимое добавлено
Hogart (обсуждение | вклад) Новая: importScript('User:Alex Smotrov/qpreview.js'); |
Hogart (обсуждение | вклад) мНет описания правки |
||
Строка 1: | Строка 1: | ||
var qPreviewKey = '`'; |
|||
importScript('User:Alex Smotrov/qpreview.js'); |
|||
var qPreviewName = 'QPreview'; |
|||
function qPreviewButton(){ |
|||
addToolbarButton(qPreviewName, qPreview, 'btnQPreview', 'Quick Preview', qPreviewKey); |
|||
//addSystemButton(qPreviewName, qPreview, 'btnQPreview', 'Quick Preview', qPreviewKey); |
|||
} |
|||
addOnloadHook(qPreviewButton); |
|||
function qPreview(){ |
|||
var divPreview = document.getElementById('wikiPreview'); |
|||
if (!divPreview) return; |
|||
var btnQPreview = document.getElementById('btnQPreview'); |
|||
if (btnQPreview) btnQPreview.value = 'Wait...'; |
|||
a = sajax_init_object(); |
|||
a.open('POST', document.editform.action+'&live', true); |
|||
var Boundary = '--------p1415'; |
|||
a.setRequestHeader('Content-Type', 'multipart/form-data; boundary='+Boundary); |
|||
var PostData = '--' + Boundary |
|||
+ '\nContent-Disposition: form-data; name="wpTextbox1"\n\n' |
|||
+ document.getElementById('wpTextbox1').value + '\n--'+Boundary; |
|||
if (a.overrideMimeType) a.overrideMimeType('text/html'); |
|||
a.send(PostData); |
|||
a.onreadystatechange = function(){ |
|||
if (a.readyState != 4) return; |
|||
var html = a.responseText; |
|||
html = html.replace(/>/g,'>').replace(/</g,'<').replace(/"/g,'"').replace(/&/g,'&').replace(/'/g,"'"); |
|||
divPreview.innerHTML = html; |
|||
if (btnQPreview) btnQPreview.value = qPreviewName; |
|||
}; |
|||
} |
|||
function addSystemButton(name, onclick, id, tooltip, accesskey){ |
|||
var wpPreview = document.getElementById('wpPreview'); |
|||
if (!wpPreview) return; |
|||
var newBtn = document.createElement('input'); |
|||
newBtn.type = 'button'; |
|||
if (name) newBtn.value = name; |
|||
if (onclick) newBtn.onclick = onclick; |
|||
if (id) newBtn.id = id; |
|||
if (tooltip) newBtn.title = tooltip; |
|||
if (accesskey) newBtn.accessKey = accesskey; |
|||
wpPreview.parentNode.insertBefore(newBtn, wpPreview); |
|||
return newBtn; |
|||
} |
|||
//Adds a text button to edit toolbar |
|||
function addToolbarButton(name, onclick, id, tooltip, accesskey){ |
|||
var toolbar = document.getElementById('toolbar'); |
|||
if (!toolbar) return; |
|||
var newBtn = document.createElement('input'); |
|||
newBtn.type = 'button'; |
|||
newBtn.style.background = '#adbede'; |
|||
newBtn.style.height = '22px'; |
|||
newBtn.style.verticalAlign = 'middle'; |
|||
if (name) newBtn.value = name; |
|||
if (onclick) newBtn.onclick = onclick; |
|||
if (id) newBtn.id = id; |
|||
if (tooltip) newBtn.title = tooltip; |
|||
if (accesskey) newBtn.accessKey = accesskey; |
|||
toolbar.appendChild(newBtn); |
|||
return newBtn; |
|||
} |
Текущая версия от 10:58, 19 мая 2007
var qPreviewKey = '`';
var qPreviewName = 'QPreview';
function qPreviewButton(){
addToolbarButton(qPreviewName, qPreview, 'btnQPreview', 'Quick Preview', qPreviewKey);
//addSystemButton(qPreviewName, qPreview, 'btnQPreview', 'Quick Preview', qPreviewKey);
}
addOnloadHook(qPreviewButton);
function qPreview(){
var divPreview = document.getElementById('wikiPreview');
if (!divPreview) return;
var btnQPreview = document.getElementById('btnQPreview');
if (btnQPreview) btnQPreview.value = 'Wait...';
a = sajax_init_object();
a.open('POST', document.editform.action+'&live', true);
var Boundary = '--------p1415';
a.setRequestHeader('Content-Type', 'multipart/form-data; boundary='+Boundary);
var PostData = '--' + Boundary
+ '\nContent-Disposition: form-data; name="wpTextbox1"\n\n'
+ document.getElementById('wpTextbox1').value + '\n--'+Boundary;
if (a.overrideMimeType) a.overrideMimeType('text/html');
a.send(PostData);
a.onreadystatechange = function(){
if (a.readyState != 4) return;
var html = a.responseText;
html = html.replace(/>/g,'>').replace(/</g,'<').replace(/"/g,'"').replace(/&/g,'&').replace(/'/g,"'");
divPreview.innerHTML = html;
if (btnQPreview) btnQPreview.value = qPreviewName;
};
}
function addSystemButton(name, onclick, id, tooltip, accesskey){
var wpPreview = document.getElementById('wpPreview');
if (!wpPreview) return;
var newBtn = document.createElement('input');
newBtn.type = 'button';
if (name) newBtn.value = name;
if (onclick) newBtn.onclick = onclick;
if (id) newBtn.id = id;
if (tooltip) newBtn.title = tooltip;
if (accesskey) newBtn.accessKey = accesskey;
wpPreview.parentNode.insertBefore(newBtn, wpPreview);
return newBtn;
}
//Adds a text button to edit toolbar
function addToolbarButton(name, onclick, id, tooltip, accesskey){
var toolbar = document.getElementById('toolbar');
if (!toolbar) return;
var newBtn = document.createElement('input');
newBtn.type = 'button';
newBtn.style.background = '#adbede';
newBtn.style.height = '22px';
newBtn.style.verticalAlign = 'middle';
if (name) newBtn.value = name;
if (onclick) newBtn.onclick = onclick;
if (id) newBtn.id = id;
if (tooltip) newBtn.title = tooltip;
if (accesskey) newBtn.accessKey = accesskey;
toolbar.appendChild(newBtn);
return newBtn;
}