slide-selector 0.1.2 → 0.1.4

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: 6ca79a64503e171a4aa6ee21cd13e844a23ca47e3cd3fe4b9935f2333a731795
4
- data.tar.gz: e636988b7b3e50fcf9b49d38f562f51b8e3e1468d88a8472c8edcf883ef65ea3
3
+ metadata.gz: e80b4df481ac573f5b8e87dc33cb713cbc31ed78752b04971a48ed6481cd2ab7
4
+ data.tar.gz: 6ffccb5a484658a6839f49bf9ad122b31e8ee02bd6e17b42cd3808ff4f88ec99
5
5
  SHA512:
6
- metadata.gz: 98551654ae619075b61d9377b942bb10a9095093d1b8683fc7b80352a775b67303cf0c99224fea0b9ef7bf2700040b0ea7a43104c0a869303769077dce205b7c
7
- data.tar.gz: 270dc5c230601ee8edfffa5ebad23f850243a409a0eb05f2be65f4f0111a257e8890b9e774346561b10bdce35dda3d15033f6973856f9d6450c0dcc170520d84
6
+ metadata.gz: a449478307359bbccdedb11a406b8b20e274b231058ae942125f2f69296ff162c6b155c1b06c2ce9feaf3b726c50236dcd7f033ed3e9d7930950ee73f3a23a15
7
+ data.tar.gz: 6e4c8a55911c493d67756246fefa8026e9a8e2c0a67a8f65747820b041999c1181d569bf1ed4d8cf388c8bdf182ec758154340ee6b212db2f1a55ad4a4ccc9fe
data/README.md CHANGED
@@ -27,38 +27,42 @@ Or install it yourself as:
27
27
  Rename applitcation.css to applitcation.scss and add `@import "slide-selector.css";`
28
28
  In applitcation.js add `//= require slide-selector` after `//= require_tree .`
29
29
 
30
- Some examples of using this tag
30
+ Syntax:
31
+ ```
32
+ <%= slide_selector_tag [:min_field, :max_field], [:min_range, :max_range], options_for_select, options = {} %>
33
+ ```
34
+ Options:
35
+ `:slider_step` - To specify the size of each moment.
36
+ `:type` - For dollar type use `'amount'`.
37
+ `:selector` - To disable drop-down options (`options_for_select` can be nil for this).
38
+ `:class` - Set class to div
39
+
40
+ Examples:
31
41
  With form:
32
42
  ```
33
43
  <%= form_for root_path do |f| %>
34
- <%= f.slide_selector [:min_rank, :max_rank], [0, 100], drop_down_options_dollar, type: 'amount', selector: false, slider_step: 5 %>
44
+ <%= f.slide_selector [:min_rank, :max_rank], [0, 100], amount_drop_down_options, type: 'amount', selector: false, slider_step: 5 %>
35
45
  <br><br>
36
- <%= f.slide_selector [:min_rank2, :max_rank2], [0, 10000], drop_down_options %>
46
+ <%= f.slide_selector [:min_rank2, :max_rank2], [0, 10000], simple_drop_down_options %>
37
47
  <% end %>
38
48
  ```
39
49
  Without form:
40
50
  ```
41
- <%= slide_selector_tag [:min_rank3, :max_rank3], [0, 10000], drop_down_options %>
51
+ <%= slide_selector_tag [:min_rank3, :max_rank3], [0, 10000], simple_drop_down_options %>
42
52
  ```
43
53
 
44
54
  In application_helper.rb
