Category Archives: javascript

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

firebug: how to place breakpoints into code

Firebug allows you to easily place breakpoints through it’s interface: display your js file into firebug find the line where you want to place your breakpoint click on the line number with the mous and you should see a red disc representing your breakpoint Alternatively, if you want to make firebug break upon executing a certain line from your code itself (ie. without going through the above process), simply write ‘debugger;’ into your js code. When this line gets executed, firebug will automatically opens itself and break on this line. From that on, you can debug your app.

javascript event: e.currentTarget vs. e.target

JS events usually have two properties: e.currentTarget & e.target As you may know, when you click on an element, ‘click’ event bubbles up to <body> node of your element. Let’s have a look at this code: <body><p><a href=”#”>some <span>text</span></a></p></body> If someone click on ‘text’, a click event will be created and bubble up from <span> node up to <body> node (going throug <span>, <a>, <p> and <body> respectively – provided we did not stop event bubbling with our js code). You can attach an event on any of these nodes (<body>, <p>, <a>, <span>) and your event-listener will fire up […]