deblan.tv/vendor/trinity/src/Trinity/Bundle/SlideshowBundle/Resources/public/js/style.js
2015-03-02 21:57:49 +01:00

83 lines
3.1 KiB
JavaScript
Executable file

$(document).ready(function() {
$('.slideshow_item_table tbody').sortable({
axis: 'y',
update: function(event, ui) {
var $table = $(this).parent().parent();
var $tbody = $table.find('tbody');
$tbody.find('tr').each(function(rank) {
var $tr = $(this);
$input = $tr.find('input.rank');
if ($input[0]) {
$input.val(rank);
}
});
}
});
$('.slideshow_item_table').each(function() {
var $table_sld = $(this);
var $tbody_sld = $table_sld.find('tbody');
var $addForm_sld = $table_sld.find('.slideshow_item_add_form');
var $addBtn_sld = $table_sld.find('.slideshow_item_add');
var $removeBtn_sld = $table_sld.find('.slideshow_item_remove');
var $editBtn_sld = $table_sld.find('.slideshow_item_edit');
var $previewBtn_sld = $table_sld.find('.slideshow_item_preview');
$addBtn_sld.click(function() {
var id = $tbody_sld.children().length - 1;
var add_form = $addForm_sld.data('prototype').replace(/__name__/g, id);
$tbody_sld.append('<tr style="background-color: #d3d3d3;">' +
'<td colspan="2" class="edit_form">' + add_form + '</td>' +
'<td width="15">' +
'<i title="Preview" data-id="' + id + '" class="slideshow_item_preview icon-eye-open"></i>' +
'<i title="Remove" data-id="' + id + '" class="slideshow_item_remove icon-remove"></i>' +
'</td>' +
'</tr>');
$tbody_sld.find('.slideshow_block_no_items').hide();
});
$removeBtn_sld.live(
'click',
function() {
$(this).parent().parent().remove();
if ($tbody_sld.children().length - 1 == 0) {
$tbody_sld.find('.slideshow_block_no_items').show();
}
return false;
}
);
$editBtn_sld.live(
'click',
function() {
$(this).parent().parent().find('.edit_form').toggle();
$(this).parent().parent().find('.preview').toggle();
return false;
}
);
$previewBtn_sld.live(
'click',
function() {
var form = $(this).parent().parent().find('.edit_form');
if ($(this).parent().parent().find('.preview').length) {
$(this).parent().parent().find('.preview').toggle();
} else {
$(this).parent().parent().prepend(
'<td width="100" class="preview"><i class="icon-file"></i></td>' +
'<td width="485" class="preview">' + form.find('.title').val() + '</td>'
);
}
form.toggle();
return false;
}
);
if ($tbody_sld.children().length - 1 == 0) {
$tbody_sld.find('.slideshow_block_no_items').show();
}
});
});