Kaynağa Gözat

Evolution #741: Sticked column

Sevajol Bastien 11 yıl önce
ebeveyn
işleme
3aeb749581

+ 27 - 7
src/Muzich/CoreBundle/Resources/public/css/main.css Dosyayı Görüntüle

@@ -237,6 +237,33 @@ div#languages:hover
237 237
   display: table-cell;
238 238
   width: 650px;
239 239
   padding-right: 30px;
240
+  float: left;
241
+  position: relative;
242
+}
243
+
244
+aside#sidebar
245
+{
246
+  display: table-cell;
247
+/*  vertical-align: top;*/
248
+  float: left;
249
+  position: relative;
250
+}
251
+
252
+aside#sidebar .sidebar
253
+{
254
+  width: 300px;
255
+/* height: 800px;
256
+ background-color: blue;*/
257
+}
258
+
259
+.top-fixed {
260
+    position: fixed;
261
+    top: 0;
262
+}
263
+
264
+.bottom-fixed {
265
+    position:fixed;
266
+    bottom: 0;
240 267
 }
241 268
 
242 269
 #mainbox
@@ -274,13 +301,6 @@ div#languages:hover
274 301
   border: 1px solid #d3d3d3;
275 302
 }
276 303
 
277
-aside#sidebar
278
-{
279
-  display: table-cell;
280
-  width: 300px;
281
-  vertical-align: top;
282
-}
283
-
284 304
 ul.elements
285 305
 {
286 306
   margin-top: 0px;

+ 17 - 0
src/Muzich/CoreBundle/Resources/public/js/muzich.js Dosyayı Görüntüle

@@ -3268,6 +3268,23 @@ $(document).ready(function(){
3268 3268
      $('div.playlists_prompt').remove();
3269 3269
      return false;
3270 3270
   });
3271
+  
3272
+  /*
3273
+   * STICK SIDEBAR
3274
+   */
3275
+  
3276
+  if ($('#sidebar .sidebar').height() < $('#content .content').height() &&
3277
+    $('#sidebar .sidebar').height() > $(window).height())
3278
+  {
3279
+    $('#content').stickySidebar();
3280
+  }
3281
+  else
3282
+  {
3283
+    $('#sidebar .sidebar').css('padding-bottom', '155px');
3284
+    $("#sidebar .sidebar").sticky({topSpacing:0});
3285
+  }
3286
+  
3287
+  
3271 3288
    
3272 3289
 });
3273 3290
 

+ 2 - 0
src/Muzich/CoreBundle/Resources/views/Layout/head_js.html.twig Dosyayı Görüntüle

@@ -8,6 +8,8 @@
8 8
   'js/jConfirmAction/jconfirmaction.jquery.js'
9 9
   'js/jquery.scrollTo.min.js'
10 10
   'js/jquery.aSimpleTour.js'
11
+  'js/jquery.stickysidebar.js'
12
+  'js/jquery.sticky.js'
11 13
   '@MuzichCoreBundle/Resources/public/js/TagPrompt.js'
12 14
   '@MuzichCoreBundle/Resources/public/js/player/*'
13 15
   '@MuzichCoreBundle/Resources/public/js/play2.js'

+ 3 - 2
src/Muzich/CoreBundle/Resources/views/Layout/side.html.twig Dosyayı Görüntüle

@@ -22,10 +22,11 @@
22 22
   {% endif %}
23 23
 
24 24
 {% else %}
25
-
26
-  <div class="side_margin_top"></div>
27 25
   
28 26
   {% if display_help %}
27
+    
28
+    <div class="side_margin_top"></div>
29
+    
29 30
     <div class="center">
30 31
       <a id="know_more" class="helpbox button" href="{{ path('helpbox_bootstrap', {'ressource_id':'know_more'}) }}" title="{{ 'help.know_more'|trans({}, 'navigationui') }}">
31 32
         {{ 'help.know_more'|trans({}, 'navigationui') }}

+ 6 - 4
src/Muzich/CoreBundle/Resources/views/layout.html.twig Dosyayı Görüntüle

@@ -28,7 +28,7 @@
28 28
       
29 29
       <div id="content">
30 30
         
