• Main
  • B2evo
  • Tutorials
  • Plugins
  • Testlab
  • Bridge

Tutorials

Tutorials and programming

Playing with jQuery

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.


  • By admin
  • January 24th, 2009
  • Posted in Images, Programming
  • 7152 views
  • Send feedback »
  Dutch (NL)  
 

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 ; 
        }
  • By admin
  • October 6th, 2008
  • Posted in Images
  • 2983 views
  • Send feedback »
  Dutch (NL)  
 

Kubuntu

Seriously thinking of moving over. This is Kubuntu 8.10 Intrepid Ibex alpha 6 in VirtualBox

Hardly any disk space left for a dual boot install. Need hardware. :p

  • By admin
  • September 21st, 2008
  • Posted in Images
  • 3024 views
  • Send feedback »
  English (UK)  
  Tags: dual boot, kubuntu, linux, ubuntu, virtualbox

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.

  • By admin
  • August 11th, 2008
  • Posted in Images
  • 8952 views
  • Send feedback »
  English (UK)  
  Tags: b2evolution, forum, greasemonkey, greasespot, javascript, phpbb, script

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.

  • By admin
  • March 25th, 2008
  • Posted in Images
  • 22362 views
  • Send feedback »
  English (UK)  
  Tags: , filteritemcontents, php, plugin, renderitemashtml, tilqicom, title, unfilteritemcontents
1 2 >>
  • July 2010
    Sun Mon Tue Wed Thu Fri Sat
     << <   > >>
            1 2 3
    4 5 6 7 8 9 10
    11 12 13 14 15 16 17
    18 19 20 21 22 23 24
    25 26 27 28 29 30 31
  • Search

  • Tutorials

  • Things that interest me, so it might interest you ;)
  • Adsense

    • Recently
    • Archives
    • Categories
    • Latest comments
  • Categories

    • All
    • Images
      • GIMP
  • XML Feeds

    • RSS 2.0: Posts, Comments
    • Atom: Posts, Comments
    • _sitemap: Posts, Comments
    What is RSS?
  • User tools

    • Login
    • Register
    • Admin
  • Adsense


Contact | Credits: Foppe Hemminga | blog engine | cheap hosting | adsense