User:F.trott/monobook.js
function ajaxPreviewInit(){
if ((wgNamespaceNumber % 2 == 0) && /\.(js|css)$/.test(wgTitle)) return
if (typeof ajaxPreviewKey != 'string') ajaxPreviewKey = 'p'
if (typeof ajaxDiffKey != 'string') ajaxDiffKey = 'v'
ajaxPreviewPos = window.ajaxPreviewPos || 'right'
if (ajaxPreviewPos != 'bottom'){
var tOld = document.getElementById('toolbar') || document.getElementById('wpTextbox1')
tOld.style.clear = 'none'
var d = document.createElement('div'); d.style.cssText = 'width:100%; clear:both'
tOld.parentNode.insertBefore(d, tOld)
var tNew = document.createElement('div'); tNew.style.cssText = 'float:'+ ajaxPreviewPos
tOld.parentNode.insertBefore(tNew, tOld)
}
addBtn(window.ajaxPreviewButton, 'wpPreview', ajaxPreviewKey)
addBtn(window.ajaxDiffButton, 'wpDiff', ajaxDiffKey)
function addBtn(name, id, akey){
var btnOld = document.getElementById(id)
if (!btnOld) return
//var
btn = document.createElement('input'); btn.type = 'button'
btn.onclick = ajaxPreviewClick; btn.id = id + 'Live'
if (!name){ //extract last word from standard buttons
name = btnOld.value.split(' '); name = name[name.length-1]
name = name.substring(0,1).toUpperCase() + name.substring(1)
}
btn.value = name; btn.title = btnOld.value + ' (Ajax)'
if (ajaxPreviewPos == 'bottom'){
btnOld.parentNode.insertBefore(btn, btnOld)
btn.value = btnOld.value
btnOld.value = '>'
}else{
btn.style.cssText = 'height:22px; padding:0 1px'
tNew.appendChild(btn)
}
if (akey){ //reassign acces key
if (btnOld.accessKey == akey){
btnOld.accessKey = ''
//btnOld.setAttribute('accesskey', '')
btnOld.title = btnOld.title.replace(tooltipAccessKeyRegexp, '')
}
//btn.setAttribute('accesskey', akey)
btn.accessKey = akey
btn.title += ' ['+tooltipAccessKeyPrefix+akey+']'
}
btn.value2 = btn.value
}
}
function ajaxPreviewClick(){ajaxPreviewRun(this)}
function ajaxPreviewRun(btn){
var wkPreview = document.getElementById('wikiPreview'), form = document.editform
var aj = sajax_init_object()
if (!wkPreview || !form || !aj) return
var oldHeight = wkPreview.offsetHeight
var el, htm, isDiff = (btn.id=='wpDiffLive')
wkPreview.style.opacity = '0.3'; wkPreview.style.color = 'gray'; document.body.style.cursor = 'wait'
if (el=document.getElementById('wikiDiff')) el.style.display = 'none'
if (el=document.getElementById('newarticletext')) el.style.display = 'none'
btn.style.width = Math.max(btn.scrollWidth, btn.offsetWidth) + 'px'; btn.value = '...'
//prepare
var txt = form.wpTextbox1.value, action = form.action
var boundary = '--------123xyz', data = ''
if (isDiff){
addData('wpDiff', ''); addData('wpStarttime'); addData('wpEdittime')
if (!window.ajaxPreview_CSS) ajaxPreview_CSS = importStylesheetURI('/skins-1.5/common/diff.css')
}else{
action += '&live'
if (form.wpSection && form.wpSection.value) txt += '\n<br /><references />'
}
addData('wpTextbox1', txt); addData('wpSection'); addData('wpSummary')
//send
aj.open('POST', action, true)
aj.setRequestHeader('Content-Type', 'multipart/form-data; boundary='+boundary)
aj.send(data + '--' + boundary)
aj.onreadystatechange = function(){
if (aj.readyState != 4) return
wkPreview.style.display = 'block'
if (isDiff){
var htm = aj.responseText
var p1 = htm.indexOf("<table class='diff'>" )
var p2 = htm.indexOf('</table>', p1)
htm = (p1!=-1 && p2!=-1) ? htm.substring(p1, p2+8) : 'Error'
}else{
htm = aj.responseText.replace(/>/g,'>').replace(/</g,'<').replace(/"/g,'"').replace(/&/g,'&').replace(/'/g,"'")
}
wkPreview.innerHTML = htm
btn.value = btn.value2
btn.blur()
if (el = wkPreview.getElementsByTagName('h2')[0]){
if (el.style.textAlign != 'right') el.innerHML += ' (Ajax)'
el.style.textAlign = 'right'
}
if (window.ajaxPreviewScrollTop && wkPreview.scrollIntoView) wkPreview.scrollIntoView()
else document.documentElement.scrollTop += wkPreview.offsetHeight - oldHeight
wkPreview.style.opacity = ''; wkPreview.style.color = ''; document.body.style.cursor = ''
if (!isDiff) ajaxPreviewFinish(wkPreview)
}
function addData(name, value){
if (!value) value = form[name] ? form[name].value : ''
data += '--' + boundary + '\nContent-Disposition: form-data; name="'+name+'"\n\n' + value + '\n'
}
}
function ajaxPreviewFinish(el){
sortables_init()
if (window.createCollapseButtons){//en.wp
createCollapseButtons()
createNavigationBarToggleButton()
}
if (window.ajaxPreviewExec) ajaxPreviewExec(el)
}
if (wgAction=='edit' || wgAction=='submit') addOnloadHook(ajaxPreviewInit)
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.