[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
rendered = this.render('views/'+ view +'.ms', data);
// Update content helper
var leSwap = function() { var leSwap = function() {
rendered.swap(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 // 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);
}); });
}; };
blockSize = $('#slider').width();
// Slide back effect // Slide back effect
if (store.get('slide') == 'back') { if (enableSlide && store.get('slide') == 'back') {
store.clear('slide'); store.clear('slide');
$('#slideBack').css('display', 'none'); $('#slideBack').css('display', 'none');
$('#slider-container').css('margin-left', '-100%'); $('#slider-container').css('margin-left', '-100%');
$('#slideTo').show().html($('#main').html()); $('#slideTo').show().html($('#main').html());
leSwap(); leSwap();
$('#slider-container').css('margin-left', '0px'); $('#slider-container').css('margin-left', '0px');
}
// Slide to effect // Slide to effect
} else if (store.get('slide') == 'to') { else if (enableSlide && store.get('slide') == 'to') {
store.clear('slide'); store.clear('slide');
$('#slideTo').css('display', 'none'); $('#slideTo').css('display', 'none');
$('#slider-container').css('margin-left', '0px'); $('#slider-container').css('margin-left', '0px');
$('#slideBack').show().html($('#main').html()); $('#slideBack').show().html($('#main').html());
leSwap(); leSwap();
$('#slider-container').css('margin-left', '-100%'); $('#slider-container').css('margin-left', '-100%');
} else {
leSwap();
} }
} else { // No slideing effect
rendered.swap(function(){ else {
// Paste <pre> helper leSwap();
c.prePaste();
// Run callback
callback();
// Force scrollTop on page load
$('html, body').scrollTop(0);
});
} }
}, },