Archive for February, 2011

Feb 19 2011

Tech Post: jQuery .live() to attach/detach events

Published by under Tech

I haven’t been putting up a bunch of tech posts lately but, despite me not having written a jQuery post in over 3 years, it’s still a regular draw of people to my site. This post is just to put a little organization to one of my more successful answer’s on stackoverflow. And to be truthfully, my old jQuery posts are pretty poor so I feel the need to redeem myself a bit with some better content.

The question that came up was “what was the best way to dynamically remove an event based on some criteria”. In the question, this was based on the value in a field. The quick and common answer was to use the obvious bind/unbind methods. In this case, there would be some onchange event that would bind/unbind the events accordingly. To be fair to those who gave answers, my solution wasn’t available when the older post was originally answered. It doesn’t say anything against all the other answers.

With the scenario given, there is also the solution that doesn’t seem to be given where the event just check the value of the field when fired. That solution seems to be just very uncreative and lacking elegance, though, so I think it says a lot about the community that it wasn’t given.

The solution I provided covers using the .live() method to dynamically “attach” the event. I’m using quotes as the live() method does not technically attach events to the elements they match, but really uses event bubbling to catch events as they happen and execute them on the elements that match the selector the event references. Since it matched to elements the time of event firing instead of needing to be bound to elements, it allows this to work for dynamically created content. Typically for ajax generated content, you would have to attach the event again (also making sure you don’t reattach the event to existing elements causing those to fire the event twice). You only have to register the event with it’s matching selector once on page load.

The benefit you get here is that all you have to do is change something on the element that would cause it to either match or be ignored based on changes to the attributes the selectors are using. A really good attribute to use is class. It’s easy to set with jQuery and it’s very robust since it can be a list unlike most of the other attributes which can only contain a singular value.

I set up an example on jsfiddle to show the example I’m describing.

For the lazy, I’ll put the relevant code here too.

The html:
<input id="eventMe" type="button" value="click me!" />
<input id="eventToggleBtn" type="button" value="toggle event" />

The JS:

$(document).ready( function () {
    $('#eventMe.clickable').live( 'click', function() {
        alert('I can haz events!');
    });
    $('#eventToggleBtn').click( function() {
        $('#eventMe').toggleClass('clickable');
        console.log($('#eventMe').class());
    });
});

In the example, I have 2 buttons. 1 with the live() event we are bind/unbinding and another button that will toggle the class (clickable) we are using as the selector. On first load, the first button does not match the selector of the live event so it doesn’t fire. Once you click the “toggle event” button, it adds the class and the event then fires when the first button is clicked. This has the added benefit of being able to dynamically change it’s appearance using the same selector in css. A disabled button could have a different appearance when the selector matches.

This isn’t completely fool proof solution, though. jQuery support for the events weren’t complete with the 1.3 version and you really would be limited to monitoring changes that could be checked in a jQuery selector, but that’s a pretty extensive set of characteristics. You could match them if they were located inside a certain parent, apply it to all matching elements other than the first, only odd elements. Your options are pretty open.

I hope that helps.

Share

One response so far

Feb 14 2011

Movies: Christopher Nolan, Hipsters and Rating with Fish

Published by under Entertainment

Time might cure all things, but it certainly doesn’t ensure a good blog post. I’ve been working on this for longer than I want to admit and it likely shows. Feel free to comment how badly organized and poorly written it is. I’ll do a real special fist pump in agreement… or at least try to not wait so long between posts.

Inception

A few weeks ago if you would have asked me who Christopher Nolan was, I doubt I would have been able to tell you much. I would have been able to tell you he was a director, but of what? I’m not sure I could have come up with much. While I like movies (as you probably can tell), I don’t always pay attention to the behind the scenes staff members. That all changed a little over a week ago when we took an afternoon off to go watch Inception at my bosses house. It was a planned thing, so I did some research on it. Turns out Nolan has a pretty impressive resume of directorial accomplishments in his career. He has 2 of the top 30 movies rated all time on imdb currently. Inception is rated #8 but I remember this summer when I first heard about the movie, it had taken the top spot from The Shawshank Redemption for a while. The other movie he has is Memento. When you combine those with Following (reviewed later) and the last 2 Batman movies (Begins and Dark Knight), he has really shown to be both a fan a critic favorite. So far the only film he’s directed that doesn’t seem to be a big a hit was Insomia. Even that seemed to do alright and is currently on my watch list if for no other reason than to complete my trip of the Nolan world.

