Skip to content

Commit

Permalink
- oprava chyby scrollTo extension, kdy:
Browse files Browse the repository at this point in the history
  - nebylo možno nastavit přes data atribut offset na 0
  - došlo k JS chybě, pokud nebyl `settings.nette.el`
  • Loading branch information
zipper committed May 15, 2018
1 parent 8f26038 commit ffe36e6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ Vlastní extensions pro nette.ajax

## Changelog

### 1.2.3
- oprava chyby `scrollTo` extension, kdy:
- nebylo možno nastavit přes data atribut offset na 0
- došlo k JS chybě, pokud nebyl `settings.nette.el`

### 1.2.2
- extension `scrollTo` je přepsané pro lepší použití uvnitř otevřeného pdboxu a je více modifikovatelné:
- přidán nastavení pro scroll offset (výchozí hodnota je 0):
Expand Down
23 changes: 14 additions & 9 deletions extensions/scrollTo.ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,33 @@
duration: 400,
defaultEvent: 'before',
checkScroll: function (settings, event) {
var scrollEvent = $(settings.nette.el).data('scrollToEvent');
if (scrollEvent === event || (! scrollEvent && event === this.defaultEvent)) {
this.doScroll(settings);
if ('nette' in settings && settings.nette.el) {
var $clickedEl = $(settings.nette.el);
var scrollEvent = $clickedEl.data('scrollToEvent');

if (scrollEvent === event || (! scrollEvent && event === this.defaultEvent)) {
this.doScroll(settings, $clickedEl);
}
}
},
doScroll: function (settings) {
if ((scrollToEl = (settings.nette !== undefined) ? settings.nette.el.data('scrollTo') : false) && $(scrollToEl).length) {
var ext = this;
var offset = $(settings.nette.el).data('scrollToOffset') || ext.offset;
doScroll: function (settings, $clickedEl) {
var dataOffset = $clickedEl.data('scrollToOffset');
var offset = (dataOffset !== undefined) ? dataOffset : this.offset;
var $scrollToEl = $( $clickedEl.data('scrollTo') );

if ($scrollToEl.length) {
// v pdboxu nelze scrollovat s documentem (zbytečné), ale je potřeba posunout samotný scroll pd-box-window
if (this.pdbox && this.pdbox.isOpen) {
var $pdbox = this.pdbox.window.elem;
var top = $pdbox.scrollTop() + $(scrollToEl).offset().top - $pdbox.offset().top - offset;
var top = $pdbox.scrollTop() + $scrollToEl.offset().top - $pdbox.offset().top - offset;

$pdbox.stop().animate({
scrollTop: top
}, this.duration);
}
else {
$('html, body').stop().animate({
scrollTop: $(scrollToEl).offset().top - offset
scrollTop: $scrollToEl.offset().top - offset
}, this.duration);
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "pd.ajax",
"title": "pd.ajax",
"description": "Collection of nette ajax extensions, including `pd` for creating disabled-by-deafult extensions",
"version": "1.2.2",
"version": "1.2.3",
"author": "PeckaDesign, s.r.o <[email protected]>",
"contributors": [
"Radek Šerý <[email protected]>",
Expand Down

0 comments on commit ffe36e6

Please sign in to comment.