Permalink
Browse files

improve select behavior; add deselect

  • Loading branch information...
jtwb2 committed Feb 28, 2010
1 parent 7ca87bd commit e8ee4bbcd51ac970919c3422f632d7b3f2ad11e6
Showing with 15 additions and 4 deletions.
  1. +4 −0 static/draggies.css
  2. +11 −4 static/draggies.js
View
@@ -43,3 +43,7 @@ html, body {
left: 0;
}
+.dg-selected {
+ background-color: orange;
+}
+
View
@@ -77,14 +77,20 @@ $(function(){
fayeclient = new Faye.Client('/fayeclient'),
remote = new Remote(fayeclient, clientId),
selected = null,
+ select = function(el) {
+ $(selected).removeClass('dg-selected');
+ selected = el == null ? null : $(el).addClass('dg-selected');
+ },
boxHtml = '<div class="dg-box"></div>',
newBox = function(id, pos) {
return $(boxHtml).appendTo($('#dg-boxstart'))
.draggable({
containment: 'window',
+ distance: 30,
grid: [51, 51],
stop: function(event, ui){
if (ui.helper.hasClass('dg-dead')) return;
+ select(ui.helper);
remote.fire('place', {
el: ui.helper.attr('id'),
pos: ui.position,
@@ -97,8 +103,7 @@ $(function(){
.click(function(e) {
console.log('box click fired');
console.log(e.target);
- $(selected).removeClass('dg-selected');
- selected = $(e.target).addClass('dg-selected');
+ select(e.target);
});
};
@@ -108,7 +113,8 @@ $(function(){
helper: 'clone',
stop: function(event, ui){
var newId = 'dg-box-' + getNewId();
- newBox(newId, ui.position);
+ var box = newBox(newId, ui.position);
+ select(box);
remote.fire('place', {
el: newId,
pos: ui.position
@@ -129,7 +135,8 @@ $(function(){
e.preventDefault();
// deselect any selected items
if (e.target == this) {
- console.log('html.click triggered');
+ console.log('html.click deselect');
+ select(null);
}
});

0 comments on commit e8ee4bb

Please sign in to comment.