After all of that, I’ve said very little about Inception itself. Inception is a unique story where people enter other people’s dream and play along trying to extract information or secrets called extraction. The question comes up if it’s possible to do the opposite and plant an idea in some one’s head instead of extracting it out – called inception. While being very scifi heavy in concept, it’s all pretty easy to follow until you take this part into consideration. They are capable of going into multiple levels of subconscious. Like multiple dreams. The actual inception task takes place through 4 levels of this subconscious with each having it’s own plot as well as the real world. The last of which is DiCaprio’s character trying to deal with his personal guilt and inner struggles. Have I lost you yet? If not, the movie will definitely attempt to. It ends up being a fairly cerebral movie. The story is engaging enough and, with that many plot lines going on, it has plenty of story to keep things moving. Given that it is well acted and visually impressive, there isn’t any question that this is one of the best movies of last year. Which is evident by how extensively it’s covered over the upcoming Academy Awards.

4.5

Changling

Angelina Jolie is arguable one of the most bat shit crazy Hollywood celebs around. I mean, Crispin Glover probably gives her a run for her money. That dude is coockoo for cocoa puffs. Despite, or perhaps even because, of her mental abnormalities, she does really pull off a lot of stuff on the big screen that few others could. Changling is a based on a true story of a child who disappears and an unsympathetic police squad tries to convince her that the wrong boy that they return to her, is her child. <story not really relevant to the review> Back when my first son was born, I had this horribly irrational fear that once he started day care as a baby, I would show up and not be able to recognize my own son. Stupid? Yes, of course. But these are the types of things that sleep deprivation of a new child brings you to. And I’m pretty positive, I got the right one home.</irrelevant story> Jolie’s character tries to convince herself that after a almost a year being gone that maybe this unfamiliar child is her son. It wasn’t. When she pushes back, the police department try and turn it on her like she is trying to shirk her motherly duties or she is just as wacko as her real life self.

This brings me to my 2nd tangent of this review. When Jolie gets thrown into the loony bin, I got distracted by the nurse who goes all TSA agent on her. I knew I had seen her somewhere but couldn’t piece it together. If you end up being tormented by this as well, I’ll let you in on it. She was the blonde in that handjob video that was all the rage a few years ago. Apparently she’s on her way to the big time now.

I apparently have the attention span of a spider monkey tonight, so I’ll try and wrap this up. The good parts: Angelina Jolie, the story and Clint Eastwood directing. Between this and Gran Torino, I’m very impressed with the films under his direction. So much so, I’m almost tempted to watch The Bridges of Madison County. Almost. The bad? I can’t really think of much. This is a really good movie that I don’t think got nearly enough respect.

4.5

Dinner For Schmucks

Everyone knows some one in their life that just messes things up. Despite their good nature and intentions, they lack the ability to make things go right. Steve Carell plays such a character in this film. His awkwardness is intended to be put on display to be the butt of a cruel dinner to showcase him and other invitees like him. The real task is getting him to the dinner before he totally obliterates Paul Rudd’s characters personal and professional lives. Many of the scenes in the movie just make you cringe at what the characters are going through as you watch the very predictable and unavoidable pains that they endure. It’s like watching some one step slowly on a nail. But in a good way. That kinda makes me sound a bit disturbed. And maybe I am, but that does not make this any less of an entertaining movie. There is just too many unbelievable situations with unrealistic characters put into absolutely ridiculous situations for it not to be.

3.5

How to Train Your Dragon

I had a chance to rewatch this; it’s still awesome.

