Index: trunk/phase3/skins/common/wikibits.js |
— | — | @@ -461,6 +461,53 @@ |
462 | 462 | } |
463 | 463 | } |
464 | 464 | |
| 465 | +function setupRightClickEdit() { |
| 466 | + if (document.getElementsByTagName) { |
| 467 | + var spans = document.getElementsByTagName('span'); |
| 468 | + for (var i = 0; i < spans.length; i++) { |
| 469 | + var el = spans[i]; |
| 470 | + if(el.className == 'editsection') { |
| 471 | + addRightClickEditHandler(el); |
| 472 | + } |
| 473 | + } |
| 474 | + } |
| 475 | +} |
| 476 | + |
| 477 | +function addRightClickEditHandler(el) { |
| 478 | + for (var i = 0; i < el.childNodes.length; i++) { |
| 479 | + var link = el.childNodes[i]; |
| 480 | + if (link.nodeType == 1 && link.nodeName.toLowerCase() == 'a') { |
| 481 | + var editHref = link.getAttribute('href'); |
| 482 | + // find the enclosing (parent) header |
| 483 | + var prev = el.parentNode; |
| 484 | + if (prev && prev.nodeType == 1 && |
| 485 | + prev.nodeName.match(/^[Hh][1-6]$/)) { |
| 486 | + prev.oncontextmenu = function(e) { |
| 487 | + if (!e) { e = window.event; } |
| 488 | + // e is now the event in all browsers |
| 489 | + var targ; |
| 490 | + if (e.target) { targ = e.target; } |
| 491 | + else if (e.srcElement) { targ = e.srcElement; } |
| 492 | + if (targ.nodeType == 3) { // defeat Safari bug |
| 493 | + targ = targ.parentNode; |
| 494 | + } |
| 495 | + // targ is now the target element |
| 496 | + |
| 497 | + // We don't want to deprive the noble reader of a context menu |
| 498 | + // for the section edit link, do we? (Might want to extend this |
| 499 | + // to all <a>'s?) |
| 500 | + if (targ.nodeName.toLowerCase() != 'a' |
| 501 | + || targ.parentNode.className != 'editsection') { |
| 502 | + document.location = editHref; |
| 503 | + return false; |
| 504 | + } |
| 505 | + return true; |
| 506 | + }; |
| 507 | + } |
| 508 | + } |
| 509 | + } |
| 510 | +} |
| 511 | + |
465 | 512 | var checkboxes; |
466 | 513 | var lastCheckbox; |
467 | 514 | |