2008-06-04 02:34:33 +00:00
|
|
|
(function($){
|
2008-09-03 15:29:45 +00:00
|
|
|
function updateUpDown(sortable) {
|
2008-06-04 02:34:33 +00:00
|
|
|
$('dl:not(.ui-sortable-helper)', sortable)
|
|
|
|
.removeClass('first').removeClass('last')
|
|
|
|
.find('.up, .down').removeClass('disabled').end()
|
|
|
|
.filter(':first').addClass('first').find('.up').addClass('disabled').end().end()
|
|
|
|
.filter(':last').addClass('last').find('.down').addClass('disabled').end().end();
|
|
|
|
};
|
|
|
|
|
2008-09-03 15:29:45 +00:00
|
|
|
function moveUpDown() {
|
2008-06-04 02:34:33 +00:00
|
|
|
var link = $(this),
|
|
|
|
dl = link.parents('dl'),
|
|
|
|
prev = dl.prev('dl'),
|
|
|
|
next = dl.next('dl');
|
|
|
|
|
|
|
|
if(link.is('.up') && prev.length > 0)
|
|
|
|
dl.insertBefore(prev);
|
|
|
|
|
|
|
|
if(link.is('.down') && next.length > 0)
|
|
|
|
dl.insertAfter(next);
|
|
|
|
|
|
|
|
updateUpDown(dl.parent());
|
|
|
|
};
|
|
|
|
|
2008-09-03 15:29:45 +00:00
|
|
|
function addControls() {
|
|
|
|
$(this).append('<span class="options"><a class="up">up</a><a class="down">down</a></span>')
|
|
|
|
.find('a.up, a.down').bind('click', moveUpDown);
|
|
|
|
updateUpDown($(this).parents(".ui-sortable:first"));
|
|
|
|
}
|
|
|
|
|
2008-09-03 13:29:43 +00:00
|
|
|
var counter = 1;
|
2008-09-03 15:29:45 +00:00
|
|
|
function addItem() {
|
|
|
|
var sortable = $(this).parents('.ui-sortable:first');
|
2008-06-04 02:34:33 +00:00
|
|
|
var options = '<span class="options"><a class="up">up</a><a class="down">down</a></span>';
|
|
|
|
var tpl = '<dl class="sort"><dt>{name}' + options + '</dt><dd>{desc}</dd></dl>';
|
2008-09-03 13:29:43 +00:00
|
|
|
var html = tpl.replace(/{name}/g, 'Dynamic name ' + counter).replace(/{desc}/g, 'Description');
|
|
|
|
counter += 1;
|
2008-06-04 02:34:33 +00:00
|
|
|
sortable.append(html).sortable('refresh').find('a.up, a.down').bind('click', moveUpDown);
|
|
|
|
updateUpDown(sortable);
|
|
|
|
};
|
|
|
|
|
2008-09-03 15:29:45 +00:00
|
|
|
function emptyTrashCan(item) {
|
2008-06-04 02:34:33 +00:00
|
|
|
item.remove();
|
|
|
|
};
|
|
|
|
|
2008-11-14 03:00:16 +00:00
|
|
|
function sortableChange(event, ui) {
|
2008-06-04 02:34:33 +00:00
|
|
|
if(ui.sender){
|
|
|
|
var w = ui.element.width();
|
|
|
|
ui.placeholder.width(w);
|
|
|
|
ui.helper.css("width",ui.element.children().width());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-11-14 03:00:16 +00:00
|
|
|
function sortableUpdate(event, ui) {
|
2008-06-04 02:34:33 +00:00
|
|
|
if(ui.element[0].id == 'trashcan'){
|
|
|
|
emptyTrashCan(ui.item);
|
|
|
|
} else {
|
|
|
|
updateUpDown(ui.element[0]);
|
|
|
|
if(ui.sender)
|
|
|
|
updateUpDown(ui.sender[0]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$(document).ready(function(){
|
|
|
|
var els = ['#header', '#content', '#sidebar', '#footer', '#trashcan'];
|
|
|
|
var $els = $(els.toString());
|
|
|
|
|
|
|
|
$('h2', $els.slice(0,-1)).append('<span class="options"><a class="add">add</a></span>');
|
2008-09-03 15:29:45 +00:00
|
|
|
$('dt', $els).each(addControls);
|
|
|
|
//$('dt', $els).append('<span class="options"><a class="up">up</a><a class="down">down</a></span>');
|
2008-06-04 02:34:33 +00:00
|
|
|
|
|
|
|
$('a.add').bind('click', addItem);
|
2008-09-03 15:29:45 +00:00
|
|
|
//$('a.up, a.down').bind('click', moveUpDown);
|
2008-06-04 02:34:33 +00:00
|
|
|
|
|
|
|
$els.each(function(){
|
|
|
|
updateUpDown(this);
|
|
|
|
});
|
|
|
|
|
|
|
|
$els.sortable({
|
|
|
|
items: '> dl',
|
|
|
|
handle: 'dt',
|
|
|
|
cursor: 'move',
|
|
|
|
//cursorAt: { top: 2, left: 2 },
|
|
|
|
//opacity: 0.8,
|
|
|
|
//helper: 'clone',
|
|
|
|
appendTo: 'body',
|
|
|
|
//placeholder: 'clone',
|
|
|
|
//placeholder: 'placeholder',
|
|
|
|
connectWith: els,
|
2008-11-14 03:00:16 +00:00
|
|
|
start: function(event,ui) {
|
2008-09-03 14:29:16 +00:00
|
|
|
ui.helper.css("width", ui.item.parent().width());
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
|
|
|
change: sortableChange,
|
|
|
|
update: sortableUpdate
|
2008-11-14 03:00:16 +00:00
|
|
|
}).bind("sortreceive", function(event, ui) {
|
2008-09-03 15:29:45 +00:00
|
|
|
$(ui.item).removeClass('ui-draggable').find('dt').each(addControls);
|
2008-06-04 02:34:33 +00:00
|
|
|
});
|
2008-09-03 14:29:16 +00:00
|
|
|
$('#components > dl').draggable({
|
2008-09-03 14:53:30 +00:00
|
|
|
connectToSortable: $els.not("#trashcan"),
|
2008-09-03 16:06:25 +00:00
|
|
|
helper: 'clone',
|
|
|
|
handle: 'dt'
|
2008-09-03 14:29:16 +00:00
|
|
|
})
|
2008-06-04 02:34:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$(window).bind('load',function(){
|
|
|
|
setTimeout(function(){
|
2008-09-03 16:06:25 +00:00
|
|
|
// fixes the weird scrolling in IE while killing the fade
|
|
|
|
$(document.body).css("height", "auto")
|
2008-06-04 02:34:33 +00:00
|
|
|
$('#overlay').fadeOut(function(){
|
2008-09-03 16:06:25 +00:00
|
|
|
$(this).remove();
|
2008-06-04 02:34:33 +00:00
|
|
|
});
|
2008-09-03 13:02:35 +00:00
|
|
|
}, 500);
|
2008-06-04 02:34:33 +00:00
|
|
|
});
|
2008-05-23 09:14:39 +00:00
|
|
|
})(jQuery);
|