The Chronicles of Narnia: The Voyage of the Dawn Treader

Watching the Narnia films is like a kid being force fed brussel sprouts disguised as ice cream. For every reason I liked Book of Eli, I dislike the Narnia films. Book of Eli just tried to tell a story that had a religious message to it. The Narnia films (and stories, I would assume but I never read them) try to weave a religious message without saying it’s a religious message. There were always certain parts to it that I disagreed with. But that is probably me just getting defensive to a feeling that I’m trying to be sold something that is disguised as something else. I’ve never been a big fan of that tactic. In this story, the big portion I got hung up on is how they really treat the book smart, science oriented cousin as a rude, spoiled brat to stubborn, or more likely, unable to understanding the world of Narnia. Of course, he turns around after he gets turned into a Dragon and becomes one with the world (I assume this is some sort of metaphor for being reborn). Despite my annoyance with all that, I think the actual story and acting were by far the best of in episode of the series. I really am trying to not go all Ricky Gervais on this movie, but it really is a deterrent for me and I have a difficulty getting passed some of the attempted subtle relationships between this and Christianity. It’s still a decent movie to take the kids to, though, and I’m sure most would like it.

3.0

Apacolypse Now

This is one of those movies with a legendary movies with such an impossibly large following among critics and film watchers that it’s almost unfathomable that some one hasn’t seen it. Much less to openly admit that one hasn’t seen it. That’s a crime isn’t it? Well, up until now, I hadn’t. To make things more confusing for someone uninitiated to the epic war drama, there is yet another version as Apacolypse Now Redux. I still am not entirely sure the difference between the 2, but my understanding is that it’s just an extended version of the original with nearly an hour of additional footage. Any one who I failed to anger or offend in the last review, get your rage running. This is one of the films that I think are truly overrated with it’s #36 rating on the IMDB top list. Don’t get me wrong, there are tons of really great actors in this film in every possible stage in their career. Obviously with Brando, Sheen (Martin, not Charlie), Robert Duvall, Dennis Hopper, Lawrence Fishburn and even Harrison Ford. There is no shortage of recognizable names here. The acting, for the most part, was top notch. For every part that was awesome, though, there were just even larger WTF moments that just didn’t make any sense. A Lieutenant Colonel that is more hell bent on finding the perfect wave? What is that about? Last thing I want is people flaming me that I wasn’t there and I don’t know, but this is just a story. And to me, that didn’t fit. There were other things that just seemed out of place too and it made it just hard to really wrap myself around it as being one of the all time best movies. That mix really made it hard for me to decide what to rate it so what do I give it?

Somewhere between a 2 and a 3.5. It’s not a cop out, I really can’t make up my mind. Of course I can do that, it’s my blog. You could get your own blog and rate films in fish if that’s what gets you off.

Following

If you ask me, Following is the best story out of all of Christopher Nolan’s films. It was also his first film so it lacks a bit of polish. This film could easily have been something made by Hitchcock. It has a lot of interesting (albeit sometimes shaky) camera work and an atypical format. It starts out at the end of the story, very similar to Memento, but unlike Memento, it gets told in a random order. I found myself trying to figure out the order of events by the physical features of the main character as he seems to have 3 pretty distinct feature changes throughout the film. The main character is a voyeur who has taken to following people to get glimpses into their lives. He ends up getting involved with a thief who has taken to thievery more on principal than for monetary gain. He enjoys the disruption of people’s lives more so than what the physical gains from the act. Eventually there get to be significant plot twists that change the whole perspective of the story – something that reminds me the most of Hitchcock films.

4.0

To get a small window into the mind of Christopher Nolan, here is one of his first short films:

Doodlebug – a short by Christopher Nolan.

Lenny

