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

(-)a/C4/Items.pm (-1 / +1 lines)
Lines 1520-1526 sub PrepareItemrecordDisplay { Link Here
1520
                        my $tab= $plugin->noclick? '-1': '';
1520
                        my $tab= $plugin->noclick? '-1': '';
1521
                        my $class= $plugin->noclick? ' disabled': '';
1521
                        my $class= $plugin->noclick? ' disabled': '';
1522
                        my $title= $plugin->noclick? 'No popup': 'Tag editor';
1522
                        my $title= $plugin->noclick? 'No popup': 'Tag editor';
1523
                        $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;
1523
                        $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;
1524
                    } else {
1524
                    } else {
1525
                        warn $plugin->errstr;
1525
                        warn $plugin->errstr;
1526
                        $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
1526
                        $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 297-390 sub _process_javascript { Link Here
297
    $script =~ s/\<script[^>]*\>\s*(\/\/\<!\[CDATA\[)?\s*//s;
297
    $script =~ s/\<script[^>]*\>\s*(\/\/\<!\[CDATA\[)?\s*//s;
298
    $script =~ s/(\/\/\]\]\>\s*)?\<\/script\>//s;
298
    $script =~ s/(\/\/\]\]\>\s*)?\<\/script\>//s;
299
299
300
    my $id = $params->{id}//'';
301
    my $bind = '';
302
    my $clickfound = 0;
300
    my $clickfound = 0;
303
    my @events = qw|click focus blur change mouseover mouseout mousedown
301
    my @events = qw|click focus blur change mousedown mouseup keydown keyup|;
304
        mouseup mousemove keydown keypress keyup|;
305
    foreach my $ev ( @events ) {
302
    foreach my $ev ( @events ) {
306
        my $scan = $ev eq 'click' && $self->{oldschool}? 'clic': $ev;
303
        my $scan = $ev eq 'click' && $self->{oldschool}? 'clic': $ev;
307
        if( $script =~ /function\s+($scan\w+)\s*\(([^\)]*)\)/is ) {
304
        if( $script =~ /function\s+($scan\w+)\s*\(/is ) {
308
            my ( $bl, $sl ) = $self->_add_binding( $1, $2, $ev, $id );
305
            my $function_name = $1;
309
            $script .= $sl;
306
            $script .= sprintf('registerFrameworkPluginHandler("%s", "%s", %s);', $self->name, $ev, $function_name);
310
            $bind .= $bl;
311
            $clickfound = 1 if $ev eq 'click';
307
            $clickfound = 1 if $ev eq 'click';
312
        }
308
        }
313
    }
309
    }
314
    if( !$clickfound ) { # make buttonDot do nothing
315
        my ( $bl ) = $self->_add_binding( 'noclick', '', 'click', $id );
316
        $bind .= $bl;
317
    }
318
    $self->{noclick} = !$clickfound;
310
    $self->{noclick} = !$clickfound;
319
    $self->{javascript}= _merge_script( $id, $script, $bind );
311
    $self->{javascript} = <<JS;
320
}
321
322
sub _add_binding {
323
# adds some jQuery code for event binding:
324
# $bind contains lines for the actual event binding: .click, .focus, etc.
325
# $script contains function definitions (if needed)
326
    my ( $self, $fname, $pars, $ev, $id ) = @_;
327
    my ( $bind, $script );
328
    my $ctl= $ev eq 'click'? 'buttonDot_'.$id: $id;
329
        #click event applies to buttonDot
330
331
    if( $pars =~ /^(e|ev|event)$/i ) { # new style event handler assumed
332
        $bind= qq|    \$("#$ctl").$ev(\{id: '$id'\}, $fname);\n|;
333
        $script='';
334
    } elsif( $fname eq 'noclick' ) { # no click: return false, no scroll
335
        $bind= qq|    \$("#$ctl").$ev(function () { return false; });\n|;
336
        $script='';
337
    } else { # add real event handler calling the function found
338
        $bind=qq|    \$("#$ctl").$ev(\{id: '$id'\}, ${fname}_handler);\n|;
339
        $script = $self->_add_handler( $ev, $fname );
340
    }
341
    return ( $bind, $script );
342
}
343
344
sub _add_handler {
345
# adds a handler with event parameter
346
# event.data.id is passed to the plugin function in parameters
347
# for the click event we always return false to prevent scrolling
348
    my ( $self, $ev, $fname ) = @_;
349
    my $first= $self->_first_item_par( $ev );
350
    my $prefix= $ev eq 'click'? '': 'return ';
351
    my $suffix= $ev eq 'click'? "\n    return false;": '';
352
    return <<HERE;
353
function ${fname}_handler(event) {
354
    $prefix$fname(${first}event.data.id);$suffix
355
}
356
HERE
357
}
358
359
sub _first_item_par {
360
    my ( $self, $event ) = @_;
361
    # needed for backward compatibility
362
    # js event functions in old style item plugins have an extra parameter
363
    # BUT.. not for all events (exceptions provide employment :)
364
    if( $self->{item_style} && $self->{oldschool} &&
365
            $event=~/focus|blur|change/ ) {
366
        return qq/'0',/;
367
    }
368
    return '';
369
}
370
371
sub _merge_script {
372
# Combine script and event bindings, enclosed in script tags.
373
# The BindEvents function is added to easily repeat event binding;
374
# this is used in additem.js for dynamically created item blocks.
375
    my ( $id, $script, $bind ) = @_;
376
    chomp ($script, $bind);
377
    return <<HERE;
378
<script>
312
<script>
313
\$(document).ready(function () {
379
$script
314
$script
380
function BindEvents$id() {
381
$bind
382
}
383
\$(document).ready(function() {
384
    BindEvents$id();
385
});
315
});
386
</script>
316
</script>
387
HERE
317
JS
388
}
318
}
389
319
390
=head1 AUTHOR
320
=head1 AUTHOR
(-)a/Koha/UI/Form/Builder/Item.pm (+1 lines)
Lines 330-335 sub generate_subfield_form { Link Here
330
                class      => $class,
330
                class      => $class,
331
                nopopup    => $plugin->noclick,
331
                nopopup    => $plugin->noclick,
332
                javascript => $plugin->javascript,
332
                javascript => $plugin->javascript,
333
                plugin     => $plugin->name,
333
            };
