Aug 242009
 

def hilite_search_criteria(pattern, search_criteria)
return if pattern.nil? or search_criteria.nil?

pattern.gsub!(/(<[^>]*>)|\n|\t/s) {” “}

match_char = pattern =~ /#{search_criteria}/i
matched_string = $~.to_s

return if match_char.nil?
start = match_char – 25
start = (start < 0 ? 0 : start) unless match_char.nil? p = pattern[start ... match_char + search_criteria.length + 25] match_char = pattern =~ /#{search_criteria}/i p[match_char, matched_string.length ] = '‘ + matched_string + “
return p
end
end

 Posted by at 9:20 am  Tagged with:
Aug 182009
 

Usually you can trust the .toggle function (or .slideToggle) to hide or show whatever you want it to. But occasionally you need to know if something is hidden or shown.

var isVisible = $(‘#giftMsg’).is(‘:visible’);
var isHidden = $(‘#giftMsg’).is(‘:hidden’);
Aug 142009
 

I have defined a click function in the document ready

$(“#submit_request_toggle”).click(function() {
$(‘#submit_request’).slideToggle(500);
});

Later, I do an ajax call and I want to be able to redefine the click so that the link doesn’t work anymore (after my ajax call)

$.ajax({
type: “POST”,
url: “index.php”,
data: “action=submit_request&first_name=” + $(‘#submit_request_form input[name=first_name]’).val() + “&last_name=” + $(‘#submit_request_form input[name=last_name]’).val() + “&message=” + $(‘#submit_request_form textarea[name=message]’).val(),
success: function(msg){

$(“#submit_request_toggle”).click(function() { return false; });
$(“#submit_request”).fadeOut(500, function() { $(“#submit_request_response”).html(msg).fadeIn(); } );
}

For some reason, this line:

$(“#submit_request_toggle”).click(function() { return false; });

doesn’t work– the link still shows the hidden div even after I redefine it. Weird.