As everyone who follows me on twitter is aware, I was kinda crabby last Saturday. What better way to cap off a bad day then watching a biopic of the notoriously foul mouthed Lenny Bruce. To be honest, I knew very little of Bruce’s act beyond the common perception of how vulgar he was and how he paved the way for a new breed of comedians. If Dustin Hoffman’s performance in this film is any where close to the actual man (which I have every reason to believe it was), then I think I would have liked him. Like Carlin and the more contemporary Lewis Black, he seemed to use offensive words to lessen their power and to bring an understanding of how ridiculous common perceptions and practices are. The movie is shot in black and white. I’m not sure the reason for it, but it seems odd for a movie that is immortalizing such a colorful character. Hoffman does a good job and it’s an easy watch. For people like me who have no point of reference to the subject, I think it’s an interesting movie. It is a shame the man died so young.

4.0

The parking Lot Movie

I haven’t watched many documentaries lately so wanted to hit another one. This one I picked just cause it sounded like it could be interesting but I didn’t have great expectations of it. It’s a movie about the attendants of a paid parking lot, FFS. How awesome could it be? But then again, it’s a documentary on parking lot attendants. Surely they must have found something worth while to spend the time making the movie. It actually ended up being kind of interesting at parts. This is what happens when you take a bunch of over educated, underachieving people and give them a lot of time on their hands. You get a 90 minute tirade of seemingly smart people getting all elitist against the mainstream population whom they say are being elitist. There is a word for people who behave like this. It’s called a hipster. Some one who wants to be popular for shunning what is popular and do so in a witty (read sarcastic) way. So if a bunch of underachieving, overeducated elitists is your thing, this movie is likely for you. Oh, alright. They weren’t all assclowns, but oddly, they all seemed to be musicians. I’m still trying to figure that one out.

3.0

Share

No responses yet

Feb 11 2011

Found It!

Published by under Personal

Maybe it was cause I was tired last night or maybe it was because I was giving it too much thought. Either way while I was distracted with work this morning, I had a moment of clarity where I recalled a couple of the lyrics to that song I was trying to track down last night.

It’s not an awesome song but I think it’s tolerable. Seldom do we get awesome songs stuck in our heads. Songs that get stuck are like parasitic viruses burrowing into your soul until you want to rip your ears off, but you know that won’t help CAUSE IT’S IN YOUR MIND!

Low and behold (note to self to look up what that expression actually means), I was at least right about the “circles” in the name. So here you have it. The song that has been eating at my brain for the last couple of days. Hopefully it torments you as much as it has me: Soul Coughing – “Circles”

Share

No responses yet

Feb 10 2011

Stuck in my Head

Published by under Personal

Totally had intentions of finishing up my latest movie post, but just wasn’t feeling it tonight. Sad part is I’ve been working on that post for the better part of the week, it still isn’t done and likely won’t be any better for the time it’s taking. I sure know how to build up anticipation, don’t I.

So if I wasn’t writing, then what was I doing? As pathetic as it sounds, I was trying to track down some song that has come up several times on my pandora account over the last week. Problem is I’ve never heard the song except on pandora and I don’t really know any of the lyrics. So I’ve been playing pandora a lot more in a desperate attempt to hopefully it would randomly come on and I could hear the song again. This time so I can remember WTF it is. It’s my attempt at virtually retracing my steps. Too bad there isn’t a virtual radiator to look behind to find lost songs. I think it has something about “circles” in the title, but I could be way off base with that one.

There was another song that has come up a few times on my account this last week, though, and I do remember the name of the song. Mostly cause it’s a dude singing it, but the song is named “Your Woman” and has the lyrics “I could never be your woman” in it. That strikes me as a bit strange each time I hear so it left an indelible mark on my brain.

So I strike up the video on youtube and, despite having an almost “Crying Game” vibe to the lyrics, the video is epically awesome. At least for some one who likes visual stories. It plays along like a silent film and, even without the song, you could follow the story just from the video itself. So I might be overselling it a bit with the epically awesome part, but for what appears to be a low budget video, I think it’s really good.

Enjoy Your Woman from White Town:

Oh, and I never did figure out that other song. There will be follow up if I hear it again. Rest assured. I’m sure you are on pins and needles.

Share

No responses yet