summaryrefslogtreecommitdiff
path: root/httemplate/elements
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2013-10-24 15:59:41 -0700
committerMark Wells <mark@freeside.biz>2013-10-24 15:59:41 -0700
commit0953ba442fbe838a6489c27ec0c348409eae3d9f (patch)
treee7aef682abaa7be9420b695f03178790b7a2df09 /httemplate/elements
parent708496b2fbc1365cb25d1a6c503c294e7c015f8b (diff)
masked input clipboard hack, #25599
Diffstat (limited to 'httemplate/elements')
-rw-r--r--httemplate/elements/tr-input-mask.html34
1 files changed, 34 insertions, 0 deletions
diff --git a/httemplate/elements/tr-input-mask.html b/httemplate/elements/tr-input-mask.html
index 33725b9a5..8a494c8de 100644
--- a/httemplate/elements/tr-input-mask.html
+++ b/httemplate/elements/tr-input-mask.html
@@ -5,6 +5,7 @@
% }
<& /elements/tr-input-text.html, id => $id, @_ &>
<script type="text/javascript">
+<&| /elements/onload.js &>
MaskedInput({
elm: document.getElementById('<%$id%>'),
format: '<% $opt{format} %>',
@@ -12,7 +13,38 @@ MaskedInput({
<% $opt{typeon} ? "typeon: '$opt{typeon}'," : '' %>
});
document.getElementById('<%$id%>').value = <% $value |js_string %>;
+% 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
+</&>
</script>
+<textarea id="<%$id%>_clipboard" style="opacity:0"></textarea>
<%shared>
my $init = 0;
</%shared>
@@ -21,6 +53,8 @@ my %opt = @_;
# must have a DOM id
my $id = $opt{id} || sprintf('input%04d',int(rand(10000)));
my $value = length($opt{curr_value}) ? $opt{curr_value} : $opt{value} || '';
+
+my $clipboard_hack = $FS::CurrentUser::CurrentUser->option('enable_mask_clipboard_hack');
</%init>
<%doc>
Set up a text input field with input masking.