1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
(function($){
var updateUpDown = function(sortable){
$('div: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();
};
var moveUpDown = function(){
var link = $(this),
dl = link.parents('div'),
prev = dl.prev('div'),
next = dl.next('div');
if(link.is('.up') && prev.length > 0)
dl.insertBefore(prev);
if(link.is('.down') && next.length > 0)
dl.insertAfter(next);
updateUpDown(dl.parent());
};
var addItem = function(){
var sortable = $(this).parents('.ui-sortable');
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>';
var html = tpl.replace(/{name}/g, 'Dynamic name :D').replace(/{desc}/g, 'Description');
sortable.append(html).sortable('refresh').find('a.up, a.down').bind('click', moveUpDown);
updateUpDown(sortable);
};
//var emptyTrashCan = function(item){
// item.remove();
//};
var sortableChange = function(e, ui){
if(ui.sender){
var w = ui.element.width();
ui.placeholder.width(w);
ui.helper.css("width",ui.element.children().width());
}
};
var sortableUpdate = function(e, ui){
//if(ui.element[0].id == 'trashcan'){
// emptyTrashCan(ui.item);
//} else {
updateUpDown(ui.element[0]);
if(ui.sender)
updateUpDown(ui.sender[0]);
//}
};
// toggle content panel
var togglePanel = function(e) {
var targetContent = $('div.panelcontent', this.parentNode.parentNode);
if (targetContent.css('display') == 'none') {
targetContent.slideDown(400);
$(this).html('[-]');
$(this).css("color","#cccccc");
} else {
targetContent.slideUp(400);
$(this).html('[+]');
$(this).css("color","#666666");
}
return false;
};
// toggle edit panel
var editpanel = function(e) {
var targetEditPanel = $('div.editpanel', this.parentNode.parentNode);
if (targetEditPanel.css('display') == 'none') {
targetEditPanel.slideDown(400);
} else {
targetEditPanel.slideUp(400);
}
$(this).toggleClass("active"); return false;
return false;
};
$(document).ready(function(){
// toggle edit panel
$('a.button_editpanel').bind('click', editpanel);
// toggle content panel
$('a.togglepanel').bind('click', togglePanel);
var els = ['#mainContent', '#sidebar_right'];
var $els = $(els.toString());
//$('h2', $els.slice(0,-1)).append('<span class="options"><a class="add">add</a></span>');
//$('dt', $els).append('<span class="options"><a class="up">up</a><a class="down">down</a></span>');
//$('a.add').bind('click', addItem);
//$('a.up, a.down').bind('click', moveUpDown);
//$els.each(function(){
// updateUpDown(this);
//});
$els.sortable({
items: '> div',
handle: 'h1',
cursor: 'move',
//revert: true,
cursorAt: { top: 10, left: 100 },
//opacity: 0.8,
containment: 'parent',
appendTo: 'body',
placeholder: 'placeholder',
connectWith: els,
start: function(e,ui) {
ui.helper.css("width", ui.item.width());
},
change: sortableChange,
update: sortableUpdate
});
});
$(window).bind('load',function(){
setTimeout(function(){
$('#overlay').fadeOut(function(){
$('body').css('overflow', 'auto');
});
}, 450);
});
})(jQuery);
|