לדלג לתוכן

מדיה ויקי:Gadget-Dwim.js: הבדלים בין גרסאות בדף

מתוך צפונות ויקי
ניסוי
מ 54 גרסאות של הדף wikipedia:he:מדיה_ויקי:Gadget-Dwim.js יובאו
 
(22 גרסאות ביניים של 5 משתמשים אינן מוצגות)
שורה 1: שורה 1:
if ( mw.user.options.get( 'skin' ) === 'vector' ) {
if ( mw.user.options.get( 'skin' ) === 'vector' ) {


var hes = "qwertyuiopasdfghjkl;zxcvbnm,./'קראטוןםפשדגכעיחלךףזסבהנמצתץ",
// Load the search suggestion logic when focus the search box.
hebeng = function ( str ) {
function dwimEventListener( e ) {
var hes = "qwertyuiopasdfghjkl;zxcvbnm,./'קראטוןםפשדגכעיחלךףזסבהנמצתץ";
if (
e.target.id === 'searchInput' ||
return (str || '').replace(/./g, function( c ) {
/(^|\s)mw-searchInput($|\s)/.test( e.target.className )
var ic = hes.indexOf( c.toLowerCase() );
) {
return ic + 1 ? hes.charAt( ( ic + 29 ) % 58 ) : c;
enableDwim();
} );
document.removeEventListener( 'focusin', dwimEventListener );
};
}
}
if ( mw.user.options.get( 'cirrussearch-completionsuggester' ) ) {
document.addEventListener( 'focusin', dwimEventListener );
 
// Load the search suggestion logic when the search box is already focused
// because the user started typing before the JavaScript is loaded.
if (
document.activeElement && (
document.activeElement.id === 'searchInput' ||
/(^|\s)mw-searchInput($|\s)/.test( document.activeElement.className )
)
) {
enableDwim();
}
 
function enableDwimModernVector() {
// @todo
}
 
function enableDwim() {
'use strict';
if(mw.loader.getState('mediawiki.searchSuggest') === 'registered') {
// Vector is using the new version of search. Exit early to avoid running incompatible code.
enableDwimModernVector();
return;
}
 
setTimeout( function() {
var hes = "qwertyuiopasdfghjkl;zxcvbnm,./'קראטוןםפשדגכעיחלךףזסבהנמצתץ",
hebeng = function ( str ) {
return ( str || '' ).replace( /./g, function( c ) {
var ic = hes.indexOf( c.toLowerCase() );


$( function() {
return ic + 1 ? hes.charAt( ( ic + 29 ) % 58 ) : c;
// Override default opensearch
} );
mw.searchSuggest.type = 'cirrus-suggest';
};
mw.searchSuggest.request = function ( api, query, response, maxRows ) {
return api.get( {
var $searchBoxes = $(
action: 'cirrus-suggest',
'#searchInput, #searchInput2, #powerSearchText, #searchText'
text: query,
);
limit: maxRows
 
} ).done( function ( data ) {
$searchBoxes.suggestions( {
var orig = $.map( data.suggest, function ( suggestion ) {
fetch: function( query ) {
return suggestion.text;
var $this = $( this ),
} ) || [];
apiUrl = mw.util.wikiScript( 'api' );
if ( orig.length >= maxRows )  
 
response( orig );
if ( query.length !== 0 ) {
else {
var params = {
api.get( {
action: 'opensearch',
action: 'cirrus-suggest',
search: query,
text: hebeng( query ),
redirects: 'return',
limit: maxRows - data.suggest.length,
suggest: true
} ).done( function ( data ) {
};
var combined = orig.concat( $.map( data.suggest, function ( suggestion ) {
 
return suggestion.text;
$.ajax( {
} ) );  
data: params,
response( combined );
url: apiUrl,
});
dataType: 'json',
success: function( data ) {
if ( $.isArray( data ) && 1 in data ) {
var orig = data[1];
 
$this.suggestions( 'suggestions', orig );
 
if ( data[1].length < 10 ) {
params.search = hebeng( query );
if ( params.search === query ) {
return;
}
 
params.limit = 10 - data[1].length;
 
$.ajax( {
data: params,
url: apiUrl,
dataType: 'json',
success: function( data ) {
if ( $.isArray( data ) && 1 in data ) {
$this.suggestions(
'suggestions',
orig.concat( data[1] )
);
}
}
} );
}
}
}
} );
}
}
} );
}
};
} );
} );
}, 1200 ); // setTimeout
}
}
else
{
$(function() {
setTimeout( function() {
    'use strict';
    var $searchBoxes = $( '#searchInput, #searchInput2, #powerSearchText, #searchText' );


    $searchBoxes.suggestions( {
} // skin === vector
        fetch: function( query ) {
            var $this = $( this );
            if ( query.length !== 0 ) {
                var params = {
                    action: 'opensearch',
                    search: query,
                    suggest: ''
                };
                $.ajax( {
                    data: params,
                    url: mw.util.wikiScript('api'),
                    dataType: 'json',
                    success: function( data ) {
                        if ($.isArray( data ) && 1 in data) {
                            var orig = data[1];
                            $this.suggestions( 'suggestions', orig );
                            if ( data[1].length < 10 ) {
                                params.search = hebeng( query );
                                if ( params.search === query )
                                    return;
                                params.limit = 10 - data[1].length;
                                $.ajax({
                                    data: params,
                                    url: mw.util.wikiScript('api'),
                                    dataType: 'json',
                                    success: function( data ) {
                                        if ( $.isArray( data ) && 1 in data )
                                            $this.suggestions( 'suggestions', orig.concat( data[1] ) );
                                    }
                                });
                            }
                        }
                    }
                } );
            }
        }
    });
}, 1200); // setTimeout
}); // document.ready
} // if (cirrus) ... else
} // skin == vector

