Permalink
Browse files

- added onRetrieve user function

  • Loading branch information...
1 parent 14d5b28 commit c066000fd4895751bec5d25eb5847378f06327a2 @guillaumepotier committed Dec 10, 2012
Showing with 34 additions and 17 deletions.
  1. +5 −0 CHANGELOG.md
  2. +2 −1 README.md
  3. +3 −3 dist/garlic-standalone.min.js
  4. +3 −3 dist/garlic.min.js
  5. +2 −2 garlic.js
  6. +18 −7 index.html
  7. +1 −1 tests/tests.js
View
@@ -1,5 +1,10 @@
#Changelog
+* **1.0.3** :
+
+ - added onRetrieve function in config. Called each time Garlic retrieves a field
+ stored value. Overridable by configuration
+
* **1.0.2** :
- fixed bug that did not allowed user to clear a field persisted by Garlic
View
@@ -10,7 +10,7 @@ http://garlicjs.org/
#Version
-1.0.2
+1.0.3
See CHANGELOG for more info.
@@ -40,6 +40,7 @@ They'll be created and dumped in the dist/ directory
* @johnrees
* @Marfa
* @leondewey
+* @willdurand
#Contribute!

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -141,7 +141,7 @@
this.$element.val( storedValue );
// trigger custom user function when data is retrieved
- this.options.retrieveTrigger( this.$element, storedValue );
+ this.options.onRetrieve( this.$element, storedValue );
return;
}
@@ -371,7 +371,7 @@
, message: 'This is your saved data. Click here to see default one' // Default message for swapping data / state
, 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
}
- , retrieveTrigger: function ( item, storedVal ) {} // This function will be triggered each time Garlic find an retrieve a local stored data for a field
+ , onRetrieve: function ( item, storedVal ) {} // This function will be triggered each time Garlic find an retrieve a local stored data for a field
}
/* GARLIC DATA-API
View
@@ -105,10 +105,10 @@ <h1 class="">
<div class="row well intro">
<div id="head-download" class="download">
- <a href="https://github.com/guillaumepotier/Garlic.js/archive/1.0.2.zip">
+ <a href="https://github.com/guillaumepotier/Garlic.js/archive/1.0.3.zip">
<img width="90" border="0" src="http://github.com/images/modules/download/zip.png" onclick="onclick=”var that=this;_gaq.push(['_trackEvent','Download','ZIP',this.href]);setTimeout(function(){location.href=that.href;},200);return false;”">
</a>
- <a href="https://github.com/guillaumepotier/Garlic.js/archive/1.0.2.tar.gz">
+ <a href="https://github.com/guillaumepotier/Garlic.js/archive/1.0.3.tar.gz">
<img width="90" border="0" src="http://github.com/images/modules/download/tar.png" onclick="onclick=”var that=this;_gaq.push(['_trackEvent','Download','TAR',this.href]);setTimeout(function(){location.href=that.href;},200);return false;”">
</a>
</div>
@@ -280,10 +280,10 @@ <h1>Requirements / Compatibiliy</h1>
<h1>Download</h1>
</div>
<div id="download" class="download">
- <a href="https://github.com/guillaumepotier/Garlic.js/archive/1.0.2.zip" onclick="onclick=”var that=this;_gaq.push(['_trackEvent','Download','ZIP',this.href]);setTimeout(function(){location.href=that.href;},200);return false;”" >
+ <a href="https://github.com/guillaumepotier/Garlic.js/archive/1.0.3.zip" onclick="onclick=”var that=this;_gaq.push(['_trackEvent','Download','ZIP',this.href]);setTimeout(function(){location.href=that.href;},200);return false;”" >
<img width="90" border="0" src="http://github.com/images/modules/download/zip.png">
</a>
- <a href="https://github.com/guillaumepotier/Garlic.js/archive/1.0.2.tar.gz" onclick="onclick=”var that=this;_gaq.push(['_trackEvent','Download','TAR',this.href]);setTimeout(function(){location.href=that.href;},200);return false;”">
+ <a href="https://github.com/guillaumepotier/Garlic.js/archive/1.0.3.tar.gz" onclick="onclick=”var that=this;_gaq.push(['_trackEvent','Download','TAR',this.href]);setTimeout(function(){location.href=that.href;},200);return false;”">
<img width="90" border="0" src="http://github.com/images/modules/download/tar.png">
</a>
</div>
@@ -327,14 +327,25 @@ <h1>Documentation</h1>
Manually call garlic in javascript<br/>
<pre>
&lt;script type="text/javascript">
- $('[rel=persist]').garlic();
+ $( '[rel=persist]' ).garlic();
&lt;/script></pre>
</li>
<li>
Destroy storage for an element <strong>(don't work on an entire form yet, only input by input)</strong><br/>
<pre>
&lt;script type="text/javascript">
- $('input.no_good').garlic('destroy');
+ $( 'input.no_good' ).garlic( 'destroy' );
+&lt;/script></pre>
+ </li>
+ <li>
+ Be notified when Garlic retrieve a field val by a custom overridable <code>onRetrieve</code> callback:
+ <pre>
+&lt;script type="text/javascript">
+ $( 'input.no_good' ).garlic( {
+ onRetrieve: function ( elem, retrievedValue ) {
+ console.log( 'The retrieved value for ' + elem.name() + ' is : ' + retrievedValue );
+ }
+ } );
&lt;/script></pre>
</li>
</ul>
@@ -374,7 +385,7 @@ <h1>Other stuff</h1>
<div class="page-header">
<h1>Version / Licence</h1>
</div>
- <a href="https://github.com/guillaumepotier/Garlic.js/blob/master/README.md">1.0.2 - MIT</a> - <a href="https://github.com/guillaumepotier/Garlic.js/blob/master/CHANGELOG.md">See changelog</a>
+ <a href="https://github.com/guillaumepotier/Garlic.js/blob/master/README.md">1.0.3 - MIT</a> - <a href="https://github.com/guillaumepotier/Garlic.js/blob/master/CHANGELOG.md">See changelog</a>
<a href="#top" class="pull-right">Top</a>
</section>
</div>
View
@@ -8,7 +8,7 @@ var testSuite = function () {
e.preventDefault();
} );
$( '#form1' ).garlic( { domain: true } );
- $( '#retrieve-trigger' ).garlic( { retrieveTrigger: function ( elem, retrieveVal ) {
+ $( '#retrieve-trigger' ).garlic( { onRetrieve: function ( elem, retrieveVal ) {
elem.attr( 'storedValue', retrieveVal );
} } );
var garlicStorage = $( '#form1' ).garlic( 'getStorage' );

0 comments on commit c066000

Please sign in to comment.