Skip to content

Commit

Permalink
build 0.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Web Advanced committed Apr 25, 2014
1 parent de5c895 commit a125f4a
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
83 changes: 83 additions & 0 deletions release/ngRemoteValidate.0.1.3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
( function( angular ) {
'use strict';
if( !angular ) {
throw 'Missing something? Please add angular.js to your project or move this script below the angular.js reference';
}

var directiveId = 'ngRemoteValidate',
remoteValidate = function( $http, $timeout ) {
return {
restrict: 'A',
require: 'ngModel',
link: function( scope, el, attrs, ngModel ) {
var cache = {},
handleChange,
setValidation,
addToCache,
originalValue,
request,
shouldProcess,
options = {
ngRemoteThrottle: 400,
ngRemoteMethod: 'POST'
};

angular.extend( options, attrs );

addToCache = function( data ) {
if ( cache[ data.value ] ) return;
cache[ data.value ] = data.valid;
};

shouldProcess = function( value ) {
var otherRulesInValid = false;
for ( var p in ngModel.$error ) {
if ( ngModel.$error[ p ] && p != directiveId ) {
otherRulesInValid = true;
break;
}
}
return !( ngModel.$pristine || value === originalValue || otherRulesInValid );
};

setValidation = function( data ) {
ngModel.$setValidity( directiveId, data.isValid );
addToCache( data );
el.removeClass( 'ng-processing' );
};

handleChange = function( value ) {

originalValue = originalValue || value;

if ( !shouldProcess( value ) ) {
return setValidation( { isValid: true, value: value } );
}

if ( cache[ value ] ) {
return setValidation( cache[ value ] );
}

if ( request ) {
$timeout.cancel( request );
}

request = $timeout( function( ) {
el.addClass( 'ng-processing' );
$http( { method: options.ngRemoteMethod, url: options.ngRemoteValidate, data: { value: value } } ).success( setValidation );
}, options.ngRemoteThrottle );
return true;
};

scope.$watch( function( ) {
return ngModel.$viewValue;
}, handleChange );
}
};
};

angular.module( 'remoteValidation', [] )
.constant('MODULE_VERSION', '0.1.3')
.directive( directiveId, [ '$http', '$timeout', remoteValidate ] );

})( this.angular );
1 change: 1 addition & 0 deletions release/ngRemoteValidate.0.1.3.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a125f4a

Please sign in to comment.