Skip to content

Commit

Permalink
Edit now works correctly.
Browse files Browse the repository at this point in the history
Fix: the progress indicator is now removed only once
  • Loading branch information
folletto committed May 20, 2012
1 parent 7c13a9f commit 5053a11
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 89 deletions.
2 changes: 1 addition & 1 deletion src/background.js
Expand Up @@ -95,7 +95,7 @@ chrome.extension.onRequest.addListener(function (resp, sender, sendResponse) {
}
}

xhr.send("details=" + resp.Data.description + "&link=" + resp.Data.url + "&board=" + resp.Data.board_id + "&csrfmiddlewaretoken=" + Pinterest.token);
xhr.send("details=" + resp.Data.description + "&link=" + resp.Data.media_url + "&board=" + resp.Data.board_id + "&csrfmiddlewaretoken=" + Pinterest.token);

});

Expand Down
179 changes: 91 additions & 88 deletions src/notification-pinned.html
Expand Up @@ -148,94 +148,97 @@ <h1 id="title"></h1>
</body>

<script>
// **************************************************************************************************** SCRIPT
var countDownAmount = 5000;
var currentCount = countDownAmount;
var data = JSON.parse(window.location.hash.split('#data=')[1]);
var EMain;


function close() {
// Send message back to remove iframe
parent.postMessage(data.pin_id, data.page_url);
}

window.onload = function () {

EMain = document.getElementById("main"),
EProgress = document.getElementById("progress");

var txtDescription = document.getElementById("txtDescription");
var btnUpdate = document.getElementById("btnUpdate");
var error = document.getElementById("error");
var img = document.getElementById("imgMain");

document.getElementById("title").innerHTML = 'Pinned to ' + data.board_name;



img.src = data.media_url;

img.onload = function () {
if (this.width >= this.height) {
this.width = Math.min(45, this.width);
} else {
this.height = Math.min(45, this.height);
}
img.style.display = "block";
}

document.getElementById("frmUpdate").onsubmit = function (e) {
e.preventDefault();
error.style.display = "none";
txtDescription.disabled = "disabled";
btnUpdate.disabled = "disabled";
btnUpdate.value = "Updating...";

data.description = txtDescription.value;

chrome.extension.sendRequest({ Data: data }, function (success) {
if (success) {
btnUpdate.value = "Updated!";
setTimeout(function () {
close();
}, 2000);
} else {
error.style.display = "block";
txtDescription.removeAttribute("disabled");
btnUpdate.removeAttribute("disabled");
btnUpdate.value = "Update";
}
});
}


var countDown = setInterval(function () {
currentCount -= 50;
if (currentCount == 0) {
close();
} else {
EProgress.style.width = Math.round((currentCount / countDownAmount) * 100) + "%";
}
}, 50);

txtDescription.placeholder = data.description;

txtDescription.onclick = btnUpdate.onclick = function () {
clearInterval(countDown);
countDown = null;
if (EProgress) {
EMain.removeChild(EProgress);
}

}




}


// **************************************************************************************************** SCRIPT
var countDownAmount = 5000;
var currentCount = countDownAmount;
var countDown = null;
var data = JSON.parse(window.location.hash.split('#data=')[1]);

window.onload = function () {
/*****************************************************************************************************
* Update the form with the right data.
*/
var txtDescription = document.getElementById("txtDescription");
var btnUpdate = document.getElementById("btnUpdate");
var error = document.getElementById("error");
var img = document.getElementById("imgMain");

document.getElementById("title").innerHTML = 'Pinned to ' + data.board_name;


// ****** On image load set correct image thumbnail size
img.src = data.media_url;

img.onload = function () {
if (this.width >= this.height) {
this.width = Math.min(45, this.width);
} else {
this.height = Math.min(45, this.height);
}
img.style.display = "block";
}

// ****** Update Pin button
document.getElementById("frmUpdate").onsubmit = function (e) {
e.preventDefault();
error.style.display = "none";
txtDescription.disabled = "disabled";
btnUpdate.disabled = "disabled";
btnUpdate.value = "Updating...";

data.description = txtDescription.value;

chrome.extension.sendRequest({ Data: data }, function (success) {
if (success) {
btnUpdate.value = "Updated!";
setTimeout(function () {
close();
}, 2000);
} else {
error.style.display = "block";
txtDescription.removeAttribute("disabled");
btnUpdate.removeAttribute("disabled");
btnUpdate.value = "Update";
}
});
}

// ****** Countdown
var EProgress = document.getElementById("progress");
countDown = setInterval(function () {
currentCount -= 50;
if (currentCount == 0) {
close();
} else {
EProgress.style.width = Math.round((currentCount / countDownAmount) * 100) + "%";
}
}, 50);

// ****** Description text field: when clicked, stop countdown
txtDescription.placeholder = data.description;
txtDescription.onclick = removeProgressBar;
btnUpdate.onclick = removeProgressBar;
}

function close() {
/*****************************************************************************************************
* Send message back to becausemac.js to remove iframe
*/
parent.postMessage(data.pin_id, data.page_url);
}

function removeProgressBar() {
/*****************************************************************************************************
* Remove the progress bar timer and indicator
*/
clearInterval(countDown);
countDown = null;

var EProgress = document.getElementById("progress");
if (EProgress) {
document.getElementById("main").removeChild(EProgress);
}
}
</script>


Expand Down

0 comments on commit 5053a11

Please sign in to comment.