diff --git a/css/popup.css b/css/popup.css index 913ff37..3d70042 100644 --- a/css/popup.css +++ b/css/popup.css @@ -140,6 +140,35 @@ a.domain { text-decoration:none; cursor: default; } +.comment { + display: none; +} +ol[data-commentspage="true"] .comment { + display: block; +} +ol[data-commentspage="true"] button.cancel { + display: none; +} +.comment fieldset { + margin: 12px 0 0; + padding: 0; + border: 0; +} +.comment textarea { + display: block; + width: 100%; + margin: 0; + padding: 0; + border: 0; + box-shadow: inset 0px 0px 2px black; + font: normal small verdana, arial, helvetica, sans-serif; +} +.comment button { + margin: 5px 5px 0 0; +} +.comment .status { + color: red; +} .morelink { display:block; text-align:center; diff --git a/js/common.js b/js/common.js index 4ef4026..c60ef67 100644 --- a/js/common.js +++ b/js/common.js @@ -587,6 +587,21 @@ RedditAPI.prototype.reportPost = function (e) { e.srcElement.parentNode.innerHTML = 'reported!'; }; +/** + * Submits a comment. + * @alias RedditAPI.submitComment(event) + * @param {Object} event The event object. + * @return {Boolean} Returns true. + * @method + */ +RedditAPI.prototype.submitComment = function (e) { + var listItem, fullName; + + listItem = e.srcElement.parentNode.parentNode.parentNode; + fullName = listItem.id; + e.srcElement.parentNode.getElementsByClassName('status')[0].innerHTML = 'Not yet programmed. ID: ' + fullName; +}; + reddit = new RedditAPI('www.reddit.com'); /** @@ -648,11 +663,11 @@ Popup.prototype.createListHTML = function (url) { throw 'Cannot create list HTML for a non-cached URL.'; } - listHTML = '
    '; + listHTML = '
      '; staleCounter = 0; utils.forEachIn(cache.get(url).posts, function (name, value) { - var data, voteDir, hiddenText, hideStatus, hideAction, saveText, saveStatus, saveAction, isFreshEnough, freshText, thumbSrc; + var data, voteDir, hiddenText, hideStatus, hideAction, saveText, saveStatus, saveAction, isFreshEnough, freshText, thumbSrc, commentText; data = value.data; if (data.likes === true) voteDir = 1; @@ -665,6 +680,7 @@ Popup.prototype.createListHTML = function (url) { saveText = saveStatus === true ? 'unsave' : 'save'; saveAction = saveStatus === true ? 'reddit.unsavePost(event)' : 'reddit.savePost(event)'; isFreshEnough = settings.get('freshCutoff') === 91 ? 'true' : data.created_utc >= utils.epoch() - settings.get('freshCutoff') * 24 * 60 * 60; + commentText = data.savedCommentText === undefined ? '' : data.savedCommentText; if (!isFreshEnough) staleCounter++; freshText = isFreshEnough ? 'fresh' : 'stale'; thumbSrc = data.thumbnail.indexOf('/') === 0 ? 'http://www.reddit.com' + data.thumbnail : data.thumbnail; @@ -687,13 +703,22 @@ Popup.prototype.createListHTML = function (url) { listHTML += '' + data.subreddit + ''; listHTML += ''; listHTML += '
      '; - listHTML += '' + data.num_comments + ' comments'; + listHTML += '' + data.num_comments + ' comments'; listHTML += ''; listHTML += '' + saveText + ''; listHTML += '' + hiddenText + ''; listHTML += 'report'; listHTML += '
      '; - listHTML += '' + listHTML += ''; + listHTML += '
      '; + listHTML += '
      '; + listHTML += 'Leave a comment'; + listHTML += ''; + listHTML += ''; + listHTML += ''; + listHTML += ''; + listHTML += '
      '; + listHTML += '
      '; listHTML += ''; }); @@ -734,3 +759,15 @@ Popup.prototype.showStalePosts = function () { stalePosts[0].className = 'stale-shown'; } }; + +/** + * Show the comment form for a given post. + * @alias Popup.showCommentForm(postId) + * @param {String} postId The ID of the thing to show the comment form for. + * @return {Boolean} Returns true. + * @method + */ +Popup.prototype.showCommentForm = function (postId) { + document.getElementById(postId).getElementsByClassName('comment')[0].style.display = 'block'; + return true; +};