Skip to content

Commit

Permalink
Fix #26, make updateValue() synchronous by default, only async if eve…
Browse files Browse the repository at this point in the history
…nt is passed in.
  • Loading branch information
cvn committed Jun 18, 2015
1 parent ac82da2 commit d269f84
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/angular-placeholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ angular.module('ng.shims.placeholder', [])

// handler for model-less inputs to interact with non-angular code
if (!ngModel) {
elem.bind('change', function () {
changePlaceholder($interpolate(elem.attr('placeholder') || '')(scope));
elem.bind('change', function (event) {
changePlaceholder($interpolate(elem.attr('placeholder') || '')(scope), event);
});
}

Expand Down Expand Up @@ -109,16 +109,16 @@ angular.module('ng.shims.placeholder', [])
documentListenersApplied = true;
}

function updateValue(e) {
function updateValue(event) {
var val = elem.val();

// don't update from placeholder, helps debounce
if (elem.hasClass(emptyClassName) && val && val === text) { return; }

conditionalDefer(function(){ setValue(val); });
conditionalDefer(function(){ setValue(val); }, event);
}

function conditionalDefer(callback) {
function conditionalDefer(callback, event) {
// IE8/9: ngModel uses a keydown handler with deferrered
// execution to check for changes to the input. this $timeout
// prevents callback from firing before the keydown handler,
Expand All @@ -127,7 +127,7 @@ angular.module('ng.shims.placeholder', [])
//
// TODO: remove this function when tab key behavior is fixed in
// angular core
if (document.documentMode <= 11) {
if (document.documentMode <= 11 && event) {
$timeout(callback, 0);
} else {
callback();
Expand Down Expand Up @@ -174,12 +174,12 @@ angular.module('ng.shims.placeholder', [])
return val;
}

function changePlaceholder(value) {
function changePlaceholder(value, event) {
if (elem.hasClass(emptyClassName) && elem.val() === text) {
elem.val('');
}
text = value;
updateValue();
updateValue(event);
}

// IE9: getting activeElement in an iframe raises error
Expand Down

0 comments on commit d269f84

Please sign in to comment.