1. 01. Incoming
  2. 02. Hifi
  3. 03. Lofi
  4. 04. The Lab
  5. 05. Tags

frequency decoder

Fixed position "droppables" for jQuery

Posted Thursday February 28, 2008

frequency decoder

A quick hack that enables you to have position:fixed droppables when using version 1.2 of the "interface elements for jQuery" library

I’m currently using interface elements for jquery, a collection of rich interface components that utilize the lightweight JavaScript library jQuery, to add drag & drop functionality to a project at work.

One of the project constraints was that the “droppables” i.e. the target drop zones for draggable elements, had to be created with a fixed position (i.e. position:fixed).

This, unfortunately, isn’t (yet) supported by the interface library and so I had to add a bit of code to the iutil.js script which makes up part of the core “interface” library.

So, without much ado and for anyone else who may require the functionality, here’s the updated/hacked portion of code in question (delimited by START and END):

  
getPositionLite : function(el) {
   var x = 0, y = 0;
   while(el) {
       // START 
       if(el.style.position == “fixed”) {
         if (document.documentElement) {
           y += document.documentElement.scrollTop;
           x += document.documentElement.scrollLeft;
         } else if (document.body) {
           y += document.body.scrollTop;
           x += document.body.scrollLeft;
         };

         x += parseInt(el.style.left, 10) || 0;
         y += parseInt(el.style.top, 10) || 0;

         break;
      };
      // END 

      x += el.offsetLeft || 0;
      y += el.offsetTop || 0;
      el = el.offsetParent;
    };                
    return {x:x, y:y};
},
  
  

et voila… you are now free to position:fixed your droppable areas.

Just to be clear, the update/hack applies to version 1.2 of the interface library – I have no idea if this will work for other versions.

Tags: interface, javascript, jquery

Previous Comments ~

Bramus! · http://www.bram.us/
#1 · Thursday February 28, 2008

Why use Interface Elements when you’ve got its successor jQuery UI" ? ;)

Nonetheless a nice fix :)

frequency decoder
#2 · Thursday February 28, 2008

@ Bramus: Hi Bramus, long time no see/hear!

I’m actually using this version as I’d have to update the entire system should I upgrade to jQuery UI – which just isn’t feasible at the moment.

When the U.I release removes the “b” from the “1.5b”, I’ll have a solid business argument for setting aside time to complete the upgrade in full.

Woah man, you’ve went freelance – respect.

Regards,
Brian

Bramus! · http://www.bram.us/
#3 · Friday March 7, 2008

Hi Brian,

indeed went freelance; Merely to handle the friend-requests (as in “My dad’s company needs a website’; ‘My friend from company Y heard you could fix his website”, etc.). Not even promoting myself and the projects just keep rolling in, thanks to word of mouth :)

Anywho, some exciting stuff got announced today over the jQuery Blog: March 14-15th will be the first Worldwide Sprint in order to prep jQuery UI for a 1.5 final :)

frequency decoder
#4 · Wednesday March 12, 2008

@ Bramus: Make sure you have the clients sign a rock-solid contract – seriously!

As for the jQuery sprint… it’s my birthday that weekend so I’ll be otherwise occupied! Good luck to the jQuery team though.

A penny for your thoughts…

Remember: Off-topic or dumb-ass comments will, of course, be deleted. Spammers shall have the scary flying-monkeys from “The Wizard of Oz” dispatched to their abode. Please remember to RTM before asking questions pertaining to any of the Lab experiments.

Reporting a bug? The error message and browser and operating system details would be much appreciated. Thanks.

Popular Frequencies

  • Unobtrusive Table Sort Script (revi…
    Saturday September 16, 2006
  • Unobtrusive Date-Picker Widget Upda…
    Monday October 02, 2006
  • Unobtrusive Table Sort Script
    Friday November 18, 2005
  • Unobtrusive Date-Picker Widgit
    Friday October 14, 2005
  • Unobtrusive Table Actions Script
    Thursday November 15, 2007

Google Ads

All articles