Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #12082 from gabrielesvelto/bug-911895-wappush-atte…
Browse files Browse the repository at this point in the history
…ntion-screen-home

Bug 911895 - Close the WAP Push attention screen when the home button is pressed r=vingtetun
  • Loading branch information
gabrielesvelto committed Sep 11, 2013
2 parents 0fdc90c + ae1731b commit 256ec63
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
14 changes: 14 additions & 0 deletions apps/wappush/js/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ var WapMessageScreen = {
this.message = document.getElementById('message');

// Event handlers
window.addEventListener('resize', this.onresize);

this.closeButton.addEventListener('click', this.onclose);

// Populate the message
Expand All @@ -42,6 +44,18 @@ var WapMessageScreen = {
window.close();
},

/**
* Close the attention screen instead of resizing it into a status-bar
*/
onresize: function wps_onresize(evt) {
/* XXX: This is a hack to close the attention screen when the user taps the
* home button. If we don't do this the attention screen will be shrunk
* into the statusbar but will still be open. */
if (window.innerHeight < 200) {
window.close();
}
},

/**
* Escapes HTML code within a string
*
Expand Down
24 changes: 19 additions & 5 deletions apps/wappush/js/wappush.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ var WapPushManager = {
var timestamp = Date.now();

if (!this._wapPushEnabled) {
window.close();
this.close();
return;
}

Expand All @@ -95,7 +95,7 @@ var WapPushManager = {
self.displayWapPushMessage(timestamp);
});

window.close();
self.close();
};
});
},
Expand All @@ -119,6 +119,8 @@ var WapPushManager = {
* @param {Number} timestamp The message timestamp
*/
displayWapPushMessage: function wpm_displayWapPushMessage(timestamp) {
var self = this;

asyncStorage.getItem(timestamp, function(message) {
var protocol = window.location.protocol;
var host = window.location.host;
Expand All @@ -132,18 +134,30 @@ var WapPushManager = {

var messageScreen = window.open(uri, 'wappush_attention', 'attention');

messageScreen.onload = function() {
messageScreen.onload = function(evt) {
messageScreen.WapMessageScreen.init();
asyncStorage.removeItem(timestamp);
};
messageScreen.onunload = function() {

messageScreen.onunload = function(evt) {
// Close the parent window to hide the application from the cards view
window.close();
if (evt.target.location != 'about:blank') {
self.close();
return;
}
};
},
function(error) {
console.log('Could not retrieve the message:' + error + '\n');
});
},

/**
* Closes the application, lets the event loop run once to ensure clean
* termination of pending events.
*/
close: function wpm_close() {
window.setTimeout(window.close);
}
};

Expand Down

0 comments on commit 256ec63

Please sign in to comment.