31
-        <div id="main">
31
+        <div id="main" class="content">
32 32
           
33 33
           <div id="mainbox" class="nicebox {% block mainbox_classes %}{% endblock %}">
34 34
             {% block main_content %}{% endblock %}
@@ -38,9 +38,11 @@
38 38
         </div>
39 39
           
40 40
         <aside id="sidebar">
41
-          {% block sidebar_top %}{% endblock %}
42
-          {% include 'MuzichCoreBundle:Layout:side.html.twig' %}
43
-          {% block sidebar_bottom %}{% endblock %}
41
+          <div class="sidebar">
42
+            {% block sidebar_top %}{% endblock %}
43
+            {% include 'MuzichCoreBundle:Layout:side.html.twig' %}
44
+            {% block sidebar_bottom %}{% endblock %}
45
+          </div>
44 46
         </aside>
45 47
           
46 48
       </div>

+ 129 - 0
web/js/jquery.sticky.js Dosyayı Görüntüle

@@ -0,0 +1,129 @@
1
+// Sticky Plugin v1.0.0 for jQuery
2
+// =============
3
+// Author: Anthony Garand
4
+// Improvements by German M. Bravo (Kronuz) and Ruud Kamphuis (ruudk)
5
+// Improvements by Leonardo C. Daronco (daronco)
6
+// Created: 2/14/2011
7
+// Date: 2/12/2012
8
+// Website: http://labs.anthonygarand.com/sticky
9
+// Description: Makes an element on the page stick on the screen as you scroll
10
+//       It will only set the 'top' and 'position' of your element, you
11
+//       might need to adjust the width in some cases.
12
+
13
+(function($) {
14
+  var defaults = {
15
+      topSpacing: 0,
16
+      bottomSpacing: 0,
17
+      className: 'is-sticky',
18
+      wrapperClassName: 'sticky-wrapper',
19
+      center: false,
20
+      getWidthFrom: ''
21
+    },
22
+    $window = $(window),
23
+    $document = $(document),
24
+    sticked = [],
25
+    windowHeight = $window.height(),
26
+    scroller = function() {
27
+      var scrollTop = $window.scrollTop(),
28
+        documentHeight = $document.height(),
29
+        dwh = documentHeight - windowHeight,
30
+        extra = (scrollTop > dwh) ? dwh - scrollTop : 0;
31
+
32
+      for (var i = 0; i < sticked.length; i++) {
33
+        var s = sticked[i],
34
+          elementTop = s.stickyWrapper.offset().top,
35
+          etse = elementTop - s.topSpacing - extra;
36
+
37
+        if (scrollTop <= etse) {
38
+          if (s.currentTop !== null) {
39
+            s.stickyElement
40
+              .css('position', '')
41
+              .css('top', '');
42
+            s.stickyElement.parent().removeClass(s.className);
43
+            s.currentTop = null;
44
+          }
45
+        }
46
+        else {
47
+          var newTop = documentHeight - s.stickyElement.outerHeight()
48
+            - s.topSpacing - s.bottomSpacing - scrollTop - extra;
49
+          if (newTop < 0) {
50
+            newTop = newTop + s.topSpacing;
51
+          } else {
52
+            newTop = s.topSpacing;
53
+          }
54
+          if (s.currentTop != newTop) {
55
+            s.stickyElement
56
+              .css('position', 'fixed')
57
+              .css('top', newTop);
58
+
59
+            if (typeof s.getWidthFrom !== 'undefined') {
60
+              s.stickyElement.css('width', $(s.getWidthFrom).width());
61
+            }
62
+
63
+            s.stickyElement.parent().addClass(s.className);
64
+            s.currentTop = newTop;
65
+          }
66
+        }
67
+      }
68
+    },
69
+    resizer = function() {
70
+      windowHeight = $window.height();
71
+    },
72
+    methods = {
73
+      init: function(options) {
74
+        var o = $.extend(defaults, options);
75
+        return this.each(function() {
76
+          var stickyElement = $(this);
77
+
78
+          var stickyId = stickyElement.attr('id');
79
+          var wrapper = $('<div></div>')
80
+            .attr('id', stickyId + '-sticky-wrapper')
81
+            .addClass(o.wrapperClassName);
82
+          stickyElement.wrapAll(wrapper);
83
+
84
+          if (o.center) {
85
+            stickyElement.parent().css({width:stickyElement.outerWidth(),marginLeft:"auto",marginRight:"auto"});
86
+          }
87
+
88
+          if (stickyElement.css("float") == "right") {
89
+            stickyElement.css({"float":"none"}).parent().css({"float":"right"});
90
+          }
91
+
92
+          var stickyWrapper = stickyElement.parent();
93
+          stickyWrapper.css('height', stickyElement.outerHeight());
94
+          sticked.push({
95
+            topSpacing: o.topSpacing,
96
+            bottomSpacing: o.bottomSpacing,
97
+            stickyElement: stickyElement,
98
+            currentTop: null,
99
+            stickyWrapper: stickyWrapper,
100
+            className: o.className,
101
+            getWidthFrom: o.getWidthFrom
102
+          });
103
+        });
104
+      },
105
+      update: scroller
106
+    };
107
+
108
+  // should be more efficient than using $window.scroll(scroller) and $window.resize(resizer):
109
+  if (window.addEventListener) {
110
+    window.addEventListener('scroll', scroller, false);
111
+    window.addEventListener('resize', resizer, false);
112
+  } else if (window.attachEvent) {
113
+    window.attachEvent('onscroll', scroller);
114
+    window.attachEvent('onresize', resizer);
115
+  }
116
+
117
+  $.fn.sticky = function(method) {
118
+    if (methods[method]) {
119
+      return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
120
+    } else if (typeof method === 'object' || !method ) {
121
+      return methods.init.apply( this, arguments );
122
+    } else {
123
+      $.error('Method ' + method + ' does not exist on jQuery.sticky');
124
+    }
125
+  };
126
+  $(function() {
127
+    setTimeout(scroller, 0);
128
+  });
129
+})(jQuery);

