resources: Strip '$' and 'mw' from file closures
[lhc/web/wiklou.git] / resources / src / mediawiki.htmlform / cloner.js
1 /*
2 * HTMLForm enhancements:
3 * Add/remove cloner clones without having to resubmit the form.
4 */
5 ( function () {
6
7 var cloneCounter = 0;
8
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 } );
14
15 $root.find( '.mw-htmlform-cloner-create-button' ).filter( ':input' ).click( function ( ev ) {
16 var $ul, $li, html;
17
18 ev.preventDefault();
19
20 $ul = $( this ).prev( 'ul.mw-htmlform-cloner-ul' );
21
22 html = $ul.data( 'template' ).replace(
23 new RegExp( mw.RegExp.escape( $ul.data( 'uniqueId' ) ), 'g' ),
24 'clone' + ( ++cloneCounter )
25 );
26
27 $li = $( '<li>' )
28 .addClass( 'mw-htmlform-cloner-li' )
29 .html( html )
30 .appendTo( $ul );
31
32 mw.hook( 'htmlform.enhance' ).fire( $li );
33 } );
34 } );
35
36 }() );