flex_infinite_scroll 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/flex_infinite_scroll/view_helpers.rb +8 -4
- data/vendor/assets/javascript/flex_infinite_scroll.js +36 -16
- metadata +20 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37a58fecb23bb9e79e62fd86a32f47175af166e28f6566434163a195383a2721
|
4
|
+
data.tar.gz: 8d4b8547f40dbc981787dad0f906cae3539e6e95c037bf9be3f5ac6744a80656
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68f06d3befe1159605f7d2a0fcee111828e3ea067eb677a4ff7ec0530164810f5bf3933812e5b6459169a4290b34cd809d9f1ecba96b6195fc71369fc65940ce
|
7
|
+
data.tar.gz: b97012ddc994ffd764a16ae40ceac2702831894012380fb9dacf191792a0892fe892f365badf802f870e2e05823e82d9682d3e346ed77ad62e3abbf121e52f2c
|
@@ -6,10 +6,14 @@ module FlexInfiniteScroll
|
|
6
6
|
include ActionView::Context
|
7
7
|
|
8
8
|
def fis_init_list(data, partial, config = {})
|
9
|
-
result =
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
result = if config[:targetContainer]
|
10
|
+
fis_get_list(data, partial, 'html')
|
11
|
+
else
|
12
|
+
content_tag :div, class: "fis-container #{config[:container_class] || ''}" do
|
13
|
+
fis_get_list(data, partial, 'html')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
config[:scrollContainer] ||= (config[:targetContainer] || 'body')
|
13
17
|
config[:targetContainer] ||= '.fis-container'
|
14
18
|
result += javascript_tag do
|
15
19
|
"$('#{config[:scrollContainer]}').flexInfiniteScroll(#{config.to_json})".html_safe
|
@@ -13,18 +13,34 @@ $.fn.extend({
|
|
13
13
|
var loadMargin = config.loadMargin || 150;
|
14
14
|
var beforeAction = config.beforeAction;
|
15
15
|
var afterAction = config.afterAction;
|
16
|
-
var targetContainer
|
17
|
-
var eventTarget;
|
16
|
+
var targetContainer= config.targetContainer || scrollContainer ;
|
17
|
+
var eventTarget = (scrollContainer.localName == 'body' ? window : scrollContainer);
|
18
18
|
if (config.lastPage) nextPage = 'last';
|
19
19
|
scrollContainer.dataset.fisNextPage = nextPage;
|
20
20
|
scrollContainer.dataset.fisUrl = dataUrl;
|
21
21
|
scrollContainer.dataset.fisLoading = 0;
|
22
|
+
|
23
|
+
function getScrollHeight(){
|
24
|
+
if (scrollContainer.localName == 'body'){
|
25
|
+
return document.documentElement.scrollHeight
|
26
|
+
} else {
|
27
|
+
return eventTarget.scrollHeight
|
28
|
+
}
|
29
|
+
|
30
|
+
}
|
31
|
+
|
22
32
|
function getData(page = 1){
|
23
33
|
// Check for loading process and last page
|
24
34
|
if (scrollContainer.dataset.fisLoading === '1' || page == 'last') return false
|
25
35
|
scrollContainer.dataset.fisLoading = 1;
|
26
36
|
// before load action
|
27
|
-
if (beforeAction)
|
37
|
+
if (beforeAction) {
|
38
|
+
if (typeof(beforeAction) == 'function') {
|
39
|
+
beforeAction();
|
40
|
+
}else if (typeof(beforeAction) == 'string') {
|
41
|
+
eval(beforeAction)
|
42
|
+
}
|
43
|
+
}
|
28
44
|
$.ajax({
|
29
45
|
url: scrollContainer.dataset.fisUrl,
|
30
46
|
// custom query params
|
@@ -47,7 +63,13 @@ $.fn.extend({
|
|
47
63
|
getData(scrollContainer.dataset.fisNextPage)
|
48
64
|
}
|
49
65
|
// after load action
|
50
|
-
if (afterAction)
|
66
|
+
if (afterAction) {
|
67
|
+
if (typeof(afterAction) == 'function') {
|
68
|
+
afterAction();
|
69
|
+
}else if (typeof(afterAction) == 'string') {
|
70
|
+
eval(afterAction)
|
71
|
+
}
|
72
|
+
}
|
51
73
|
},
|
52
74
|
error: function() {
|
53
75
|
scrollContainer.dataset.fisLoading = 0;
|
@@ -60,29 +82,27 @@ $.fn.extend({
|
|
60
82
|
getData(startPage)
|
61
83
|
} else if (scrollNotApear()) {
|
62
84
|
// check if on initial load not enough elements on screen
|
63
|
-
getData(scrollContainer.dataset.fisNextPage)
|
85
|
+
getData(scrollContainer.dataset.fisNextPage);
|
64
86
|
}
|
65
87
|
|
88
|
+
// check if body scroll
|
89
|
+
|
66
90
|
function scrollNotApear(){
|
67
|
-
|
68
|
-
var scrollSize=
|
69
|
-
return (scrollSize - containerSize -
|
91
|
+
var containerSize=$(eventTarget).innerHeight();
|
92
|
+
var scrollSize=getScrollHeight();
|
93
|
+
return (scrollSize - containerSize - loadMargin <= 0)
|
70
94
|
}
|
71
95
|
|
72
|
-
// check if body scroll
|
73
|
-
eventTarget = (scrollContainer.localName == 'body' ? window : scrollContainer);
|
74
|
-
|
75
96
|
$(eventTarget).on('scroll', () => {
|
76
97
|
var scrollTop=$(eventTarget).scrollTop();
|
77
|
-
var containerSize=$(
|
78
|
-
var scrollSize=
|
79
|
-
console.log(scrollSize - loadMargin)
|
80
|
-
console.log(scrollTop + containerSize)
|
98
|
+
var containerSize=$(eventTarget).innerHeight();
|
99
|
+
var scrollSize=getScrollHeight();
|
81
100
|
if (scrollTop + containerSize > scrollSize - loadMargin && scrollContainer.dataset.fisNextPage != 'last'){
|
82
|
-
console.log(1)
|
83
101
|
getData(scrollContainer.dataset.fisNextPage);
|
84
102
|
};
|
85
103
|
})
|
86
104
|
|
105
|
+
|
106
|
+
|
87
107
|
}
|
88
108
|
})
|
metadata
CHANGED
@@ -1,29 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flex_infinite_scroll
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Ignatov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-04-
|
11
|
+
date: 2019-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sanitize
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.1.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.1.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.0'
|
27
41
|
description:
|
28
42
|
email: belmek@me.com
|
29
43
|
executables: []
|
@@ -52,7 +66,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
66
|
- !ruby/object:Gem::Version
|
53
67
|
version: '0'
|
54
68
|
requirements:
|
55
|
-
- Rails
|
56
69
|
- jQuery
|
57
70
|
rubyforge_project:
|
58
71
|
rubygems_version: 2.7.6
|