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.
Testing dp.SyntaxHighlighter plugin
c#:firstline[1]:nogutter from plugin settings
////// The main entry point for the application. /// [STAThread] static void Main() { Application.Run(new MyClockForm()); } private void MyClockForm_Load(object sender, System.EventArgs e) { // Set the interval time ( 1000 ms == 1 sec ) // after which the timer function is activated timer1.Interval = 1000 ; // Start the Timer timer1.Start(); // Enable the timer. The timer starts now timer1.Enabled = true ; }
Greasemonkey
A long time ago I installed Greasemonkey and with the latest upgrade it survived after transition to Firefox 3.0.
Greasemonkey allows you to run javaScripts that you created yourself on somebody else's sites. That's the short explanation. Anyway, the script does not need to be included in the source as you might expect from a normal javaScript. You may want to change the background colour or the font size of an arbitrary site you often visit. Those are common uses, together with removal of certain elements most notably adds. You can completely restyle a webpage.
The main site Greasespot holds a huge collection of scripts. Installing a script is easy. If Greasemonkey is installed you only need to click the link to the Greasemonkey script to trigger an installer. You will see at the end of this post how that goes. Unfortunately I didn't find the Killer App there. I don't believe there is. So the use of Greasemonkey is in practice limited to things you make cy yourself. Luckily the huge script library is of great help there. You are bound to find a script that does 'almost' what you want.
In the Greasespot site you find a link to the Open Source (downloadable) book Dive Into Greasemonkey which is an excellent guide to get started apart from the fact that most of the examples don't run. The book is simply outdated. But worth a glance anyway.
For the B2evolution forums I wanted some hacks. One of them is available as Greasemonkey script. That is phpBB No Stretch. If a post contains a code with a very long line as can be the case with an URL the post itself becomes very wide rather than wrapping rhe long line. The phpBB No Stretch plugin for Greasespot does just that. It wraps the long line.
A very impressive plugin is IMDB Pirated Version It adds a bar with links to torrents of the particular movie from the page you're at. Have a look at this picture:

The line just under the film title is added by the script. If you click it it Ajaxes to the sites it gets its information from. Actually, this is a kind of Killer App.
Manipulating the title with a plugin
tilqicom came with a problem. He wanted some specific changes to the title of a post automated. At first I got it wrong, thinking that he wanted some text replacement in the body of a post. That's fairly easy, use the RenderItemAsHtml function in a plugin. When I finished that I heard that he specifically wanted to automatically change some text in the title. We are talking about a change like the input '[date]' to 'Tuesday March 24 2008'.
That caused some serious problems because I hadn't seen it done before.
