Merge branch 'noguchi' into qa

This commit is contained in:
Barbara Miller 2016-10-21 19:19:53 -07:00
commit 73893f41f7

View file

@ -17,89 +17,71 @@
* limitations under the License. * limitations under the License.
*/ */
var umbraAboveBelowOrOnScreen = function(e) {
var eTop = e.getBoundingClientRect().top;
if (eTop < window.scrollY) {
return -1; // above
} else if (eTop > window.scrollY + window.innerHeight) {
return 1; // below
} else {
return 0; // on screen
}
};
var UMBRA_N_USER_NAME = "${parameter_username}"; var UMBRA_N_USER_NAME = "${parameter_username}";
var UMBRA_N_PASSWORD = "${parameter_password}"; var UMBRA_N_PASSWORD = "${parameter_password}";
var umbraState = {'idleSince':null}; var umbraState = {'idleSince': null};
var re = /(?:Previous){0,1}\s+(page (\d+)\/\d+)\s+(?:Next){0,1}/; var re = /(?:Previous){0,1}\s+(page\s(\d+)\/\d+)\s+(?:Next){0,1}/;
var umbraIntervalFunc = function() { var umbraIntervalFunc = function () {
var clickedSomething = false; "use strict";
var somethingLeftBelow = false; var target = null;
var somethingLeftAbove = false; var linktext = "";
var target = null; var i = 0;
var linktext = "";
var navlinks = document.querySelectorAll("div.nav > a"); var navlinks = document.querySelectorAll("div.nav > a");
for (i = 0; i < navlinks.length; i++) { for (i = 0; i < navlinks.length; i += 1) {
linktext = navlinks[i].textContent; linktext = navlinks[i].textContent;
if (linktext.indexOf("Next") > -1) { if (linktext.indexOf("Next") > -1) {
target = navlinks[i]; target = navlinks[i];
} }
} }
if (target) { if (target) {
var where = umbraAboveBelowOrOnScreen(target); umbraState.idleSince = null;
if (where === 0) { var target_page = re.exec(document.querySelector("div.nav").textContent);
umbraState.idleSince = null; console.log('loaded ' + target_page[1]);
var target_page = re.exec(document.querySelector("div.nav").textContent); jQuery("#resultBox").load("/index.php/Search/Index/page/" + (+target_page[2] + 1));
console.log('loaded ' + target_page[1]); }
jQuery("#resultBox").load("/index.php/Search/Index/page/" + (+target_page[2] + 1));
} else if (where > 0) {
somethingLeftBelow = true;
} else if (where < 0) {
somethingLeftAbove = true;
}
}
if (umbraState.idleSince == null) { if (umbraState.idleSince === null) {
umbraState.idleSince = Date.now(); umbraState.idleSince = Date.now();
} }
} };
// If we haven't had anything to do (scrolled, clicked, etc) in this amount of // If we haven't had anything to do (scrolled, clicked, etc) in this amount of
// time, then we consider ourselves finished with the page. // time, then we consider ourselves finished with the page.
var UMBRA_USER_ACTION_IDLE_TIMEOUT_SEC = 5; var UMBRA_USER_ACTION_IDLE_TIMEOUT_SEC = 5;
// Called from outside of this script. // Called from outside of this script.
var umbraBehaviorFinished = function() { var umbraBehaviorFinished = function () {
if (umbraState.idleSince != null) { "use strict";
var idleTimeMs = Date.now() - umbraState.idleSince; if (umbraState.idleSince !== null) {
if (idleTimeMs / 1000 > UMBRA_USER_ACTION_IDLE_TIMEOUT_SEC) { var idleTimeMs = Date.now() - umbraState.idleSince;
clearInterval(umbraIntervalId); if (idleTimeMs / 1000 > UMBRA_USER_ACTION_IDLE_TIMEOUT_SEC) {
return true; clearInterval(umbraIntervalId);
return true;
}
} }
} return false;
return false; };
}
var umbraNLogin = function() { var umbraNLogin = function () {
var login_inputs = document.querySelectorAll("#loginForm > form > div > input"); "use strict";
var emailInput = login_inputs[0]; var login_inputs = document.querySelectorAll("#loginForm > form > div > input");
var passwordInput = login_inputs[1]; var emailInput = login_inputs[0];
emailInput.value=UMBRA_N_USER_NAME; var passwordInput = login_inputs[1];
passwordInput.value=UMBRA_N_PASSWORD; emailInput.value = UMBRA_N_USER_NAME;
document.forms.login.submit(); passwordInput.value = UMBRA_N_PASSWORD;
return false; document.forms.login.submit();
} return false;
};
if (document.getElementById("loginForm") == null || UMBRA_N_USER_NAME.indexOf("parameter")>0 || UMBRA_N_PASSWORD.indexOf("parameter")>0 ) {//check for unset parameters if (document.getElementById("loginForm") === null || UMBRA_N_USER_NAME.indexOf("parameter") > 0 || UMBRA_N_PASSWORD.indexOf("parameter") > 0) {//check for unset parameters
console.log("missing #loginForm or login credentials; maybe already logged in for " + location.href); console.log("missing #loginForm or login credentials; maybe already logged in for " + location.href);
var umbraIntervalId = setInterval(umbraIntervalFunc, 5000); var umbraIntervalId = setInterval(umbraIntervalFunc, 5000);
} } else {//login
else {//login console.log("#loginForm and credentials found for " + location.href);
console.log("#loginForm and credentials found for " + location.href); umbraNLogin();
umbraNLogin();
} }