simple_form_extension 1.2.21 → 1.3.0

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
  SHA1:
3
- metadata.gz: e370539cbb41a3fadee1616fab1de6f18e4e72c1
4
- data.tar.gz: a3e2e7f10511fd4bd99779e256f4f281365be79d
3
+ metadata.gz: 88f0bf75c6d43b626fe22ec5fdb9771157da4eb2
4
+ data.tar.gz: 380443d6c110fcbc8949bf3900a90ae5cd92a006
5
5
  SHA512:
6
- metadata.gz: 35be6562973b9c43412da2b3459b8b7e286f75919a313d55f5500ff56c4e241cd153197463e85510cd5daaa5435f3c2c9a107554a0b32993e9bbd3b894b4ab5a
7
- data.tar.gz: 0669e178bcd964fbfeee69bec192eddc1b2a35e0e5f9717e01477ab0fbc1ad60160ecc6a4569c77a165da747a435d038d17411f7de01ee5b3681e6820f677d47
6
+ metadata.gz: 90f046a027bae80df700bdbbc4bcb50cb8b9f1b115e15dbed2ce43c305e9b61fb31343f2f240033c81362a2db600ff387c5fbec141654ea4148b13e0574329e7
7
+ data.tar.gz: 3dc2a04b168821621c36bfaf1e5190fd180b36e4d07e1c049cafd72479d5ee44e16686b46baa69ed1503d6567242059852e8209bdff23cd9f930ea017de55412
data/README.md CHANGED
@@ -16,6 +16,18 @@ Or install it yourself as:
16
16
 
17
17
  $ gem install simple_form_extension
18
18
 
19
+ Add to your `application.css` :
20
+
21
+ ```css
22
+ *= require simple_form_extension
23
+ ```
24
+
25
+ Add to your `application.js` :
26
+
27
+ ```javascript
28
+ //= require simple_form_extension
29
+ ```
30
+
19
31
  ## Usage
20
32
 
21
33
  To use the popover component, please include in a javascript file :
@@ -24,18 +36,65 @@ To use the popover component, please include in a javascript file :
24
36
  $('body').popover(selector: '[rel="popover"]')
25
37
  ```
26
38
 
27
- For the [Redactor](https://github.com/SammyLin/redactor-rails) component to
28
- work, require the javascript files :
39
+ ### Available inputs
40
+
41
+ The following custom Simple Form inputs are available :
42
+
43
+ * boolean
44
+ * collection_check_boxes
45
+ * collection_radio_buttons
46
+ * color
47
+ * date_time
48
+ * file
49
+ * image
50
+ * numeric
51
+ * redactor
52
+ * selectize
53
+ * slider
54
+
55
+ ### Javascript Plugins
56
+
57
+ Simple Form Extension comes with several javascript plugins built-in for the
58
+ inputs to work properly.
59
+
60
+ Plugins are automatically initialized on page load, with or without Turbolinks.
61
+
62
+ This means that for a classic page you don't need to initialize anything yourself.
63
+
64
+ #### Manual javascript plugins initialization
65
+
66
+ If you append some HTML, after the page is loaded, containing inputs that you
67
+ need to initialize, you'll need to manually call the Simple Form Extension
68
+ plugins initialization method.
69
+
70
+ > Note : Most of the javascript-bound inputs need their associated plugin to be
71
+ run to build their final appearance. So their initialization can't be deferred,
72
+ and you need to initialize them manually when appending HTML to the page after
73
+ the page is loaded
74
+
75
+ All you need to do is calling the following `simpleForm` jQuery plugin :
29
76
 
30
77
  ```javascript
31
- //= require simple_form_extension
78
+ $fragment.simpleForm()`
32
79
  ```
33
80
 
34
- TODO: Write usage instructions here
81
+ As an example, if you're loading a form from the server, you can do the
82
+ following :
83
+
84
+ ```javascript
85
+ $.get('/form/url', function(response) {
86
+ // Store the fragment loaded from the server in a variable
87
+ $fragment = $(response)
88
+ // Append it to the DOM
89
+ $fragment.appendTo('body')
90
+ // Initialize Simple Form Extension plugins
91
+ $fragment.simpleForm()
92
+ })
93
+ ```
35
94
 
36
95
  ## Contributing
37
96
 
