Category Archives: dojo

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 […]

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.

.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 http://w3schools.com/jsref/jsref_obj_array.asp http://www.pearweb.com/javascript/array-index-of.html http://api.dojotoolkit.org/jsdoc/1.3/dojo.indexOf

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 […]

dojo: ‘load’ function on xhrGet not called

I had hard time finding this out, I will put it here. My ‘load’ function set on xhrGet() object was not called at all upon successful ajax query. Query was performed but load function was simply ignored (no error, nothing). I also directly registered another function through .addCallback() method, and same result. Plainly ignored! After loosing half of my hair, I tried to remove ‘handleAs’ option too, and finally it worked. Both functions were triggered! ‘handleAs’ was set to ‘json’ and returned code is wrapped into textarea node as explained in js documentation (this is what caused below error, json […]

multi-file upload with dojo

If you use dojo, you might want a nice file-uploader. Good news is that such a widget exits! Bad news is that it’s not very easy to use, at least for now. I will try here to gather what I’ve learnt while using it (or at least while trying to make it work). Maybe someone will find it useful. Before we start As of now (dojo 1.3.1), I’m using trunk version of dojox.fileUploader (it has more features and greater flexibility than version available in dojo 1.3.1). => you will need to download trunk version too (http://archive.dojotoolkit.org/nightly/) if you want example […]

Browser detection with dojo

Browser detection in dojo is pretty easy, simply use dojo.isXXX() properties. ex: dojo.isFF; dojo.isIE; dojo.isChrome; dojo.isOpera; Let’s get it more interesting. You’re targeting a specific version of IE? then use: if (dojo.isIE > 6) {  // code to execute for ie7 and more } sources http://api.dojotoolkit.org http://www.dojotoolkit.org/forum/support/general-support/browser-detection http://dojotoolkit.org/book/dojo-porting-guide-0-4-x-0-9/style-html-utility-function-changes/browser-detection

dojo: create your own widget templates based on other widgets

If you create your own widget template, and if this template makes use of other widgets too, don’t forget to activate ‘widgetsInTemplate‘ option on the widget you are created. dojo.declare( ‘myjs.MyClass’, dijit._Widget, { templatePath: <path-to-your-template>, widgetsInTemplate: true, … } ); sources http://api.dojotoolkit.org/jsdoc/1.3/dijit._Templated