[enh] Cleanup app view() helper.

This commit is contained in:
opi 2016-05-23 21:15:06 +02:00
parent da9aa7d8c9
commit 35146cbd41

View file

@ -180,18 +180,24 @@
view: function (view, data, callback, enableSlide) { view: function (view, data, callback, enableSlide) {
c = this; c = this;
// Default
callback = typeof callback !== 'undefined' ? callback : function() {}; callback = typeof callback !== 'undefined' ? callback : function() {};
rendered = this.render('views/'+ view +'.ms', data);
enableSlide = (typeof enableSlide !== 'undefined') ? enableSlide : true; // Change to false to disable animation enableSlide = (typeof enableSlide !== 'undefined') ? enableSlide : true; // Change to false to disable animation
loaded = true; loaded = true;
// Hide loader and modal
$('div.loader').remove(); $('div.loader').remove();
$('#modal').modal('hide'); $('#modal').modal('hide');
if (enableSlide) { // Render content
var leSwap = function() { rendered = this.render('views/'+ view +'.ms', data);
rendered.swap(function() {
// Update content helper
var leSwap = function() {
rendered.swap(function() {
// Slide direction
if (enableSlide) {
$('.slide, .btn-breadcrumb a:not(:last-child)').on('click', function() { $('.slide, .btn-breadcrumb a:not(:last-child)').on('click', function() {
$(this).addClass('active'); $(this).addClass('active');
if ($(this).hasClass('back') || $(this).parent('.btn-breadcrumb').length) { if ($(this).hasClass('back') || $(this).parent('.btn-breadcrumb').length) {
@ -200,47 +206,40 @@
store.set('slide', 'to'); store.set('slide', 'to');
} }
}); });
// Paste <pre> helper }
c.prePaste();
// Run callback
callback();
// Force scrollTop on page load
$('html, body').scrollTop(0);
});
};
blockSize = $('#slider').width();
// Slide back effect
if (store.get('slide') == 'back') {
store.clear('slide');
$('#slideBack').css('display', 'none');
$('#slider-container').css('margin-left', '-100%');
$('#slideTo').show().html($('#main').html());
leSwap();
$('#slider-container').css('margin-left', '0px');
// Slide to effect
} else if (store.get('slide') == 'to') {
store.clear('slide');
$('#slideTo').css('display', 'none');
$('#slider-container').css('margin-left', '0px');
$('#slideBack').show().html($('#main').html());
leSwap();
$('#slider-container').css('margin-left', '-100%');
} else {
leSwap();
}
} else {
rendered.swap(function(){
// Paste <pre> helper // Paste <pre> helper
c.prePaste(); c.prePaste();
// Run callback // Run callback
callback(); callback();
// Force scrollTop on page load // Force scrollTop on page load
$('html, body').scrollTop(0); $('html, body').scrollTop(0);
}); });
};
// Slide back effect
if (enableSlide && store.get('slide') == 'back') {
store.clear('slide');
$('#slideBack').css('display', 'none');
$('#slider-container').css('margin-left', '-100%');
$('#slideTo').show().html($('#main').html());
leSwap();
$('#slider-container').css('margin-left', '0px');
}
// Slide to effect
else if (enableSlide && store.get('slide') == 'to') {
store.clear('slide');
$('#slideTo').css('display', 'none');
$('#slider-container').css('margin-left', '0px');
$('#slideBack').show().html($('#main').html());
leSwap();
$('#slider-container').css('margin-left', '-100%');
}
// No slideing effect
else {
leSwap();
} }
}, },