var lsTrBuilder = { timeout: null, selectTransition: function(el) { // Gather info var $el = jQuery(el), $parent = $el.closest('ul'), type = $parent.data('type'), $target = jQuery('.ls-tr-list-'+type), index = $el.index(); // Stop preview this.stopPreview(); // Maintain selection on sidebar jQuery('.ls-transitions-sidebar li').removeClass('active'); $el.addClass('active'); // Switch between transition types and select new transition $target.show().siblings().hide(); jQuery('.ls-transition-item').removeClass('active'); $target.children().eq(index).addClass('active'); // Start preview this.startPreview(true); }, addTransition: function(el) { // Get select var $list = jQuery(el).parent().next(), type = $list.data('type'), $target = jQuery('.ls-tr-list-'+type); // Remove notification (if any) $list.next().addClass('ls-hidden'); // Append clone var $template = jQuery( jQuery('#ls-'+type+'-transition-template').text() ); var $tr = $template.clone().prependTo($target); // Append tr to list and select it jQuery('.ls-transitions-sidebar li').removeClass('active'); var $item = jQuery( jQuery('#ls-tr-builder-list-entry').text() ).hide().prependTo($list); // Animate list item $item.css({ opacity: 0, marginLeft: -300 }).show().animate({ opacity: 1, marginLeft: 0 }); // Select new transition and focus into text field $item.click().find('input').focus().select(); }, removeTransition: function(el) { // Ask confirmation to continue ... if(!confirm(LS_l10n.TBRemoveConfirmation)) { return; } // Gather info var $el = jQuery(el).closest('li'), $parent = $el.parent(), type = $parent.data('type'), $target = jQuery('.ls-tr-list-'+type), index = $el.index(), $tr = $target.children().eq(index); if($parent.children().length > 1) { // Get next items var newIndex = ($tr.prev().length > 0) ? (index -1) : (index+1); // Select new transition $parent.children().eq(newIndex).click(); } // Remove transition $tr.remove(); $el.remove(); // Add notification if needed if($parent.children().length === 0) { $parent.next().removeClass('ls-hidden'); } else { $parent.next().addClass('ls-hidden'); } }, importTransition: function(el) { // Get transition object var $el = jQuery(el), index = jQuery(el).data('key'), section = jQuery(el).closest('section').index(), type = (section === 0) ? '2d' : '3d', transition = layerSliderTransitions['t'+type][(index-1)], $list = jQuery('.ls-transitions-sidebar ul[data-type="'+type+'"'), $target = jQuery('.ls-tr-list-'+type); // Hide transition gallery window.lsHideTransition(); LS_TransitionGallery.closeTransitionGallery(); setTimeout(function() { // Add transition entry jQuery('.ls-transitions-sidebar h3').eq(section).find('a:last-child').click(); // Change name $list.find('li:first-child input').val( jQuery('
').html(transition.name).text() ); // Update form items lsTrBuilder.updateControls($target.children('.active'), transition); lsTrBuilder.startPreview(true); }, 1000); }, updateControls: function($tr, transition) { jQuery.each(transition, function(idx, val) { var $area; // General options if(idx === 'cols' || idx === 'rows') { if(jQuery.type(val) === 'array') { val = val.join(','); } jQuery(':input[name="'+idx+'"]', $tr).val(val); // Animation objects } else if(jQuery.type(val) === 'object') { $area = jQuery('tbody.'+idx, $tr); // Iterate over animation objects jQuery.each(val, function(aIdx, aVal) { if(jQuery.type(aVal) !== 'object') { jQuery(':input[name="'+aIdx+'"]', $area).val(aVal); } else { $area.prev().find(':checkbox').click(); jQuery.each(aVal, function(tIdx, tVal) { // Remove previous transition properties jQuery('.ls-tr-tags', $area).empty(); // Add transition property jQuery('.ls-tr-tags', $area).append( jQuery('') .append(''+tIdx+'') ).append( jQuery( LS_InterfaceIcons.times ) ) ); }); } }); } }); }, toggleTableGroup: function(el) { var $tbody = jQuery(el).closest('thead').next(); if($tbody.hasClass('ls-builder-collapsed')) { $tbody.removeClass('ls-builder-collapsed'); } else { $tbody.addClass('ls-builder-collapsed'); } }, addProperty: function(el) { // Gather info var list = jQuery(el).parent().prev(), select = jQuery(el).next(), title = select.children(':selected').text(), name = select.children(':selected').val().split(',')[0], value = select.children(':selected').val().split(',')[1]; // Build tag list.append( jQuery('
')
.append(''+title+'')
).append( jQuery( LS_InterfaceIcons.times ) )
);
this.startPreview(true);
},
removeProperty: function(el) {
jQuery(el).closest('li').remove();
this.startPreview(true);
},
serializeTransitions: function(el) {
// Prepare transition object
layerSliderCustomTransitions = { t2d: [], t3d: [] };
jQuery('.ls-tr-options').children().each(function() {
// Iterate over 3D transitions
jQuery('.ls-transition-item', this).each(function(index) {
// Get working transition object & store its name
var trType = jQuery(this).closest('.ls-tr-list-2d').length ? '2d' : '3d';
var tr = layerSliderCustomTransitions['t'+trType][index] = {};
tr.name = jQuery('.ls-transitions-sidebar ul.'+trType+' li:eq('+index+') input').val();
// Iterate over other sections
jQuery(this).find('tbody:gt(0)').each(function() {
// Skip 'before' and 'after' transitions if they aren't set
if( jQuery(this).prev().find(':checkbox:not(:checked)').length ) {
return;
}
// Get section name
var area, section = jQuery(this).attr('class');
if( section ) {
section = section.split(' ')[0];
tr[ section ] = {};
area = tr[ section ];
} else {
area = tr;
}
// Iterate over the fields
var trOptions = false,
elements = jQuery(this).find('input,select'),
$this, name, val;
for( var c = 0; c < elements.length; c++) {
// Get input details
$this = jQuery( elements[c] );
name = $this.attr('name');
val = $this.val();
// Skip iteration if it's
// a GUI only element
if( ! name ) { return; }
// Get working area
if( ! trOptions && $this.closest('tr.transition').length) {
trOptions = true;
area = area.transition = {};
}
// Set values
if($this.is(':checkbox')){
if($this.prop('checked')) {
area[name] = $this.val();
}
} else if(val !== '') {
if( (name === 'rows' && val.indexOf(',') !== -1) ||
(name === 'cols' && val.indexOf(',') !== -1)) {
val = val.split(',');
area[name] = [parseInt(jQuery.trim(val[0])), parseInt(jQuery.trim(val[1]))];
} else {
area[name] = jQuery.isNumeric(val) ? Number(val) : val;
}
}
}
});
});
});
},
stopPreview: function() {
jQuery('.ls-transition-item.active').each(function() {
var $item = jQuery(this);
if($item.hasClass('playing')) {
$item.removeClass('playing');
var $parent = jQuery($item).find('.ls-builder-preview');
jQuery('.transitionpreview', $parent).layerSlider( 'destroy', true );
$parent.append(
jQuery('', { 'src' : lsTrImgPath + 'sample_slide_1.jpg' })
);
}
});
},
startPreview: function(forceStart) {
var $item = jQuery('.ls-transition-item.active');
// Check playing status
if($item.hasClass('playing')) {
this.stopPreview();
if(!forceStart) {
return;
}
}
// Serialize
this.serializeTransitions();
$item.addClass('playing');
// Get transition details
var index = $item.index(),
trType = $item.closest('.ls-tr-list-3d').length ? '3d' : '2d',
trObj = layerSliderCustomTransitions['t'+trType+''][index];
// Try preview
try {
jQuery($item).find('.ls-builder-preview').empty();
window.lsStartTransitionPreview( jQuery('.ls-builder-preview', $item ), {
type: 'fixedsize',
width: 300,
height: 150,
transitionType: trType,
transitionObject: trObj,
imgPath: lsTrImgPath,
skinsPath: pluginPath+'layerslider/skins/',
sliderFadeInDuration: 0,
delay: 500,
});
// Aw, Snap! Something went wrong.
// Stop preview and display error message.
} catch(err) {
//alert('Oops, something went wrong, please check your transitions settings and enter valid values. Error: '+err);
this.stopPreview();
}
},
save: function(el) {
// Temporary disable submit button
jQuery('.ls-publish').addClass('saving').find('button').text(LS_l10n.saving).attr('disabled', true);
// Serialize & store JSON
this.serializeTransitions();
jQuery(el).find('input[name="ls-transitions"]').val(
JSON.stringify( layerSliderCustomTransitions )
);
// Post
jQuery.post( window.location.href, jQuery(el).serialize(), function() {
// Give feedback
jQuery('.ls-publish').removeClass('saving').addClass('saved').find('button').text(LS_l10n.saved);
// Re-enable the button
setTimeout(function() {
jQuery('.ls-publish').removeClass('saved').find('button').attr('disabled', false).text(LS_l10n.save);
}, 2000);
});
}
};
var LS_TransitionGallery = {
openTransitionGallery: function() {
kmw.modal.open({
content: '#tmpl-ls-transition-modal',
minWidth: 980,
maxWidth: 980,
maxHeight: '100%',
onBeforeClose: function() {
if( window.lsHideTransition ) {
window.lsHideTransition();
}
}
});
// Append transitions
LS_TransitionGallery.appendTransition(0, '', '2d_transitions', layerSliderTransitions.t2d);
LS_TransitionGallery.appendTransition(1, '', '3d_transitions', layerSliderTransitions.t3d);
// Select proper tab
jQuery('#ls-transition-window .filters li.active').click();
},
closeTransitionGallery: function() {
kmw.modal.close();
},
appendTransition: function(index, title, tbodyclass, transitions) {
// Append new section
var section = jQuery('#ls-transitions-list section').eq(index).empty();
if(title) {
section.append('