/** * @author Jyri Annunen * http://www.infokartta.fi * * Released under the GNU GENERAL PUBLIC LICENSE Version 2 */ (function($){ var barWidth = 9; var methods = { _init: function() { return this.each(function() { var $this = $(this); var data = $this.data("buttonscroller"); if ($this.children(".buttonscroller-container").length == 0) { // Initialize the scrollbarPaper. $this.css({overflow: "hidden"}); var content = $this.html(); var cWidth = $this.width(); $this.append("
"); var up_button = $this.find(".buttonscroller-up_button"); up_button.css({position: "absolute", height: "49%", width: barWidth+"px", top: "0px", right: "4px", border: "2px solid grey", "z-index": "99999", "border-top-left-radius": "10px 10px", "border-top-right-radius": "10px 10px", background: "transparent url('https://kartta.jict.fi/infogis-pvp/style/img/scrollbutton_up.png') no-repeat center center"}); var down_button = $this.find(".buttonscroller-down_button"); down_button.css({position: "absolute", height: "49%", width: barWidth+"px", top: "49%", right: "4px", border: "2px solid grey", "z-index": "99999", "border-bottom-left-radius": "10px 10px", "border-bottom-right-radius": "10px 10px", background: "transparent url('https://kartta.jict.fi/infogis-pvp/style/img/scrollbutton_down.png') no-repeat center center"}); var container = $this.children(".buttonscroller-container"); container.css({height: $this.height()+"px",width: (barWidth+4)+"px", "top": "0px", "right": "0px", position: "absolute"}); $this.moveUp = function(longPress) { var mtop = parseInt($this.children().eq(0).css("margin-top")); var allH = 0; $this.children().not(".buttonscroller-container").each(function() { allH += $(this).height(); }); var step = longPress? 20:10; if(mtop*-1 < allH-30)$this.children().eq(0).css({"margin-top": (mtop-step)}); if($this.pressed) { $this.pressedTimerId = window.setTimeout( OpenLayers.Function.bind($this.moveUp, this, true), 200 ); } }; $this.moveDown = function(longPress) { var mtop = parseInt($this.children().eq(0).css("margin-top")); var step = longPress? 20:10; if(mtop < 0)$this.children().eq(0).css({"margin-top": (mtop+step)}); if(mtop > 0)$this.children().eq(0).css({"margin-top": 0}); if($this.pressed) { $this.pressedTimerId = window.setTimeout( OpenLayers.Function.bind($this.moveDown, this, true), 200 ); } }; down_button.bind("touchstart touchend mousedown", function(){$this.pressed = true;$this.moveUp(false); return false;}); up_button.bind("touchstart touchend mousedown", function(){$this.pressed = true;$this.moveDown(false); return false;}); down_button.bind("touchend mouseup", function(){$this.pressed = false; window.clearTimeout($this.pressedTimerId); $this.pressedTimerId = null; return false;}); up_button.bind("touchend mouseup", function(){$this.pressed = false; window.clearTimeout($this.pressedTimerId); $this.pressedTimerId = null; return false;}); container.bind("touchstart touchend mousedown touchend mouseup", function(){return false;}); $this.data("buttonscroller", { up_button: up_button, down_button: down_button, container: container }); } else { $this.buttonscroller('update'); } }); }, update: function() { this.each(function() { $(this).children(".buttonscroller-container").css({height: $(this).height()+"px"}); }); } }; $.fn.buttonscroller = function(method) { if (methods[method]) { return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); } else if (typeof method === "object" || !method) { return methods._init.apply(this, arguments); } else { throw "Method " + method + " does not exist on jQuery.buttonScroller."; } }; })(jQuery);