How to Only Listen for Ajax Responses That Matter

I ran into a situation within a widget that I am building for a client. There are a lot of Ajax requests being made to create form fragments and updated search results based on user input to a search filtering widget (Think shopping online through Amazon or Best-buy). Sometimes 2 parts of the form will be updating along with a new results set, so as the widget became more and more complex, I began to see that a series of quick clicks to different check-boxes and drop-downs could result in the wrong form fragment loading for half a second here and there before the latest updated fragment finally returns from the server to replace it. For example, your filtering automobiles and click ‘Cars off’, ‘Trucks on’, then change your mind, ‘Trucks off’, ‘Cars on’. Unfortunately if you click faster then the response takes to return, even though your done clicking, the response from ‘Trucks on’ may load first, until finally the response from ‘Cars On’ (the correct response) is loaded over it. If you mess with widgets around the web you’ll find that a lot of sites have issues like this. If you don’t have preventive code, then it’s just going to occur. The internet is fast, but it still hasn’t caught up to the ever changing mind of the global consumer…


Waking Up to a Stack Exchange Full of Points

Dev Diary,
Nice surprise this morning, I logged onto the computer to get ready for work, and noticed that I had been awarded +400 points on the Stack Exchange network. The past couple of weeks I’ve been trying to make a habit to get over to the Wordpress Stack Exchange to answer a question if I have time. It is actually a fun thing to do, I even learn new things answering questions, and it helps other developers out, so it’s a win-win and feels good too!

 

When a member first joins one of the Stack Exchange sites (there are sites ranging for Web apps to Web masters, game development to game playing, there are actually Stack Exchange sites for coffee and beer), they are given limited privileges. New members earn the privilege to comment, to 1-up or 1-down comments, approve answers, ect. Through this structure, the site members actually become the site moderators, after achieving high enough rankings. It’s a cool system and all the Stack Exchanges are excellent sources for information. Today when I woke up I saw that I had earned +400 points. 100 of the points came from answering a bounty put out on this question here. Then 100 points from the Ubuntu SE, the Wordpress SE and Stack Overflow for being trusted on other sites in the network. Earning that allows a member to comment and enjoy other benefits on those other SE sites without first having to earn the privilege. Felt good ;P Wish I had started sooner.

 

I’m sure if you are into web development or any computer science, then you frequent a few of the Stack Exchanges from time to time. For me, visits used to be primarily made after scanning the results of a Google search. More often then not, when I would have a good question, Stack Exchanges would provide equally good answers. Up until recently I wasn’t really participating or answering questions, but now that I am, I enjoy the time spent finding solutions, or even just discussing possible ways to find solutions. If your bored, or looking for something to do, head over to the Wordpress Stack Exchange, or the more broad scoped Stack Overflow, or any of the many Stack Exchanges.


Take the Next Step

Dev Diary,

Today I got a piece of junk mail from a site that I developed on awhile back. I didn’t build the site, just coded one feature, color schemes. So when I saw the newsletter in my email box, I decided to go see how the script I wrote was holding up. I called the script “ColorSchemerJS”, it is a purely JavaScript controlled setting that allows visitors on your site to choose a color scheme, and that scheme will persist across the whole site without having to use PHP or MySQL. They had asked me to do it with cookies, but instead I went with Local Storage and just used cookies as a fall back. Next week I’ll get the script up on Github for anyone who wants to take a look or use it.

Basically all you have to do to get it to work is define an object that has {name : Array} pairs. The Arrays just list every CSS selector that you want to be set to a certain color (or actually any rule). That can be as little or large as you would like. Then you pass that into the colorSchemer Object allow with another object that has {name: ‘rule’} pairs and colorSchemer will apply every selector linked to name in the first object up with any rule linked to name in the second object. The only thing that the script actually has to pass from page to page with LocalStorage if I remember correctly, is the color scheme object. Each page will have it’s own set of selectors so there is no reason to pass that information along. There were a few default rules like primary, secondary background colors and font colors.

At any rate, I was just doing a little work on this site before bed, starting the Dev-Diary Template. Not much different from the rest of the site. I’m exhausted. Good night Dev.


New Goal: Infilitrate the Core, the WP Core

Dev Diary,

I spent half the day today working on the Captcha program for the new tutorial that I am going to write. Hopefully I will be able to get that tutorial this week. It was a pretty cool “day project”, I’ve never really spent that much time working with images in PHP. It was fun. I’ve decided that I would like to start moving through some of the core contributors documentation for Wordpress. I’d like to be able to help work on bugs and the experience can only help make my own coding better. So right now I’m going to sit down with my tablet and burn through a few pages. If your interested in seeing what is happening with Wordpress, you should check out Make Wordpree, it’s a cool site. I’m just really just making my way through it right now, I’ve spent a lot of time in the Codex the past 5 months, and since I’ve been writing a lot of WP sites, I am interested in getting closer to the group that builds Wordpress. So that’s what is on the agenda for the rest of my Saturday night, reading the WP Core Best practices. Good night!


How to Create a JavaScript Timer (Building Objects Using Recursion and Closures)

In this post I’m going to demonstrate how to build a timer object in JavaScript that will output to any html element. Now if you wanted, you could easily manipulate this to return the data wherever needed, but for this tutorial we are going to assume that you want the clock timer displayed somewhere within your HTML. If you want to see how the timer performs when it’s finished then you can check out the small mini-game Rederranged that it runs over, or you could check out the jsFiddle that I originally coded it in for a more detailed view…