Permalink
Browse files

don't persist password fields by default

closes #21
  • Loading branch information...
1 parent 6ab3200 commit 9ada6dbd48de8827ef9d5a90603e8db53f8a2819 @nashby nashby committed Dec 31, 2012
Showing with 66 additions and 58 deletions.
  1. +1 −3 bin/minify
  2. +37 −38 dist/garlic-standalone.min.js
  3. +5 −5 dist/garlic.min.js
  4. +7 −2 garlic.js
  5. +5 −2 tests/index.html
  6. +11 −8 tests/tests.js
View
@@ -34,8 +34,6 @@ else
File.open(output, 'w') do |f|
f.write "/* Garlicjs %s build version %s http://garlicjs.org */\n" %
[output, garlic_version]
- f.write Closure::Compiler.new.compile(input.map { |file|
- File.read(file)
- })
+ f.write Closure::Compiler.new.compile_files(input)
end
end

Large diffs are not rendered by default.

Oops, something went wrong.
View

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

Oops, something went wrong.
View
@@ -211,7 +211,7 @@
, conflictManager: function () {
// user can define here a custom function that could stop Garlic default behavior, if returns false
- if ( 'function' === typeof this.options.conflictManager.onConflictDetected
+ if ( 'function' === typeof this.options.conflictManager.onConflictDetected
&& !this.options.conflictManager.onConflictDetected( this.$element, this.storage.get( this.path ) ) ) {
return false;
}
@@ -356,6 +356,11 @@
return;
}
+ // don't bind a password type field
+ if ( 'password' === $( self ).attr( 'type' ) ) {
+ return;
+ }
+
// if data never binded, bind it right now!
if ( !data ) {
$this.data( 'garlic', ( data = new Garlic( self, storage, fieldOptions ) ) );
@@ -398,7 +403,7 @@
, expires: false // false for no expiration, otherwise (int) in seconds for auto-expiration
, conflictManager: {
enabled: true // Manage default data and persisted data. If false, persisted data will always replace default ones
- , garlicPriority: true // If form have default data, garlic persisted data will be shown first
+ , garlicPriority: true // If form have default data, garlic persisted data will be shown first
, template: '<span class="garlic-swap"></span>' // Template used to swap between values if conflict detected
, 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
View
@@ -105,11 +105,14 @@
<form data-persist="garlic">
<input type="email" id="email" />
</form>
+ <form data-persist="garlic">
+ <input type="password" id="password" />
+ </form>
<input type="submit" id="submit2" />
<select id="select23" data-persist="garlic">
<option value="foo">foo</option>
<option value="bar">bar</option>
- <option value="baz">baz</option>
+ <option value="baz">baz</option>
</select>
<form data-persist="garlic">
<input type="text" id="input12" />
@@ -220,4 +223,4 @@
};
</script>
</body>
-</html>
+</html>
View
@@ -114,6 +114,9 @@ var testSuite = function () {
it ( 'On a form that is of type email', function () {
expect( $( '#email' ).hasClass( 'garlic-auto-save' ) ).to.be( true );
} )
+ it ( 'On a form that is of type password', function () {
+ expect( $( '#password' ).hasClass( 'garlic-auto-save' ) ).to.be( false );
+ } )
} )
/***************************************
@@ -190,7 +193,7 @@ var testSuite = function () {
it ( 'If data auto-expires, data is persisted an expires flag is set in localStorage', function () {
$( '#auto-expires' ).bind( 'change', function () {
- var garlicFlagDate = garlicStorage.get( 'garlic:' + document.domain + window.location.pathname + '>form:eq(22)_flag' )
+ var garlicFlagDate = garlicStorage.get( 'garlic:' + document.domain + window.location.pathname + '>form:eq(23)_flag' )
, diffDates = parseInt( garlicFlagDate ) - new Date().getTime()
, expireFlag2 = garlicFlagDate;
@@ -201,7 +204,7 @@ var testSuite = function () {
} )
} )
$( '#auto-expires-2' ).bind( 'change', function () {
- var garlicFlagDate = garlicStorage.get( 'garlic:' + document.domain + window.location.pathname + '>form:eq(22)_flag' )
+ var garlicFlagDate = garlicStorage.get( 'garlic:' + document.domain + window.location.pathname + '>form:eq(23)_flag' )
, diffDates = parseInt( garlicFlagDate ) - new Date().getTime()
, expireFlag2 = garlicFlagDate;
@@ -230,7 +233,7 @@ var testSuite = function () {
expect( expireFlag1 ).to.be( expireFlag2 );
} )
it ( 'Data is not persisted in localStorage anymore after expiration time', function () {
- garlicStorage.set( 'garlic:' + document.domain + window.location.pathname + '>form:eq(22)_flag', ( new Date().getTime() - 200 ).toString() );
+ garlicStorage.set( 'garlic:' + document.domain + window.location.pathname + '>form:eq(23)_flag', ( new Date().getTime() - 200 ).toString() );
$( '#auto-expires' ).garlic( 'retrieve', function () {
expect( garlicStorage.has( $( '#auto-expires' ).garlic( 'getPath' ) ) ).to.be( false );
} )
@@ -316,7 +319,7 @@ var testSuite = function () {
// tests for conflicts management, only for supported yet fields
var conflicts = [ 'input', 'textarea', 'select' ];
for ( var i in conflicts ) {
- garlicStorage.set ( $( '#' + conflicts[ i ] + '14' ).garlic( 'getPath' ), 'not default' );
+ garlicStorage.set ( $( '#' + conflicts[ i ] + '14' ).garlic( 'getPath' ), 'not default' );
}
it ( 'If ' + conflicts.join( ',' ) + ' fields have default value and conflictManager enabled, detect conflict', function () {
@@ -382,14 +385,14 @@ var testSuite = function () {
} )
}
}
- } )
+ } )
it ( 'Reset button should remove both text and localStorage, but only on current form', function () {
garlicStorage.set( $( '#input8' ).garlic( 'getPath' ), 'foo' );
garlicStorage.set( $( '#input9' ).garlic( 'getPath' ), 'foo' );
expect( garlicStorage.get( $( '#input8' ).garlic( 'getPath' ) ) ).to.be( 'foo' );
expect( garlicStorage.get( $( '#input9' ).garlic( 'getPath' ) ) ).to.be( 'foo' );
-
+
$('#reset1').click();
$('#reset1').click( function () {
expect( $( '#input9' ).val() ).to.be( '' );
@@ -407,10 +410,10 @@ var testSuite = function () {
} )
it ( 'Do not destroy localStorage if data-destroy=false', function () {
garlicStorage.set( $( '#textarea40' ).garlic( 'getPath' ), 'foo' );
- $( '#reset40' ).click( function () {
+ $( '#reset40' ).click( function () {
expect( garlicStorage.get( $( '#textarea40' ).garlic( 'getPath' ) ) ).to.be( 'foo' );
} )
- $( '#submit40' ).click( function ( e ) {
+ $( '#submit40' ).click( function ( e ) {
expect( garlicStorage.get( $( '#textarea40' ).garlic( 'getPath' ) ) ).to.be( 'foo' );
e.preventDefault();
} )

2 comments on commit 9ada6db

Awesome, thanks @nashby!

Contributor

nashby replied Dec 31, 2012

@ndbroadbent you are welcome!

Please sign in to comment.