| 358 | | var ctx = document.getElementById("dtaCtxCompact").parentNode; |
|---|
| | 358 | this.direct = {}; |
|---|
| | 359 | this.compact = {}; |
|---|
| | 360 | |
|---|
| | 361 | var ctxItem = document.getElementById("dtaCtxCompact"); |
|---|
| | 362 | var ctx = ctxItem.parentNode; |
|---|
| | 363 | var cont = document.getElementById('dtaCtxSubmenu'); |
|---|
| | 364 | |
|---|
| | 365 | ['SepBack', 'Pref', 'SepPref', 'TDTA', 'DTA', 'SaveT', 'Save', 'SepFront'].forEach( |
|---|
| | 366 | function(id) { |
|---|
| | 367 | this.compact[id] = document.getElementById('dtaCtx' + id); |
|---|
| | 368 | var node = document.getElementById('dtaCtx' + id).cloneNode(true); |
|---|
| | 369 | node.setAttribute('id', node.id + "-direct"); |
|---|
| | 370 | ctx.insertBefore(node, ctxItem.nextSibling); |
|---|
| | 371 | this.direct[id] = node; |
|---|
| | 372 | }, |
|---|
| | 373 | this |
|---|
| | 374 | ); |
|---|
| | 375 | // intitalize those to have Menu Editor pick up "good" text |
|---|
| | 376 | [this.direct, this.compact].forEach( |
|---|
| | 377 | function(m) { |
|---|
| | 378 | m.Save.label = this.getString('dtasavelink'); |
|---|
| | 379 | m.SaveT.label = this.getString('turbosavelink'); |
|---|
| | 380 | }, |
|---|
| | 381 | this |
|---|
| | 382 | ); |
|---|
| | 383 | |
|---|
| 393 | | if (window.gContextMenu != null) { |
|---|
| 394 | | return gContextMenu; |
|---|
| 395 | | } |
|---|
| 396 | | var cm = { |
|---|
| 397 | | onLink: false, |
|---|
| 398 | | onImage: false, |
|---|
| 399 | | target: document.popupNode, |
|---|
| 400 | | fake: true |
|---|
| 401 | | }; |
|---|
| 402 | | if (cm.target) { |
|---|
| 403 | | var node = cm.target; |
|---|
| 404 | | if (node instanceof Components.interfaces.nsIImageLoadingContent && node.currentURI) { |
|---|
| 405 | | cm.onImage = true; |
|---|
| 406 | | } |
|---|
| 407 | | while (node && !cm.onLink) { |
|---|
| 408 | | if (node instanceof HTMLAnchorElement && node.href) { |
|---|
| 409 | | cm.onLink = true; |
|---|
| 410 | | } |
|---|
| 411 | | node = node.parentNode; |
|---|
| 412 | | } |
|---|
| 413 | | } |
|---|
| 414 | | return cm; |
|---|
| | 408 | if (window.gContextMenu != null) { |
|---|
| | 409 | return gContextMenu; |
|---|
| | 410 | } |
|---|
| | 411 | var cm = { |
|---|
| | 412 | onLink: false, |
|---|
| | 413 | onImage: false, |
|---|
| | 414 | target: document.popupNode, |
|---|
| | 415 | fake: true |
|---|
| | 416 | }; |
|---|
| | 417 | if (cm.target) { |
|---|
| | 418 | var node = cm.target; |
|---|
| | 419 | if (node instanceof Components.interfaces.nsIImageLoadingContent && node.currentURI) { |
|---|
| | 420 | cm.onImage = true; |
|---|
| | 421 | } |
|---|
| | 422 | while (node && !cm.onLink) { |
|---|
| | 423 | if (node instanceof HTMLAnchorElement && node.href) { |
|---|
| | 424 | cm.onLink = true; |
|---|
| | 425 | } |
|---|
| | 426 | node = node.parentNode; |
|---|
| | 427 | } |
|---|
| | 428 | } |
|---|
| | 429 | return cm; |
|---|
| 462 | | if (menu[2]) { |
|---|
| 463 | | show.push('Pref'); |
|---|
| 464 | | if (compact) { |
|---|
| 465 | | show.push('SepPref'); |
|---|
| 466 | | } else { |
|---|
| 467 | | show.push('SepBack'); |
|---|
| 468 | | show.push('SepFront'); |
|---|
| 469 | | } |
|---|
| 470 | | } |
|---|
| 471 | | |
|---|
| 472 | | // general setup |
|---|
| 473 | | var base = document.getElementById(this.ctxBase.getAttribute('insertafter')); |
|---|
| 474 | | if (compact) { |
|---|
| 475 | | this.ctxBase.hidden = false; |
|---|
| 476 | | base.parentNode.insertBefore(this.ctxBase, base.nextSibling); |
|---|
| 477 | | } else { |
|---|
| 478 | | this.ctxBase.hidden = true; |
|---|
| 479 | | } |
|---|
| 480 | | |
|---|
| 481 | | // show the items. |
|---|
| 482 | | for (var i in this.ctx) { |
|---|
| 483 | | var cur = this.ctx[i]; |
|---|
| 484 | | cur.hidden = show.indexOf(i) == -1; |
|---|
| 485 | | if (cur.hidden) { |
|---|
| | 484 | if (items[2]) { |
|---|
| | 485 | show.push(menu.Pref); |
|---|
| | 486 | if (compact && (items[0] || items[1])) { |
|---|
| | 487 | show.push(menu.SepPref); |
|---|
| | 488 | } |
|---|
| | 489 | } |
|---|
| | 490 | |
|---|
| | 491 | // show the seperators, if required. |
|---|
| | 492 | var n = menu.SepFront; |
|---|
| | 493 | while ((n = n.previousSibling)) { |
|---|
| | 494 | if (n.hidden) { |
|---|
| 488 | | if (compact) { |
|---|
| 489 | | this.ctxMenu.insertBefore(cur, this.ctxMenu.firstChild); |
|---|
| 490 | | } |
|---|
| 491 | | else { |
|---|
| 492 | | base.parentNode.insertBefore(cur, base); |
|---|
| 493 | | base = cur; |
|---|
| 494 | | } |
|---|
| 495 | | } |
|---|
| 496 | | |
|---|
| 497 | | // add separators |
|---|
| 498 | | if (!compact) { |
|---|
| 499 | | var node = this.ctx.SepFront.previousSibling; |
|---|
| 500 | | while (node && node.hidden) { |
|---|
| 501 | | node = node.previousSibling; |
|---|
| 502 | | } |
|---|
| 503 | | if (node && node.nodeName == 'menuseparator') { |
|---|
| 504 | | this.ctx.SepFront.hidden = true; |
|---|
| 505 | | } |
|---|
| 506 | | node = this.ctx.SepBack.nextSibling; |
|---|
| 507 | | while (node && node.hidden) { |
|---|
| 508 | | node = node.nextSibling; |
|---|
| 509 | | } |
|---|
| 510 | | if (node && node.nodeName == 'menuseparator') { |
|---|
| 511 | | this.ctx.SepBack.hidden = true; |
|---|
| 512 | | } |
|---|
| 513 | | } |
|---|
| | 497 | if (n.nodeName != 'menuseparator') { |
|---|
| | 498 | show.push(menu.SepFront); |
|---|
| | 499 | } |
|---|
| | 500 | break; |
|---|
| | 501 | } |
|---|
| | 502 | n = menu.SepBack; |
|---|
| | 503 | while ((n = n.nextSibling)) { |
|---|
| | 504 | if (n.hidden) { |
|---|
| | 505 | continue; |
|---|
| | 506 | } |
|---|
| | 507 | if (n.nodeName != 'menuseparator') { |
|---|
| | 508 | show.push(menu.SepBack); |
|---|
| | 509 | } |
|---|
| | 510 | break; |
|---|
| | 511 | } |
|---|
| | 512 | |
|---|
| | 513 | show.forEach( |
|---|
| | 514 | function (node) { |
|---|
| | 515 | node.hidden = false; |
|---|
| | 516 | } |
|---|
| | 517 | ); |
|---|
| | 518 | |
|---|