博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mootools_新的MooTools插件:ElementFilter
阅读量:2511 次
发布时间:2019-05-11

本文共 4339 字,大约阅读时间需要 14 分钟。

mootools

My new MooTools plugin, ElementFilter, provides a great way for you to allow users to search through the text of any mix of elements. Simply provide a text input box and ElementFilter does the rest of the work.

我的新MooTools插件ElementFilter为您提供了一种绝佳的方式,允许用户搜索任何混合元素的文本。 只需提供一个文本输入框,ElementFilter即可完成其余工作。

XHTML (The XHTML)

  • ADDRESS
  • APPLET
  • AREA
  • A
  • BASE
  • BASEFONT
  • BIG
  • BLOCKQUOTE
  • BODY
  • BR

I've used a list for this example but you can use any type or mix of elements that you'd like.

在此示例中,我使用了一个列表,但是您可以使用任何类型的混合元素。

MooTools JavaScript (The MooTools JavaScript)

var ElementFilter = new Class({	//implements	Implements: [Options,Events],	//options	options: {		cache: true,        caseSensitive: false,        ignoreKeys: [13, 27, 32, 37, 38, 39, 40],        matchAnywhere: true,        property: 'text',        trigger: 'mouseup',        onStart: $empty,        onShow: $empty,        onHide: $empty,        onComplete: $empty	},	//initialization	initialize: function(observeElement,elements,options) {		//set options        this.setOptions(options);        //set elements and element        this.observeElement = document.id(observeElement);        this.elements = $$(elements);        this.matches = this.elements;		this.misses = [];        //start the listener        this.listen();	},		//adds a listener to the element (if there's a value and if the event code shouldn't be ignored)	listen: function() {		//add the requested event        this.observeElement.addEvent(this.options.trigger,function(e) {			//if there's a value in the box...			if(this.observeElement.value.length) {				//if the key should not be ignored...				if(!this.options.ignoreKeys.contains(e.code)) {					this.fireEvent('start');					this.findMatches(this.options.cache ? this.matches : this.elements);					this.fireEvent('complete');				}			}			else{				//show all of the elements				this.findMatches(this.elements,false);			}        }.bind(this));	},	//check for matches within specified elements	findMatches: function(elements,matchOverride) {		//settings        var value = this.observeElement.value;        var regExpPattern = this.options.matchAnywhere ? value : '^' + value;        var regExpAttrs = this.options.caseSensitive ? '' : 'i';		var filter = new RegExp(regExpPattern, regExpAttrs);		var matches = [];				        //recurse        elements.each(function(el){          	var match = (matchOverride == undefined ? filter.test(el.get(this.options.property)) : matchOverride);			//if this element matches, store it...			if(match) { 				if(!el.retrieve('showing')){					this.fireEvent('show',[el]);				}				matches.push(el); 				el.store('showing',true);			}			else {				if(el.retrieve('showing')) {					this.fireEvent('hide',[el]);				}				el.store('showing',false);			}			return true;        }.bind(this));		return matches;	}});

The above options are pretty self explanatory so I'll skip the formalities. As you can see, all you need to do is provide the text element to listen to, the elements to search, and your option values.

上面的选项很容易解释,因此我将跳过手续。 如您所见,您所要做的就是提供要收听的文本元素,要搜索的元素以及您的选项值。

MooTools示例用法 (The MooTools Sample Usage)

/* usage */window.addEvent('domready',function() {  var myFilter = new ElementFilter('search-term', '#my-list li', {    trigger: 'keyup',	cache: true,    onShow: function(element) {		element.set('morph',{			onComplete: function() {				element.setStyle('background-color','#fff');			}		});		element.morph({'padding-left':30,'background-color':'#a5faa9'});    },    onHide: function(element) {		element.set('morph',{			onComplete: function() {				element.setStyle('background-color','#fff');			}		});		element.morph({'padding-left':0,'background-color':'#fac3a5'});    }  });});

This is a sample usage of this plugin. When a match is found, the element's background turns green and fades back to white. When an element no longer matches, I do the same effect but with red.

这是此插件的示例用法。 找到匹配项后,元素的背景变为绿色,然后变回白色。 当某个元素不再匹配时,我将执行相同的操作,但使用红色。

This plugin provides a great way to search for specific text within elements on a page. I recommend using a list (UL or OL) as they are very easily searchable.

该插件提供了一种在页面元素内搜索特定文本的好方法。 我建议使用列表(UL或OL),因为它们很容易搜索。

A special thanks to for his help in developing this plugin!

特别感谢在开发此插件方面的帮助!

翻译自:

mootools

转载地址:http://gdpwd.baihongyu.com/

你可能感兴趣的文章
Spring+SpringMVC+MyBatis深入学习及搭建(四)——MyBatis输入映射与输出映射
查看>>
opacity半透明兼容ie8。。。。ie8半透明
查看>>
CDOJ_24 八球胜负
查看>>
Alpha 冲刺 (7/10)
查看>>
一款jQuery打造的具有多功能切换的幻灯片特效
查看>>
SNMP从入门到开发:进阶篇
查看>>
@ServletComponentScan ,@ComponentScan,@Configuration 解析
查看>>
unity3d 射弹基础案例代码分析
查看>>
thinksns 分页数据
查看>>
os模块
查看>>
LINQ to SQL vs. NHibernate
查看>>
基于Angular5和WebAPI的增删改查(一)
查看>>
windows 10 & Office 2016 安装
查看>>
最短路径(SP)问题相关算法与模板
查看>>
js算法之最常用的排序
查看>>
Python——交互式图形编程
查看>>
经典排序——希尔排序
查看>>
团队编程项目作业2-团队编程项目代码设计规范
查看>>
英特尔公司将停止910GL、915GL和915PL芯片组的生产
查看>>
团队编程项目作业2-团队编程项目开发环境搭建过程
查看>>