From 35146cbd419b1d31450bebe3457400a67e9eca86 Mon Sep 17 00:00:00 2001 From: opi Date: Mon, 23 May 2016 21:15:06 +0200 Subject: [PATCH] [enh] Cleanup app view() helper. --- src/js/yunohost/helpers.js | 75 +++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/src/js/yunohost/helpers.js b/src/js/yunohost/helpers.js index e7a2f38a..b4279360 100644 --- a/src/js/yunohost/helpers.js +++ b/src/js/yunohost/helpers.js @@ -180,18 +180,24 @@ view: function (view, data, callback, enableSlide) { c = this; + // Default 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 loaded = true; + + // Hide loader and modal $('div.loader').remove(); $('#modal').modal('hide'); - if (enableSlide) { - var leSwap = function() { - rendered.swap(function() { + // Render content + rendered = this.render('views/'+ view +'.ms', data); + + // Update content helper + var leSwap = function() { + rendered.swap(function() { + // Slide direction + if (enableSlide) { $('.slide, .btn-breadcrumb a:not(:last-child)').on('click', function() { $(this).addClass('active'); if ($(this).hasClass('back') || $(this).parent('.btn-breadcrumb').length) { @@ -200,47 +206,40 @@ store.set('slide', 'to'); } }); - // Paste
 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 
 helper
                     c.prePaste();
+
                     // Run callback
                     callback();
+
                     // Force scrollTop on page load
                     $('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();
             }
         },