Archives

Posts Tagged ‘javascript’

Jul 20th

JavaScript – $(document).ready() without jQuery

2011
2 comments | 1825 views

Everyone who has been using jQuery knows the purpose and how to use the jQuery(document).ready() function. But what if you want or need to implement such a construct without jQuery (for whatever reason, one  would be to avoid the jQuery overhead if all you really need is the ready() handler?

One would think it's as simple as using a onload event, just like:

<body onload="myReadyHandler();">

But it is not. There is an important and significant difference between onload and document.ready():

Read more...

1 Like Like

Jul 16th

JavaScript – why simulating a click using the click() method doesn’t work in Chrome

2011
2 comments | 1358 views

Chrome doesn't allow simulating a click using the click() method.

While working on some WordPress plugin to enhance the comment system with a couple of Ajax features, i ran into a problem. My code was using the click() method on a link object to simulate a click on this link and while this did work fine in Opera, Firefox and Internet Explorer, it did not so in Google Chrome. Now, I know using click() is a bad thing and there is almost always a better way but in this specific case, there wasn't so I had to find a solution.

The reason why Chrome doesn't allow this is most likely related to its security model and I think it does it on purpose which is all fine, because  such functionality is rarely, if ever, needed.

Read more...

2 Likes Like

May 31st

Passive share and Tweet buttons in WordPress

2011
2 comments | 1154 views

The crux with the Like

As a matter of fact, there are a lot of privacy concerns with the viral Like and Tweet buttons that appear almost everywhere on the net. While the feature itself is nice and can certainly help to attract visitors and generate traffic, people often fail to see the risks. Do you really want allow Facebook to track ALL your surfing activity, because that's exactly what they can do with these buttons?

When you are logged into your Fb account (and I think, most Facebook users are permanently logged in most of the time) AND have your browser configured in a way that makes it possible to use the Like buttons (it must, at least, grant read access to 3rd party cookies), every page you visit that embeds such a button could - at least in theory - be tracked by Facebook. In theory, they know what pages you visit and can connect your surfing behavior to your account profile. Whether they do this or not isn't really relevant. Maybe they only do it for certain pages, or don't do it at all. Maybe they'll do it in the future - nobody really knows. What matters is that these buttons build the technical foundation to track users.

Read more...

2 Likes Like

May 29th

Are you afraid of JavaScript?

2011
4 comments | 1169 views

How do you deal with JavaScript?

How do you deal with JavaScript?

View Results

Loading ... Loading ...

A couple of days ago, I had one of these discussion with a good friend, who is - like myself - a typical "IT guy". Many of his opinions can be seen as fairly "old school", but he does have a lot of experience, particularly with network security and the evils of the Internet. I would say, he is a highly qualified expert in that area and he certainly knows his stuff.

While browsing my site, he noticed that it recently has become quite heavy on JavaScript with all the things I integrated, particularly the colorbox script, the syntax highlighter and some jQuery stuff. I know, he is not a fan of script heavy sites at all and he prefers to surf the net with JavaScript disabled by default.

Read more...

2 Likes Like

Apr 30th

Simple JavaScript font size switcher

2011
No comments | 868 views

Fonts are a matter of personal taste, especially the size. People are different, some prefer smaller sized text, others can't stand it. Visitors have different browsers, are using different screens, different resolutions, DPI settings and even different zoom levels and if you are using a non-standard font for your page, browsers might have to substitute it with an available font. No matter how carefully you select the font and its size, it will most likely not please everyone. Allowing visitors to quickly change the text size and remember their preference is convenient and can improve reading experience.

The goal(s)

  • Allow visitors to change the font size of articles in a convenient way, providing 2 simple buttons to increase or decrease the font size.
  • Save the selection to a cookie, thus making it persistent for later visits.
  • Make it look nice so that no ugly and disturbing page reflows happen due to changing the font size after the page has been loaded.
  • Use jQuery where possible.

First, I only want to change the font size for the actual content. The header, footer and sidebar should not be affected, only the posts and pages, because this is what people are actually reading and where text size matters most. This is fairly easy to achieve because most WordPress themes use a wrapper class for posts, so it should be sufficient to change the font size for this class. For my theme, posts and pages are wrapped within a <div class="post"> and the actual content of the post (the article text or excerpt) is wrapped into another <div class="content">.

Read more...

Like

Apr 26th

Valid XHTML Facebook like and Twitter tweet buttons for WordPress

2011
16 comments | 5058 views

Summary: Create fully XHTML compliant asynchronous Facebook like and Twitter tweet buttons for your WordPress blog using a pure JavaScript approach and implemented as a simple WordPress template function. Small, clean and lightweight.

Yes, I'm talking about the Facebook like (or recommend) and Twitter tweet buttons. Implementing them on your site is fairly easy - Facebook has a developers page where the anatomy of a like button is documented and you can even use it to generate the HTML code. For twitter, you can find similar information here.

With all that information, it should not be hard to add such buttons to your blog by simply creating the necessary HTML code and fill in the permalink of the article to like or tweet. The result will be a page with working like and tweet buttons but the code will no longer be valid XHTML and all the IFRAMEs may delay the loading process of your page more than necessary. So, there must be a better way, right?

Read more...

19 Likes Like