Category Archives: javascript

javascript: suffle array (one-line script)

Here is a fantastic way to shuffle an array in javascript: myArray.sort(function() {return 0.5 – Math.random()}); So simple yet so efficient, I love it sources

jquery plugins: popup message

Here are some great jquery plugins for showing up popup messages:  

google script equivalent of xlDown, xlRight

I recently started creating scripts for google spreadsheet documents, the javascript based scripts. Unfortunately, I could not find the equivalent of xls vba range(“A1”).end(xlDown) in native google script functions. As such I created a working js equivalent. Only issue with it is performance. It is not really fast, but this is more due to Apps Script rather than the code itself or the fact that it is written in js. In case someone find a native equivalent to this function, please do not hesitate to share. /** * V0.2 => PERF IMPROVED * * Home-made equivalent of xls range().end(xlToRight) function […]

Create a custom dojo build

When you develop an application with dojo, you can pretty quickly end-up with tens of http calls to load all dojo.require() files on demand. In my case, for a simple script relying on dijit.Dialog & dijit.Tooltip, firebug reporting more than 25 http calls for individual files. In production, this is not optimal at all. So we will try to use dojo utilities to create our custom dojo file containing all (and only) the required dojo code into a single file. Problem is that there is scarce help on this matter on the Internet and official documentation is not correct! Here […]

issues with IE when cloning file input node

I wrote a js script in which I needed to clone an <input type=”file”> node. As usual, IE spoiled the party. It appears that when you clone an <input type=”file”> node (through “node.cloneNode(true);” or “dojo.clone(node);”), the value property is not cloned. Therefore you end-up with an almost useless cloned node. For security reasons, .value property of such node is not writable with js (only readable), this part I understand fully, but why on earth can’t IE  set it on the cloned node??? FF does it pretty well… Only solution I came up with was to attach input node into a […]

cannot set a name on hidden node in IE

I tried to create an hidden input node with dojo using dojo.create(‘input’, {type:’hidden’, name:’foo’, value:’bar’}). It worked fine in FF, but when looking at IE7, created node always had no name. After multiple attempts, the only workaround I found was to create an outer node and fill it with hidden node converted as string, using .innerHTML and then retrieve it back using .firstChild property of outer node. Here is the example: var dummy = dojo.create(‘div’, {innerHTML: ‘<input type=”hidden” name=”foo” value=”bar”/>’}); var myInput = dummy.firstChild; By doing this, when myInput got inserted into DOM, it kept its name property.

how to debug/keep-an-eye on all your http traffic

While looking for a way to track xhr/http request in IE, I found out fiddler ( This tool is simply fantastic, it allows you to keep an eye on all your http requests!!!! ALL of them. Very useful to check if a file is still being uploaded, to track xhr requests and so on… For privacy concerns, make sure to use it while debugging only (it acts as a proxy, god knows what they do with proxied data). sources

.indexOf on arrays with IE

IE (at least version 7) has no implementation of ‘indexOf’ function on arrays. Good news is that dojo has implemented a function just for this, and guess what, it’s dojo.indexOf(). Here is the signature of the function: dojo.indexOf(/* array */haystack, /* mixed */ needle, /* integer? */fromIndex, /* boolean? */findLast); sources

how to set minimum Heigth in dijit.form.Textarea

[UPDATE]: rather than using below code, simply use css min-height property. Styling with ‘height’ does not work since dojo changes it dynamically, but min-height works great (too bad for IE6 users, but it’s time to update guys!). ************************************** With v.1.3.1, dojo comes with a really nice feature on textarea form. They automatically expand while user is writting. While this feature is great, it’s pittyful that for now, no option exists to prevent box resizing upon creation. Therefore your textarea looks like a single line <input type=”text”> node and user simply has no idea that he can write a lot of […]

dojo + php = multi-file upload + progress bar

In a previous post (simple multifile upload with dojo), I explained how to have multifile upload thanks to dojo. In this post we will simply add the progress bar to our uploader (=> you might find useful to read the previous post first). For now, flash server file served with dojo for testing looks like it’s not working properly (or at least that I don’t use it properly) => for this post, I will focus on JS multi-file uploader (you will have to select files one by one, sorry). server side requirements By default, php does not permit to access […]