X-Git-Url: http://git.shiar.net/sheet.git/blobdiff_plain/4b28462f6dccd2437a3313b02a2ec678a4bf674b..5a85c6bfca6be44dadd58eedd0d9f0d1d5619e5f:/clipboard.js diff --git a/clipboard.js b/clipboard.js new file mode 100644 index 0000000..cbf43d6 --- /dev/null +++ b/clipboard.js @@ -0,0 +1,47 @@ +copyhint = true; +function clipboardcopy(val) { + if (window && window.clipboardData) { + // msie + return window.clipboardData.setData('text', val); + } + + if (netscape && netscape.security) { + // request access to XPCOM api + try { + netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); + } + catch(e) { + if (copyhint) + alert('Cannot access clipboard.\nSet boolean signed.applets.codebase_principal_support in about:config'); + copyhint = false; + return false; + } + + // use nsIClipboard interface + try { + Components.classes['@mozilla.org/widget/clipboardhelper;1'] + .getService(Components.interfaces.nsIClipboardHelper) + .copyString(val); + return true; + } + catch(e) { + alert('Copy failed'); + return false; + } + } +} + +charmatch = /^U\+([0-9A-F]{4,})/; +function copycellchars() { + var unicode = charmatch.exec(this.title); + var str = String.fromCharCode(parseInt(unicode[1], 16)); + return clipboardcopy(str); +} + +var cells = document.getElementsByTagName('TD'); +for (var i = 0; i < cells.length; i++) { + if (!cells[i].title) continue; + if (!charmatch.test(cells[i].title)) continue; + cells[i].onclick = copycellchars; +} +