38
- 1. Fork it ( http://github.com/<my-github-username>/simple_form_extension/fork )
97
+ 1. Fork it ( http://github.com/xana68/simple_form_extension/fork )
39
98
  2. Create your feature branch (`git checkout -b my-new-feature`)
40
99
  3. Commit your changes (`git commit -am 'Add some feature'`)
41
100
  4. Push to the branch (`git push origin my-new-feature`)
@@ -1,3 +1,3 @@
1
1
  module SimpleFormExtension
2
- VERSION = "1.2.21"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -10,10 +10,30 @@
10
10
  #= require_self
11
11
  #= require_tree ./simple_form_extension
12
12
 
13
- $.fn.simpleForm = {}
13
+ $.simpleForm =
14
+ # Bind a callback to run when a DOM or sub-DOM is ready to be initialized
15
+ # Allows abstracting the following cases :
16
+ # - Document is ready with $(document).ready()
17
+ # - Document is ready with Turbolinks $(document).on('page:change')
18
+ # - A sub-DOM is dynamically added and needs all the plugins to be
19
+ # initialized, ex: for nested forms
20
+ #
21
+ onDomReady: (callback) ->
22
+ $(document).on 'initialize.simpleform', (e, $fragment) ->
23
+ callback($fragment)
14
24
 
15
- window.onPageReady = (callback) ->
16
- $(document).ready ->
17
- callback() if window.Turbolinks is undefined
25
+ # Trigger all the registered callbacks and run them on the target element
26
+ $.fn.simpleForm = ->
27
+ @each (i, fragment) ->
28
+ $(document).trigger('initialize.simpleform', [$(fragment)])
18
29
 
19
- $(document).on('page:change', callback);
30
+ # Classic document ready binding
31
+ # Does not run when Turbolinks is present and supported by the browser
32
+ #
33
+ $(document).ready ->
34
+ $('body').simpleForm() unless window.Turbolinks && window.Turbolinks.supported
35
+
36
+ # Turbolinks document ready binding
37
+ #
38
+ $(document).on 'page:change', ->
39
+ $('body').simpleForm()
@@ -9,5 +9,5 @@ $.fn.simpleFormColorpicker = ->
9
9
  instance = new ColorPicker($input)
10
10
  $input.data('simple-form:colorpicker', instance)
11
11
 
12
- onPageReady ->
13
- $('[data-colorpicker]').simpleFormColorpicker()
12
+ $.simpleForm.onDomReady ($document) ->
13
+ $document.find('[data-colorpicker]').simpleFormColorpicker()
@@ -40,8 +40,12 @@ class TimePicker extends DateTimePicker
40
40
  format: @$input.data('format')
41
41
  )
42
42
 
43
- # Lazy initialization of date and datetime pickers
44
- onPageReady ->
43
+
44
+ $.simpleForm.onDomReady ($document) ->
45
+ # Plugin initialization delegated to body, so we do not need to run the
46
+ # initialization process when the body has not changed
47
+ return unless $document.is('body')
48
+
45
49
  $('body').on 'click', 'input.datetime', (e) ->
46
50
  DateTimePicker.forInput($(e.currentTarget), DateTimePicker).show()
47
51
 
@@ -55,11 +59,11 @@ onPageReady ->
55
59
  $('body').on 'click', '.date .datetimepicker-trigger', (e) ->
56
60
  $input = $(e.currentTarget).closest('.date').find('input.date')
57
61
  DatePicker.forInput($input, DatePicker).show()
58
-
62
+
59
63
  $('body').on 'click', 'input.time', (e) ->
60
64
  TimePicker.forInput($(e.currentTarget), TimePicker).show()
61
65
 
62
66
  $('body').on 'click', '.time .datetimepicker-trigger', (e) ->
63
67
  $input = $(e.currentTarget).closest('.time').find('input.time')
64
68
  TimePicker.forInput($input, TimePicker).show()
65
-
69
+
@@ -26,7 +26,11 @@ class ExistingFileField
26
26
  @$existingFile.show(0)
27
27
  @$removeButtonIcon.attr(class: @originalClass)
28
28
 
29
- onPageReady ->
29
+ $.simpleForm.onDomReady ($document) ->
30
+ # Plugin initialization delegated to body, so we do not need to run the
31
+ # initialization process when the body has not changed
32
+ return unless $document.is('body')
33
+
30
34
  $('body').on 'click', '[data-dismiss="existing-file"]', (e) ->
31
35
  $button = $(e.currentTarget)
32
36
  $field = $button.closest('[data-provides="existing-file"]')
@@ -52,5 +52,5 @@ $.fn.simpleFormRedactor = ->
52
52
  instance = new Redactor($textarea)
53
53
  $textarea.data('simple-form:redactor', instance)
54
54
 
55
- onPageReady ->
56
- $('[data-redactor]').simpleFormRedactor()
55
+ $.simpleForm.onDomReady ($document) ->
56
+ $document.find('[data-redactor]').simpleFormRedactor()
@@ -50,5 +50,5 @@ $.fn.simpleFormSelectize = (options = {}) ->
50
50
  instance = new Selectize($select, options)
51
51
  $select.data('simple-form:selectize', instance)
52
52
 
53
- onPageReady ->
54
- $('[data-selectize]').simpleFormSelectize()
53
+ $.simpleForm.onDomReady ($document) ->
54
+ $document.find('[data-selectize]').simpleFormSelectize()
@@ -12,5 +12,5 @@ $.fn.simpleFormSlider = ->
12
12
  instance = new Slider($select)
13
13
  $select.data('simple-form:slider', instance)
14
14
 
15
- onPageReady ->
16
- $('[data-slider]').simpleFormSlider()
15
+ $.simpleForm.onDomReady ($document) ->
16
+ $document.find('[data-slider]').simpleFormSlider()
@@ -1,7 +1,7 @@
1
1
  class Spinbox
2
2
  constructor: (@$el) ->
3
3
  @$el.spinbox(max: Number.POSITIVE_INFINITY)
4
-
4
+
5
5
 
6
6
  $.fn.simpleFormSpinbox = ->
7
7
  @each (i, el) ->
@@ -9,9 +9,9 @@ $.fn.simpleFormSpinbox = ->
9
9
  return if $input.data('simple-form:spinbox')
10
10
  instance = new Spinbox($input)
11
11
  $input.data('simple-form:spinbox', instance)
12
-
13
- onPageReady ->
14
- $spinbox = $('.spinbox')
12
+
13
+ $.simpleForm.onDomReady ($document) ->
14
+ $spinbox = $document.find('.spinbox')
15
15
  return unless $spinbox.length
16
16
  $spinbox.simpleFormSpinbox()
17
-
17
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_form_extension
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.21
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre Vasseur
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-20 00:00:00.000000000 Z
11
+ date: 2015-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails