-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmenuWithDelayedInitialization.html
More file actions
35 lines (33 loc) · 4.13 KB
/
menuWithDelayedInitialization.html
File metadata and controls
35 lines (33 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<!DOCTYPE HTML>
<meta charset="utf-8"/>
<title>Example: menu with delayed initialization [0.1.1 - 2013-02-08]</title>
<body>
<a href="custombutton://%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%3F%3E%0D%0A%3Ccustombutton%20xmlns%3Acb%3D%22http%3A//xsms.nm.ru/custombuttons/%22%3E%0A%20%20%3Cname%3EExample%3A%20menu%20with%20delayed%20initialization%3C/name%3E%0A%20%20%3Cimage%3E%3C%21%5BCDATA%5Bcustombuttons-stdicon-1%5D%5D%3E%3C/image%3E%0A%20%20%3Cmode%3E2%3C/mode%3E%0A%20%20%3Cinitcode%3E%3C%21%5BCDATA%5B//%3D%3D%20%22Initialization%22%20section%3A%0ALOG%28%22init%28%29%22%29%3B%0Athis.type%20%3D%20%22menu%22%3B%0Athis.orient%20%3D%20%22horizontal%22%3B%0Avar%20mp%20%3D%20this.mp%20%3D%20document.createElement%28%22menupopup%22%29%3B%0Amp.setAttribute%28%22onpopupshowing%22%2C%20%22this.parentNode.initMenuOnce%28%29%3B%22%29%3B%0Athis.appendChild%28mp%29%3B%0A%0Athis.initMenuOnce%20%3D%20function%28%29%20%7B%0A%09LOG%28%22onpopupshowing%22%29%3B%0A%09delete%20this.initMenuOnce%3B%0A%09//%20Looks%20like%20Gecko%20bug%3A%20handler%20can%27t%20be%20removed%20using%20removeAttribute%28%29%0A%09mp.setAttribute%28%22onpopupshowing%22%2C%20%22%22%29%3B%0A%09mp.removeAttribute%28%22onpopupshowing%22%29%3B%0A%09this.doCommand%28%29%3B%0A%7D%3B%5D%5D%3E%3C/initcode%3E%0A%20%20%3Ccode%3E%3C%21%5BCDATA%5B//%20https%3A//github.com/Infocatcher/Custom_Buttons/blob/master/code_snippets/menuWithDelayedInitialization.js%0A%0A//%20Example%20menu%20button%20for%20Custom%20Buttons%0A//%20Code%20for%20%22code%22%20and%20%22initialization%22%20sections%20%28see%20comments%29%0A%0A//%20%28c%29%20Infocatcher%202013%0A//%20version%200.1.1%20-%202013-02-08%0A%0A%0A//%3D%3D%20%22Code%22%20section%3A%0Aif%28%21event.target%29%20%7B%20//%20Button%27s%20hotkey%20pressed%0A%09LOG%28%22hotkey%22%29%3B%0A%09this.open%20%3D%20true%3B%0A%09return%3B%0A%7D%0Aif%28event.target%20%21%3D%20this%29%20%7B%0A%09LOG%28%22code%28%29%20from%20child%20node%22%29%3B%0A%09return%3B%0A%7D%0ALOG%28%22code%28%29%22%29%3B%0Avar%20mp%20%3D%20this.mp%3B%20//%20See%20initialization%0AaddEventListener%28%22command%22%2C%20function%28e%29%20%7B%0A%09//%20Button%20shouldn%27t%20handle%20%22command%22%20event%20from%20child%20nodes%0A%09e.stopPropagation%28%29%3B%0A%7D%2C%20false%2C%20mp%29%3B%0A//%20Create%20menu%20contents%20%28just%20an%20example%29%3A%0Avar%20df%20%3D%20document.createDocumentFragment%28%29%3B%0Afor%28var%20i%20%3D%201%3B%20i%20%3C%3D%2010%3B%20++i%29%20%7B%0A%09var%20mi%20%3D%20document.createElement%28%22menuitem%22%29%3B%0A%09mi.setAttribute%28%22label%22%2C%20%22Item%20%23%22%20+%20i%29%3B%0A%09mi.setAttribute%28%22oncommand%22%2C%20%22this.parentNode.parentNode.handleCommand%28%22%20+%20i%20+%20%22%29%3B%22%29%3B%0A%09df.appendChild%28mi%29%3B%0A%7D%0Amp.appendChild%28df%29%3B%0Athis.handleCommand%20%3D%20function%28i%29%20%7B%0A%09alert%28%22Command%20%23%22%20+%20i%29%3B%0A%7D%3B%5D%5D%3E%3C/code%3E%0A%20%20%3Caccelkey%3E%3C%21%5BCDATA%5BCtrl+Shift+A%5D%5D%3E%3C/accelkey%3E%0A%20%20%3Chelp%3E%3C%21%5BCDATA%5B%5D%5D%3E%3C/help%3E%0A%20%20%3Cattributes/%3E%0A%3C/custombutton%3E"
>Install</a>
| <a href="https://github.com/Infocatcher/Custom_Buttons/blob/master/code_snippets/menuWithDelayedInitialization.js">Source</a>
| <a href="https://github.com/Infocatcher/Custom_Buttons#usage">Instructions</a>
<script type="text/javascript">
var a = document.getElementsByTagName("a")[0];
a.title = document.title;
if(/%3Cimage%3E%3C%21%5BCDATA%5B(data%3A\S+)%5D%5D%3E%3C\/image%3E/.test(a.href)) {
var icon = decodeURIComponent(RegExp.$1);
var img = document.createElement("img");
img.src = icon;
img.alt = "";
img.style.verticalAlign = "middle";
img.style.marginRight = "4px";
img.style.border = "none";
a.insertBefore(img, a.firstChild);
var link = document.createElement("link");
link.rel = "shortcut icon";
link.href = icon;
document.documentElement.insertBefore(link, document.documentElement.firstChild);
}
</script>
<script type="text/javascript" src="https://infocatcher.github.io/Custom_Buttons/viewCustomButton.js"></script>
<script type="text/javascript">
if("viewCustomButtonCode" in window) setTimeout(function() {
viewCustomButtonCode(a.href);
}, 0);
</script>
</body>