From 128f310047ce6d3dc7a42fa2384a1fe9bf88a36d Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Thu, 7 Mar 2013 08:57:23 +0100 Subject: [PATCH] ClientJS: Methoden "focus" und "action" --- SL/ClientJS.pm | 42 ++++++++++++++++++++++++++++++++++++++++++ js/client_js.js | 3 +++ 2 files changed, 45 insertions(+) diff --git a/SL/ClientJS.pm b/SL/ClientJS.pm index 6f9ce5adb..99598afc6 100644 --- a/SL/ClientJS.pm +++ b/SL/ClientJS.pm @@ -59,6 +59,9 @@ my %supported_methods = ( data => 3, removeData => 2, + # Form Events + focus => 1, + # ## jstree plugin ## pattern: $.jstree._reference($()).() # Operations on the whole tree @@ -93,6 +96,11 @@ sub AUTOLOAD { my $method = $AUTOLOAD; $method =~ s/.*:://; return if $method eq 'DESTROY'; + return $self->action($method, @args); +} + +sub action { + my ($self, $method, @args) = @_; $method = (delete($self->{_prefix}) || '') . $method; my $num_args = $supported_methods{$method}; @@ -263,6 +271,36 @@ instance. For example: =head1 FUNCTIONS EVALUATED ON THE CLIENT SIDE +=head2 GENERIC FUNCTION + +All of the following functions can be invoked in two ways: either by +calling the function name directly on C<$self> or by calling +L with the function name as the first parameter. Therefore +the following two calls are identical: + + $js->insertAfter($html, '#some-id'); + $js->action('insertAfter', $html, '#some-id'); + +The second form, calling L, is more to type but can be useful +in situations in which you have to call one of two functions depending +on context. For example, when you want to insert new code in a +list. If the list is empty you might have to use C, if it +isn't you might have to use C. Example: + + my $html = $self->render(...); + $js->action($list_is_empty ? 'appendTo' : 'insertAfter', $html, '#text-block-' . ($list_is_empty ? 'list' : $self->text_block->id)); + +Instead of: + + my $html = $self->render(...); + if ($list_is_empty) { + $js->appendTo($html, '#text-block-list'); + } else { + $js->insertAfter($html, '#text-block-' . $self->text_block->id); + } + +The first variation is obviously better suited for chaining. + =head2 JQUERY FUNCTIONS The following jQuery functions are supported: @@ -301,6 +339,10 @@ C, C, C, C, C C, C +=item Form Events + +C + =back =head2 JSTREE JQUERY PLUGIN diff --git a/js/client_js.js b/js/client_js.js index 34b254b5a..08b9b7248 100644 --- a/js/client_js.js +++ b/js/client_js.js @@ -60,6 +60,9 @@ function eval_json_result(data) { else if (action[0] == 'data') $(action[1]).data(action[2], action[3]); else if (action[0] == 'removeData') $(action[1]).removeData(action[2]); + // Form Events + else if (action[0] == 'focus') $(action[1]).focus(); + // ## jstree plugin ## // Operations on the whole tree -- 2.20.1