Left: | ||
Right: |
OLD | NEW |
---|---|
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 // TODO: Implement context menu | 526 var contextMenu = []; |
527 var isContextMenuHidden = false; | |
527 ext.contextMenus = { | 528 ext.contextMenus = { |
528 create: function(title, contexts, onclick) {}, | 529 addMenuItem: function(title, contexts, onclick) |
529 removeAll: function(callback) {} | 530 { |
531 contextMenu.push({ | |
532 id: "block-element", | |
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, | |
534 item: null, | |
535 contexts: contexts, | |
536 onclick: onclick | |
537 }); | |
538 }, | |
539 removeMenuItems: function() | |
540 { | |
541 contextMenu = []; | |
542 }, | |
543 showMenu: function() | |
544 { | |
545 isContextMenuHidden = false; | |
546 }, | |
547 hideMenu: function() | |
548 { | |
549 isContextMenuHidden = true; | |
550 } | |
530 }; | 551 }; |
531 | 552 |
553 // Create context menu items | |
554 safari.application.addEventListener("contextmenu", function(event) | |
555 { | |
556 var context = event.userInfo.tagName.toLowerCase(); | |
557 if (context == "img") | |
558 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 | |
560 for (var i = 0; i < contextMenu.length; i++) | |
561 { | |
562 if (isContextMenuHidden) | |
563 return; | |
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 | |
566 var menuItem = contextMenu[i]; | |
567 if (menuItem.contexts.indexOf("all") == -1 && menuItem.contexts.indexOf(co ntext) == -1) | |
568 return; | |
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 | |
570 menuItem.item = event.contextMenu.appendContextMenuItem(menuItem.id, menuI tem.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 } | |
572 }, false); | |
573 | |
574 // Handle context menu item clicks | |
575 safari.application.addEventListener("command", function(event) | |
576 { | |
577 for (var i = 0; i < contextMenu.length; i++) | |
578 { | |
579 if (contextMenu[i].id == event.command) | |
580 { | |
581 contextMenu[i].onclick(event.userInfo.srcUrl, new Tab(safari.application .activeBrowserWindow.activeTab)); | |
582 break; | |
583 } | |
584 } | |
585 }, false); | |
586 | |
532 // Safari will load the bubble once, and then show it everytime the icon is | 587 // Safari will load the bubble once, and then show it everytime the icon is |
533 // clicked. While Chrome loads it everytime you click the icon. So in order to | 588 // clicked. While Chrome loads it everytime you click the icon. So in order to |
534 // force the same behavior in Safari, we are going to reload the page of the | 589 // force the same behavior in Safari, we are going to reload the page of the |
535 // bubble everytime it is shown. | 590 // bubble everytime it is shown. |
536 if (safari.extension.globalPage.contentWindow != window) | 591 if (safari.extension.globalPage.contentWindow != window) |
537 safari.application.addEventListener("popover", function() | 592 safari.application.addEventListener("popover", function() |
538 { | 593 { |
539 document.documentElement.style.display = "none"; | 594 document.documentElement.style.display = "none"; |
540 document.location.reload(); | 595 document.location.reload(); |
541 }, true); | 596 }, true); |
542 })(); | 597 })(); |
OLD | NEW |