Rip's Domain

jQuery: My new plugin swapit!!!!

Posted in Jquery, SwapIt by rip747 on December 15, 2006

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)
{
return this.each(function()
{
var i = (new Image).src = a;
var i2;
var c;
// bind the mouseover and mouseout event to swap the images
if($(this).get(0).tagName.toUpperCase() == “IMG”)
{
i2 = $(this).attr(“src”);

$(this).mouseover(function(i2)
{
$(this).attr(“src”, i2);
}).mouseout(function()
{
$(this).attr(“src”, a);
});
}else{
i2 = $(this).css(“background-image”);
$(this).mouseover(function()
{
c = “url(” + a + “)”;
$(this).css({“background-image”:c});
}).mouseout(function(){
$(this).css({“background-image”:i2});
});
}
});
}

The following shows how to use it with a div and an img tag:

$(function(){
$(“#test”).swapit(“b-aboutus-over.jpg”);
$(“.over”).swapit(“b-contactus-over.jpg”)
});

<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.

jQuery: background() bug? Am I doing something wrong?

Posted in Jquery by rip747 on December 15, 2006

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.

<html>
<head>
<script type=”text/javascript” src=”jquery.js”></script>
<style type=”text/css” media=”all”>
#test{width:276px;height:110px;background:blue;}
</style>
<script type=”text/javascript”>
$(function(){
// style before changing through jquery
$(“#test1”).html($(“#test”).background());
$(“#test1a”).html($(“#test”).width());
$(“#test1b”).html($(“#test”).height());

$(“#test2”).html($(“#testa”).background());
$(“#test2a”).html($(“#testa”).width());
$(“#test2b”).html($(“#testa”).height());

// change through jquery
$(“#test”).background(“red”);
$(“#testa”).background(“green”);

// style after changing through jquery
$(“#test3”).html($(“#test”).background());
$(“#test3a”).html($(“#test”).width());
$(“#test3b”).html($(“#test”).height());

$(“#test4”).html($(“#testa”).background());
$(“#test4a”).html($(“#testa”).width());
$(“#test4b”).html($(“#testa”).height());
});
</script>
</head>
<body>
<div id=”test”></div>
<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>
</body>
</html>

jQuery: 1.0.4 is out. Time to upgrade!!!

Posted in Jquery by rip747 on December 13, 2006

Yesterday saw another fantastic release of jQuery to 1.0.4. The are numerous bug fixes in this release, too many to go over.

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.

Another great thing is that they managed to fix 4 memory leaks with 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.

jQuery: Goodbye jquery.com, Hello getjquery.org?

Posted in Jquery by rip747 on December 12, 2006

EDIT:

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 :).

ORIGINAL POST:
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.

Ear infections: Little health tip

Posted in Health by rip747 on December 8, 2006

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.

read more | digg story

jQuery: getjquery.org is up

Posted in Jquery by rip747 on December 8, 2006

In case you don’t read Nabble.

getjquery.org has been launched. Get over there, create and account and start adding content this weekend people! 🙂

jQuery: Come up with a new slogan?

Posted in Jquery by rip747 on December 7, 2006

So there is a thread going on on Nabble on the effort to convert people over to jQuery. We’re not talking about a religious conversion here, just an effort to get people to take a look at jQuery and get it more exposure. One of the posters commented that maybe we ought to come up with a new slogan besides “New Wave JavaScript”, something catchier and describes the power of using it.

This is something that I think jQuery could use. As people have pointed out, a catchy slogan makes all the difference in marketing, no matter what the product, even if it is a JavaScript toolkit. To date, I think the best slogan I have seen for any of the toolkits out there, hands down, goes to Mochikit – “Makes JavaScript suck less.” This is just funny, brilliant and to the point: JavaScript sucks and anything that can make it easier for me is worth the investment to look into.

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: Making JavaScript it’s bitch.

jQuery: Dominate the DOM

I hate Christmas

Posted in Christmas, Rants by rip747 on December 7, 2006

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.

Why are you people forgetting about VIEWS?

Posted in ColdFusion, SQL by rip747 on December 4, 2006

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:

SELECT
[user name],
[password],
[first name],
[last name]
FROM Users

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
AS

SELECT
[pk_User] AS userid,
[user name] AS username,
[password] AS password,
[first name] AS firstname,
[last name] AS lastname
[active user] AS active
FROM Users

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
(
userid,
username,
password,
firstname,
lastname,
active
)
VALUES
(
newid(),
‘rip’,
‘mypass’,
‘Tony’,
‘Petruzzi’,
1
)

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
AS

SELECT *
FROM vwUsers
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
<cfquery

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.