+ 153 - 0
web/js/jquery.stickysidebar.js Dosyayı Görüntüle

@@ -0,0 +1,153 @@
1
+/*jslint browser:true */
2
+/*global jQuery*/
3
+
4
+(function ($, window, undefined) {
5
+    'use strict';
6
+
7
+    var pluginName = 'stickySidebar',
8
+        document = window.document,
9
+        defaults = {
10
+            sidebar: '.sidebar',
11
+            content: '.content',
12
+            tolerance: 110
13
+        },
14
+        clearPosition = {
15
+            position: '',
16
+            top: ''
17
+        };
18
+
19
+    function Plugin(element, options) {
20
+        this.options = $.extend({}, defaults, options);
21
+
22
+        this.defaults = defaults;
23
+        this.name = pluginName;
24
+
25
+        this.root = $(element);
26
+
27
+        this.init();
28
+    }
29
+
30
+    Plugin.prototype.init = function () {
31
+        var self = this;
32
+
33
+        this.sidebar = this.root.find(this.options.sidebar);
34
+        this.content = this.root.find(this.options.content);
35
+        this.lastScrollTop = 0;
36
+
37
+        if (this.canBeSticky() === true) {
38
+            $(window).bind('scroll.sticky_sidebar', function () {
39
+                self.setScrollDirection()
40
+                    .setBoundaries()
41
+                    .positionSidebar();
42
+            });
43
+        }
44
+    };
45
+
46
+    Plugin.prototype.canBeSticky = function () {
47
+        return this.sidebar.height() < this.content.height() &&
48
+               this.sidebar.height() > $(window).height();
49
+    };
50
+
51
+    Plugin.prototype.setBoundaries = function () {
52
+        var contentTop = this.content.offset().top,
53
+            contentHeight = this.content.outerHeight();
54
+        this.boundaries = {
55
+            contentTop: contentTop,
56
+            contentBottom: contentTop + contentHeight,
57
+            contentHeight: contentHeight,
58
+            sidebarHeight: this.sidebar.outerHeight(),
59
+            windowHeight: $(window).height()
60
+        };
61
+        return this;
62
+    };
63
+
64
+    Plugin.prototype.positionSidebar = function () {
65
+        if (this.lastScrollTop > this.boundaries.contentTop &&
66
+                this.lastScrollTop < this.boundaries.contentBottom) {
67
+            this[this.scrollDirection === 'DOWN' ? 'scrollDown' : 'scrollUp']();
68
+        } else if (this.lastScrollTop < this.boundaries.contentTop) {
69
+            this.sidebar.css('top', '').removeClass('top-fixed');
70
+        }
71
+        return this;
72
+    };
73
+
74
+    Plugin.prototype.scrollDown = function () {
75
+        var windowScroll = this.lastScrollTop + this.boundaries.windowHeight,
76
+            sidebarOffsetTop;
77
+        if (this.sidebar.hasClass('scrolling-up')) {
78
+            this.sidebar.removeClass('scrolling-up')
79
+                .addClass('scrolling-down');
80
+        } else if (this.sidebar.hasClass('top-fixed')) {
81
+            sidebarOffsetTop = this.sidebar.offset().top - this.boundaries.contentTop;
82
+            this.sidebar.removeClass('top-fixed')
83
+                .css({
84
+                    position: 'absolute',
85
+                    top: sidebarOffsetTop
86
+                })
87
+                .addClass('scrolling-down');
88
+        }
89
+        if (this.sidebar.hasClass('scrolling-down')) {
90
+            if (windowScroll > this.sidebar.offset().top + this.boundaries.sidebarHeight) {
91
+                this.sidebar.css(clearPosition)
92
+                            .addClass('bottom-fixed')
93
+                            .removeClass('scrolling-down');
94
+            }
95
+        } else {
96
+            if (windowScroll > this.boundaries.contentBottom) {
97
+                this.sidebar.removeClass('bottom-fixed').css({
98
+                    position: 'absolute',
99
+                    top: this.boundaries.contentHeight - this.boundaries.sidebarHeight
100
+                });
101
+            } else if (windowScroll + this.options.tolerance >
102
+                       this.boundaries.sidebarHeight + this.boundaries.contentTop) {
103
+                this.sidebar.css(clearPosition)
104
+                            .removeClass('top-fixed')
105
+                            .addClass('bottom-fixed');
106
+            }
107
+        }
108
+    };
109
+
110
+    Plugin.prototype.scrollUp = function () {
111
+        if (this.sidebar.hasClass('scrolling-down')) {
112
+            this.sidebar.removeClass('scrolling-down')
113
+                        .addClass('scrolling-up');
114
+        } else if (this.sidebar.hasClass('bottom-fixed')) {
115
+            this.sidebar.css({
116
+                position: 'absolute',
117
+                top: this.sidebar.offset().top - this.boundaries.contentTop
118
+            }).removeClass('bottom-fixed').addClass('scrolling-up');
119
+        }
120
+        if (this.sidebar.hasClass('scrolling-up')) {
121
+            if (this.lastScrollTop < this.sidebar.offset().top) {
122
+                this.sidebar.css(clearPosition)
123
+                            .addClass('top-fixed')
124
+                            .removeClass('scrolling-up');
125
+            }
126
+        } else {
127
+            if (this.lastScrollTop < this.boundaries.contentTop) {
128
+                this.sidebar.css('position', '').removeClass('top-fixed');
129
+            } else if (this.lastScrollTop - this.options.tolerance <
130
+                       this.boundaries.contentBottom - this.boundaries.sidebarHeight) {
131
+                this.sidebar.css(clearPosition)
132
+                            .removeClass('bottom-fixed')
133
+                            .addClass('top-fixed');
134
+            }
135
+        }
136
+    };
137
+
138
+    Plugin.prototype.setScrollDirection = function () {
139
+        var scrollTop = $(window).scrollTop();
140
+        this.scrollDirection = (scrollTop > this.lastScrollTop ? 'DOWN' : 'UP');
141
+        this.lastScrollTop = scrollTop;
142
+        return this;
143
+    };
144
+
145
+    $.fn[pluginName] = function (options) {
146
+        return this.each(function () {
147
+            if (!$.data(this, 'plugin_' + pluginName)) {
148
+                $.data(this, 'plugin_' + pluginName, new Plugin(this, options));
149
+            }
150
+        });
151
+    };
152
+
153
+}(jQuery, window));