Wednesday, February 16, 2011
Tuesday, January 18, 2011
Delegation Drag
Its been some time since I have written something and its simply because there is not much to write about. But now I have something :P
The application that I'm working on currently use a lot of drag and drop features for many objects. The number of these objects in the UI varies from user to user. The code has been written to create a DragDrop object for each of these UI elements. Therefore if you were supposed to have many elements, the page would stall thus making actions damn slow. I was told to improve performance by changing this to a delegation model.
The delegation model would find the event attachments done to the main container and not the individual elements. The event would bubble up to the container which would be handled by the handler written for this. The container would be specified as well as the css selector for the elements which would have the drag and drop feature.
To make this work was pretty easy with YUI3. A delegation class was present which gave me the initial stuff to get started. But then came problems.
The application would have different drop targets at different points of time. An ajax action would change the UI which would then have different drop targets. Now if you were using delegation, you need to specify the drop objects in the constructor. I did not find a way where I could add/remove drop targets dynamically. This is when I saw a post from an author who did a work around for this. He had created the drop targets inside the mouseover action of the drag, thus scoping it :). I put these drop objects inside a scoped variable so that when the UI changed, I reset this variable.
I also required there be different drag objects. Those which went to specific drop targets. I started specifying the 'container' parameter instead of the 'cont' parameter and that solved some issues. To have another set of delegates, I just took the above code and changed the 'container' parameter to get the correct set of draggables. I also change the groups parameter bit that did not seem to make a difference ...
References
http://yuilibrary.com/forum/viewtopic.php?p=17845
http://developer.yahoo.com/yui/3/dd/
http://developer.yahoo.com/yui/3/examples/dd/
The application that I'm working on currently use a lot of drag and drop features for many objects. The number of these objects in the UI varies from user to user. The code has been written to create a DragDrop object for each of these UI elements. Therefore if you were supposed to have many elements, the page would stall thus making actions damn slow. I was told to improve performance by changing this to a delegation model.
The delegation model would find the event attachments done to the main container and not the individual elements. The event would bubble up to the container which would be handled by the handler written for this. The container would be specified as well as the css selector for the elements which would have the drag and drop feature.
To make this work was pretty easy with YUI3. A delegation class was present which gave me the initial stuff to get started. But then came problems.
The application would have different drop targets at different points of time. An ajax action would change the UI which would then have different drop targets. Now if you were using delegation, you need to specify the drop objects in the constructor. I did not find a way where I could add/remove drop targets dynamically. This is when I saw a post from an author who did a work around for this. He had created the drop targets inside the mouseover action of the drag, thus scoping it :). I put these drop objects inside a scoped variable so that when the UI changed, I reset this variable.
YUI().use('dd-delegate', 'dd-constrain', 'dd-proxy', 'dd-drop', function(Y) {
var del = new Y.DD.Delegate({
container: '#container1',
nodes: '.appt',
target: true,
dragConfig: { groups: ['default']}
});
del.dd.plug(Y.Plugin.DDConstrained, {
constrain2node: '#container1'
});
del.dd.plug(Y.Plugin.DDProxy, {
moveOnEnd: false,
cloneNode: false
});
del.on('drag:mouseDown', function(e){
if(_self.createdDrops.length ==0){
var drops = Y.all('td.day');
Y.each(drops, function(v, k) {
var tar = new Y.DD.Drop({
node: v,
groups: ['default']
});
_self.createdDrops.push(tar);
});
}
});
del.on('drag:start', function(e) {
_self.delDragStart(e, Y);
});
del.on('drag:end', function(e) {
_self.delDragStop(e);
});
del.on('drag:drophit', function(e) {
_self.delDragHit(e,Y);
});
del.on('drag:over', function(e){
_self.delDragOver(e);
});
del.on('drag:exit', function(e){
_self.delDragExit(e);
});
_self.del = del;
});
I also required there be different drag objects. Those which went to specific drop targets. I started specifying the 'container' parameter instead of the 'cont' parameter and that solved some issues. To have another set of delegates, I just took the above code and changed the 'container' parameter to get the correct set of draggables. I also change the groups parameter bit that did not seem to make a difference ...
References
http://yuilibrary.com/forum/viewtopic.php?p=17845
http://developer.yahoo.com/yui/3/dd/
http://developer.yahoo.com/yui/3/examples/dd/
Thursday, October 28, 2010
Backup the Pod
I have found it very hard to backup the music from the iPod to the system. Especially when the music inside is encrypted in some weird fashion. To see this go to /Volumes/Ipod/iPod_Control/Music from the command line and look at the contents inside. They are categorized in a weird fashion and make no sense.
I was done with those softwares which let me backup only 100 songs or so. Therefore I tried what I could do programmatically to get those lost song names (file names) right.
I went through those Meta Data accessing libraries written by brilliant people and managed to find a good one. The Library had very much of what I wanted. It could access those meta tags like title, artist and album. All I needed was a API thing for Ruby (I love Ruby :P ). TagLib also had language bindings for the ruby language !
You need to download the package and then run
Thats it ! You have installed the C stuff. Now do a
for the ruby package. The help docs are here. Try it out in irb and you will be pleased.
Now for the backup. I did a
to get all the encoded mp3s in a directory from the iPodControl/Music directory.
Now came the ruby code ....
This gave some warnings and stuff but generally did the trick for me. I now have an organized view of my files !!!!
I was done with those softwares which let me backup only 100 songs or so. Therefore I tried what I could do programmatically to get those lost song names (file names) right.
I went through those Meta Data accessing libraries written by brilliant people and managed to find a good one. The Library had very much of what I wanted. It could access those meta tags like title, artist and album. All I needed was a API thing for Ruby (I love Ruby :P ). TagLib also had language bindings for the ruby language !
You need to download the package and then run
./configure
make
sudo make install
make clean
Thats it ! You have installed the C stuff. Now do a
sudo gem install rtaglib
for the ruby package. The help docs are here. Try it out in irb and you will be pleased.
Now for the backup. I did a
cp -r **/*.mp3 /My/HOME/NEWDIR/.
to get all the encoded mp3s in a directory from the iPodControl/Music directory.
Now came the ruby code ....
require 'rubygems'
require 'tagfile/tagfile'
f = Dir.glob('/My/HOME/NEWDIR/*mp3')
f.each{|i|
begin
tag=TagFile::File.new(i)
nn = i.split('/')
nn[-1]=(tag.title.to_s + '-' + tag.artist.to_s + '-' + tag.album.to_s).gsub('/','') + '.mp3'
nn=nn.join('/')
p 'Renaming file '+i+ ' to '+ nn
File.rename(i,nn);
sleep 2
rescue
print "An error occurred: ",$!, "\n"
break
end
}
This gave some warnings and stuff but generally did the trick for me. I now have an organized view of my files !!!!
Monday, October 25, 2010
Mac on Lenovo
Franki just did the most amazing thing by installing OS X - 10.6 on a Lenovo. He tried out with Pally Sir's CD at first but that did not go well. I would confer with him and convince him to write about the set up and hacks here. Stay Tuned.
Subscribe to:
Posts (Atom)