diff --git a/app/assets/javascripts/closet_hangers/index.js b/app/assets/javascripts/closet_hangers/index.js index 065288fe..02f81ae1 100644 --- a/app/assets/javascripts/closet_hangers/index.js +++ b/app/assets/javascripts/closet_hangers/index.js @@ -440,6 +440,13 @@ updateBulkActions(); }); + // hahaha, nasty hacks to make stickUp use our old jQuery + $.fn.on = $.fn.bind; + + $(function() { + $('.bulk-actions').stickUp(); + }); + function maintainCheckboxes(fn) { var checkedIds = getCheckedIds(); diff --git a/app/assets/javascripts/stickUp.min.js b/app/assets/javascripts/stickUp.min.js new file mode 100644 index 00000000..88dc671e --- /dev/null +++ b/app/assets/javascripts/stickUp.min.js @@ -0,0 +1 @@ +jQuery(function($){$(document).ready(function(){var contentButton = [];var contentTop = [];var content = [];var lastScrollTop = 0;var scrollDir = '';var itemClass = '';var itemHover = '';var menuSize = null;var stickyHeight = 0;var stickyMarginB = 0;var currentMarginT = 0;var topMargin = 0;$(window).scroll(function(event){var st = $(this).scrollTop();if (st > lastScrollTop){scrollDir = 'down';} else {scrollDir = 'up';}lastScrollTop = st;});$.fn.stickUp = function( options ) {$(this).addClass('stuckMenu');var objn = 0;if(options != null) {for(var o in options.parts) {if (options.parts.hasOwnProperty(o)){content[objn] = options.parts[objn];objn++;}}if(objn == 0) {console.log('error:needs arguments');}itemClass = options.itemClass;itemHover = options.itemHover;if(options.topMargin != null) {if(options.topMargin == 'auto') {topMargin = parseInt($('.stuckMenu').css('margin-top'));} else {if(isNaN(options.topMargin) && options.topMargin.search("px") > 0){topMargin = parseInt(options.topMargin.replace("px",""));} else if(!isNaN(parseInt(options.topMargin))) {topMargin = parseInt(options.topMargin);} else {console.log("incorrect argument, ignored.");topMargin = 0;} }} else {topMargin = 0;}menuSize = $('.'+itemClass).size();}stickyHeight = parseInt($(this).height());stickyMarginB = parseInt($(this).css('margin-bottom'));currentMarginT = parseInt($(this).next().closest('div').css('margin-top'));vartop = parseInt($(this).offset().top);};$(document).on('scroll', function() {varscroll = parseInt($(document).scrollTop());if(menuSize != null){for(var i=0;i < menuSize;i++){contentTop[i] = $('#'+content[i]+'').offset().top;function bottomView(i) {contentView = $('#'+content[i]+'').height()*.4;testView = contentTop[i] - contentView;if(varscroll > testView){$('.'+itemClass).removeClass(itemHover);$('.'+itemClass+':eq('+i+')').addClass(itemHover);} else if(varscroll < 50){$('.'+itemClass).removeClass(itemHover);$('.'+itemClass+':eq(0)').addClass(itemHover);}}if(scrollDir == 'down' && varscroll > contentTop[i]-50 && varscroll < contentTop[i]+50) {$('.'+itemClass).removeClass(itemHover);$('.'+itemClass+':eq('+i+')').addClass(itemHover);}if(scrollDir == 'up') {bottomView(i);}}}if(vartop < varscroll + topMargin){$('.stuckMenu').addClass('isStuck');$('.stuckMenu').next().closest('div').css({'margin-top': stickyHeight + stickyMarginB + currentMarginT + 'px'}, 10);$('.stuckMenu').css("position","fixed");$('.isStuck').css({top: '0px'}, 10, function(){});};if(varscroll + topMargin < vartop){$('.stuckMenu').removeClass('isStuck');$('.stuckMenu').next().closest('div').css({'margin-top': currentMarginT + 'px'}, 10);$('.stuckMenu').css("position","relative");};});});}); \ No newline at end of file diff --git a/app/assets/stylesheets/closet_hangers/_index.sass b/app/assets/stylesheets/closet_hangers/_index.sass index b9f5f42b..5e0c516a 100644 --- a/app/assets/stylesheets/closet_hangers/_index.sass +++ b/app/assets/stylesheets/closet_hangers/_index.sass @@ -88,7 +88,6 @@ body.closet_hangers-index .bulk-actions display: none - text-align: center #closet-hangers clear: both @@ -372,10 +371,19 @@ body.closet_hangers-index content: "…" .bulk-actions + background: $background-color border-top: 1px solid $module-border-color + box-sizing: border-box display: block font-size: 85% padding: .5em 1em + text-align: center + width: $container-width + + &.isStuck + border-bottom: 1px solid $module-border-color + border-top: 0 + z-index: 11 /* beat the visibility form */ .bulk-actions-intro, .bulk-actions-target-desc-singular display: none diff --git a/app/views/closet_hangers/index.html.haml b/app/views/closet_hangers/index.html.haml index cbc2c96d..39b9b0cf 100644 --- a/app/views/closet_hangers/index.html.haml +++ b/app/views/closet_hangers/index.html.haml @@ -155,4 +155,4 @@ - content_for :javascripts do = include_javascript_libraries :jquery, :jquery_tmpl = javascript_include_tag 'ajax_auth', 'jquery.ui', 'jquery.jgrowl', - 'placeholder', 'closet_hangers/index' \ No newline at end of file + 'placeholder', 'stickUp.min', 'closet_hangers/index' \ No newline at end of file