Wednesday, January 16, 2013

Getting properties and functions of JavaScript objects

I was looking for a way to get all the properties and functions for a particular JavaScript object. Looking around the web I found this discussion of StackOverflow which gave me my answer. I created a small helper function to which you pass your object and it spit out all its properties and function in the console. This is how it looks like:


You may argue that content assist in IDEs already give you this information. But there are slight differences in implementation of JavaScript of each browser. Looking into the document object on Chrome I found a property webkitIsFullScreen, but on Firefox there is not corresponding property with name mozIsFullScreen (I am looking at Firefox 16).

Thursday, December 20, 2012

Using indexOf method on array in server side JavaScript

Sometime back I was trying to use indexOf method on an Array object in server-side JavaScript (SSJS) code. But it was giving me error that indexOf method is not defined. I also couldn't find this method in help documentation. It was then it struck me that the implementation indexOf method in client side JavaScript itself is a bit fuzzy with Internet Explorer not supporting it. It can be defined using prototype property.

I found a simple solution here which implements the method. Just add the below code snippet to your SSJS code and then you would be able to use indexOf method.


Remember that this would be required for SSJS. For client side JavaScript I would recommend using dojo.indexOf.

Wednesday, December 19, 2012

Charging pattern on HTC One X

My HTC One X has a pattern in which it charges itself.


In the above screenshot of my battery usage you can see that from 10% battery level to 60% battery level my phone charges at a constant rate. But from 60% up till around 75% this rate dramatically drops and it takes much longer to charge. Then picks up again until around 90% and afterwards it charges very quickly. I don't know why does this happen and what is its significance. I contacted HTC support but there response was not satisfactory either.

So if you notice the same pattern while charging or a different one do post it in the comments.

Sunday, December 9, 2012

New features in HTC One X after Jelly Bean update

Some time back I updated my HTC One X to Jelly Bean (JB) using OTA update. The update takes your Android version to 4.1.1 and Sense to 4+.


Its been almost a 2 weeks with this update and the most noticeable improvement I can see is of battery usage. My phone lasts 1-2 hours more than it used to before. Well done HTC! There also some additions (and deletions) which I am going to describe here. Now I not an Android expert so I don't know all the new features in JB itself, so you may find a feature new in JB listed here. Also you won't find Google Now and Google Play Music here as I know they are new to JB and not HTC One X.

Sunday, December 2, 2012

Making internet pass-through work after updating HTC One X to Jelly Bean

Update 22 Jan 2013: "HTC Sync" seems to have been discontinued so the download links given below will not work. "HTC Sync" is different from "HTC Sync Manager". For exact difference read on.

I recently upgraded my HTC One X to Jelly Bean via OTA update. After updating I was unable to use internet pass-through which used to work flawlessly before and I already had HTC Sync installed on my PC. I uninstalled, installed, uninstalled again and installed again to make it work. But it simply refused. It gave me error of "Either you do not have the latest version of HTC Sync installed on your PC, or another phone is already using Internet pass-through on your PC." on my phone.


From this discussion on XDA Developers forum I found that there is something called as HTC Sync Manager. This is different from HTC Sync which I had installed on my machine. I don't know why HTC did this but its really confusing. Here's how these two software look.

Wednesday, November 21, 2012

Adding caption to image in form

When you add an image on to your form in Lotus Notes you can specify a caption for that image. In the image properties you will find this option along with where do you want to position this caption.


I usually use this technique to put text on fancy button images. So with just one image resource I can have multiple buttons with each having different text on it. You can even change the font by clicking on the image and then setting font properties in toolbar.



Some limitations of this technique are that the caption cannot be computed and it does not work on web.

Thursday, November 15, 2012

Drag out file links from download control to save just like in Gmail

Google adds a lot of interesting features in it products. One of them is dragging a file link in your Gmail on to your desktop (or a folder) to download it. This article on CSS Ninja explains exactly how it is done.

We can also put this feature in our download control so that each file link can be dragged on to your folder to start download without going through save dialog.

Step 1: Identifying the file links in a download control

This is actually pretty simple. XPages by default sets the class name of the file links in download control to xspLinkFileDownload. So all you need to do is to use a simple dojo.query to find all those link and loop through them.

Step 2: Adding attributes to anchor tag

Now you need to set two attributes in the anchor tags of file links - draggable and ondragstart. The draggable attribute needs to be set to true, that's all.

Setting ondragstart requires a bit more details. You need to call event.dataTransfer.setData("DownloadURL", "application/octet-stream:<FILE NAME>:<FILE DOWNLOAD URL>"). Note that while specifying <FILE DOWNLOAD URL> make sure its the complete path start from http://. These attributes can be set using dojo.attr.

So your final JavaScript code looks something like this:


One limitation here is that this only works for Google Chrome. I have put this script block on XSnippets here. Just copy it from there and put it into your XPage.