From: zuber Date: Tue, 18 Aug 2009 10:50:57 +0000 (+0200) Subject: Dodanie możliwości włączania i wyłączania automatycznego przewijania. X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/0beb0bf8e1f061894f48523e5d134c6b923f4c32?ds=sidebyside;hp=3ed251508dd18e0afc8f62bd18802e2e1c72737c Dodanie możliwości włączania i wyłączania automatycznego przewijania. --- diff --git a/project/static/js/jquery.autoscroll.js b/project/static/js/jquery.autoscroll.js index c342bdf5..f8c07fbd 100644 --- a/project/static/js/jquery.autoscroll.js +++ b/project/static/js/jquery.autoscroll.js @@ -1,6 +1,7 @@ (function($) { $.fn.autoscroll = function(synchronizeWith, options) { - var self = $(this); + var $this = $(this); + var self = $this; var selfContainer = self.parent(); var synchronizeWith = $(synchronizeWith); var synchronizeWithContainer = synchronizeWith.parent(); @@ -17,15 +18,30 @@ synchronizeWithContainer = $('body', eventContainer); synchronizeWith = synchronizeWithContainer; } - - synchronizeWithContainer.data('autoscroll.lastCheckedScrollTop', synchronizeWithContainer.scrollTop()); + + $this.data('autoscroll:enabled', true); + synchronizeWithContainer.data('autoscroll:lastCheckedScrollTop', synchronizeWithContainer.scrollTop()); eventContainer.scroll(function() { - var distanceScrolled = synchronizeWithContainer.scrollTop() - synchronizeWithContainer.data('autoscroll:lastCheckedScrollTop'); - var percentScrolled = distanceScrolled / synchronizeWith.height(); - selfContainer.scrollTop(selfContainer.scrollTop() + percentScrolled * self.height()); + if ($this.data('autoscroll:enabled')) { + var distanceScrolled = synchronizeWithContainer.scrollTop() - synchronizeWithContainer.data('autoscroll:lastCheckedScrollTop'); + var percentScrolled = distanceScrolled / synchronizeWith.height(); + selfContainer.scrollTop(selfContainer.scrollTop() + percentScrolled * self.height()); + } synchronizeWithContainer.data('autoscroll:lastCheckedScrollTop', synchronizeWithContainer.scrollTop()); }); - }; + }, + + $.fn.enableAutoscroll = function() { + $(this).data('autoscroll:enabled', true); + }, + + $.fn.disableAutoscroll = function() { + $(this).data('autoscroll:enabled', false); + }, + + $.fn.toggleAutoscroll = function() { + $(this).data('autoscroll:enabled', !$(this).data('autoscroll:enabled')); + } })(jQuery); diff --git a/project/templates/explorer/file_xml.html b/project/templates/explorer/file_xml.html index 5bad3c4a..e9cd85c0 100644 --- a/project/templates/explorer/file_xml.html +++ b/project/templates/explorer/file_xml.html @@ -50,7 +50,13 @@ $('iframe').load(function() { $('#images').autoscroll('iframe'); - + $('.toggleAutoscroll').toggle(function() { + $(this).html('Synchronizuj przewijanie'); + $('#images').disableAutoscroll(); + }, function() { + $(this).html('Nie synchronizuj przewijania'); + $('#images').enableAutoscroll(); + }) setTimeout(function() {resizePanels();}, 10); }) @@ -84,7 +90,12 @@
{{ form.user.errors }} {{ form.commit_message.errors }} -

Użytkownik: {{ form.user }} Opis zmian: {{ form.commit_message }}

+

+ Użytkownik: {{ form.user }} + Opis zmian: {{ form.commit_message }} + + Nie synchronizuj przewijania +

{% endblock maincontent %}