Skip to content

Commit

Permalink
Merge pull request #23 from BruceBGordon/yahoo-fix-button-handler-dep2
Browse files Browse the repository at this point in the history
remove dependency on tuneup.js
  • Loading branch information
jonathanpenn committed Jul 6, 2015
2 parents 2b6676b + 4ec7c87 commit 4317af5
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions buttonHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,47 @@ function ButtonHandler(buttonName, checkEveryNumber, useNavBar, optionalIsTrueFu
this.statsHandleInvokedCount = 0;
this.statsHandleNotValidAndVisibleCount = 0;
this.statsHandleErrorCount = 0;
this.debugLogElementTreeOnIsTrue = false;
}

ButtonHandler.prototype.setDebugLogElementTreeOnIsTrue = function(aBool) {
this.debugLogElementTreeOnIsTrue = aBool;
}

ButtonHandler.prototype.isObjectNil = function(anObject) {
return anObject.toString() == "[object UIAElementNil]"
};

ButtonHandler.prototype.isValidAndVisible = function(aButtonOrNil) {
if (this.isObjectNil(aButtonOrNil)) {
return false;
}
//we now expect aButtonOrNil to be a button
return aButtonOrNil.checkIsValid() && aButtonOrNil.isVisible();
}

// return true if we our button is visible
ButtonHandler.prototype.isTrue = function(target, eventCount, mainWindow) {
this.statsIsTrueInvokedCount++;
var result;
if (this.optionalIsTrueFunction == null) {
if (this.debugLogElementTreeOnIsTrue) {
UIATarget.localTarget().logElementTree();
}
var aButton = this.findButton(target);
result = aButton.isNotNil() && aButton.validAndVisible();
} else {
result = this.optionalIsTrueFunction(target, eventCount, mainWindow);
}
if (result) {
this.statsIsTrueReturnedTrue++;
} else {
this.statsIsTrueReturnedFalse++;
};
return result;
result = this.isValidAndVisible(aButton);
} else {
result = this.optionalIsTrueFunction(target, eventCount, mainWindow);
}
if (result) {
this.statsIsTrueReturnedTrue++;
} else {
this.statsIsTrueReturnedFalse++;
};
return result;
};


ButtonHandler.prototype.findButton = function(target) {
return this.useNavBar ?
target.frontMostApp().mainWindow().navigationBar().buttons()[this.buttonName] :
Expand All @@ -82,7 +103,7 @@ ButtonHandler.prototype.isExclusive = function() {
ButtonHandler.prototype.handle = function(target, mainWindow) {
this.statsHandleInvokedCount++;
var button = this.findButton(target);
if (button.validAndVisible()) {
if (this.isValidAndVisible(button)) {
try{
button.tap();
} catch(err) {
Expand Down

0 comments on commit 4317af5

Please sign in to comment.