Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Los_Angeles' for 'PDT/-7.0/DST' instead in /home/hemmi3/public_html/blog/inc/items/model/_itemquery.class.php on line 628
Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Los_Angeles' for 'PDT/-7.0/DST' instead in /home/hemmi3/public_html/blog/inc/items/model/_itemquery.class.php on line 628
| Testing dp.SyntaxHighlighter plugin » |
Playing with jQuery
Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Los_Angeles' for 'PDT/-7.0/DST' instead in /home/hemmi3/public_html/blog/inc/sessions/model/_hit.class.php on line 901
While playing with the upcoming B2evolution version I ran across an ancient piece of javaScript. And I thought I could do better in jQuery. That's what I thought.
Yes I made it several lines shorter but I still used the original logic and a major slash of that code.
Here is the problem. When you write a post you have a title. You would want to dynamically have that title in the top bar of the browser. In (X)HTML you use the <title> tag in <head> for that.
javaScript can edit the title with document.title. And that's what was used. An event listener checks if the title is changed (keyup is hte best event for that, so when you lift the finger from the key. Keydown is before the key is pressed so you lag one character. onchange is way to late. That will only happen when the inputbox looses focus.)
I'll present the jQuery code and run through it:
jQuery(function(){
var generateTitle = function()
{
currentPostTitle = jQuery('#post_title').val()
document.title = document.title.replace(/(Poster dans le blog\:).*$/, '$1 '+currentPostTitle)
}
generateTitle()
jQuery('#post_title').keyup(generateTitle)
})
We make a function because we call it twice - and repeatedly when the title is changed.
The variable currentPostTitle is filled with the contents of the textfield. That's the proposed title. Then in the next line the document.title is changed, basically the latest content of currentPostTitle is appended to what is already there. As you can see this is the most powerful line of all. And I took it from the original javaScript. I Googled the net and found this:
$(this).attr("title", "Your text goes here")
But it didn't seem to work. All other bits of advise point to document.title.
Of course jQuery is better. I have the event easily attached to the inputfield where Francois needed to create the event and the listener. My code can go anywhere. The old code needed to be placed after the textfield. All in all it's progression.
I put up a simple version for you to play with. Have fun.
Trackback address for this post
Feedback awaiting moderation
This post has 1 feedback awaiting moderation...