Jump to content

User:Js/ajaxPreview.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Js (talk | contribs) at 19:46, 14 March 2011 (new version, calling User:Js/preview2.js as the main script). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
window.ajaxPreviewMsg =
{emptydiff: 'No chages'
,difftip: 'shift-click the button to show changes compared to this old version'
,diff2old: 'comparison to old version'
,viewtip: 'shift-click the button to update interwiki and categories as well\
 (<a href=/wiki/user:js/ajaxPreview#preview target=_blank>more</a>)'
}


function ajaxPreviewButtons(){

 ajaxPreviewPos = window.ajaxPreviewPos || 'right'

 if (ajaxPreviewPos != 'bottom'){
   var previewToolbar = $('<div style="float:'+ajaxPreviewPos+'" />')
   if ($.wikiEditor){
      $('#wikiPreview').after('<div style="width:100%; clear:both" />', previewToolbar)
   }else{
     var el = $('#toolbar')
   if (el.length) el.prepend(previewToolbar)
   else $('#editform').before(previewToolbar)
   }
 }
 addBtn(window.ajaxPreviewButton, 'wpPreview', window.ajaxPreviewKey || 'p')
 addBtn(window.ajaxDiffButton, 'wpDiff', window.ajaxDiffKey || 'v')

 function addBtn(name, id, akey){
  var btnOld = $('#'+id)
  if (!btnOld) return
  var btn = $('<input type=button id="'+id+'Live" title="'+btnOld.val() + ' (ajax)" />')
  if (ajaxPreviewPos == 'bottom'){
    btn.val( btnOld.val() ).insertBefore( btnOld.val('>') )
  }else{
    if (!name){ //extract last word from standard buttons
      var name = btnOld.val(); var i = name.lastIndexOf(' ') + 1
      name = name.substring(i, i+1).toUpperCase() + name.substring(i+1)
    }
    btn.val(name).css('height','22px').css('padding','0 1px').appendTo(previewToolbar)
  }
  if (akey){ //reassign acces key
    if (btnOld.attr('accesskey') == akey)
      btnOld.removeAttr('accesskey').attr('title', btnOld.attr('title').replace(tooltipAccessKeyRegexp, '') )
  btn.attr('accesskey', akey).attr('title', btn.attr('title') + ' ['+tooltipAccessKeyPrefix+akey+']' )
  }
 }
}



if (/edit|submit/.test(wgAction) && wgCanonicalNamespace!='Special'){
  ajaxPreviewButtons()
  importScriptURI('http://en.wikipedia.org/w/index.php?title=User:Js/preview2.js&action=raw&ctype=text/javascript')
}