So I’m still trying to get over the bug hump from the last post, but while I’m waiting to work that problem out, I went ahead with my new plugin swapit.
Swapit makes swapping images and background images easy and it works like any other plugin. Below is the code:
$.fn.swapit = function(a)
var i = (new Image).src = a;
// bind the mouseover and mouseout event to swap the images
if($(this).get(0).tagName.toUpperCase() == “IMG”)
i2 = $(this).attr(“src”);
i2 = $(this).css(“background-image”);
c = “url(” + a + “)”;
The following shows how to use it with a div and an img tag:
<div id=”test” style=”background-image:url(b-aboutus.jpg);”></div>
<img src=”b-contactus.jpg” class=”over”>Like always, tell me what I’m doing wrong or how I can improve the plugin. I’ll be posting it to jQuery.com and getjuqery.org sometime tonight.
UPDATE: This problem also happens even if you use .css(“background”). Could this be a browser issue and not jQuery’s problem? This seems to happen in both IE and FF.
If you’ve been using jQuery for a while, you’ve probably have used the awesome Auto plugin. I thought that I would expand apon it by writing my own plugin that would not only switch the src of img tags, but also background image of any other tags.
So like all other good programmers, I started by doing some tests before diving in to help me plan out what I need to write. This is where I ran into an interesting bug and since jquery.com seems to be having issues right now, I though I blog it so I don’t forget it.
There seems to be a problem when trying to retrieve the background style of an element when it is set through an external style sheet or style block. Unless you set it through jQuery using .background(), you will get a blank string. However if you set the style of the element though an inline style, everything works fine, though I never have a problem retrieve other styles from the element.
I know this sounds confusing so I wrote up a test page that you can copy. Word of warning, you will need the latest version of jQuery and since jquery.com is having server issues, I don’t know how you will get it.
<style type=”text/css” media=”all”>
// style before changing through jquery
// change through jquery
// style after changing through jquery
<div id=”testa” style=”width:276px;height:110px;background:orange;”></div>
<p><b>Background of test set from style block, should be blue: <span id=”test1″></span></b></p>
<p>Width of test set from style block: <span id=”test1a”></span></p>
<p>Height of test set from style block: <span id=”test1b”></span></p>
<p>Background of testa set from inline style: <span id=”test2″></span></p>
<p>Width of testa set from inline style: <span id=”test2a”></span></p>
<p>Height of testa set from inline style: <span id=”test2b”></span></p>
<p>Background of test after altering though jQuery: <span id=”test3″></span></p>
<p>Width of test after altering though jQuery: <span id=”test3a”></span></p>
<p>Height of test after altering though jQuery: <span id=”test3b”></span></p>
<p>Background of testa after altering though jQuery: <span id=”test4″></span></p>
<p>Width of testa after altering though jQuery: <span id=”test4a”></span></p>
<p>Height of testa after altering though jQuery: <span id=”test4b”></span></p>
I’m guessing that the biggest focus of this release, besides the bug fixes, are the extensions to $.ajax as this method received a lot of attention in this release.
All and all a very nice job jQuery team!
On a side note, remember that the api documents are dynamically updated with each release. If you’re like me and you still see the old 1.0.2 documentation when you go the api site, hard refresh (SHIFT + Refresh in FF) the page and you should see the current release.
I want to take a moment and say that the following post is IN NO WAY a hit at the jQuery developers in any way. Believe me when I say that I respect and think highly of everyone involved with bringing jQuery to web. I really wish that I could being more to the table within the community then this blog and getting the word out more.
That said, I was both shocked and extremely honored that John and Rey took the time to comment on this post. I apologize if I came off too strong, I was just venting my feeling about the spam situation. I guess spam has a tendency to get under my skin :).
One of the things that has been annoying me for quite sometime since I’ve in utter lust with jQuery is it’s web site. I guess the thing that is really bothering me about it is the amount of vandalism and spam that gets posted there on a daily basis.
Take a sec to look at the change log for just today. There have been 5 spam tickets created, an old spam ticket was reopened and then spammed again and this is just today! Besides the spam tickets popping up at a rate I can hardly believe, someone keeps editing the Plugins page and posting spam there. This is also happening with the demos page as well.
It sucks that this keeps going on. For one it make the preconception that jQuery is a joke and can’t be taken seriously. After all who wants to use a toolkit that can’t keep it’s page spam under control. It also makes it hard to get valid bugs and change requests into the system since they get overwritten and lost because of the amount of spam.
But as with anything bad, there is a glimmering of hope. Since getjquery.org has been launched, I’ve watched it sprung up over the last couple of weeks. It’s looking really good and more and more content is being posted to it. I have a feeling that soon this will become the jQuery portal.
In the coming weeks I’m going to be posting and moving alot of the stuff from jquery.com to getjquery.org so to have a spam free environment for us.
Digg is running a story about health myths for kids. One the things that caught my attention was the one about colds causing ear infections.
This is something I’m an expert in since I’m cursed with ear infections all the time (thanks Dad!). Anywho, the best thing to do for these is to use rubbing alcohol.
Just take a cotton ball and apply a liberal amount of rubbing alcohol on it. Tilt your head to the side so your ear is elevated. Then sqeeze the cotton ball so that rubbing alcohol fills the ear. Usually you need about 8 – 10 drops. Let the alcohol sit in the ear for about 30 – 60 seconds. Then tilt your head the other way to drain the alcohol out and dry out the ear with toilet paper or a towel. Do this about 3 times a day.
If done on the first signs of an infection, you can usual cure it before it gets out of hand. Most of the time I can tell I’m getting one because it feels like I have water in the ear, like I just came out of a pool.
As a bonus (for all you swimmers out there), you can use this method to also remove any water you might get in your ear from swimming in a pool. I also do this whenever I go swimming in a lake or the ocean since you never know what might be lurking in the open water.
With that, I think we ought to run with this. Let’s see if anyone out there has a cool, upbeat, funny, catchy new slogan for my favorite toolkit, and yours, jQuery. Leave a comment here with your slogan or vote for one that someone posts. I’ll tally them up at the end of the month and send the top suggestions to John. Who knows, he might like one of them and decided to use it or he might decide not to use any of them and stick with the current one. In any event it should be fun seeing what the community and other people come up with.
I’ll go first:
jQuery: one line, unlimited power.
jQuery: Dominate the DOM
Yes you read that right, I hate Christmas. I
think know the holiday has lost all meaning and people are only concerned about receiving gifts. It’s so commercialized now, what good is it. They should just get rid of the holiday and give us the day off for Halloween instead….
but then I read things like this.
Maybe there is hope.
UPDATE: I can’t believe this post still get people commenting on it after a whole year.
I don’t know why the fullasagoog list has turned into the SQL newsgroup lately but there are some good articles coming our way nonetheless.
The one thing that is bothering me though is that every single person out there is forgetting about views and their importance in database design.
Views are basically a query that act like a table. That’s the best part about them. Using views you can do insert, update, delete statements against them, include them in other views, trigger and stored procedures. Some database even allow you to have indexes against (MSSQL 2000 and up).
So why use them? Take this post about bad column names. Why subject yourself to remembering to enclose a column name with . Why not just create a view for the table and name the column what you want. For instance, take this crappy query:
You usually see this when someone upgrade a MSAccess database to MSSQL. Instead of trying to remember the column names and remembering to enclose the column name that have spaces in them within , just write a view for the table like so:
CREATE VIEW vwUsers
[pk_User] AS userid,
[user name] AS username,
[password] AS password,
[first name] AS firstname,
[last name] AS lastname
[active user] AS active
Now when you need to get a record from the user table, you can use the view and have the column name already to you liking. Plus you can perform all insert, update, and delete statements using the view instead of the underline table:
INSERT INTO vwUsers
Another cool thing is that you can use views to filter other views, so that you have to write less SQL code for you application. Take for instance the table above, let’s say it had 10,000 users in it and 5,000 of those users are inactive. You want to retrive all of the active users from this view. You could write another view to do this for you
CREATE VIEW vwUsersActive
WHERE active = 1
Now inside you CF application all you have to do is write a CFQUERY against the view to retrieve all the active user:
<cfquery name=”q” datasource=”#mydsn#”>
SELECT * FROM vwUsersActive
Obviously this is a very basic query and not al that pratical. However normally when writing an application you can get pretty complex with your queries and views are there to simply them.