45
55
  ```
46
56
  module ApplicationHelper
47
- def drop_down_options
48
- {"$0.01" => 1, "$0.50" => 50, "$1" => 100, "$2" => 200, "$3" => 300, "$4" => 400, "$5" => 500, "$10" => 1000, "$15" => 1500, "$25" => 2500, "$50" => 5000, "$75" => 7500, "$100" => 10000}
57
+ def amount_drop_down_options
58
+ {"$1" => 100, "$5" => 500, "$10" => 1000, "$25" => 2500, "$50" => 5000, "$75" => 7500, "$100" => 10000, "$250" => 25000, "$500" => 50000}
49
59
  end
50
- def drop_down_options2
51
- {"1" => 1, "50" => 50, "100" => 100, "200" => 200, "300" => 300, "400" => 400, "500" => 500, "1000" => 1000, "1500" => 1500, "2500" => 2500, "5000" => 5000, "7500" => 7500, "10000" => 10000}
60
+ def simple_drop_down_options
61
+ {"1" => 1, "50" => 50, "100" => 100, "200" => 200, "300" => 300, "400" => 400, "500" => 500, "1000" => 1000, "1500" => 1500, "2000" => 2000, "5000" => 5000}
52
62
  end
53
63
  end
54
64
  ```
55
65
 
56
- ## Development
57
-
58
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
59
-
60
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
61
-
62
66
  ## Contributing
63
67
 
64
68
  Bug reports and pull requests are welcome on GitHub at https://github.com/touqeer-tqr/slide-selector. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
@@ -13,39 +13,36 @@ module Slide
13
13
  options[:suggestions] = false if options[:suggestions].nil?
14
14
  options[:slider_step] = 1 if options[:slider_step].nil?
15
15
  options[:selector] = true if options[:selector].nil?
16
- options[:value] = [select_options.keys.first, select_options.keys.last] if options[:value].nil? && options[:selector]
17
16
  options[:type] = options[:type] == 'amount' ? '$' : ''
18
17
  selectors = selectors.map &:to_s
