From: Mischa POSLAWSKY Date: Wed, 31 Mar 2010 21:38:34 +0000 (+0000) Subject: unicode: copy glyph to clipboard on cell click X-Git-Tag: v1.3~16 X-Git-Url: http://git.shiar.nl/sheet.git/commitdiff_plain/5a85c6bfca6be44dadd58eedd0d9f0d1d5619e5f?hp=4b28462f6dccd2437a3313b02a2ec678a4bf674b unicode: copy glyph to clipboard on cell click Assume the only reason to click a cell is to copy the glyph contents, so help the user by copying it automatically, avoiding the need for exact selection and usually a copy command. Should support Trident browsers out of the box, and Gecko with effort. (At last a feature where the IE(>6) solution is vastly superior.) Tested in MSIE 6.0/7.0 and Iceweasel 3.5.8/3.6.3 with XPCOM enabled. --- 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; +} + diff --git a/unicode.plp b/unicode.plp index 7149953..184fcb6 100644 --- a/unicode.plp +++ b/unicode.plp @@ -218,3 +218,5 @@ $verbose ? ( + +