Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
3 * Copyright (C) 2006-2013 Eyeo GmbH | 3 * Copyright (C) 2006-2013 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
516 | 516 |
517 ext.backgroundPage = { | 517 ext.backgroundPage = { |
518 getWindow: function() | 518 getWindow: function() |
519 { | 519 { |
520 return safari.extension.globalPage.contentWindow; | 520 return safari.extension.globalPage.contentWindow; |
521 } | 521 } |
522 }; | 522 }; |
523 | 523 |
524 ext.onMessage = new MessageEventTarget(safari.application); | 524 ext.onMessage = new MessageEventTarget(safari.application); |
525 | 525 |
526 var contextMenu = []; | 526 var contextMenuItems = []; |
527 var isContextMenuHidden = false; | 527 var isContextMenuHidden = true; |
528 ext.contextMenus = { | 528 ext.contextMenus = { |
529 addMenuItem: function(title, contexts, onclick) | 529 addMenuItem: function(title, contexts, onclick) |
530 { | 530 { |
531 contextMenu.push({ | 531 contextMenuItems.push({ |
532 id: "block-element", | 532 id: String(contextMenuItems.length), |
Wladimir Palant
2014/01/17 15:36:55
So all menu items have the same ID?
How about usi
Thomas Greiner
2014/01/18 10:32:05
Done. According to Apple "The identifier must be u
| |
533 title: title, | 533 title: title, |
534 item: null, | |
535 contexts: contexts, | 534 contexts: contexts, |
536 onclick: onclick | 535 onclick: onclick |
537 }); | 536 }); |
537 this.showMenuItems(); | |
538 }, | 538 }, |
539 removeMenuItems: function() | 539 removeMenuItems: function() |
540 { | 540 { |
541 contextMenu = []; | 541 contextMenuItems = []; |
542 }, | 542 this.hideMenuItems(); |
543 showMenu: function() | 543 }, |
544 showMenuItems: function() | |
544 { | 545 { |
545 isContextMenuHidden = false; | 546 isContextMenuHidden = false; |
546 }, | 547 }, |
547 hideMenu: function() | 548 hideMenuItems: function() |
548 { | 549 { |
549 isContextMenuHidden = true; | 550 isContextMenuHidden = true; |
550 } | 551 } |
551 }; | 552 }; |
552 | 553 |
553 // Create context menu items | 554 // Create context menu items |
554 safari.application.addEventListener("contextmenu", function(event) | 555 safari.application.addEventListener("contextmenu", function(event) |
555 { | 556 { |
557 if (isContextMenuHidden) | |
558 return; | |
559 | |
556 var context = event.userInfo.tagName.toLowerCase(); | 560 var context = event.userInfo.tagName.toLowerCase(); |
Wladimir Palant
2014/01/18 11:13:39
Nit: toLowerCase() is no longer necessary now that
| |
557 if (context == "img") | 561 if (context == "img") |
558 context = "image"; | 562 context = "image"; |
Wladimir Palant
2014/01/17 15:36:55
Seeing that srcUrl can be null, it probably makes
Thomas Greiner
2014/01/18 10:32:05
Done.
| |
559 | 563 if (!event.userInfo.srcUrl) |
560 for (var i = 0; i < contextMenu.length; i++) | 564 context = null; |
561 { | 565 |
562 if (isContextMenuHidden) | 566 for (var i = 0; i < contextMenuItems.length; i++) |
563 return; | 567 { |
Wladimir Palant
2014/01/17 15:36:55
Why is this check inside the loop? This belongs to
Thomas Greiner
2014/01/18 10:32:05
Done.
| |
564 | |
565 // Supported contexts are: all, audio, image, video | 568 // Supported contexts are: all, audio, image, video |
566 var menuItem = contextMenu[i]; | 569 var menuItem = contextMenuItems[i]; |
567 if (menuItem.contexts.indexOf("all") == -1 && menuItem.contexts.indexOf(co ntext) == -1) | 570 if (menuItem.contexts.indexOf("all") == -1 && menuItem.contexts.indexOf(co ntext) == -1) |
568 return; | 571 continue; |
Wladimir Palant
2014/01/17 15:36:55
This should be continue, not return - there can be
Thomas Greiner
2014/01/18 10:32:05
Done.
| |
569 | 572 |
570 menuItem.item = event.contextMenu.appendContextMenuItem(menuItem.id, menuI tem.title); | 573 event.contextMenu.appendContextMenuItem(menuItem.id, menuItem.title); |
Wladimir Palant
2014/01/17 15:36:55
I don't think that menuItem.item is being used, no
Thomas Greiner
2014/01/18 10:32:05
Done.
| |
571 } | 574 } |
572 }, false); | 575 }, false); |
573 | 576 |
574 // Handle context menu item clicks | 577 // Handle context menu item clicks |
575 safari.application.addEventListener("command", function(event) | 578 safari.application.addEventListener("command", function(event) |
576 { | 579 { |
577 for (var i = 0; i < contextMenu.length; i++) | 580 for (var i = 0; i < contextMenu.length; i++) |
578 { | 581 { |
579 if (contextMenu[i].id == event.command) | 582 if (contextMenu[i].id == event.command) |
580 { | 583 { |
581 contextMenu[i].onclick(event.userInfo.srcUrl, new Tab(safari.application .activeBrowserWindow.activeTab)); | 584 contextMenu[i].onclick(event.userInfo.srcUrl, new Tab(safari.application .activeBrowserWindow.activeTab)); |
582 break; | 585 break; |
583 } | 586 } |
584 } | 587 } |
585 }, false); | 588 }, false); |
586 | 589 |
587 // Safari will load the bubble once, and then show it everytime the icon is | 590 // Safari will load the bubble once, and then show it everytime the icon is |
588 // clicked. While Chrome loads it everytime you click the icon. So in order to | 591 // clicked. While Chrome loads it everytime you click the icon. So in order to |
589 // force the same behavior in Safari, we are going to reload the page of the | 592 // force the same behavior in Safari, we are going to reload the page of the |
590 // bubble everytime it is shown. | 593 // bubble everytime it is shown. |
591 if (safari.extension.globalPage.contentWindow != window) | 594 if (safari.extension.globalPage.contentWindow != window) |
592 safari.application.addEventListener("popover", function() | 595 safari.application.addEventListener("popover", function() |
593 { | 596 { |
594 document.documentElement.style.display = "none"; | 597 document.documentElement.style.display = "none"; |
595 document.location.reload(); | 598 document.location.reload(); |
596 }, true); | 599 }, true); |
597 })(); | 600 })(); |
LEFT | RIGHT |