garlicjs-rails 1.0.2 → 1.0.3

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.
data/README.md CHANGED
@@ -20,7 +20,7 @@ Add the following directive to your Javascript manifest file (application.js):
20
20
 
21
21
  ## Versioning
22
22
 
23
- garlicjs-rails 1.0.2 == Garlic.js 1.0.2
23
+ garlicjs-rails 1.0.3 == Garlic.js 1.0.3
24
24
 
25
25
  ## Contributing
26
26
 
@@ -1,5 +1,5 @@
1
1
  module Garlicjs
2
2
  module Rails
3
- VERSION = "1.0.2"
3
+ VERSION = "1.0.3"
4
4
  end
5
5
  end
@@ -115,6 +115,7 @@
115
115
  /* retrieve localStorage data / state and update elem accordingly */
116
116
  , retrieve: function () {
117
117
  if ( this.storage.has( this.path ) ) {
118
+ var storedValue = this.storage.get( this.path );
118
119
 
119
120
  // if conflictManager enabled, manage fields with already provided data, different from the one stored
120
121
  if ( this.options.conflictManager.enabled && this.detectConflict() ) {
@@ -125,11 +126,11 @@
125
126
  if ( this.$element.is( 'input[type=radio], input[type=checkbox]' ) ) {
126
127
 
127
128
  // for checkboxes and radios
128
- if ( 'checked' === this.storage.get( this.path ) || this.storage.get( this.path ) === this.$element.val() ) {
129
+ if ( 'checked' === storedValue || this.$element.val() === storedValue ) {
129
130
  return this.$element.attr( 'checked', true );
130
131
 
131
132
  // only needed for checkboxes
132
- } else if ( 'unchecked' === this.storage.get( this.path ) ) {
133
+ } else if ( 'unchecked' === storedValue ) {
133
134
  this.$element.attr( 'checked', false );
134
135
  }
135
136
 
@@ -137,7 +138,12 @@
137
138
  }
138
139
 
139
140
  // for input[type=text], select and textarea, just set val()
140
- this.$element.val( this.storage.get( this.path ) );
141
+ this.$element.val( storedValue );
142
+
143
+ // trigger custom user function when data is retrieved
144
+ this.options.onRetrieve( this.$element, storedValue );
145
+
146
+ return;
141
147
  }
142
148
  }
143
149
 
@@ -178,7 +184,7 @@
178
184
  , conflictManager: function () {
179
185
 
180
186
  // user can define here a custom function that could stop Garlic default behavior, if returns false
181
- if ( 'function' === typeof this.options.conflictManager.onConflictDetected
187
+ if ( 'function' === typeof this.options.conflictManager.onConflictDetected
182
188
  && !this.options.conflictManager.onConflictDetected( this.$element, this.storage.get( this.path ) ) ) {
183
189
  return false;
184
190
  }
@@ -354,17 +360,18 @@
354
360
  $.fn.garlic.Constructor = Garlic;
355
361
 
356
362
  $.fn.garlic.defaults = {
357
- destroy: true // remove or not localstorage on submit & clear
363
+ destroy: true // Remove or not localstorage on submit & clear
358
364
  , inputs: 'input, textarea, select' // Default supported inputs.
359
- , events: [ 'DOMAttrModified', 'textInput', 'input', 'change', 'keypress', 'paste', 'focus' ] // events list that trigger a localStorage
360
- , domain: false // store et retrieve forms data accross all domain, not just on
365
+ , events: [ 'DOMAttrModified', 'textInput', 'input', 'change', 'keypress', 'paste', 'focus' ] // Events list that trigger a localStorage
366
+ , domain: false // Store et retrieve forms data accross all domain, not just on
361
367
  , conflictManager: {
362
- enabled: true // manage default data and persisted data. If false, persisted data will always replace default ones
363
- , garlicPriority: true // if form have default data, garlic persisted data will be shown first
364
- , template: '<span class="garlic-swap"></span>' // template used to swap between values if conflict detected
365
- , message: 'This is your saved data. Click here to see default one' // default message for swapping data / state
368
+ enabled: true // Manage default data and persisted data. If false, persisted data will always replace default ones
369
+ , garlicPriority: true // If form have default data, garlic persisted data will be shown first
370
+ , template: '<span class="garlic-swap"></span>' // Template used to swap between values if conflict detected
371
+ , message: 'This is your saved data. Click here to see default one' // Default message for swapping data / state
366
372
  , onConflictDetected: function ( item, storedVal ) { return true; } // This function will be triggered if a conflict is detected on an item. Return true if you want Garlic behavior, return false if you want to override it
367
373
  }
374
+ , onRetrieve: function ( item, storedVal ) {} // This function will be triggered each time Garlic find an retrieve a local stored data for a field
368
375
  }
369
376
 
370
377
  /* GARLIC DATA-API
@@ -376,4 +383,4 @@
376
383
  });
377
384
 
378
385
  // This plugin works with jQuery or Zepto (with data extension builded for Zepto. See changelog 0.0.6)
379
- }(window.jQuery || window.Zepto);
386
+ }(window.jQuery || window.Zepto);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: garlicjs-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-04 00:00:00.000000000 Z
12
+ date: 2012-12-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
@@ -58,7 +58,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
58
58
  version: '0'
59
59
  segments:
60
60
  - 0
61
- hash: 1480325064676632536
61
+ hash: -2086385096376470105
62
62
  required_rubygems_version: !ruby/object:Gem::Requirement
63
63
  none: false
64
64
  requirements:
@@ -67,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
67
  version: '0'
68
68
  segments:
69
69
  - 0
70
- hash: 1480325064676632536
70
+ hash: -2086385096376470105
71
71
  requirements: []
72
72
  rubyforge_project:
73
73
  rubygems_version: 1.8.24