334
            };
334
        }
335
        }
335
        else {
336
        else {
(-)a/authorities/authorities.pl (+1 lines)
Lines 199-204 sub create_input { Link Here
199
                maxlength => $max_length,
199
                maxlength => $max_length,
200
                javascript => $plugin->javascript,
200
                javascript => $plugin->javascript,
201
                noclick    => $plugin->noclick,
201
                noclick    => $plugin->noclick,
202
                plugin     => $plugin->name,
202
            };
203
            };
203
        } else { # warn and supply default field
204
        } else { # warn and supply default field
204
            warn $plugin->errstr;
205
            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 135-145 Link Here
135
                        [% IF mv.readonly %]
135
                        [% IF mv.readonly %]
136
                            <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" />
136
                            <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" />
137
                        [% ELSE %]
137
                        [% ELSE %]
138
                            <input type="text" id="[%- mv.id | html -%]" name="[% kohafield | html %]" class="input_marceditor [% kohafield | html %]" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" />
138
                            <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 %]" />
139
                            [% IF ( mv.nopopup ) %]
139
                            [% IF ( mv.nopopup ) %]
140
                                <a href="#" id="buttonDot_[%- mv.id | html -%]" class="[%- mv.class | html -%]" title="No  popup">...</a>
140
                                <a href="#" id="buttonDot_[%- mv.id | html -%]" class="[%- mv.class | html -%]" title="No  popup" data-plugin="[% mv.plugin | html %]">...</a>
141
                            [% ELSE  %]
141
                            [% ELSE  %]
142
                                <a href="#" id="buttonDot_[%- mv.id | html -%]" class="[%- mv.class | html -%]" title="Tag editor">...</a>
