User:Milnivri/monaco.js: Difference between revisions

From Wikifang, a definitive guide to Telefang, Dino Device and Bugsite
Jump to navigation Jump to search
No edit summary
No edit summary
Line 5: Line 5:
   addPortletLink('p-cactions', editTab.firstChild.href + '&externaledit=true', '→', 'ca-exted', 'Edit with External Editor ',, editTab.nextSibling);
   addPortletLink('p-cactions', editTab.firstChild.href + '&externaledit=true', '→', 'ca-exted', 'Edit with External Editor ',, editTab.nextSibling);
})
})
function addPortletLink(portlet, href, text, id, tooltip, accesskey, nextnode) {
var root = document.getElementById(portlet);
if ( !root ) return null;
var node = root.getElementsByTagName( "ul" )[0];
if ( !node ) return null;
// unhide portlet if it was hidden before
root.className = root.className.replace( /(^| )emptyPortlet( |$)/, "$2" );
var span = document.createElement( "span" );
span.appendChild( document.createTextNode( text ) );
var link = document.createElement( "a" );
link.appendChild( span );
link.href = href;
var item = document.createElement( "li" );
item.appendChild( link );
if ( id ) item.id = id;
if ( accesskey ) {
link.setAttribute( "accesskey", accesskey );
tooltip += " ["+accesskey+"]";
}
if ( tooltip ) {
link.setAttribute( "title", tooltip );
}
if ( accesskey && tooltip ) {
updateTooltipAccessKeys( new Array( link ) );
}
if ( nextnode && nextnode.parentNode == node )
node.insertBefore( item, nextnode );
else
node.appendChild( item ); // IE compatibility (?)
return item;
}

Revision as of 01:12, 16 December 2009

//add ExtEdit link 
addOnloadHook(function(){
  var editTab = document.getElementById('ca-edit');
  if (!editTab) return;
  addPortletLink('p-cactions', editTab.firstChild.href + '&externaledit=true', '→', 'ca-exted', 'Edit with External Editor ',, editTab.nextSibling);
})

function addPortletLink(portlet, href, text, id, tooltip, accesskey, nextnode) {
 var root = document.getElementById(portlet);
 if ( !root ) return null;
 var node = root.getElementsByTagName( "ul" )[0];
 if ( !node ) return null;

 // unhide portlet if it was hidden before
 root.className = root.className.replace( /(^| )emptyPortlet( |$)/, "$2" );

 var span = document.createElement( "span" );
 span.appendChild( document.createTextNode( text ) );

 var link = document.createElement( "a" );
 link.appendChild( span );
 link.href = href;

 var item = document.createElement( "li" );
 item.appendChild( link );
 if ( id ) item.id = id;

 if ( accesskey ) {
 link.setAttribute( "accesskey", accesskey );
 tooltip += " ["+accesskey+"]";
 }
 if ( tooltip ) {
 link.setAttribute( "title", tooltip );
 }
 if ( accesskey && tooltip ) {
 updateTooltipAccessKeys( new Array( link ) );
 }

 if ( nextnode && nextnode.parentNode == node )
 node.insertBefore( item, nextnode );
 else
 node.appendChild( item ); // IE compatibility (?)

 return item;
}