View | Details | Raw Unified | Return to bug 30975
Collapse All | Expand All

(-)a/C4/Items.pm (-1 / +1 lines)
Lines 1518-1524 sub PrepareItemrecordDisplay { Link Here
1518
                        my $tab= $plugin->noclick? '-1': '';
1518
                        my $tab= $plugin->noclick? '-1': '';
1519
                        my $class= $plugin->noclick? ' disabled': '';
1519
                        my $class= $plugin->noclick? ' disabled': '';
1520
                        my $title= $plugin->noclick? 'No popup': 'Tag editor';
1520
                        my $title= $plugin->noclick? 'No popup': 'Tag editor';
1521
                        $subfield_data{marc_value} = qq[<input type="text" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="50" maxlength="$maxlength" value="$defaultvalue" /><a href="#" id="buttonDot_$subfield_data{id}" class="buttonDot $class" title="$title">...</a>\n].$plugin->javascript;
1521
                        $subfield_data{marc_value} = qq[<input type="text" id="$subfield_data{id}" name="field_value" class="input_marceditor framework_plugin" size="50" maxlength="$maxlength" value="$defaultvalue" data-plugin="$plugin->{name}" /><a href="#" id="buttonDot_$subfield_data{id}" class="buttonDot $class" title="$title" data-plugin="$plugin->{name}">...</a>\n].$plugin->javascript;
1522
                    } else {
1522
                    } else {
1523
                        warn $plugin->errstr;
1523
                        warn $plugin->errstr;
1524
                        $subfield_data{marc_value} = qq(<input type="text" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="50" maxlength="$maxlength" value="$defaultvalue" />); # supply default input form
1524
                        $subfield_data{marc_value} = qq(<input type="text" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="50" maxlength="$maxlength" value="$defaultvalue" />); # supply default input form
(-)a/Koha/FrameworkPlugin.pm (-77 / +7 lines)
Lines 307-400 sub _process_javascript { Link Here
307
    $script =~ s/\<script[^>]*\>\s*(\/\/\<!\[CDATA\[)?\s*//s;
307
    $script =~ s/\<script[^>]*\>\s*(\/\/\<!\[CDATA\[)?\s*//s;
308
    $script =~ s/(\/\/\]\]\>\s*)?\<\/script\>//s;
308
    $script =~ s/(\/\/\]\]\>\s*)?\<\/script\>//s;
309
309
310
    my $id = $params->{id}//'';
311
    my $bind = '';
312
    my $clickfound = 0;
310
    my $clickfound = 0;
313
    my @events = qw|click focus blur change mouseover mouseout mousedown
311
    my @events = qw|click focus blur change mousedown mouseup keydown keyup|;
314
        mouseup mousemove keydown keypress keyup|;
315
    foreach my $ev ( @events ) {
312
    foreach my $ev ( @events ) {
316
        my $scan = $ev eq 'click' && $self->{oldschool}? 'clic': $ev;
313
        my $scan = $ev eq 'click' && $self->{oldschool}? 'clic': $ev;
317
        if( $script =~ /function\s+($scan\w+)\s*\(([^\)]*)\)/is ) {
314
        if( $script =~ /function\s+($scan\w+)\s*\(/is ) {
318
            my ( $bl, $sl ) = $self->_add_binding( $1, $2, $ev, $id );
315
            my $function_name = $1;
319
            $script .= $sl;
316
            $script .= sprintf('registerFrameworkPluginHandler("%s", "%s", %s);', $self->name, $ev, $function_name);
320
            $bind .= $bl;
321
            $clickfound = 1 if $ev eq 'click';
317
            $clickfound = 1 if $ev eq 'click';
322
        }
318
        }
323
    }
319
    }
324
    if( !$clickfound ) { # make buttonDot do nothing
325
        my ( $bl ) = $self->_add_binding( 'noclick', '', 'click', $id );
326
        $bind .= $bl;
327
    }
328
    $self->{noclick} = !$clickfound;
320
    $self->{noclick} = !$clickfound;
329
    $self->{javascript}= _merge_script( $id, $script, $bind );
321
    $self->{javascript} = <<JS;
330
}
331
332
sub _add_binding {
333
# adds some jQuery code for event binding:
334
# $bind contains lines for the actual event binding: .click, .focus, etc.
335
# $script contains function definitions (if needed)
336
    my ( $self, $fname, $pars, $ev, $id ) = @_;
337
    my ( $bind, $script );
338
    my $ctl= $ev eq 'click'? 'buttonDot_'.$id: $id;
339
        #click event applies to buttonDot
340
341
    if( $pars =~ /^(e|ev|event)$/i ) { # new style event handler assumed
342
        $bind   = qq|    \$("#$ctl").off('$ev').on('$ev', \{id: '$id'\}, $fname);\n|;    # remove old handler if any
343
        $script = q{};
344
    } elsif( $fname eq 'noclick' ) { # no click: return false, no scroll
345
        $bind   = qq|    \$("#$ctl").$ev(function () { return false; });\n|;
346
        $script = q{};
347
    } else { # add real event handler calling the function found
348
        $bind   = qq|    \$("#$ctl").off('$ev').on('$ev', \{id: '$id'\}, ${fname}_handler);\n|;
349
        $script = $self->_add_handler( $ev, $fname );
350
    }
351
    return ( $bind, $script );
352
}
353
354
sub _add_handler {
355
# adds a handler with event parameter
356
# event.data.id is passed to the plugin function in parameters
357
# for the click event we always return false to prevent scrolling
358
    my ( $self, $ev, $fname ) = @_;
359
    my $first= $self->_first_item_par( $ev );
360
    my $prefix= $ev eq 'click'? '': 'return ';
361
    my $suffix= $ev eq 'click'? "\n    return false;": '';
362
    return <<HERE;
363
function ${fname}_handler(event) {
364
    $prefix$fname(${first}event.data.id);$suffix
365
}
366
HERE
367
}
368
369
sub _first_item_par {
370
    my ( $self, $event ) = @_;
371
    # needed for backward compatibility
372
    # js event functions in old style item plugins have an extra parameter
373
    # BUT.. not for all events (exceptions provide employment :)
374
    if( $self->{item_style} && $self->{oldschool} &&
375
            $event=~/focus|blur|change/ ) {
376
        return qq/'0',/;
377
    }
378
    return '';
379
}
380
381
sub _merge_script {
382
# Combine script and event bindings, enclosed in script tags.
383
# The BindEvents function is added to easily repeat event binding;
384
# this is used in additem.js for dynamically created item blocks.
385
    my ( $id, $script, $bind ) = @_;
386
    chomp ($script, $bind);
387
    return <<HERE;
388
<script>
322
<script>
323
\$(document).ready(function () {
389
$script
324
$script
390
function BindEvents$id() {
391
$bind
392
}
393
\$(document).ready(function() {
394
    BindEvents$id();
395
});
325
});
396
</script>
326
</script>
397
HERE
327
JS
398
}
328
}
399
329
400
=head1 AUTHOR
330
=head1 AUTHOR
(-)a/Koha/UI/Form/Builder/Item.pm (+1 lines)
Lines 338-343 sub generate_subfield_form { Link Here
338
                class      => $class,
338
                class      => $class,
339
                nopopup    => $plugin->noclick,
339
                nopopup    => $plugin->noclick,
340
                javascript => $plugin->javascript,
340
                javascript => $plugin->javascript,
341
                plugin     => $plugin->name,
341
            };
