Archive for category JavaScript
Sprinting new concepts
Posted by Børge Antonsen in JavaScript, jQuery on November 22, 2010
I decided to do a sprint this weekend, I’m currently working on my bachelor project so I didn’t want to have some big project floating around at the same time, but I needed to do something different so I decided to come up with a new (to me) concept.
I love data and trying to figure out what to do with it, so the natural choice was to find some sort of free data and (ab)use it in a very simple page/web app. The Norwegian Public Roads Administration, or Statens Vegvesen as they’re called in Norway, have an XML feed available with all the information about the roads in Norway (closed roads, weather conditions and so on).
By using CakePHP to convert it to JSON and cache it to avoid getting banned for DoS’ing their server, and jQuery for the front end, it took 3 days (including horse riding, football(soccer) on TV, gaming, etc) to get everything up and running.
Overall doing this sprint gave me some useful information:
- Programming too much makes it hard to sleep
- When you sleep, you dream about code
- Keeping the code maintainable when on a tight deadline can be a challenge, even when its only yourself you have to kneel down and apologize to from the bottom of your heart.
- At the very least, add comments shortly after implementing something (useful after some sleep!)
- Sometimes development can be fun, if you can tear yourself away from the worries about security flaws, browser incompatibilities, LOLcode and the kind of feedback which only is appropriate in TV-shows about cooking.
https://github.com/bovan/Trafikkmeldinger
Dojo vs jQuery in a jQuery based system
Posted by Børge Antonsen in Dojo, JavaScript, jQuery on June 15, 2010
I recently had to evaluate which JavaScript framework/toolkit/library I wanted to use for developing a workflow engine inside a system that already uses jQuery.
Using jQuery would include less files and have (hopefully) no chance of conflicts. However, 1 year into the future, when I’m most likely not working here at CERN, what would happen if the system that my application is embedded inside would be updated with a newer jQuery version?
As one doesn’t know the changes in future versions of jQuery (I’ve seen plugins break before), one could run into the risk of having the embedded application stop working, because it wasn’t updated along with jQuery.
This makes a strong point for my development using Dojo instead. Dojo uses it’s own namespace, and if one updates jQuery it shouldn’t affect the Dojo-application. Add to the fact that with Dojo one have less need for 3rd party plugins, as it has got so much more included in the package, and the survivability of the application should be longer.
Fixing usability with GreaseMonkey
Posted by Børge Antonsen in GreaseMonkey, JavaScript on June 11, 2010
Sometimes there are annoying small usability issues, like on cds.cern.ch, where the standard option is to select ALL categories when you search.
Usually I know what I want to search for, and there’s a big difference in searching for books and multimedia, which means I don’t want to have books popping up if I want a picture.
Luckily a simple GreaseMonkey fix can solve such annoyances with no effort at all:
var inputFields = document.getElementsByTagName("input");
for(key in inputFields)
{
if(inputFields[key].type == "checkbox" && inputFields[key].checked == true)
inputFields[key].checked = false;
}
Now I just select what I want, instead of deselecting what I don’t want, which usually leads to a lot less clicking.
Thank you GreaseMonkey!
Embedding CSS from JavaScript
Posted by Børge Antonsen in ByteStork, JavaScript on June 10, 2010
After spending some time in JavaScript (and modifying my CSS a tad), I managed to add a semi-flexible global sitemap (on top).
I wanted something that could be easily attached to any site, with adding just a simple script.
Also, as I wanted it to work independent of jQuery, Dojo etc, it has to be vanilla JS.
Satisfying IE is still a pain in the ass, and it doesn’t help that one chose not to use jQuery and Dojo for simplifying cross-browser support.
One example is the function I have for putting CSS into the HTML page. I really didn’t want to add another stylesheet, to reduce the number of page loads.
However, IE didn’t like the:
styles.appendChild(document.createTextNode(css[key]));
Thus I was forced to find some way of making it accept it:
function bytestorkStyles()
{
// Storing styles
var css = [];
css[0] = "div#bytestorkSiteMap { ..stuff here..} \n";
css[1] = "div#bytestorkSiteMap ul { ..more stuff here...}"
css[2] = "div#bytestorkSiteMap ul li { ..and so on.. }\n";
// create style element
var styles = document.createElement("style");
styles.setAttribute('type', 'text/css');
// the usual IE hack fix
if(styles.styleSheet)
{
styles.styleSheet.cssText = '';
for(key in css)
{
styles.styleSheet.cssText += css[key];
}
} else{
for(key in css)
{
styles.appendChild(document.createTextNode(css[key]));
}
}
//throw it into the head tag
document.getElementsByTagName("head")[0].appendChild(styles);
}
Maybe not the cleanest code, but it helped me not having to put all the styles into the elements themselves. Perhaps a better solution would be a cacheable CSS file, but it’s not like this is gonna kill a computer.
My CERN page made in Dojo
Posted by Børge Antonsen in CERN, JavaScript on June 9, 2010
I finally got the required project homepage for my degree work up and running.
Playing around with Dojo to make some functionality behind it:
- Data is stored in JSON files
- A template for each page is stored in a seperate file
- When you enter the site, all the content and the template is stored in the user’s browser.
This has the effect that it might take a few milliseconds more to load the page, but after that there is no more page loading.
This makes the server very happy:
