Pārlūkot izejas kodu

Refactor <scroll> element to .scrollable class

It's a win!!! :)
@soyjavi 14 gadi atpakaļ
vecāks
revīzija
bd68629ee5
2 mainītis faili ar 31 papildinājumiem un 9 dzēšanām
  1. 1 1
      src/boot/Lungo.Boot.Article.js
  2. 30 8
      src/view/Lungo.View.Scroll.js

+ 1 - 1
src/boot/Lungo.Boot.Article.js

@@ -13,7 +13,7 @@ LUNGO.Boot.Article = (function(lng, undefined) {
 
     var SELECTORS = {
         LIST_IN_ARTICLE: 'article.list',
-        SCROLL_IN_ARTICLE: 'scroll',
+        SCROLL_IN_ARTICLE: '.scrollable',
         CHECKBOX_IN_ARTICLE: '.checkbox, .radio'
     };
 

+ 30 - 8
src/view/Lungo.View.Scroll.js

@@ -1,6 +1,6 @@
-/** 
+/**
  * Wrapper of the third library iScroll
- * 
+ *
  * @namespace LUNGO.View
  * @class Scroll
  * @requires Zepto
@@ -27,6 +27,8 @@ LUNGO.View.Scroll = (function(lng, undefined) {
 
     var CACHE_KEY = 'scrolls';
 
+    var HEADER_FOOTER_BLEEDING = 90;
+
     /**
      * Creates a new iScroll element.
      *
@@ -38,13 +40,15 @@ LUNGO.View.Scroll = (function(lng, undefined) {
     var create = function(id, properties) {
         if (id) {
             var scroll = lng.Dom.query('#' + id);
-            var scroll_children = scroll.children();
-            var need_scroll = (scroll_children.height() >= scroll.height());
 
-            if (scroll_children.length > 0 && need_scroll) {
-                properties = _mixProperties(scroll, properties);
-                _saveScrollInCache(id, properties);
-            }
+            //ToDo >> Refactor
+            setTimeout(function() {
+                if (_needScroll(scroll)) {
+                    properties = _mixProperties(scroll, properties);
+                    _saveScrollInCache(id, properties);
+                }
+            }, 100);
+
         } else {
             lng.Core.log(3, 'ERROR: Impossible to create a <scroll> without ID');
         }
@@ -97,6 +101,24 @@ LUNGO.View.Scroll = (function(lng, undefined) {
         return (scroll.hasClass(HORIZONTAL_CLASS)) ? true : false;
     };
 
+    var _needScroll = function(scroll) {
+        var is_necessary = false;
+
+        var element = scroll[0];
+        if (element.clientHeight < element.scrollHeight) {
+            is_necessary = true;
+            var child_height = element.scrollHeight + HEADER_FOOTER_BLEEDING;
+            _resizeChildContainer(element, child_height);
+        }
+
+        return is_necessary;
+    };
+
+    var _resizeChildContainer = function(element, height) {
+        var child_container = lng.Dom.query(element).children().first();
+        child_container.css('height', height + 'px');
+    };
+
     var _saveScrollInCache = function(id, properties) {
         _createScrollIndexInCache();