Add preview as HTML functionality

Add a toolbar button that opens a new window and shows the content
of the pad as text/html. Used the 'eye' icon from the Iconic set at
http://somerandomdude.com/work/iconic/
This commit is contained in:
Johan Friis 2012-09-11 17:37:40 +02:00
parent b2c06e78d0
commit fd3472589b
7 changed files with 103 additions and 1 deletions

View file

@ -11,6 +11,7 @@
{ "name": "webaccess", "hooks": { "expressConfigure": "ep_etherpad-lite/node/hooks/express/webaccess:expressConfigure" } },
{ "name": "apicalls", "hooks": { "expressCreateServer": "ep_etherpad-lite/node/hooks/express/apicalls:expressCreateServer" } },
{ "name": "importexport", "hooks": { "expressCreateServer": "ep_etherpad-lite/node/hooks/express/importexport:expressCreateServer" } },
{ "name": "preview", "hooks": { "expressCreateServer": "ep_etherpad-lite/node/hooks/express/preview:expressCreateServer" } },
{ "name": "errorhandling", "hooks": { "expressCreateServer": "ep_etherpad-lite/node/hooks/express/errorhandling:expressCreateServer" } },
{ "name": "socketio", "hooks": { "expressCreateServer": "ep_etherpad-lite/node/hooks/express/socketio:expressCreateServer" } },
{ "name": "adminplugins", "hooks": {

View file

@ -0,0 +1,68 @@
/**
* Handles the preview requests
*/
/*
* 2011 Peter 'Pita' Martischka (Primary Technology Ltd)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var ERR = require("async-stacktrace");
var padManager = require("../db/PadManager");
/**
* do a requested preview
*/
function _cleanText(text)
{
if (!text)
return null;
var atext = text.split('\n');
var clean = Array();
for (n in atext)
{
var line = atext[n];
if (line[0] === "*")
line = line.substring(1);
clean.push(line);
}
return clean.join('\n');
}
exports.doPreview = function(req, res, padId, type)
{
padManager.getPad(padId, function(err, pad)
{
ERR(err);
if(type == "html")
{
res.header("Content-Type","text/html; charset=utf-8");
if(req.params.rev){
pad.getInternalRevisionAText(req.params.rev, function(junk, text)
{
res.write(_cleanText(text.text));
});
}
else
{
res.write(_cleanText(pad.text()));
}
res.end();
}
});
};

View file

@ -0,0 +1,19 @@
var hasPadAccess = require("../../padaccess");
var previewHandler = require('../../handler/PreviewHandler');
exports.expressCreateServer = function (hook_name, args, cb) {
args.app.get('/p/:pad/:rev?/preview/:type', function(req, res, next) {
var types = ['html'];
//send a 404 if we don't support this filetype
if (types.indexOf(req.params.type) == -1) {
next();
return;
}
res.header("Access-Control-Allow-Origin", "*");
hasPadAccess(req, res, function() {
previewHandler.doPreview(req, res, req.params.pad, req.params.type);
});
});
}

View file

@ -815,6 +815,9 @@ table#otheruserstable {
.buttonicon-savedRevision {
background-position: 0px -493px
}
.buttonicon-preview {
background-image: url('../../static/img/preview.png');
}
#focusprotector {
z-index: 100;
position: absolute;

BIN
src/static/img/preview.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 B

View file

@ -98,6 +98,11 @@ var padeditbar = (function()
init: function()
{
var self = this;
//get /p/padname
var pad_root_path = new RegExp(/.*\/p\/[^\/]+/).exec(document.location.pathname)
//get http://example.com/p/padname
var pad_root_url = document.location.href.replace(document.location.pathname, pad_root_path)
$("#editbar .editbarbutton").attr("unselectable", "on"); // for IE
$("#editbar").removeClass("disabledtoolbar").addClass("enabledtoolbar");
$("#editbar [data-key]").each(function (i, e) {
@ -106,6 +111,7 @@ var padeditbar = (function()
event.preventDefault();
});
});
$("#previewhtmllink").attr("href", pad_root_url + "/preview/html");
},
isEnabled: function()
{

View file

@ -108,8 +108,13 @@
</a>
</li>
<li class="separator"></li>
<li>
<a class="grouped-left" id="previewhtmllink" title="Preview current pad as html" target="_blank">
<span class="buttonicon buttonicon-preview"></span>
</a>
</li>
<li onClick="document.location = document.location.pathname+ '/timeslider'">
<a id="timesliderlink" title="Show the history of this pad">
<a class="grouped-right" id="timesliderlink" title="Show the history of this pad">
<span class="buttonicon buttonicon-history"></span>
</a>
</li>