DOM click() event and link fragments in

If you have <a href=”#anchor”> style links click() event does not perform as expected on the link element.

Think the following jQuery Mobile code on <a href=”#ancho”>:

$list.delegate( "li", "click", function(event) {
 if ( !$( event.target ).closest( "a" ).length ) {
   var a = $( this ).find( "a" );
   a.first().trigger( "click" );
   return false;
  }
})

This code would go to  directory/#anchor instead of directory/page.html#anchor.

This does seem to be desired behavior as both Firefox and Webkit engines do it. However, it is quite puzzling.

Here is a temporary workaround directly hacked into jQuery Mobile version:

// tapping the whole LI triggers click on the first link
 $list.delegate( "li", "click", function(event) {
  if ( !$( event.target ).closest( "a" ).length ) {
 
  var a = $( this ).find( "a" );                
  var href = a.attr("href");
 
  if(href && href[0] == '#') {
     window.location.hash = href;    
     return true;
   } else {
     a.first().trigger( "click" );    
   }                
   return false;
   }
 });

This case surfaced when debugging why jQuery Mobile list views didn’t work correctly on Sphinx table of contents internal to the page.

Also, onhashchange listener in jQuery Mobile has to be disabled, but it seems to be irrelevant for this case.

Encrypted partition on an external hard disk in Ubuntu Linux

Here are short instructions how to create and use encrypted hard disk on Ubuntu Linux. These instructions are tested on Ubuntu 10.10 Maverick Meekat.

We are going to use the following strategy

  • Use cryptoloop kernel module. This is 100% open source software and the part of mainstream Linux (as opposite to TrueCrypt)
  • No additional software installations needed – stock Ubuntu is fine
  • These instructions work also on a server – no GUI needed
  • We will create an encrypted file on the target hard-drive partition. The target partition can be even NTFS, so the hard disk acts normally in Windows, though you still need Linux to read encrypted files
  • The encrypted file system will be Ext4 and mounted through a loop device

1. Prerequisites

  • Ubuntu Linux
  • Basic terminal / command-line know how

2. Creating an encrypted partition on an external driver

Plug-in the hard disk to Ubuntu Desktop – it will automount it over USB.

Install cryptoloop driver

    sudo modprobe cryptoloop

Check what mount point the new disk has – in your case it is /media/Elements:

ls /media
cdrom  cdrom0  Elements

Check how much space the disk contains

df -h
/dev/sdc1             932G   94M  932G   1% /media/Elements

Create a loopback file – don’t use the whole disk. In our case, allocate just 500 GB for the encrypted file system. Note that this may take time:

dd if=/dev/zero bs=1G count=500 of=/media/Elements/encrypted-fs

Now mount this file as a crypted loopback device. Note that need you to give separate password for sudo and the encryption. We use SHA-1 encryption. Don’t use password, use passphrase. SHA-1 has 160 bit key and to produce enough entropy, you need a latin sentence of at least 27 case-sensitive alphanumeric characters. We do this using losetup command.

sudo losetup -e sha1 /dev/loop0 /media/Elements/encrypted-fs

Then format this encrypted partition as ext4 file system.

mkfs.ext4 /dev/loop0

And now start using it

mkdir /media/encrypted
mount /dev/loop0 /media/encrypted

3. Usage

Later when you remount the encrypted partition you can simply do

sudo losetup -e sha1 /dev/loop0 /media/Elements/encrypted-fs
mount /dev/loop0 /media/encrypted

After usage always cleanly unmount the encrypted partition before unplugging the external hard-drive

umount /media/encrypted

4. More info

 

 

 

\"\" Subscribe to RSS feed Follow me on Twitter Follow me on Facebook Follow me Google+