Utente:Jalo/monobook.js/test: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Nessun oggetto della modifica
Nessun oggetto della modifica
Riga 4 220:
id: 'wikieditor-toolbar-aiutare',
html: '\
<div id="wikieditor-toolbar-replace-message">\
<div id="wikieditor-toolbar-replace-nomatch" rel="wikieditor-toolbar-tool-replace-nomatch"></div>\
<div id="wikieditor-toolbar-replace-success"></div>\
<div id="wikieditor-toolbar-replace-emptysearch" rel="wikieditor-toolbar-tool-replace-emptysearch"></div>\
<div id="wikieditor-toolbar-replace-invalidregex"></div>\
</div>\
<fieldset>\
<div class="wikieditor-toolbar-field-wrapper">\
<label for="wikieditor-toolbar-replace-searchArgomento" rel="wikieditor-toolbar-tool-replace-searchArgomento"></label>\
<input type="text" id="wikieditor-toolbar-replace-searchargomento" style="width: 100%;" />\
</div>\
<div class="wikieditor-toolbar-field-wrapper">\
<label for="wikieditor-toolbar-replace-replaceMotivo" rel="wikieditor-toolbar-tool-replace-replaceMotivo"></label>\
<input type="text" id="wikieditor-toolbar-replace-replacemotivo" style="width: 100%;" />\
</div>\
<div class="wikieditor-toolbar-field-wrapper">\
<input type="checkbox" id="wikieditor-toolbar-replace-case" />\
<label for="wikieditor-toolbar-replace-case" rel="wikieditor-toolbar-tool-replace-case"></label>\
</div>\
<div class="wikieditor-toolbar-field-wrapper">\
<input type="checkbox" id="wikieditor-toolbar-replace-regex" />\
<label for="wikieditor-toolbar-replace-regex" rel="wikieditor-toolbar-tool-replace-regex"></label>\
</div>\
</fieldset>',
Riga 4 253 ⟶ 4 239:
// TODO: Find a cleaner way to share this function
$j(this).data( 'replaceCallbackFicus', function( mode ) {
// nascondi la roba inutile $j( '#wikieditor-toolbar-replace-nomatch, #wikieditor-toolbar-replace-success, #wikieditor-toolbar-replace-emptysearch, #wikieditor-toolbar-replace-invalidregex' ).hide();
// mostra roba utile var searchStr = $j( '#wikieditor-toolbar-replace-searchemptysearch' ).valshow();
ifvar ( searchStrargomento == $j( '#wikieditor-toolbar-argomento' ) {.val();
var motivo = $j( '#wikieditor-toolbar-replace-emptysearchmotivo' ).showval();
return;
}
var replaceStr = $j( '#wikieditor-toolbar-replace-replace' ).val();
var flags = 'm';
var matchCase = $j( '#wikieditor-toolbar-replace-case' ).is( ':checked' );
var isRegex = $j( '#wikieditor-toolbar-replace-regex' ).is( ':checked' );
if ( !matchCase ) {
flags += 'i';
}
if ( mode == 'replaceAll' ) {
flags += 'g';
}
if ( !isRegex ) {
searchStr = RegExp.escape( searchStr );
}
try {
var regex = new RegExp( searchStr, flags );
} catch( e ) {
$j( '#wikieditor-toolbar-replace-invalidregex' )
.text( u.getMsg( 'wikieditor-toolbar-tool-replace-invalidregex',
e.message ) )
.show();
return;
}
var $textarea = $j(this).data( 'context' ).$textarea;
var text = $textarea.textSelection( 'getContents' );
var match = false;
text = "{{A|"+motivo+"|"+argomento+"|"+"{{subst:CURRENTMONTHNAME}} {{subst:CURRENTYEAR}}|firma=~~~~}}\n"+text;
var offset, s;
 
if ( mode != 'replaceAll' ) {
offset = $j(this)textarea.dataval( 'offset'text );
s = text.substr( offset );}
match = s.match( regex );
}
if ( !match ) {
// Search hit BOTTOM, continuing at TOP
offset = 0;
s = text;
match = s.match( regex );
}
if ( !match ) {
$j( '#wikieditor-toolbar-replace-nomatch' ).show();
} else if ( mode == 'replaceAll' ) {
// Instead of using repetitive .match() calls, we use one .match() call with /g
// and indexOf() followed by substr() to find the offsets. This is actually
// faster because our indexOf+substr loop is faster than a match loop, and the
// /g match is so ridiculously fast that it's negligible.
var index;
for ( var i = 0; i < match.length; i++ ) {
index = s.indexOf( match[i] );
if ( index == -1 ) {
// This shouldn't happen
break;
}
s = s.substr( index + match[i].length );
var start = index + offset;
var end = start + match[i].length;
var newEnd = start + replaceStr.length;
$textarea
.textSelection( 'setSelection', { 'start': start, 'end': end } )
.textSelection( 'encapsulateSelection', {
'peri': replaceStr,
'replace': true } )
.textSelection( 'setSelection', { 'start': start, 'end': newEnd } );
offset = newEnd;
}
$j( '#wikieditor-toolbar-replace-success' )
.text( u.getMsg( 'wikieditor-toolbar-tool-replace-success', match.length ) )
.show();
$j(this).data( 'offset', 0 );
} else {
var start = match.index + offset;
var end = start + match[0].length;
var newEnd = start + replaceStr.length;
var context = $j( this ).data( 'context' );
$textarea.textSelection( 'setSelection', { 'start': start,
'end': end } );
if ( mode == 'replace' ) {
$textarea
.textSelection( 'encapsulateSelection', {
'peri': replaceStr,
'replace': true } )
.textSelection( 'setSelection', {
'start': start,
'end': newEnd } );
}
$textarea.textSelection( 'scrollToCaretPosition' );
$textarea.textSelection( 'setSelection', { 'start': start,
'end': mode == 'replace' ? newEnd : end } );
$j( this ).data( 'offset', mode == 'replace' ? newEnd : end );
var textbox = typeof context.$iframe != 'undefined' ? context.$iframe[0].contentWindow : $textarea[0];
textbox.focus();
}
});
},
dialog: {
Riga 4 358 ⟶ 4 256:
dialogClass: 'wikiEditor-toolbar-dialog',
buttons: {
'wikieditor-toolbar-toolficus-replace-button-findnextok': function( e ) {
$j(this).closest( '.ui-dialog' ).data( 'dialogaction', e.target );
$j(this).data( 'replaceCallback' ).call( this, 'find' );
},
'wikieditor-toolbar-tool-replace-button-replacenext': function( e ) {
$j(this).closest( '.ui-dialog' ).data( 'dialogaction', e.target );
$j(this).data( 'replaceCallback' ).call( this, 'replace' );
},
'wikieditor-toolbar-tool-replace-button-replaceall': function( e ) {
$j(this).closest( '.ui-dialog' ).data( 'dialogaction', e.target );
$j(this).data( 'replaceCallbackFicus' ).call( this, 'replaceAllA' );
},
'wikieditor-toolbar-tool-replaceficus-close': function() {
$j(this).dialog( 'close' );
}
Riga 4 376 ⟶ 4 266:
open: function() {
$j(this).data( 'offset', 0 );
$j( '#wikieditor-toolbar-replaceficus-searchok' ).focus();
//nascondi roba inutile $j( '#wikieditor-toolbar-replace-nomatch, #wikieditor-toolbar-replace-success, #wikieditor-toolbar-replace-emptysearch, #wikieditor-toolbar-replace-invalidregex' ).hide();
if ( !( $j(this).data( 'onetimeonlystuff' ) ) ) {
$j(this).data( 'onetimeonlystuff', true );