342
            };
342
        }
343
        }
343
        else {
344
        else {
(-)a/authorities/authorities.pl (+1 lines)
Lines 200-205 sub create_input { Link Here
200
                maxlength => $max_length,
200
                maxlength => $max_length,
201
                javascript => $plugin->javascript,
201
                javascript => $plugin->javascript,
202
                noclick    => $plugin->noclick,
202
                noclick    => $plugin->noclick,
203
                plugin     => $plugin->name,
203
            };
204
            };
204
        } else { # warn and supply default field
205
        } else { # warn and supply default field
205
            warn $plugin->errstr;
206
            warn $plugin->errstr;
(-)a/cataloguing/value_builder/EXAMPLE.pl (-22 / +4 lines)
Lines 65-101 my $builder= sub { Link Here
65
<script>
65
<script>
66
function Focus$id(event) {
66
function Focus$id(event) {
67
    if( \$('#'+event.data.id).val()=='' ) {
67
    if( \$('#'+event.data.id).val()=='' ) {
68
        \$('#'+event.data.id).val('EXAMPLE:');
68
        \$('#'+event.data.id).val('Focus');
69
    }
69
    }
70
}
70
}
71
71
72
function MouseOver$id(event) {
72
function Blur$id(event) {
73
    return Focus$id(event);
73
    if( \$('#'+event.data.id).val()=='' ) {
74
    /* just redirecting it to Focus for the same effect */
74
        \$('#'+event.data.id).val('Blur');
75
}
76
77
function KeyPress$id(event) {
78
    if( event.which == 64 ) { /* at character */
79
        var f= \$('#'+event.data.id).val();
80
        \$('#'+event.data.id).val( f + 'AT' );
81
        return false; /* prevents getting the @ character back too */
82
    }
83
}
84
85
function Change$id(event) {
86
    var colors= [ 'rgb(0, 0, 255)', 'rgb(0, 128, 0)', 'rgb(255, 0, 0)' ];
87
    var curcol= \$('#'+event.data.id).css('color');
88
    var i= Math.floor( Math.random() * 3 );
89
    if( colors[i]==curcol ) {
90
        i= (i + 1)%3;
91
    }
75
    }
92
    var f= \$('#'+event.data.id).css('color',colors[i]);
93
}
76
}
94
77
95
function Click$id(event) {
78
function Click$id(event) {
96
    var fieldvalue=\$('#'+event.data.id).val();
79
    var fieldvalue=\$('#'+event.data.id).val();
97
    window.open(\"../cataloguing/plugin_launcher.pl?plugin_name=EXAMPLE.pl&index=\"+event.data.id+\"&result=\"+fieldvalue,\"tag_editor\",'width=700,height=700,toolbar=false,scrollbars=yes');
80
    window.open(\"../cataloguing/plugin_launcher.pl?plugin_name=EXAMPLE.pl&index=\"+event.data.id+\"&result=\"+fieldvalue,\"tag_editor\",'width=700,height=700,toolbar=false,scrollbars=yes');
98
    return false; /* prevents scrolling */
99
}
81
}
100
</script>|;
82
</script>|;
101
};
83
};
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc (-3 / +3 lines)
Lines 144-154 Link Here
144
                        [% IF mv.readonly %]
144
                        [% IF mv.readonly %]
145
                            <input type="text" id="[%- mv.id | html -%]" name="[% kohafield | html %]" class="input_marceditor [% kohafield | html %]" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" readonly="readonly" />
145
                            <input type="text" id="[%- mv.id | html -%]" name="[% kohafield | html %]" class="input_marceditor [% kohafield | html %]" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" readonly="readonly" />
146
                        [% ELSE %]
146
                        [% ELSE %]
147
                            <input type="text" id="[%- mv.id | html -%]" name="[% kohafield | html %]" class="input_marceditor [% kohafield | html %]" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" />
147
                            <input type="text" id="[%- mv.id | html -%]" name="[% kohafield | html %]" class="input_marceditor framework_plugin [% kohafield | html %]" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" data-plugin="[% mv.plugin | html %]" />
148
                            [% IF ( mv.nopopup ) %]
148
                            [% IF ( mv.nopopup ) %]
149
                                <a href="#" id="buttonDot_[%- mv.id | html -%]" class="[%- mv.class | html -%]" title="No  popup">...</a>
149
                                <a href="#" id="buttonDot_[%- mv.id | html -%]" class="[%- mv.class | html -%]" title="No  popup" data-plugin="[% mv.plugin | html %]">...</a>
150
                            [% ELSE  %]
150
                            [% ELSE  %]
151
                                <a href="#" id="buttonDot_[%- mv.id | html -%]" class="[%- mv.class | html -%]" title="Tag editor">...</a>
151
                                <a href="#" id="buttonDot_[%- mv.id | html -%]" class="[%- mv.class | html -%]" title="Tag editor" data-plugin="[% mv.plugin | html %]">...</a>
152
                            [% END %]
152
                            [% END %]
153
                            [% UNLESS no_plugin %][%# FIXME - from batchMod-edit, jQuery is included at the end of the template and cataloguing plugins are not working in this situation %]
153
                            [% UNLESS no_plugin %][%# FIXME - from batchMod-edit, jQuery is included at the end of the template and cataloguing plugins are not working in this situation %]
154
                                [%- mv.javascript | $raw -%]
154
                                [%- mv.javascript | $raw -%]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt (-1 / +1 lines)
Lines 546-552 Link Here
546
              <div class="alert alert-info">The autoBarcode system preference is set to [% Koha.Preference('autoBarcode') | html %] and items with blank barcodes will have barcodes generated upon save to database</div>
546
              <div class="alert alert-info">The autoBarcode system preference is set to [% Koha.Preference('autoBarcode') | html %] and items with blank barcodes will have barcodes generated upon save to database</div>
547
          [% END %]
547
          [% END %]
548
548
549
          <div id="outeritemblock"></div>
549
          <div id="outeritemblock" class="marc_editor"></div>
550
550
551
      </fieldset>
551
      </fieldset>
552
      [% END %][%# | html UNLESS subscriptionid %]
552
      [% END %][%# | html UNLESS subscriptionid %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt (-1 / +1 lines)
Lines 243-249 Link Here
243
                                                used
243
                                                used
244
                                            </p>
244
                                            </p>
245
                                        [% END %]
245
                                        [% END %]
246
                                        <div id="outeritemblock"></div>
246
                                        <div id="outeritemblock" class="marc_editor"></div>
247
                                    </div>
247
                                    </div>
248
                                </div>
248
                                </div>
249
                                <div id="acq-create-ordering">
249
                                <div id="acq-create-ordering">
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tt (-2 / +2 lines)
Lines 473-479 Link Here
473
                    </div>
473
                    </div>
474
                [% END # /IF duplicateauthid %]
474
                [% END # /IF duplicateauthid %]
475
475
476
                <form method="post" id="f" name="f" action="/cgi-bin/koha/authorities/authorities.pl">
476
                <form method="post" id="f" name="f" action="/cgi-bin/koha/authorities/authorities.pl" class="marc_editor">
477
                    [% INCLUDE 'csrf-token.inc' %]
477
                    [% INCLUDE 'csrf-token.inc' %]
478
                    <input type="hidden" name="op" value="cud-add" />
478
                    <input type="hidden" name="op" value="cud-add" />
479
                    <input type="hidden" name="original_op" value="[% op | html %]" />
479
                    <input type="hidden" name="original_op" value="[% op | html %]" />
Lines 767-773 Link Here
767
                                                                    [% IF mv.noclick %]
767
                                                                    [% IF mv.noclick %]
768
                                                                        <a href="#" class="buttonDot tag_editor disabled" tabindex="-1" title="No popup">...</a>
768
                                                                        <a href="#" class="buttonDot tag_editor disabled" tabindex="-1" title="No popup">...</a>
769
                                                                    [% ELSE %]
769
                                                                    [% ELSE %]
770
                                                                        <a href="#" id="buttonDot_[% mv.id | html %]" class="buttonDot tag_editor" title="Tag editor">...</a>
770
                                                                        <a href="#" id="buttonDot_[% mv.id | html %]" class="buttonDot tag_editor" title="Tag editor" data-plugin="[% mv.plugin | html %]">...</a>
771
                                                                    [% END %]
771
                                                                    [% END %]
772
                                                                    [% mv.javascript | $raw %]
772
                                                                    [% mv.javascript | $raw %]
773
                                                                [% END #/IF ( mv.type == 'text1' ) %]
773
                                                                [% END #/IF ( mv.type == 'text1' ) %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt (-4 / +4 lines)
Lines 843-849 $(document).ready(function(){ Link Here
843
843
844
    <div class="main container-fluid">
844
    <div class="main container-fluid">
845
        <div class="row">
845
        <div class="row">
846
            <div class="col-md-10 offset-md-1">
846
            <div class="col-md-10 offset-md-1 marc_editor">
847
                [% INCLUDE 'messages.inc' %]
847
                [% INCLUDE 'messages.inc' %]
848
                [% IF ( INVALID_METADATA ) %]
848
                [% IF ( INVALID_METADATA ) %]
849
                    <div class="page-section bg-danger">
849
                    <div class="page-section bg-danger">
Lines 1188-1194 $(document).ready(function(){ Link Here
1188
                                                            [% END %]
1188
                                                            [% END %]
1189
1189
1190
                                                        [% ELSIF ( mv.type == 'text_complex' ) %]
1190
                                                        [% ELSIF ( mv.type == 'text_complex' ) %]
1191
                                                            <input type="text" id="[%- mv.id | html -%]" name="[%- mv.name | html -%]" value="[%- mv.value | html -%]" class="input_marceditor framework_plugin" tabindex="1" size="[%- mv.size | html -%]" maxlength="[%- mv.maxlength | html -%]" />
1191
                                                            <input type="text" id="[%- mv.id | html -%]" name="[%- mv.name | html -%]" value="[%- mv.value | html -%]" class="input_marceditor framework_plugin" tabindex="1" size="[%- mv.size | html -%]" maxlength="[%- mv.maxlength | html -%]" data-plugin="[% mv.plugin | html %]" />
1192
                                                            [% mv.javascript | $raw %]
1192
                                                            [% mv.javascript | $raw %]
1193
                                                        [% ELSIF ( mv.type == 'hidden' ) %]
1193
                                                        [% ELSIF ( mv.type == 'hidden' ) %]
1194
                                                            <input tabindex="1" type="hidden" id="[%- mv.id | html -%]" name="[%- mv.name | html -%]" size="[%- mv.size | html -%]" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" />
1194
                                                            <input tabindex="1" type="hidden" id="[%- mv.id | html -%]" name="[%- mv.name | html -%]" size="[%- mv.size | html -%]" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" />
Lines 1240-1248 $(document).ready(function(){ Link Here
1240
                                                                    <span class="buttonDot tag_editor disabled" tabindex="-1" title="Field autofilled by plugin"></span>
1240
                                                                    <span class="buttonDot tag_editor disabled" tabindex="-1" title="Field autofilled by plugin"></span>
1241
                                                                [% ELSE %]
1241
                                                                [% ELSE %]
1242
                                                                    [% IF mv.plugin == "upload.pl" %]
1242
                                                                    [% IF mv.plugin == "upload.pl" %]
1243
                                                                        <a href="#" id="buttonDot_[% mv.id | html %]" class="tag_editor upload framework_plugin" tabindex="1"><i class="fa fa-upload" aria-hidden="true"></i> Upload</a>
1243
                                                                        <a href="#" id="buttonDot_[% mv.id | html %]" class="tag_editor upload framework_plugin" tabindex="1" data-plugin="[% mv.plugin | html %]"><i class="fa fa-upload" aria-hidden="true"></i> Upload</a>
1244
                                                                    [% ELSE %]
1244
                                                                    [% ELSE %]
1245
                                                                        <a href="#" id="buttonDot_[% mv.id | html %]" class="buttonDot tag_editor framework_plugin" tabindex="1" title="Tag editor">Tag editor</a>
1245
                                                                        <a href="#" id="buttonDot_[% mv.id | html %]" class="buttonDot tag_editor framework_plugin" tabindex="1" title="Tag editor" data-plugin="[% mv.plugin | html %]">Tag editor</a>
1246
                                                                    [% END %]
1246
                                                                    [% END %]
1247
                                                                [% END %]
1247
                                                                [% END %]
1248
                                                            </span>
1248
                                                            </span>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt (-1 / +1 lines)
Lines 188-194 Link Here
188
    </div>
188
    </div>
189
    <div class="col-md-10 order-md-2 order-sm-1">
189
    <div class="col-md-10 order-md-2 order-sm-1">
190
190
191
<div id="cataloguing_additem_newitem" class="item_edit_form page-section">
191
<div id="cataloguing_additem_newitem" class="item_edit_form page-section marc_editor">
192
    <form id="f" method="post" action="/cgi-bin/koha/cataloguing/additem.pl?biblionumber=[% biblio.biblionumber | html %]" name="f">
192
    <form id="f" method="post" action="/cgi-bin/koha/cataloguing/additem.pl?biblionumber=[% biblio.biblionumber | html %]" name="f">
193
        [% INCLUDE 'csrf-token.inc' %]
193
        [% INCLUDE 'csrf-token.inc' %]
194
    <input type="hidden" name="op" value="[% op | html %]" />
194
    <input type="hidden" name="op" value="[% op | html %]" />
(-)a/koha-tmpl/intranet-tmpl/prog/js/additem.js (-14 lines)
Lines 227-250 function cloneItemBlock(index, unique_item_fields, callback) { Link Here
227
                var cloneIndex = "itemblock"+random;
227
                var cloneIndex = "itemblock"+random;
228
                callback(cloneIndex);
228
                callback(cloneIndex);
229
            }
229
            }
230
            BindPluginEvents(data);
231
        }
230
        }
232
    });
231
    });
233
}
232
}
234
233
235
function BindPluginEvents(data) {
236
// the script tag in data for plugins contains a document ready that binds
237
// the events for the plugin
238
// when we append, this code does not get executed anymore; so we do it here
239
    var events= data.match(/BindEventstag_\d+_subfield_._\d+/g);
240
    if ( events == null ) return;
241
    for(var i=0; i<events.length; i++) {
242
        window[events[i]]();
243
        if( i<events.length-1 && events[i]==events[i+1] ) { i++; }
244
        // normally we find the function name twice
245
    }
246
}
247
248
function clearItemBlock(node) {
234
function clearItemBlock(node) {
249
    var index = $(node).closest("div").attr('id');
235
    var index = $(node).closest("div").attr('id');
250
    var block = $("#"+index);
236
    var block = $("#"+index);
(-)a/koha-tmpl/intranet-tmpl/prog/js/cataloging.js (-56 / +46 lines)
Lines 1-5 Link Here
1
/* global __ */
1
/* global __ */
2
/* exported openAuth ExpandField CloneField CloneSubfield UnCloneField CloneItemSubfield CheckMandatorySubfields */
2
/* exported openAuth ExpandField CloneField CloneSubfield UnCloneField CloneItemSubfield CheckMandatorySubfields registerFrameworkPluginHandler */
3
3
4
/*
4
/*
5
 * Unified file for catalogue edition
5
 * Unified file for catalogue edition
Lines 185-192 function CloneField(index, hideMarc, advancedMARCEditor) { Link Here
185
185
186
            var inputs   = divs[i].getElementsByTagName('input');
186
            var inputs   = divs[i].getElementsByTagName('input');
187
            var id_input = "";
187
            var id_input = "";
188
            var olddiv;
189
            var oldcontrol;
190
188
191
            for( j = 0 ; j < inputs.length ; j++ ) {
189
            for( j = 0 ; j < inputs.length ; j++ ) {
192
                if(inputs[j].getAttribute("id") && inputs[j].getAttribute("id").match(/^tag_/) ){
190
                if(inputs[j].getAttribute("id") && inputs[j].getAttribute("id").match(/^tag_/) ){
Lines 228-238 function CloneField(index, hideMarc, advancedMARCEditor) { Link Here
228
                        }
226
                        }
229
                    }
227
                    }
230
                }
228
                }
231
                if( $(inputs[1]).hasClass('framework_plugin') ) {
232
                    olddiv= original.getElementsByTagName('li')[i];
233
                    oldcontrol= olddiv.getElementsByTagName('input')[1];
234
                    AddEventHandlers( oldcontrol,inputs[1],id_input );
235
                }
236
            }
229
            }
237
            // when cloning a subfield, re set its label too.
230
            // when cloning a subfield, re set its label too.
238
            try {
231
            try {
Lines 270-291 function CloneField(index, hideMarc, advancedMARCEditor) { Link Here
270
                if(!CloneButtonPlus){ // it s impossible to have  + ... (buttonDot AND buttonPlus)
263
                if(!CloneButtonPlus){ // it s impossible to have  + ... (buttonDot AND buttonPlus)
271
                    buttonDot = spans[0];
264
                    buttonDot = spans[0];
272
                    if(buttonDot){
265
                    if(buttonDot){
273
                        // 2 possibilities :
266
                        try {
274
                        try{
267
                            // do not copy the script section.
275
                            if( $(buttonDot).hasClass('framework_plugin') ) {
268
                            var script = spans[0].getElementsByTagName('script')[0];
276
                                olddiv= original.getElementsByTagName('li')[i];
269
                            spans[0].removeChild(script);
277
                                oldcontrol= olddiv.getElementsByTagName('a')[0];
270
                        } catch(e) {
278
                                AddEventHandlers(oldcontrol,buttonDot,id_input);
271
                            // do nothing if there is no script
279
                            }
280
                            try {
281
                                // do not copy the script section.
282
                                var script = spans[0].getElementsByTagName('script')[0];
283
                                spans[0].removeChild(script);
284
                            } catch(e) {
285
                                // do nothing if there is no script
286
                            }
287
                        } catch(e){
288
                            //
289
                        }
272
                        }
290
                    }
273
                    }
291
                }
274
                }
Lines 353-359 function CloneSubfield(index, advancedMARCEditor){ Link Here
353
    var selects    = clone.getElementsByTagName('select');
336
    var selects    = clone.getElementsByTagName('select');
354
    var textareas  = clone.getElementsByTagName('textarea');
337
    var textareas  = clone.getElementsByTagName('textarea');
355
    var linkid;
338
    var linkid;
356
    var oldcontrol;
357
339
358
    // input
340
    // input
359
    var id_input = "";
341
    var id_input = "";
Lines 367-378 function CloneSubfield(index, advancedMARCEditor){ Link Here
367
        linkid = id_input;
349
        linkid = id_input;
368
    }
350
    }
369
351
370
    // Plugin input
371
    if( $(inputs[1]).hasClass('framework_plugin') ) {
372
        oldcontrol= original.getElementsByTagName('input')[1];
373
        AddEventHandlers( oldcontrol, inputs[1], linkid );
374
    }
375
376
    // select
352
    // select
377
    for(i=0,len=selects.length; i<len ; i++ ){
353
    for(i=0,len=selects.length; i<len ; i++ ){
378
        id_input = selects[i].getAttribute('id')+new_key;
354
        id_input = selects[i].getAttribute('id')+new_key;
Lines 393-405 function CloneSubfield(index, advancedMARCEditor){ Link Here
393
        linkid = id_input;
369
        linkid = id_input;
394
    }
370
    }
395
371
396
    // Handle click event on buttonDot for plugin
397
    var links  = clone.getElementsByTagName('a');
398
    if( $(links[0]).hasClass('framework_plugin') ) {
399
        oldcontrol= original.getElementsByTagName('a')[0];
400
        AddEventHandlers( oldcontrol, links[0], linkid );
401
    }
402
403
    if(advancedMARCEditor == '0') {
372
    if(advancedMARCEditor == '0') {
404
        // when cloning a subfield, reset its label too.
373
        // when cloning a subfield, reset its label too.
405
        var label = clone.getElementsByTagName('label')[0];
374
        var label = clone.getElementsByTagName('label')[0];
Lines 438-460 function CloneSubfield(index, advancedMARCEditor){ Link Here
438
    clone.querySelectorAll('input.input_marceditor').value = "";
407
    clone.querySelectorAll('input.input_marceditor').value = "";
439
}
408
}
440
409
441
function AddEventHandlers (oldcontrol, newcontrol, newinputid ) {
442
// This function is a helper for CloneField and CloneSubfield.
443
// It adds the event handlers from oldcontrol to newcontrol.
444
// newinputid is the id attribute of the cloned controlling input field
445
// Note: This code depends on the jQuery data for events; this structure
446
// is moved to _data as of jQuery 1.8.
447
    var ev = $._data(oldcontrol, "events");
448
    if(typeof ev != 'undefined') {
449
        $.each(ev, function(prop,val) {
450
            $.each(val, function(prop2,val2) {
451
                $(newcontrol).off( val2.type );
452
                $(newcontrol).on( val2.type, {id: newinputid}, val2.handler );
453
            });
454
        });
455
    }
456
}
457
458
/**
410
/**
459
 * This function removes or clears unwanted subfields
411
 * This function removes or clears unwanted subfields
460
 */
412
 */
Lines 654-656 $(document).ready(function() { Link Here
654
    });
606
    });
655
607
656
});
608
});
657
- 
609
610
Koha.frameworkPlugins ||= {};
611
function registerFrameworkPluginHandler(name, eventType, handler) {
612
    // 'focus' and 'blur' events do not bubble,
613
    // so we have to use 'focusin' and 'focusout' instead
614
    if (eventType === 'focus') eventType = 'focusin';
615
    else if (eventType === 'blur') eventType = 'focusout';
616
617
    Koha.frameworkPlugins[name] ||= {};
618
    Koha.frameworkPlugins[name][eventType] ||= handler;
619
}
620
$(document).ready(function() {
621
    function callClickPluginEventHandler (event) {
622
        event.preventDefault();
623
        callPluginEventHandler.call(this, event);
624
    }
625
626
    function callPluginEventHandler (event) {
627
        event.stopPropagation();
628
629
        const plugin = event.target.getAttribute('data-plugin');
630
        if (plugin && plugin in Koha.frameworkPlugins && event.type in Koha.frameworkPlugins[plugin]) {
631
            event.data = {};
632
            if (event.target.classList.contains('buttonDot')) {
633
                event.data.id = event.target.closest('.subfield_line').querySelector('input.input_marceditor').id;
634
            } else {
635
                event.data.id = event.target.id;
636
            }
637
638
            Koha.frameworkPlugins[plugin][event.type].call(this, event);
639
        }
640
    }
641
642
    // We use delegated event handlers here so that dynamically added elements
643
    // (like when cloning a field or a subfield) respond to these events
644
    // without having to re-attach events manually
645
    $('.marc_editor').on('click', '.buttonDot', callClickPluginEventHandler);
646
    $('.marc_editor').on('focusin focusout change mousedown mouseup keydown keyup', 'input.input_marceditor.framework_plugin', callPluginEventHandler);
647
});

Return to bug 30975