diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-05-22 18:19:50 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-05-22 18:19:50 +0300 |
commit | 74079fe2369c20767cb6c639eec1886c9822fefc (patch) | |
tree | 8435098f5b15ac5c15ce5cfa577c2eb3e6e66741 | |
parent | 9f80ab8e75181534cb21809258337f081beaf918 (diff) | |
download | gitlab-ce-74079fe2369c20767cb6c639eec1886c9822fefc.tar.gz |
Fix scroll to highlighted line. Replace scrollTO js file with gem
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
-rw-r--r-- | Gemfile | 1 | ||||
-rw-r--r-- | Gemfile.lock | 3 | ||||
-rw-r--r-- | app/assets/javascripts/application.js.coffee | 2 | ||||
-rw-r--r-- | app/assets/javascripts/blob.js.coffee | 2 | ||||
-rw-r--r-- | vendor/assets/javascripts/jquery.scrollto.js | 225 |
5 files changed, 6 insertions, 227 deletions
@@ -163,6 +163,7 @@ gem 'select2-rails' gem 'jquery-atwho-rails', "~> 0.3.3" gem "jquery-rails" gem "jquery-ui-rails" +gem "jquery-scrollto-rails" gem "raphael-rails", "~> 2.1.2" gem 'bootstrap-sass', '~> 3.0' gem "font-awesome-rails", '~> 3.2' diff --git a/Gemfile.lock b/Gemfile.lock index f5f31105e18..86c752505bd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -250,6 +250,8 @@ GEM jquery-rails (3.1.0) railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) + jquery-scrollto-rails (1.4.3) + railties (> 3.1, < 5.0) jquery-turbolinks (2.0.1) railties (>= 3.1.0) turbolinks @@ -607,6 +609,7 @@ DEPENDENCIES jasmine (= 2.0.0.rc5) jquery-atwho-rails (~> 0.3.3) jquery-rails + jquery-scrollto-rails jquery-turbolinks jquery-ui-rails kaminari (~> 0.15.1) diff --git a/app/assets/javascripts/application.js.coffee b/app/assets/javascripts/application.js.coffee index a22ff6dec31..587e51a7a83 100644 --- a/app/assets/javascripts/application.js.coffee +++ b/app/assets/javascripts/application.js.coffee @@ -13,7 +13,7 @@ #= require jquery.history #= require jquery.waitforimages #= require jquery.atwho -#= require jquery.scrollto +#= require jquery.scrollTo #= require jquery.blockUI #= require turbolinks #= require jquery.turbolinks diff --git a/app/assets/javascripts/blob.js.coffee b/app/assets/javascripts/blob.js.coffee index 584f6faea16..9db919e5a62 100644 --- a/app/assets/javascripts/blob.js.coffee +++ b/app/assets/javascripts/blob.js.coffee @@ -26,7 +26,7 @@ class BlobView unless isNaN first_line $("#tree-content-holder .highlight .line").removeClass("hll") $("#LC#{line}").addClass("hll") for line in [first_line..last_line] - $("#L#{first_line}").ScrollTo() unless e? + $.scrollTo("#L#{first_line}") unless e? # parse selected lines from hash # always return first and last line (initialized to NaN) diff --git a/vendor/assets/javascripts/jquery.scrollto.js b/vendor/assets/javascripts/jquery.scrollto.js deleted file mode 100644 index 7f10b7f1082..00000000000 --- a/vendor/assets/javascripts/jquery.scrollto.js +++ /dev/null @@ -1,225 +0,0 @@ -/** - * @depends jquery - * @name jquery.scrollto - * @package jquery-scrollto {@link http://balupton.com/projects/jquery-scrollto} - */ - -/** - * jQuery Aliaser - */ -(function(window,undefined){ - // Prepare - var jQuery, $, ScrollTo; - jQuery = $ = window.jQuery; - - /** - * jQuery ScrollTo (balupton edition) - * @version 1.2.0 - * @date July 9, 2012 - * @since 0.1.0, August 27, 2010 - * @package jquery-scrollto {@link http://balupton.com/projects/jquery-scrollto} - * @author Benjamin "balupton" Lupton {@link http://balupton.com} - * @copyright (c) 2010 Benjamin Arthur Lupton {@link http://balupton.com} - * @license MIT License {@link http://creativecommons.org/licenses/MIT/} - */ - ScrollTo = $.ScrollTo = $.ScrollTo || { - /** - * The Default Configuration - */ - config: { - duration: 400, - easing: 'swing', - callback: undefined, - durationMode: 'each', - offsetTop: 0, - offsetLeft: 0 - }, - - /** - * Configure ScrollTo - */ - configure: function(options){ - // Apply Options to Config - $.extend(ScrollTo.config, options||{}); - - // Chain - return this; - }, - - /** - * Perform the Scroll Animation for the Collections - * We use $inline here, so we can determine the actual offset start for each overflow:scroll item - * Each collection is for each overflow:scroll item - */ - scroll: function(collections, config){ - // Prepare - var collection, $container, container, $target, $inline, position, - containerScrollTop, containerScrollLeft, - containerScrollTopEnd, containerScrollLeftEnd, - startOffsetTop, targetOffsetTop, targetOffsetTopAdjusted, - startOffsetLeft, targetOffsetLeft, targetOffsetLeftAdjusted, - scrollOptions, - callback; - - // Determine the Scroll - collection = collections.pop(); - $container = collection.$container; - container = $container.get(0); - $target = collection.$target; - - // Prepare the Inline Element of the Container - $inline = $('<span/>').css({ - 'position': 'absolute', - 'top': '0px', - 'left': '0px' - }); - position = $container.css('position'); - - // Insert the Inline Element of the Container - $container.css('position','relative'); - $inline.appendTo($container); - - // Determine the top offset - startOffsetTop = $inline.offset().top; - targetOffsetTop = $target.offset().top; - targetOffsetTopAdjusted = targetOffsetTop - startOffsetTop - parseInt(config.offsetTop,10); - - // Determine the left offset - startOffsetLeft = $inline.offset().left; - targetOffsetLeft = $target.offset().left; - targetOffsetLeftAdjusted = targetOffsetLeft - startOffsetLeft - parseInt(config.offsetLeft,10); - - // Determine current scroll positions - containerScrollTop = container.scrollTop; - containerScrollLeft = container.scrollLeft; - - // Reset the Inline Element of the Container - $inline.remove(); - $container.css('position',position); - - // Prepare the scroll options - scrollOptions = {}; - - // Prepare the callback - callback = function(event){ - // Check - if ( collections.length === 0 ) { - // Callback - if ( typeof config.callback === 'function' ) { - config.callback.apply(this,[event]); - } - } - else { - // Recurse - ScrollTo.scroll(collections,config); - } - // Return true - return true; - }; - - // Handle if we only want to scroll if we are outside the viewport - if ( config.onlyIfOutside ) { - // Determine current scroll positions - containerScrollTopEnd = containerScrollTop + $container.height(); - containerScrollLeftEnd = containerScrollLeft + $container.width(); - - // Check if we are in the range of the visible area of the container - if ( containerScrollTop < targetOffsetTopAdjusted && targetOffsetTopAdjusted < containerScrollTopEnd ) { - targetOffsetTopAdjusted = containerScrollTop; - } - if ( containerScrollLeft < targetOffsetLeftAdjusted && targetOffsetLeftAdjusted < containerScrollLeftEnd ) { - targetOffsetLeftAdjusted = containerScrollLeft; - } - } - - // Determine the scroll options - if ( targetOffsetTopAdjusted !== containerScrollTop ) { - scrollOptions.scrollTop = targetOffsetTopAdjusted; - } - if ( targetOffsetLeftAdjusted !== containerScrollLeft ) { - scrollOptions.scrollLeft = targetOffsetLeftAdjusted; - } - - // Perform the scroll - if ( $.browser.safari && container === document.body ) { - window.scrollTo(scrollOptions.scrollLeft, scrollOptions.scrollTop); - callback(); - } - else if ( scrollOptions.scrollTop || scrollOptions.scrollLeft ) { - $container.animate(scrollOptions, config.duration, config.easing, callback); - } - else { - callback(); - } - - // Return true - return true; - }, - - /** - * ScrollTo the Element using the Options - */ - fn: function(options){ - // Prepare - var collections, config, $container, container; - collections = []; - - // Prepare - var $target = $(this); - if ( $target.length === 0 ) { - // Chain - return this; - } - - // Handle Options - config = $.extend({},ScrollTo.config,options); - - // Fetch - $container = $target.parent(); - container = $container.get(0); - - // Cycle through the containers - while ( ($container.length === 1) && (container !== document.body) && (container !== document) ) { - // Check Container for scroll differences - var scrollTop, scrollLeft; - scrollTop = $container.css('overflow-y') !== 'visible' && container.scrollHeight !== container.clientHeight; - scrollLeft = $container.css('overflow-x') !== 'visible' && container.scrollWidth !== container.clientWidth; - if ( scrollTop || scrollLeft ) { - // Push the Collection - collections.push({ - '$container': $container, - '$target': $target - }); - // Update the Target - $target = $container; - } - // Update the Container - $container = $container.parent(); - container = $container.get(0); - } - - // Add the final collection - collections.push({ - '$container': $( - ($.browser.msie || $.browser.mozilla) ? 'html' : 'body' - ), - '$target': $target - }); - - // Adjust the Config - if ( config.durationMode === 'all' ) { - config.duration /= collections.length; - } - - // Handle - ScrollTo.scroll(collections,config); - - // Chain - return this; - } - }; - - // Apply our jQuery Prototype Function - $.fn.ScrollTo = $.ScrollTo.fn; - -})(window); |