MediaWiki:Common.js/gridfiltering.js

/* License:   CC-BY-SA 3.0 */

( function( $ ) {	function gridFiltering {		var grid = $(gridContainer)		if(!grid.length) return		if(!gridFilteringSwitches) return		window.gridElements = []		grid.find('.servant-icon').each(function { var obj = {} var elem = $(this) obj['*'] = elem for(x in gridFilters) { obj[x] = elem.data(x).split(',') for(var y=0;y').appendTo(container).attr('id', container.attr('id')+'-field').data('type', 'search')				field.keyup(function { gridFilteringApply if(window.gridFiltersTimeout) window.clearTimeout(window.gridFiltersTimeout) window.gridFiltersTimeout = window.setTimeout(gridFilteringClear, 30000) })			} else if(gridFilters[x] instanceof Array) {				var field = $(' ').appendTo(container).attr('id', container.attr('id')+'-field').data('type', 'select')				$('  ').appendTo(field).attr('value', ).html(gridFilters[x][0])				for(var y=1;y<gridFilters[x].length;y++) {					$('  ').appendTo(field).attr('value', gridFilters[x][y][0]).html(gridFilters[x][y][1])				}				field.val()				field.change(function { gridFilteringApply if(window.gridFiltersTimeout) window.clearTimeout(window.gridFiltersTimeout) window.gridFiltersTimeout = window.setTimeout(gridFilteringClear, 30000) })			}		}		return flag	}	function gridFilteringClear {		for(x in gridFilters) {			$('#grid-filter-'+x+'-field').val()		}		gridFilteringApply	}	function gridFilteringApply {		for(var x=0;x<gridElements.length;x++) {			var elem = $(gridElements[x]['*'])			var active = true			for(y in gridFilters) {				var field = $('#grid-filter-'+y+'-field')				var value = field.val.toLowerCase				if(value == ) continue;				var type = field.data('type')				if(type == 'search') {					var rx = new RegExp('^.*?(' + value.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&") + ').*?$','i');					var flag = rx.test(gridElements[x][y].join(', '))					if(!flag) active = false				} else if(type == 'select') {					if(gridElements[x][y].indexOf(value) == -1) active = false				}			}			if(active) gridFilteringShow(elem)			else gridFilteringHide(elem)		}	}	function gridFilteringHide(elem) {		$(elem).stop(true); $(elem).fadeTo(200, 0.1); }	function gridFilteringShow(elem) { $(elem).stop(true); $(elem).fadeTo(200, 1); }	$( gridFiltering ) } )( jQuery );