Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implement TEXT expando type and tumblr handling for it

The inline image viewer now handles TEXT types for tumblr.

I do not at this time do anything to protect from malicious HTML. (I
trust tumblr enough, but this is a general purpose feature)

Consider porting the tweet viewer to run in the image viewer.
  • Loading branch information...
commit 502b64a46fd0729a3ea2e452a7e06af69f8a5301 1 parent e5d7b75
@gamefreak authored
Showing with 63 additions and 3 deletions.
  1. +63 −3 lib/reddit_enhancement_suite.user.js
View
66 lib/reddit_enhancement_suite.user.js
@@ -8323,9 +8323,10 @@ all embedding information (except 'site') is to be attatched the
html anchor in the handleInfo function
required type:
- 'IMAGE' for single images | 'GALLERY' for image galleries
+ 'IMAGE' for single images | 'GALLERY' for image galleries | 'TEXT' html/text is intended to be displayed
required src:
if type is IMAGE then src is an image URL string
+ if type is TEXT then src is HTML code
if type is GALLERY then src is an array javascript objects of the form:
{
required src:
@@ -8745,8 +8746,10 @@ modules['showImages'] = {
this.imageList.push(elem);
var expandLink = document.createElement('a');
- expandLink.className = 'toggleImage expando-button image collapsed';
- if (elem.type == 'GALLERY') expandLink.className += ' gallery';
+ expandLink.className = 'toggleImage expando-button collapsed';
+ if (elem.type == 'IMAGE') expandLink.className += ' image';
+ if (elem.type == 'GALLERY') expandLink.className += ' image gallery';
+ if (elem.type == 'TEXT') expandLink.className += ' selftext';
expandLink.innerHTML = ' ';
expandLink.addEventListener('click', function(e) {
e.preventDefault();
@@ -8822,6 +8825,8 @@ modules['showImages'] = {
case 'GALLERY':
this.generateGalleryExpando(expandoButton, imageLink);
break;
+ case 'TEXT':
+ this.generateTextExpando(expandoButton, imageLink);
}
}
},
@@ -9002,6 +9007,46 @@ modules['showImages'] = {
this.trackImageLoad(imageLink, image);
this.makeImageZoomable(image);
},
+ generateTextExpando: function(expandoButton, imageLink) {
+ var wrapperDiv = document.createElement('div');
+ addClass(wrapperDiv, 'usertext');
+
+ var imgDiv = document.createElement('div');
+ addClass(imgDiv, 'madeVisible usertext-body');
+
+ var header = document.createElement('h3');
+ header.className = 'imgTitle';
+ header.innerHTML = imageLink.imageTitle || '';
+ imgDiv.appendChild(header);
+
+ var text = document.createElement('div');
+ text.className = 'md';
+ //<iframe> or sanitization???
+ text.innerHTML = imageLink.src;
+ imgDiv.appendChild(text);
+
+ var captions = document.createElement('div');
+ captions.className = 'imgCaptions';
+ captions.innerHTML = imageLink.caption || '';
+ imgDiv.appendChild(captions);
+
+ var credits = document.createElement('div');
+ credits.className = 'imgCredits';
+ credits.innerHTML = imageLink.credits || '';
+ imgDiv.appendChild(credits);
+
+ wrapperDiv.appendChild(imgDiv);
+ if (hasClass(expandoButton, 'commentImg')) {
+ insertAfter(expandoButton, wrapperDiv);
+ } else {
+ expandoButton.parentNode.appendChild(wrapperDiv);
+ }
+
+ removeClass(expandoButton, 'collapsed');
+ addClass(expandoButton, 'expanded');
+
+ //TODO: mark in history?
+ },
trackImageLoad: function(link, image) {
if (modules['showImages'].options.markVisited.value) {
image.addEventListener('load', function(e) {
@@ -9558,6 +9603,21 @@ modules['showImages'] = {
elem.href = post.photos[0].original_size.url;
}
break;
+ case 'text':
+ elem.type = 'TEXT';
+ elem.imageTitle = post.title;
+ /*
+ * While I trust tumblr adequately, I am not sure what
+ * kind of sanitisation that they do on the returned
+ * HTML and therefore how safe it is.
+ *
+ * It may be a good idea to either do some of our own
+ * sanitisation or to place it in an <iframe>.
+ */
+ elem.src = post.body;
+ //I am not sure how to pick alternate URLs for this so this becomes unnecessary.
+ delete elem.hrefOverride;
+ break;
default:
return;
break;
Please sign in to comment.
Something went wrong with that request. Please try again.