גרסה אחרונה מ־07:25, 5 בדצמבר 2022

if ( mw.user.options.get( 'skin' ) === 'vector' ) {

// Load the search suggestion logic when focus the search box.
function dwimEventListener( e ) {
	if (
		e.target.id === 'searchInput' ||
		/(^|\s)mw-searchInput($|\s)/.test( e.target.className )
	) {
		enableDwim();
		document.removeEventListener( 'focusin', dwimEventListener );
	}
}
document.addEventListener( 'focusin', dwimEventListener );

// Load the search suggestion logic when the search box is already focused
// because the user started typing before the JavaScript is loaded.
if (
	document.activeElement && (
		document.activeElement.id === 'searchInput' ||
		/(^|\s)mw-searchInput($|\s)/.test( document.activeElement.className )
	)
) {
	enableDwim();
}

function enableDwimModernVector() {
	// @todo
}

function enableDwim() {
	'use strict';
	if(mw.loader.getState('mediawiki.searchSuggest') === 'registered') {
		// Vector is using the new version of search. Exit early to avoid running incompatible code.
		enableDwimModernVector();
		return;
	}

	setTimeout( function() {
		var hes = "qwertyuiopasdfghjkl;zxcvbnm,./'קראטוןםפשדגכעיחלךףזסבהנמצתץ",
			hebeng = function ( str ) {
				return ( str || '' ).replace( /./g, function( c ) {
					var ic = hes.indexOf( c.toLowerCase() );

					return ic + 1 ? hes.charAt( ( ic + 29 ) % 58 ) : c;
				} );
			};
		
		var $searchBoxes = $(
			'#searchInput, #searchInput2, #powerSearchText, #searchText'
		);

		$searchBoxes.suggestions( {
			fetch: function( query ) {
				var $this = $( this ),
					apiUrl = mw.util.wikiScript( 'api' );

				if ( query.length !== 0 ) {
					var params = {
						action: 'opensearch',
						search: query,
						redirects: 'return',
						suggest: true
					};

					$.ajax( {
						data: params,
						url: apiUrl,
						dataType: 'json',
						success: function( data ) {
							if ( $.isArray( data ) && 1 in data ) {
								var orig = data[1];

								$this.suggestions( 'suggestions', orig );

								if ( data[1].length < 10 ) {
									params.search = hebeng( query );
									
									if ( params.search === query ) {
										return;
									}

									params.limit = 10 - data[1].length;

									$.ajax( {
										data: params,
										url: apiUrl,
										dataType: 'json',
										success: function( data ) {
											if ( $.isArray( data ) && 1 in data ) {
												$this.suggestions(
													'suggestions',
													orig.concat( data[1] )
												);
											}
										}
									} );
								}
							}
						}
					} );
				}
			}
		} );
	}, 1200 ); // setTimeout
}

} // skin === vector