Created
October 21, 2011 01:43
-
-
Save VoQn/1302910 to your computer and use it in GitHub Desktop.
mistake I did
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// already loaded jQuery.js | |
(function(){ | |
function searchHoge(name, list){ | |
var reg = new RegExp('^'+name+'$','m'); | |
return list.filter(function(i, v){ | |
return reg.test($(v).text()); // v -> TopLevelHTMLObject | |
}); | |
} | |
var Search = { | |
search : function(name, list) { | |
var reg = new RegExp('^'+name+'$','m'); | |
return list.filter(function(i, v){ | |
return reg.test($(v).text()); // v -> list[i] | |
}); | |
} | |
factory : function(form_view, submit_view, list_view) { | |
var self = this; | |
var getTextsFromInput = function(){ | |
return $(form_view).val().replace(/^\s+|\s+$/,'').split(/\s+/); | |
} | |
// Effective | |
$(submit_view).click(function(){ | |
var texts = getTextsFromInput(); | |
if (texts.length > 0){ | |
self.search(texts[0], $(list_view)); | |
} | |
}); | |
// Not Expected | |
$(from_view).keydown(function(e){ | |
var texts = getTextsFromInput(); | |
if (e.keyCode == 13) { | |
searchHoge(texts[0], $(list_view)); | |
} | |
}); | |
} | |
}; | |
window.Search = Search; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment