flex_infinite_scroll 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 125e4f628fdad23f1e968f3cc131cd18903577db0450880253f9658aeefd73dc
|
4
|
+
data.tar.gz: 2c1ec04e55f76d94fe8444bcd15fd32dcf31c3694d2934e79f7168cb225cf846
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f88222c0722ed0ba5c2fb51464b1ce43019e28daf99494615b807fab79d256d0d854883888f701aa6add9539ae344df447fc4c3419fcf384f4628e67d5f0e34d
|
7
|
+
data.tar.gz: d2cd42824a91fca0561c034b548fa87c03e6ad20a7154a4d163594fa54ca661d73b1d4112ea17c7bd091775769aaa4c432f10736e8825d89ae7738c6cbb6809c
|
data/lib/flex_infinite_scroll.rb
CHANGED
@@ -1,11 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Infinite scroll module
|
4
|
+
require 'flex_infinite_scroll/view_helpers'
|
5
|
+
require 'sanitize'
|
6
|
+
|
2
7
|
module FlexInfiniteScroll
|
3
|
-
class Engine < ::Rails::Engine
|
8
|
+
class Engine < ::Rails::Engine
|
9
|
+
ActionView::Base.send :include, FlexInfiniteScroll::ViewHelpers
|
10
|
+
end
|
4
11
|
extend ActiveSupport::Concern
|
5
12
|
def infinite_scroll(page = 1, page_size = (ENV['FIS_PAGE_SIZE'] || 20))
|
13
|
+
page ||= 1
|
6
14
|
page = page.to_i if page.class == String
|
7
15
|
offset_skip = (page - 1) * page_size
|
8
|
-
total_page = (count / page_size.to_f).ceil
|
16
|
+
total_page = (count('*') / page_size.to_f).ceil
|
9
17
|
{
|
10
18
|
data: offset(offset_skip).limit(page_size),
|
11
19
|
total_page: total_page,
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FlexInfiniteScroll
|
4
|
+
module ViewHelpers
|
5
|
+
include ActionView::Helpers::TagHelper
|
6
|
+
include ActionView::Context
|
7
|
+
|
8
|
+
def fis_init_list(data, partial, config = {})
|
9
|
+
result = content_tag :div, class: "fis-container #{config[:container_class] || ''}" do
|
10
|
+
fis_get_list(data, partial, 'html')
|
11
|
+
end
|
12
|
+
config[:scrollContainer] ||= 'body'
|
13
|
+
config[:targetContainer] ||= '.fis-container'
|
14
|
+
result += javascript_tag do
|
15
|
+
"$('#{config[:scrollContainer]}').flexInfiniteScroll(#{config.to_json})".html_safe
|
16
|
+
end
|
17
|
+
Sanitize.fragment(result,
|
18
|
+
Sanitize::Config.merge(Sanitize::Config::RELAXED,
|
19
|
+
elements: Sanitize::Config::RELAXED[:elements] + %w(script))).html_safe
|
20
|
+
end
|
21
|
+
|
22
|
+
def fis_next_page(data, partial)
|
23
|
+
data[:data] = fis_get_list(data, partial, 'json')
|
24
|
+
data
|
25
|
+
end
|
26
|
+
|
27
|
+
def fis_get_list(data, partial, format)
|
28
|
+
result = ''
|
29
|
+
data[:data].each do |member|
|
30
|
+
result += if format == 'json'
|
31
|
+
render_to_string(partial: partial, locals: { fis_object: member })
|
32
|
+
else
|
33
|
+
render partial: partial, locals: { fis_object: member }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
Sanitize.fragment(result, Sanitize::Config::RELAXED).html_safe
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -10,7 +10,7 @@ $.fn.extend({
|
|
10
10
|
var queryParams = config.queryParams;
|
11
11
|
var dataProcess = config.dataProcess;
|
12
12
|
var initialLoad = config.initialLoad;
|
13
|
-
var loadMargin = config.loadMargin ||
|
13
|
+
var loadMargin = config.loadMargin || 150;
|
14
14
|
var beforeAction = config.beforeAction;
|
15
15
|
var afterAction = config.afterAction;
|
16
16
|
var targetContainer = config.targetContainer || scrollContainer ;
|
@@ -19,7 +19,6 @@ $.fn.extend({
|
|
19
19
|
scrollContainer.dataset.fisNextPage = nextPage;
|
20
20
|
scrollContainer.dataset.fisUrl = dataUrl;
|
21
21
|
scrollContainer.dataset.fisLoading = 0;
|
22
|
-
|
23
22
|
function getData(page = 1){
|
24
23
|
// Check for loading process and last page
|
25
24
|
if (scrollContainer.dataset.fisLoading === '1' || page == 'last') return false
|
@@ -77,7 +76,10 @@ $.fn.extend({
|
|
77
76
|
var scrollTop=$(eventTarget).scrollTop();
|
78
77
|
var containerSize=$(scrollContainer).innerHeight();
|
79
78
|
var scrollSize=scrollContainer.scrollHeight;
|
79
|
+
console.log(scrollSize - loadMargin)
|
80
|
+
console.log(scrollTop + containerSize)
|
80
81
|
if (scrollTop + containerSize > scrollSize - loadMargin && scrollContainer.dataset.fisNextPage != 'last'){
|
82
|
+
console.log(1)
|
81
83
|
getData(scrollContainer.dataset.fisNextPage);
|
82
84
|
};
|
83
85
|
})
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
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.1
|
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-
|
12
|
-
dependencies:
|
11
|
+
date: 2019-04-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sanitize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
description:
|
14
28
|
email: belmek@me.com
|
15
29
|
executables: []
|
@@ -17,6 +31,7 @@ extensions: []
|
|
17
31
|
extra_rdoc_files: []
|
18
32
|
files:
|
19
33
|
- lib/flex_infinite_scroll.rb
|
34
|
+
- lib/flex_infinite_scroll/view_helpers.rb
|
20
35
|
- vendor/assets/javascript/flex_infinite_scroll.js
|
21
36
|
homepage: https://github.com/aignatov-bio/flex_infinite_scroll
|
22
37
|
licenses:
|
@@ -36,7 +51,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
36
51
|
- - ">="
|
37
52
|
- !ruby/object:Gem::Version
|
38
53
|
version: '0'
|
39
|
-
requirements:
|
54
|
+
requirements:
|
55
|
+
- Rails
|
56
|
+
- jQuery
|
40
57
|
rubyforge_project:
|
41
58
|
rubygems_version: 2.7.6
|
42
59
|
signing_key:
|