Browse files

Added attempt to focus.

  • Loading branch information...
1 parent a3843ac commit 1e91bcb5ccb2f0a6ca71fff4859a3a24ba2951c2 Sheridan Rawlins committed Feb 18, 2012
View
4 tools/chrome/extensions/shorten-services/goo.gl/launch.html
@@ -11,6 +11,10 @@ <h1 id="state">Processing</h1>
Shortening <span id="long"></span>
to <a id="short"></a>.
<button id="return">Return</button>
+ <form id="short-form">
+ <input id="short-text" type="text">
+ </form>
+ <button id="focus">focus</button>
</div>
</body>
</html>
View
40 tools/chrome/extensions/shorten-services/goo.gl/launch.js
@@ -1,4 +1,11 @@
var shortUrl;
+
+// TODO(scr) remove this when done debugging.
+var printFocus = function() {
+ var focused = document.querySelectorAll(':focus');
+ console.log(focused);
+};
+
var fetchData = function() {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
@@ -7,28 +14,53 @@ var fetchData = function() {
var resDiv = document.getElementById("result");
var shortDiv = document.getElementById("short");
var longDiv = document.getElementById("long");
+ var shortText = document.getElementById("short-text");
shortUrl = result.id;
shortDiv.innerText = shortUrl;
shortDiv.href = shortUrl;
longDiv.innerText = window.intent.data;
resDiv.style.display = "block";
+
+ // Select the text for copying.
+ shortText.value = shortUrl;
+ shortText.select();
+ shortText.focus();
+
+ // TODO(scr) remove when done debugging.
+ setTimeout(function timer() {
+ printFocus();
+ setTimeout(timer, 1000);
+ }, 1000)
+ printFocus();
}
};
xhr.open('POST', 'https://www.googleapis.com/urlshortener/v1/url');
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify({'longUrl': window.intent.data}));
};
+function finishIntent() {
+ window.intent.postResult(shortUrl);
+ window.close();
+}
+
window.addEventListener("DOMContentLoaded", function() {
if(window.intent) {
fetchData();
}
var retButton = document.getElementById("return");
- retButton.addEventListener("click", function() {
- window.intent.postResult(shortUrl);
- window.close();
- });
+ retButton.addEventListener("click", finishIntent);
+ var shortForm = document.getElementById("short-form");
+ shortForm.addEventListener('submit', finishIntent);
+
+ // TODO(scr) remove when done debugging.
+ var focusButton = document.getElementById("focus");
+ focusButton.addEventListener('click', function() {
+ var shortText = document.getElementById("short-text");
+ shortText.select();
+ shortText.focus();
+ });
}, false);

0 comments on commit 1e91bcb

Please sign in to comment.