142
                                <a href="#" id="buttonDot_[%- mv.id | html -%]" class="[%- mv.class | html -%]" title="Tag editor" data-plugin="[% mv.plugin | html %]">...</a>
143
                            [% END %]
143
                            [% END %]
144
                            [% 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 %]
144
                            [% 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 %]
145
                                [%- mv.javascript | $raw -%]
145
                                [%- mv.javascript | $raw -%]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt (-1 / +1 lines)
Lines 349-355 Link Here
349
              <div class="dialog message">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>
349
              <div class="dialog message">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>
350
          [% END %]
350
          [% END %]
351
351
352
          <div id="outeritemblock"></div>
352
          <div id="outeritemblock" class="marc_editor"></div>
353
353
354
      </fieldset>
354
      </fieldset>
355
      [% END %][%# | html UNLESS subscriptionid %]
355
      [% END %][%# | html UNLESS subscriptionid %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt (-1 / +1 lines)
Lines 221-227 Link Here
221
                      used
221
                      used
222
                  </p>
222
                  </p>
223
              [% END %]
223
              [% END %]
224
              <div id="outeritemblock"></div>
224
              <div id="outeritemblock" class="marc_editor"></div>
225
          </fieldset>
225
          </fieldset>
226
        [% END %]
226
        [% END %]
227
    [% ELSIF (AcqCreateItem == 'ordering') %]
227
    [% ELSIF (AcqCreateItem == 'ordering') %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tt (-2 / +2 lines)
Lines 366-372 Link Here
366
                                This authority is not used in any records.
366
                                This authority is not used in any records.
367
                        [% END %]
367
                        [% END %]
368
                    </div>
368
                    </div>
369
                    <div id="authoritytabs" class="toptabs numbered">
369
                    <div id="authoritytabs" class="toptabs numbered marc_editor">
370
                        <div class="tab-content">
370
                        <div class="tab-content">
371
                            [% FOREACH BIG_LOO IN BIG_LOOP %]
371
                            [% FOREACH BIG_LOO IN BIG_LOOP %]
372
                                [% IF loop.first %]
372
                                [% IF loop.first %]
Lines 558-564 Link Here
558
                                                                    [% IF mv.noclick %]
558
                                                                    [% IF mv.noclick %]
559
                                                                        <a href="#" class="buttonDot tag_editor disabled" tabindex="-1" title="No popup">...</a>
559
                                                                        <a href="#" class="buttonDot tag_editor disabled" tabindex="-1" title="No popup">...</a>
560
                                                                    [% ELSE %]
560
                                                                    [% ELSE %]
561
                                                                        <a href="#" id="buttonDot_[% mv.id | html %]" class="buttonDot tag_editor" title="Tag editor">...</a>
561
                                                                        <a href="#" id="buttonDot_[% mv.id | html %]" class="buttonDot tag_editor" title="Tag editor" data-plugin="[% mv.plugin | html %]">...</a>
562
                                                                    [% END %]
562
                                                                    [% END %]
563
                                                                    [% mv.javascript | $raw %]
563
                                                                    [% mv.javascript | $raw %]
564
                                                                [% END #/IF ( mv.type == 'text1' ) %]
564
                                                                [% END #/IF ( mv.type == 'text1' ) %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt (-4 / +4 lines)
Lines 1004-1010 function PopupMARCFieldDoc(field) { Link Here
1004
                <input type="hidden" name="breedingid" value="[% breedingid | html %]" />
1004
                <input type="hidden" name="breedingid" value="[% breedingid | html %]" />
1005
                <input type="hidden" name="changed_framework" value="" />
1005
                <input type="hidden" name="changed_framework" value="" />
1006
1006
1007
                <div id="addbibliotabs" class="toptabs numbered">
1007
                <div id="addbibliotabs" class="toptabs numbered marc_editor">
1008
                    <div class="tab-content">
1008
                    <div class="tab-content">
1009
1009
1010
                        [% FOREACH BIG_LOO IN BIG_LOOP %]
1010
                        [% FOREACH BIG_LOO IN BIG_LOOP %]
Lines 1137-1143 function PopupMARCFieldDoc(field) { Link Here
1137
                                                            [% END %]
1137
                                                            [% END %]
1138
1138
1139
                                                        [% ELSIF ( mv.type == 'text_complex' ) %]
1139
                                                        [% ELSIF ( mv.type == 'text_complex' ) %]
1140
                                                            <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 -%]" />
1140
                                                            <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 %]" />
1141
                                                            [% mv.javascript | $raw %]
1141
                                                            [% mv.javascript | $raw %]
1142
                                                        [% ELSIF ( mv.type == 'hidden' ) %]
1142
                                                        [% ELSIF ( mv.type == 'hidden' ) %]
1143
                                                            <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 -%]" />
1143
                                                            <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 1178-1186 function PopupMARCFieldDoc(field) { Link Here
1178
                                                                    <span class="buttonDot tag_editor disabled" tabindex="-1" title="Field autofilled by plugin"></span>
1178
                                                                    <span class="buttonDot tag_editor disabled" tabindex="-1" title="Field autofilled by plugin"></span>
1179
                                                                [% ELSE %]
1179
                                                                [% ELSE %]
1180
                                                                    [% IF mv.plugin == "upload.pl" %]
1180
                                                                    [% IF mv.plugin == "upload.pl" %]
1181
                                                                        <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>
1181
                                                                        <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>
1182
                                                                    [% ELSE %]
1182
                                                                    [% ELSE %]
1183
                                                                        <a href="#" id="buttonDot_[% mv.id | html %]" class="buttonDot tag_editor framework_plugin" tabindex="1" title="Tag editor">Tag editor</a>
1183
                                                                        <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>
1184
                                                                    [% END %]
1184
                                                                    [% END %]
1185
                                                                [% END %]
1185
                                                                [% END %]
1186
                                                            </span>
1186
                                                            </span>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt (-1 / +1 lines)
Lines 155-161 Link Here
155
    </div>
155
    </div>
156
    <div class="col-sm-10">
156
    <div class="col-sm-10">
157
157
158
<div id="cataloguing_additem_newitem" class="item_edit_form page-section">
158
<div id="cataloguing_additem_newitem" class="item_edit_form page-section marc_editor">
159
    <form id="f" method="post" action="/cgi-bin/koha/cataloguing/additem.pl?biblionumber=[% biblio.biblionumber | html %]" name="f">
159
    <form id="f" method="post" action="/cgi-bin/koha/cataloguing/additem.pl?biblionumber=[% biblio.biblionumber | html %]" name="f">
160
    <input type="hidden" name="op" value="[% op | html %]" />
160
    <input type="hidden" name="op" value="[% op | html %]" />
161
    [% IF (popup) %]
161
    [% IF (popup) %]
(-)a/koha-tmpl/intranet-tmpl/prog/js/additem.js (-14 lines)
Lines 213-236 function cloneItemBlock(index, unique_item_fields, callback) { Link Here
213
                var cloneIndex = "itemblock"+random;
213
                var cloneIndex = "itemblock"+random;
214
                callback(cloneIndex);
214
                callback(cloneIndex);
215
            }
215
            }
216
            BindPluginEvents(data);
217
        }
216
        }
218
    });
217
    });
219
}
218
}
220
219
221
function BindPluginEvents(data) {
222
// the script tag in data for plugins contains a document ready that binds
223
// the events for the plugin
224
// when we append, this code does not get executed anymore; so we do it here
225
    var events= data.match(/BindEventstag_\d+_subfield_._\d+/g);
226
    if ( events == null ) return;
227
    for(var i=0; i<events.length; i++) {
228
        window[events[i]]();
229
        if( i<events.length-1 && events[i]==events[i+1] ) { i++; }
230
        // normally we find the function name twice
231
    }
232
}
233
234
function clearItemBlock(node) {
220
function clearItemBlock(node) {
235
    var index = $(node).closest("div").attr('id');
221
    var index = $(node).closest("div").attr('id');
236
    var block = $("#"+index);
222
    var block = $("#"+index);
(-)a/koha-tmpl/intranet-tmpl/prog/js/cataloging.js (-56 / +42 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 182-189 function CloneField(index, hideMarc, advancedMARCEditor) { Link Here
182
182
183
            var inputs   = divs[i].getElementsByTagName('input');
183
            var inputs   = divs[i].getElementsByTagName('input');
184
            var id_input = "";
184
            var id_input = "";
185
            var olddiv;
186
            var oldcontrol;
187
185
188
            for( j = 0 ; j < inputs.length ; j++ ) {
186
            for( j = 0 ; j < inputs.length ; j++ ) {
189
                if(inputs[j].getAttribute("id") && inputs[j].getAttribute("id").match(/^tag_/) ){
187
                if(inputs[j].getAttribute("id") && inputs[j].getAttribute("id").match(/^tag_/) ){
Lines 224-234 function CloneField(index, hideMarc, advancedMARCEditor) { Link Here
224
                        }
222
                        }
225
                    }
223
                    }
226
                }
224
                }
227
                if( $(inputs[1]).hasClass('framework_plugin') ) {
228
                    olddiv= original.getElementsByTagName('li')[i];
229
                    oldcontrol= olddiv.getElementsByTagName('input')[1];
230
                    AddEventHandlers( oldcontrol,inputs[1],id_input );
231
                }
232
            }
225
            }
233
            // when cloning a subfield, re set its label too.
226
            // when cloning a subfield, re set its label too.
234
            try {
227
            try {
Lines 266-287 function CloneField(index, hideMarc, advancedMARCEditor) { Link Here
266
                if(!CloneButtonPlus){ // it s impossible to have  + ... (buttonDot AND buttonPlus)
259
                if(!CloneButtonPlus){ // it s impossible to have  + ... (buttonDot AND buttonPlus)
267
                    buttonDot = spans[0];
260
                    buttonDot = spans[0];
268
                    if(buttonDot){
261
                    if(buttonDot){
269
                        // 2 possibilities :
262
                        try {
270
                        try{
263
                            // do not copy the script section.
271
                            if( $(buttonDot).hasClass('framework_plugin') ) {
264
                            var script = spans[0].getElementsByTagName('script')[0];
272
                                olddiv= original.getElementsByTagName('li')[i];
265
                            spans[0].removeChild(script);
273
                                oldcontrol= olddiv.getElementsByTagName('a')[0];
266
                        } catch(e) {
274
                                AddEventHandlers(oldcontrol,buttonDot,id_input);
267
                            // do nothing if there is no script
275
                            }
276
                            try {
277
                                // do not copy the script section.
278
                                var script = spans[0].getElementsByTagName('script')[0];
279
                                spans[0].removeChild(script);
280
                            } catch(e) {
281
                                // do nothing if there is no script
282
                            }
283
                        } catch(e){
284
                            //
285
                        }
268
                        }
286
                    }
269
                    }
287
                }
270
                }
Lines 343-349 function CloneSubfield(index, advancedMARCEditor){ Link Here
343
    var selects    = clone.getElementsByTagName('select');
326
    var selects    = clone.getElementsByTagName('select');
344
    var textareas  = clone.getElementsByTagName('textarea');
327
    var textareas  = clone.getElementsByTagName('textarea');
345
    var linkid;
328
    var linkid;
346
    var oldcontrol;
347
329
348
    // input
330
    // input
349
    var id_input = "";
331
    var id_input = "";
Lines 357-368 function CloneSubfield(index, advancedMARCEditor){ Link Here
357
        linkid = id_input;
339
        linkid = id_input;
358
    }
340
    }
359
341
360
    // Plugin input
361
    if( $(inputs[1]).hasClass('framework_plugin') ) {
362
        oldcontrol= original.getElementsByTagName('input')[1];
363
        AddEventHandlers( oldcontrol, inputs[1], linkid );
364
    }
365
366
    // select
342
    // select
367
    for(i=0,len=selects.length; i<len ; i++ ){
343
    for(i=0,len=selects.length; i<len ; i++ ){
368
        id_input = selects[i].getAttribute('id')+new_key;
344
        id_input = selects[i].getAttribute('id')+new_key;
Lines 382-394 function CloneSubfield(index, advancedMARCEditor){ Link Here
382
        linkid = id_input;
358
        linkid = id_input;
383
    }
359
    }
384
360
385
    // Handle click event on buttonDot for plugin
386
    var links  = clone.getElementsByTagName('a');
387
    if( $(links[0]).hasClass('framework_plugin') ) {
388
        oldcontrol= original.getElementsByTagName('a')[0];
389
        AddEventHandlers( oldcontrol, links[0], linkid );
390
    }
391
392
    if(advancedMARCEditor == '0') {
361
    if(advancedMARCEditor == '0') {
393
        // when cloning a subfield, reset its label too.
362
        // when cloning a subfield, reset its label too.
394
        var label = clone.getElementsByTagName('label')[0];
363
        var label = clone.getElementsByTagName('label')[0];
Lines 427-449 function CloneSubfield(index, advancedMARCEditor){ Link Here
427
    clone.querySelectorAll('input.input_marceditor').value = "";
396
    clone.querySelectorAll('input.input_marceditor').value = "";
428
}
397
}
429
398
430
function AddEventHandlers (oldcontrol, newcontrol, newinputid ) {
431
// This function is a helper for CloneField and CloneSubfield.
432
// It adds the event handlers from oldcontrol to newcontrol.
433
// newinputid is the id attribute of the cloned controlling input field
434
// Note: This code depends on the jQuery data for events; this structure
435
// is moved to _data as of jQuery 1.8.
436
    var ev= $(oldcontrol).data('events');
437
    if(typeof ev != 'undefined') {
438
        $.each(ev, function(prop,val) {
439
            $.each(val, function(prop2,val2) {
440
                $(newcontrol).off( val2.type );
441
                $(newcontrol).on( val2.type, {id: newinputid}, val2.handler );
442
            });
443
        });
444
    }
445
}
446
447
/**
399
/**
448
 * This function removes or clears unwanted subfields
400
 * This function removes or clears unwanted subfields
449
 */
401
 */
Lines 639-641 $(document).ready(function() { Link Here
639
    });
591
    });
640
592
641
});
593
});
642
- 
594
595
Koha.frameworkPlugins ||= {};
596
function registerFrameworkPluginHandler(name, eventType, handler) {
597
    // 'focus' and 'blur' events do not bubble,
598
    // so we have to use 'focusin' and 'focusout' instead
599
    if (eventType === 'focus') eventType = 'focusin';
600
    else if (eventType === 'blur') eventType = 'focusout';
601
602
    Koha.frameworkPlugins[name] ||= {};
603
    Koha.frameworkPlugins[name][eventType] ||= handler;
604
}
605
$(document).ready(function() {
606
    function callPluginEventHandler (event) {
607
        event.preventDefault();
608
        event.stopPropagation();
609
610
        const plugin = event.target.getAttribute('data-plugin');
611
        if (plugin && plugin in Koha.frameworkPlugins && event.type in Koha.frameworkPlugins[plugin]) {
612
            event.data = {};
613
            if (event.target.classList.contains('buttonDot')) {
614
                event.data.id = event.target.closest('.subfield_line').querySelector('input.input_marceditor').id;
615
            } else {
616
                event.data.id = event.target.id;
617
            }
618
619
            Koha.frameworkPlugins[plugin][event.type].call(this, event);
620
        }
621
    }
622
623
    // We use delegated event handlers here so that dynamically added elements
624
    // (like when cloning a field or a subfield) respond to these events
625
    // without having to re-attach events manually
626
    $('.marc_editor').on('click', '.buttonDot', callPluginEventHandler)
627
    $('.marc_editor').on('focusin focusout change mousedown mouseup keydown keyup', 'input.input_marceditor.framework_plugin', callPluginEventHandler);
628
});

Return to bug 30975