var FS = window.FS || {};
FS.Search = FS.Search || {};
FS.Search.UI = function() {
undefined;
//yui libs
var Event = YAHOO.util.Event;
var Dom = YAHOO.util.Dom;
var defaultSearchValue = 'Search';
return {
searchBox: 'textSearchBox',
init: function() {
var textSearchBox = Dom.get(this.searchBox);
if (textSearchBox !== null) {
Event.on(textSearchBox, 'focus', this.onFocus, this, true);
Event.on(textSearchBox, 'blur', this.onBlur, this, true);
}
},
onFocus: function(e) {
if(Dom.get(this.searchBox).value === defaultSearchValue) {
Dom.get(this.searchBox).value = '';
Dom.get(this.searchBox).style.fontStyle = 'normal';
}
},
onBlur: function(e) {
if(Dom.get(this.searchBox).value === '') {
Dom.get(this.searchBox).value = defaultSearchValue;
Dom.get(this.searchBox).style.fontStyle = 'italic';
}
console.time('create list');
}
};
}();
YAHOO.util.Event.onDOMReady(function() {
FS.Search.UI.init();
});
or this one?
$(function() {
var GD = window.GD || {};
GD.Search = GD.Search || {};
GD.Search.UI = function() {
defaultValue = $('#textSearchBox').val();
$('#textSearchBox').focus(function() {
if($(this).val() === defaultValue) {
$(this).val("");
$(this).css("fontStyle","normal");
}
});
$('#textSearchBox').blur(function() {
if ($(this).val() === "") {
$(this).val(defaultValue);
$(this).css("fontStyle","italic");
}
});
}();
});
they both have the same functionality, may I ask your opinion about my code in my jQuery. How to optimize the code or are there other ways or other best practice than this one? Thanks