Показать сообщение отдельно
  #7 (permalink)  
Старый 24.06.2014, 12:51
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,103

yura29, убрал немного лишнего из плагина - сейчас клик по диву должен сразу срабатывать
<!DOCTYPE HTML>

<html>

<head>
  <title>Title</title>
  <meta charset="utf-8">
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>
/**
 * fastLiveFilter jQuery plugin 1.0.3
 *
 * Copyright (c) 2011, Anthony Bush
 * License: <http://www.opensource.org/licenses/bsd-license.php>
 * Project Website: http://anthonybush.com/projects/jquery_fast_live_filter/
 **/

jQuery.fn.fastLiveFilter = function(list, options) {
	// Options: input, list, timeout, callback
	options = options || {};
	list = jQuery(list);
	var input = this;
	var lastFilter = '';
	var timeout = options.timeout || 0;
	var callback = options.callback || function() {};



	// NOTE: because we cache lis & len here, users would need to re-init the plugin
	// if they modify the list in the DOM later.  This doesn't give us that much speed
	// boost, so perhaps it's not worth putting it here.
	var lis = list.children();
	var len = lis.length;
	var oldDisplay = len > 0 ? lis[0].style.display : "block";
	callback(len); // do a one-time callback on initialization to make sure everything's in sync

	input.on("input",function() {
		// var startTime = new Date().getTime();
		var filter = input.val().toLowerCase();
		var li, innertext, old;
		var numShown = 0;
		var num = "\\s?\\)?\\-?\\(?"
		for(i = 0; i<filter.length; i++){
			num += filter.substring(i,i+1) + "\\s?\\)?\\-?\\(?";
		}
		for (var i = 0; i < len; i++) {
			li = lis[i];
			innertext = !options.selector ?
				(li.textContent || li.innertext || "") :
				$(li).find(options.selector).text();

				li.innerHTML = li.innerHTML.replace(/<span style\=\"background-color\: \#E66A57\">/g ,"").replace(/\<\/span \>/);
			if (innertext.match(RegExp(num))) {
				li.innerHTML = li.innerHTML.replace(innertext.match(RegExp(num)), "<span style\=\"background-color: #E66A57\">" + innertext.match(RegExp(num)) + "</span c>");
				if (li.style.display == "none") {
					li.style.display = oldDisplay;
				}
				numShown++;
			} else {
				if (li.style.display != "none") {
					li.style.display = "none";
				}
			}
		}
		callback(numShown);
		// var endTime = new Date().getTime();
		// console.log('Search for ' + filter + ' took: ' + (endTime - startTime) + ' (' + numShown + ' results)');
		return false;
	})
	return this; // maintain jQuery chainability
}

$(document).ready(function(){
	$('#list').fastLiveFilter("#aza");
    $("#aza").on("click", "div", function(){alert("lol");});
   //	$("#aza").on("click", "span", function(){alert("alalalala");});
});
</script>
</head>

<body>
	<input id="list">
	<ul id="aza">
		<li><div>899999999</div><span>gggggg</span></li>
		<li><div>877777777</div></li>
		<li><div>866666666</div></li>
		<li>855555555</li>
	</ul>
</body>

</html>
Ответить с цитированием