Jump to content

User:Ernestfax/modern.js

From Wikipedia, the free encyclopedia
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.
(function ernestfaxWrapper() {

function ernestfaxGrabPreview( e ) {
  // grabbing the preview button
  var txt = $( "#wpTextbox1" ),
      alltext = txt.val(),
      reflist = /<references|\{\{reflist/i ; // |\{\{refbegin/i refbegin seems unnecessary here

  if ( -1 !== alltext.search( "<ref" ) && -1 === alltext.search( reflist ) ) {
    txt.val( alltext + "{{reflist}}" ); // add in a </references> just for the ajax preview
    doLivePreview(e);
    txt.val( alltext ); // restore it as it was, before the above insertions
  } else {
    doLivePreview(e);
  }
  return false;
}

function ernestfaxgo(e) {             // once page is ready
  $("#wpPreview").
    unbind( "click", doLivePreview ). // remove the ajax preview handler. it will get called from ernestfaxGrabPreview
    click( ernestfaxGrabPreview );    // add the call to prepare for the preview
}

try {
  $( document ).ready( ernestfaxgo );
} catch ( err ) {
  // no jquery present, so not on an edit page, so don't do anything
}

}() );