+% if ( $clipboard_hack ) {
+var t = document.getElementById('<% $id %>');
+var container = document.getElementById('<%$id%>_clipboard');
+var KeyHandlerDown = t.onkeydown
+t.onkeydown = function(e) {
+ // intercept ctrl-c and ctrl-x
+ // and cmd-c and cmd-x on mac
+ // when text is selected
+ if ( ( e.ctrlKey || e.metaKey ) ) {
+ // do the dance
+ var separators = /[\\/:-]/g;
+ var s = t.value.substr(t.selectionStart, t.selectionEnd);
+ if ( s ) {
+ container.value = s.replace(separators, '');
+ container.previous = t;
+ container.focus();
+ container.select();
+ return true;
+ }
+ }
+ return KeyHandlerDown.call(t, e);
+};
+container.onkeyup = function(e) {
+ if ( container.previous ) {
+ setTimeout(function() {container.previous.focus();}, 10);
+ }
+ return true;
+}
+% } # clipboard hack
+</&>