tablets 0.2.0 → 0.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: 073682f3e75df008250ab8ec39352ed307eb797e
4
- data.tar.gz: e811d153b45b6bce4396f9711aa45e2c039b6fea
3
+ metadata.gz: 08132fccd6b5eb432ef7cad745f40235ab6b6bde
4
+ data.tar.gz: fe36e379b7c6157a90fd8e5e218fd205838daa30
5
5
  SHA512:
6
- metadata.gz: c0603710b65211af597d17c3015e6b175871f44c3d5d417f9560fe810c0c6c172e1bfe90d4472beb85e31d81d2e67902274a151a34210bbbd16a6362a429f511
7
- data.tar.gz: 086fe45cd22de329a6fc4da74dcc5f273cccdd4e724380d15ff3e4c24e3d8457b0e59c848288f4dd7db1d38747fd31e99f0f38b445d0f8aafb214ff2fd2e0d50
6
+ metadata.gz: aad3e1ab54407056b782808eb5ee9c11e0ca58822e9dcc0e2d08842e76e6a281e8e53b1af72dc46ee7c819a0bdc12fbb175a19bfbdba0b96750f64828bcefa97
7
+ data.tar.gz: 6a3b5dc7ebbc29fa564376c290c796baa42b0cbd9884017c8af269f26137e4730761b24b2413d552decea370a0e53dc45ba11690affc9ce945ae2ab599a4704b
data/README.md CHANGED
@@ -88,32 +88,46 @@ In `app/views/posts/index.html.erb`:
88
88
  In `app/assets/javascripts/posts.js`:
89
89
 
90
90
  ``` javascript
91
- $('.tablet[name="posts"]').on('click', 'tbody > tr[role=row]', function() {
91
+ $('.tablet[data-name="posts"]').on('click', 'tbody > tr[role=row]', function() {
92
92
  Tablets.toggleDetails($(this).closest('tr'));
93
93
  });
94
-
95
94
  ```
96
95
 
97
96
  Use `'.tablet.has-details'` for all tablets that has details.
98
97
 
99
- ## JavaScript callbacks
98
+ ## JavaScript API
99
+
100
+ Fields:
101
+
102
+ ``` javascript
103
+ tablet.element // root element
104
+ tablet.table // jquery datatable object
105
+ ```
106
+
107
+ Open details for row.
108
+
109
+ ``` javascript
110
+ Tablets.toggleDetails($tr);
111
+ ```
112
+
113
+ ### JavaScript callbacks
114
+
115
+ Callbacks called on tablet. You can use `this` to access tablet from callback.
100
116
 
101
117
  Called just before datatable initialization.
102
118
 
103
119
  ``` javascript
104
- Tablets.Callbacks.beforeInit = function(element, options) {};
120
+ Tablets.on('beforeInit', function(options) {});
105
121
  ```
106
122
 
107
123
  Called after datatable initialization.
108
124
 
109
125
  ``` javascript
110
- Tablets.Callbacks.afterInit = function(table) {};
126
+ Tablets.on('afterInit', function() {});
111
127
  ```
112
128
 
113
- ## JavaScript API
114
-
115
- Open details for row.
129
+ Called before AJAX request.
116
130
 
117
131
  ``` javascript
118
- Tablets.toggleDetails($tr);
132
+ Tablets.on('beforeRequest', function(params) {});
119
133
  ```
@@ -1,3 +1,12 @@
1
- Tablets.Callbacks =
2
- beforeInit: (element, options) ->
3
- afterInit: (table) ->
1
+ $.extend Tablets,
2
+ callbacks:
3
+ beforeInit: []
4
+ afterInit: []
5
+ beforeRequest: []
6
+
7
+ on: (event, callback) ->
8
+ @callbacks[event].push callback
9
+
10
+ trigger: (event, tablet, args = []) ->
11
+ for callback in @callbacks[event]
12
+ callback.apply(tablet, args)
@@ -1,3 +1,3 @@
1
- $.extend @Tablets,
1
+ $.extend Tablets,
2
2
  toggleDetails: ($tr) ->
3
3
  @tabletForElement($tr).toggleDetails($tr)
@@ -1,4 +1,4 @@
1
- $.extend @Tablets,
1
+ $.extend Tablets,
2
2
  tabletId: ($element) ->
3
3
  $element.closest('.tablet').attr('id')
4
4
  tabletForElement: ($element) ->
@@ -1,4 +1,4 @@
1
- $.extend @Tablets,
1
+ $.extend Tablets,
2
2
  set: (id, tablet) ->
3
3
  (@store ||= {})[id] = tablet
4
4
  get: (id) ->
@@ -7,16 +7,23 @@ class Tablets.Tablet
7
7
  dataTableOptions: ->
8
8
  $.extend {}, @options,
9
9
  fnServerParams: (data) =>
10
- data.params = @params
10
+ data.params = @serverParams()
11
+
12
+ serverParams: ->
13
+ params = $.extend({}, @params)
14
+
15
+ @trigger('beforeRequest', params)
16
+
17
+ params
11
18
 
12
19
  initTable: ->
13
20
  options = @dataTableOptions()
14
21
 
15
- Tablets.Callbacks.beforeInit(@element, options)
22
+ @trigger('beforeInit', options)
16
23
 
17
24
  @table = $(@element).DataTable(options)
18
25
 
19
- Tablets.Callbacks.afterInit(@table)
26
+ @trigger('afterInit')
20
27
 
21
28
  toggleDetails: (tr) ->
22
29
  row = @table.row tr
@@ -30,3 +37,6 @@ class Tablets.Tablet
30
37
  row.child("<span>#{data}</span>").show()
31
38
  tr.addClass 'expanded'
32
39
  tr.addClass 'shown'
40
+
41
+ trigger: (event, params...) ->
42
+ Tablets.trigger(event, this, params)
@@ -1,3 +1,3 @@
1
1
  module Tablets
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tablets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yevhen Shemet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-12 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