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 #10942 from crdlc/bug-892357-master
Browse files Browse the repository at this point in the history
Bug 892357 - Followup to bug 890454 - [Homescreen] The save-bookmark scr...
  • Loading branch information
Cristian Rodriguez committed Jul 15, 2013
2 parents 057202a + 7d028ec commit 7cce92f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
26 changes: 19 additions & 7 deletions apps/homescreen/js/bookmark.js
Expand Up @@ -47,6 +47,21 @@ var BookmarkEditor = {
this.data = options.data;
this.onsaved = options.onsaved;
this.oncancelled = options.oncancelled;
this.origin = document.location.protocol + '//homescreen.' +
document.location.host.replace(/(^[\w\d]+.)?([\w\d]+.[a-z]+)/, '$2');
if (document.readyState === 'complete' ||
document.readyState === 'interactive') {
this._init();
} else {
var self = this;
document.addEventListener('DOMContentLoaded', function loaded() {
document.removeEventListener('DOMContentLoaded', loaded);
self._init();
});
}
},

_init: function bookmarkEditor_init() {
document.getElementById('bookmark-form').onsubmit = function() {
return false;
};
Expand All @@ -57,28 +72,25 @@ var BookmarkEditor = {
this.addButton = document.getElementById('button-bookmark-add');

this.cancelButton.addEventListener('click', this.close.bind(this));
this.addButton.addEventListener('click', this.save.bind(this));
this.saveListener = this.save.bind(this);
this.addButton.addEventListener('click', this.saveListener);
this.addButton.removeAttribute('disabled');

this.bookmarkTitle.value = this.data.name || '';
this.bookmarkUrl.value = this.data.url || '';

this.origin = document.location.protocol + '//homescreen.' +
document.location.host.replace(/(^[\w\d]+.)?([\w\d]+.[a-z]+)/, '$2');
},

close: function bookmarkEditor_close() {
this.oncancelled();
},

save: function bookmarkEditor_save(evt) {
evt.stopPropagation();
evt.preventDefault();
this.addButton.removeEventListener('click', this.saveListener);

// Only allow http(s): urls to be bookmarked.
if (/^https?:/.test(this.bookmarkUrl.value) == false)
return;

this.addButton.disabled = true;
this.data.name = this.bookmarkTitle.value;
this.data.bookmarkURL = this.bookmarkUrl.value;

Expand Down
2 changes: 1 addition & 1 deletion apps/homescreen/save-bookmark.html
Expand Up @@ -42,7 +42,7 @@ <h1 data-l10n-id="add-to-home-screen">Add to Home Screen</h1>
<label data-l10n-id="address">
Address <input type="url" id="bookmark-url"></input>
</label>
<button id="button-bookmark-add" data-l10n-id="add-to-home-screen">Add to Home Screen</button>
<button id="button-bookmark-add" disabled data-l10n-id="add-to-home-screen">Add to Home Screen</button>
</form>
</section>
</body>
Expand Down

0 comments on commit 7cce92f

Please sign in to comment.