In memory of Ben “bushing” Byer, who passed away on Monday, February 8th, 2016.

User:GabberNL/monobook.js: Difference between revisions

From WiiBrew
Jump to navigation Jump to search
GabberNL (talk | contribs)
Undo revision 59300 by GabberNL (Talk)
GabberNL (talk | contribs)
experimental
Line 1: Line 1:
/* <source lang="javascript"> */
/* Move top tabs inside body content */


/**** LiveClock ****/
addOnloadHook(function () {
function liveClock()
     content = document.getElementById("column-content");   // Find the main content column
{
liveClock.node = addPortletLink( 'p-personal', wgServer + wgScriptPath + '/index.php?title=' + encodeURIComponent(wgPageName) + '&action=purge', '', 'utcdate' );
liveClock.node.style.fontSize = 'larger';
liveClock.node.style.fontWeight = 'bolder';
showTime();
}
addOnloadHook(liveClock)
function showTime()
{
var dateNode = liveClock.node;
if( !dateNode ) {
return;
}
     var now = new Date();
var hh = now.getUTCHours();
var mm = now.getUTCMinutes();
var ss = now.getUTCSeconds();
var time = ( hh < 10 ? '0' + hh : hh ) + ':' + ( mm < 10 ? '0' + mm : mm ) + ':' + ( ss < 10 ? '0' + ss : ss );
dateNode.firstChild.replaceChild( document.createTextNode( time ), dateNode.firstChild.firstChild );
    window.setTimeout(showTime, 1000);
}
/**** End LiveClock ****/


    footer = document.getElementById("footer");  // Find the footer
    footer.parentNode.removeChild(footer);    // Remove the footer from the global wrapper
    content.appendChild(footer);    // Place footer at the end of the content column;


/**** QueryString ****
     tabs = document.getElementById("p-cactions");  // Find the top tab list
* Maps the querystring to an object
    tabs.parentNode.removeChild(tabs);   // Remove the tab list from the side column
*
    content.insertBefore(tabs,content.firstChild);   // Place tab list at the beginning of the content column
* Functions:
});
*
* QueryString.exists(key)
*     returns true if the particular key is set
* QueryString.get(key)
*    returns the value associated to the key
* QueryString.equals(key, value)
*    returns true if the value associated with given key equals given value
* QueryString.toString()
*    returns the query string as a string
* QueryString.create( hash )
*    creates an querystring and encodes strings via encodeURIComponent and joins arrays with |
*
* In static context, the value of location.search.substring(1), else the value given to the constructor is going to be used. The mapped hash is saved in the object.
*
* Example:
*
* var value = QueryString.get('key');
* var obj = new QueryString('foo=bar&baz=quux');
* value = obj.get('foo');
*/
function QueryString(qString) {
this.string = qString;
this.params = {};
if( qString.length == 0 ) {
return;
}
qString.replace(/\+/, ' ');
var args = qString.split('&');
for( var i in args ) {
if( typeof( args[i] ) != 'string' ) {
continue;
}
var pair = args[i].split( '=' );
var key = decodeURIComponent( pair[0] ), value = key;
if( pair.length == 2 ) {
value = decodeURIComponent( pair[1] );
}
this.params[key] = value;
}
}
QueryString.static = null;
QueryString.staticInit = function() {
if( QueryString.static == null ) {
QueryString.static = new QueryString(location.search.substring(1));
}
}
QueryString.get = function(key) {
QueryString.staticInit();
return QueryString.static.get(key);
};
QueryString.prototype.get = function(key) {
return this.params[key] ? this.params[key] : null;
};
QueryString.exists = function(key) {
QueryString.staticInit();
return QueryString.static.exists(key);
}
QueryString.prototype.exists = function(key) {
return this.params[key] ? true : false;
}
QueryString.equals = function(key, value) {
QueryString.staticInit();
return QueryString.static.equals(key, value);
}
QueryString.prototype.equals = function(key, value) {
return this.params[key] == value ? true : false;
}
QueryString.toString = function() {
QueryString.staticInit();
return QueryString.static.toString();
}
QueryString.prototype.toString = function() {
return this.string ? this.string : null;
}
QueryString.create = function( arr ) {
var resarr = Array();
for( var i in arr ) {
if( typeof arr[i] == 'object' ){
var v =  Array();
for(var j in arr[i] ) {
v[j] = encodeURIComponent( arr[i][j] );
}
resarr.push( encodeURIComponent( i ) + '=' +  v.join('|')  );
} else {
resarr.push( encodeURIComponent( i ) + '=' + encodeURIComponent( arr[i] ) );
}
}
return resarr.join('&');
}
QueryString.prototype.create = QueryString.create;
 
/**** End QueryString ****/
 
 
/**** Quick Preview ****/
addOnloadHook(doAddQuickPreview);
function doAddQuickPreview() {
  if ((wgAction != "edit") && (wgAction != "submit")) return;
  var qbutton = document.getElementById("wpPreview").cloneNode(false);
   qbutton.value = "Quick preview";
  qbutton.type="button";
  qbutton.tabindex="6";
  qbutton.accessKey="g";
  qbutton.id="dlQuickPreview";
  qbutton.title="Preview your changes";
  qbutton.addEventListener("click", doQuickPreview, false);
  document.getElementById("wpPreview").parentNode.insertBefore(qbutton,document.getElementById("wpDiff"));
}
function doQuickPreview() {
  var bt = document.getElementById("dlQuickPreview");
  document.getElementById("contentSub").innerHTML = "Getting preview";
  bt.value="Getting preview";
  bt.disabled=true;
  var form = document.editform;
  var postData = {
    'wpMinoredit': form.wpMinoredit.checked,
    'wpWatchthis': form.wpWatchthis.checked,
    'wpStarttime': form.wpStarttime.value,
    'wpEdittime': form.wpEdittime.value,
    'wpAutoSummary': form.wpAutoSummary.value,
    'wpEditToken': form.wpEditToken.value,
    'wpSummary': "Quick preview",
    'wpTextbox1': document.editform.wpTextbox1.value 
  };
  var addr = document.URL;
  addr = addr.replace("&action=edit", "&action=submit");
  addr += "&wpPreview=true&live=true";
  var qwxmlhttp = sajax_init_object(null);
  qwxmlhttp.overrideMimeType('text/xml');
  qwxmlhttp.open( 'POST' , addr, true);
  qwxmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
  qwxmlhttp.onload = function() {
  document.getElementById("wikiPreview").innerHTML =  unescape(qwxmlhttp.responseText.replace(/&gt;/g,">").replace(/&lt;/g,"<").replace(/&amp;/g,"&").replace(/&quot;/g,'"'));
  bt.disabled=false;
  bt.value = "Quick preview";
  document.getElementById("contentSub").innerHTML = "";
  }
  qwxmlhttp.send(QueryString.create(postData));
}
/**** End Quick Preview ****/
 
/* </source> */

Revision as of 19:44, 25 June 2009

/* Move top tabs inside body content */

addOnloadHook(function () {
    content = document.getElementById("column-content");    // Find the main content column

    footer = document.getElementById("footer");  // Find the footer
    footer.parentNode.removeChild(footer);    // Remove the footer from the global wrapper
    content.appendChild(footer);    // Place footer at the end of the content column;

    tabs = document.getElementById("p-cactions");   // Find the top tab list
    tabs.parentNode.removeChild(tabs);    // Remove the tab list from the side column
    content.insertBefore(tabs,content.firstChild);    // Place tab list at the beginning of the content column
});