19
- get_select_field = lambda { |selector, select_type|
18
+ get_select_field = lambda { |selector, select_type, value = nil|
20
19
  result = self.hidden_field(selector)
21
- if result.include?('value')
20
+ if result.include?('value') || value.present?
22
21
  result = Hash.from_xml(result)['input']
23
- selected = {result['value'] => result['value']}
22
+ selected = value.present? ? {value => value} : {result['value'] => result['value']}
24
23
  return self.select(selector, options_for_select(select_options.merge(selected), selected.to_a.last))
25
24
  else
26
25
  selected = select_type == 'min' ? select_options.first : select_options.to_a.last
27
26
  return self.select(selector, options_for_select(select_options, selected))
28
27
  end
29
28
  }
29
+ "<div class='#{options[:class]}' data-slide-selector=true data-options='{\"suggestions\": #{options[:suggestions]}, \"selector\": #{options[:selector]}, \"type\": \"#{options[:type]}\"}' >".html_safe+
30
30
  (if options[:selector]
31
- get_select_field.call(selectors[0], 'min')
31
+ get_select_field.call(selectors[0], 'min', (options[:value][0] if options[:value].present?))
32
+ elsif options[:value].present?
33
+ self.text_field(selectors[0], value: options[:value][0])
32
34
  else
33
35
  self.text_field(selectors[0])
34
36
  end)+
35
- text_field_tag(selectors[0]+'_'+selectors[1], nil, data: {'slider-step': options[:slider_step]})+
37
+ text_field_tag(selectors[0]+'_'+selectors[1], nil, data: {'slider-step': options[:slider_step], 'slide-range': ranges.map(&:to_s)})+
36
38
  (if options[:selector]
37
- get_select_field.call(selectors[1], 'max')
39
+ get_select_field.call(selectors[1], 'max', (options[:value][1] if options[:value].present?))
40
+ elsif options[:value].present?
41
+ self.text_field(selectors[1], value: options[:value][1])
38
42
  else
39
43
  self.text_field(selectors[1])
40
44
  end)+
41
- generate_script(selectors, ranges, options).html_safe
42
- end
43
- def generate_script(selectors, ranges, options)
44
- return <<-SCRIPT
45
- <script type='text/javascript'>
46
- setSlider(#{selectors.map{ |field_name| object_name.to_s+'_'+field_name.to_s}}, #{ranges.map(&:to_s)}, #{options.to_json}, '#{selectors[0]+'_'+selectors[1]}')
47
- </script>
48
- SCRIPT
45
+ "</div>".html_safe
49
46
  end
50
47
  end
51
48
  end
@@ -1,5 +1,5 @@
1
1
  module Slide
2
2
  module Selector
3
- VERSION = "0.1.2"
3
+ VERSION = "0.1.4"
4
4
  end
5
5
  end
@@ -9,26 +9,19 @@ module Slide
9
9
  options[:type] = options[:type] == 'amount' ? '$' : ''
10
10
  options[:selector] = true if options[:selector].nil?
11
11
  selectors = selectors.map &:to_s
12
+ "<div class='#{options[:class]}' data-slide-selector=true data-options='{\"suggestions\": #{options[:suggestions]}, \"selector\": #{options[:selector]}, \"type\": \"#{options[:type]}\"}' >".html_safe+
12
13
  (if options[:selector]
13
14
  select_tag(selectors[0], options_for_select(select_options), value: options[:value][0])
14
15
  else
15
16
  text_field_tag(selectors[0], nil, value: options[:value][0])
16
17
  end)+
17
- text_field_tag(selectors[0]+'_'+selectors[1], nil, data: {'slider-step': options[:slider_step]})+
18
+ text_field_tag(selectors[0]+'_'+selectors[1], nil, data: {'slider-step': options[:slider_step], 'slide-range': ranges.map(&:to_s)})+
18
19
  (if options[:selector]
19
20
  select_tag(selectors[1], options_for_select(select_options), value: options[:value][1])
20
21
  else
21
22
  text_field_tag(selectors[1], nil, value: options[:value][1])
22
23
  end)+
23
- generate_script(selectors, ranges, options).html_safe
24
- end
25
- private
26
- def generate_script(selectors, ranges, options)
27
- return <<-SCRIPT
28
- <script type='text/javascript'>
29
- setSlider(#{selectors.map(&:to_s)}, #{ranges.map(&:to_s)}, #{options.to_json}, '#{selectors[0]+'_'+selectors[1]}')
30
- </script>
31
- SCRIPT
24
+ "</div>".html_safe
32
25
  end
33
26
  end
34
27
  end
@@ -98,7 +98,6 @@ setSlider = function(selectors, ranges, options, sliderField){
98
98
  slideValue.val(ranges[1]);
99
99
  }
100
100
  sliderRange = [parseFloat(slideMinValue.val().replace(/[$,]/g, '')), parseFloat(slideValue.val().replace(/[$,]/g, ''))];
101
- console.log(sliderRange);
102
101
  mySlider = new Slider('#'+sliderField, {
103
102
  id: 'slider12c',
104
103
  min: parseFloat(ranges[0]),
@@ -122,4 +121,18 @@ setSlider = function(selectors, ranges, options, sliderField){
122
121
  $('#'+selectors[0]).blur();
123
122
  $('#'+selectors[1]).blur();
124
123
  setOnChangeListner(selectors, ranges, mySlider);
125
- }
124
+ }
125
+
126
+ $( document ).ready(function() {
127
+ $('[data-slide-selector=true]').each(function() {
128
+ dataTags = $(this).data('options');
129
+ if(!dataTags['selector']){
130
+ inputTags = $(this).find('input');
131
+ setSlider([inputTags[0].id, inputTags[2].id], $(inputTags[1]).data('slideRange'), $(this).data('options'), inputTags[1].id);
132
+ }else{
133
+ selectTags = $(this).find('select');
134
+ inputTags = $(this).find('input');
135
+ setSlider([selectTags[0].id, selectTags[1].id], $(inputTags[0]).data('slideRange'), $(this).data('options'), inputTags[0].id);
136
+ }
137
+ });
138
+ });
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slide-selector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Touqeer-tqr
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-15 00:00:00.000000000 Z
11
+ date: 2019-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler