Fix Selenium tests
[mediawiki.git] / resources / src / mediawiki / htmlform / cloner.js
blobab81580beebe9a92dee2628ef3caf9a1c048c7e1
1 /*
2  * HTMLForm enhancements:
3  * Add/remove cloner clones without having to resubmit the form.
4  */
5 ( function ( mw, $ ) {
7         var cloneCounter = 0;
9         mw.hook( 'htmlform.enhance' ).add( function ( $root ) {
10                 $root.find( '.mw-htmlform-cloner-delete-button' ).filter( ':input' ).click( function ( ev ) {
11                         ev.preventDefault();
12                         $( this ).closest( 'li.mw-htmlform-cloner-li' ).remove();
13                 } );
15                 $root.find( '.mw-htmlform-cloner-create-button' ).filter( ':input' ).click( function ( ev ) {
16                         var $ul, $li, html;
18                         ev.preventDefault();
20                         $ul = $( this ).prev( 'ul.mw-htmlform-cloner-ul' );
22                         html = $ul.data( 'template' ).replace(
23                                 new RegExp( mw.RegExp.escape( $ul.data( 'uniqueId' ) ), 'g' ),
24                                 'clone' + ( ++cloneCounter )
25                         );
27                         $li = $( '<li>' )
28                                 .addClass( 'mw-htmlform-cloner-li' )
29                                 .html( html )
30                                 .appendTo( $ul );
32                         mw.hook( 'htmlform.enhance' ).fire( $li );
33                 } );
34         } );
36 }( mediaWiki, jQuery ) );