countries: hardcode reservations
[sheet.git] / clipboard.js
1 copyhint = true;
2 function clipboardcopy(val) {
3         if (window && window.clipboardData) {
4                 // msie
5                 return window.clipboardData.setData('text', val);
6         }
7
8         if (netscape && netscape.security) {
9                 // request access to XPCOM api
10                 try {
11                         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
12                 }
13                 catch(e) {
14                         if (copyhint)
15                                 alert('Cannot access clipboard.\nSet boolean signed.applets.codebase_principal_support in about:config');
16                         copyhint = false;
17                         return false;
18                 }
19
20                 // use nsIClipboard interface
21                 try {
22                         Components.classes['@mozilla.org/widget/clipboardhelper;1']
23                                 .getService(Components.interfaces.nsIClipboardHelper)
24                                 .copyString(val);
25                         return true;
26                 }
27                 catch(e) {
28                         alert('Copy failed');
29                         return false;
30                 }
31         }
32 }
33
34 charmatch = /^U\+([0-9A-F]{4,})/;
35 function copycellchars() {
36         var unicode = charmatch.exec(this.title);
37         var str = String.fromCharCode(parseInt(unicode[1], 16));
38         return clipboardcopy(str);
39 }
40
41 var cells = document.getElementsByTagName('TD');
42 for (var i = 0; i < cells.length; i++) {
43         if (!cells[i].title) continue;
44         if (!charmatch.test(cells[i].title)) continue;
45         cells[i].onclick = copycellchars;
46 }
47