mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-05-10 00:45:01 -04:00
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:
parent
b2c06e78d0
commit
fd3472589b
7 changed files with 103 additions and 1 deletions
|
@ -11,6 +11,7 @@
|
||||||
{ "name": "webaccess", "hooks": { "expressConfigure": "ep_etherpad-lite/node/hooks/express/webaccess:expressConfigure" } },
|
{ "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": "apicalls", "hooks": { "expressCreateServer": "ep_etherpad-lite/node/hooks/express/apicalls:expressCreateServer" } },
|
||||||
{ "name": "importexport", "hooks": { "expressCreateServer": "ep_etherpad-lite/node/hooks/express/importexport: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": "errorhandling", "hooks": { "expressCreateServer": "ep_etherpad-lite/node/hooks/express/errorhandling:expressCreateServer" } },
|
||||||
{ "name": "socketio", "hooks": { "expressCreateServer": "ep_etherpad-lite/node/hooks/express/socketio:expressCreateServer" } },
|
{ "name": "socketio", "hooks": { "expressCreateServer": "ep_etherpad-lite/node/hooks/express/socketio:expressCreateServer" } },
|
||||||
{ "name": "adminplugins", "hooks": {
|
{ "name": "adminplugins", "hooks": {
|
||||||
|
|
68
src/node/handler/PreviewHandler.js
Normal file
68
src/node/handler/PreviewHandler.js
Normal 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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
19
src/node/hooks/express/preview.js
Normal file
19
src/node/hooks/express/preview.js
Normal 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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
|
@ -815,6 +815,9 @@ table#otheruserstable {
|
||||||
.buttonicon-savedRevision {
|
.buttonicon-savedRevision {
|
||||||
background-position: 0px -493px
|
background-position: 0px -493px
|
||||||
}
|
}
|
||||||
|
.buttonicon-preview {
|
||||||
|
background-image: url('../../static/img/preview.png');
|
||||||
|
}
|
||||||
#focusprotector {
|
#focusprotector {
|
||||||
z-index: 100;
|
z-index: 100;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
|
BIN
src/static/img/preview.png
Normal file
BIN
src/static/img/preview.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 328 B |
|
@ -98,6 +98,11 @@ var padeditbar = (function()
|
||||||
init: function()
|
init: function()
|
||||||
{
|
{
|
||||||
var self = this;
|
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 .editbarbutton").attr("unselectable", "on"); // for IE
|
||||||
$("#editbar").removeClass("disabledtoolbar").addClass("enabledtoolbar");
|
$("#editbar").removeClass("disabledtoolbar").addClass("enabledtoolbar");
|
||||||
$("#editbar [data-key]").each(function (i, e) {
|
$("#editbar [data-key]").each(function (i, e) {
|
||||||
|
@ -106,6 +111,7 @@ var padeditbar = (function()
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
$("#previewhtmllink").attr("href", pad_root_url + "/preview/html");
|
||||||
},
|
},
|
||||||
isEnabled: function()
|
isEnabled: function()
|
||||||
{
|
{
|
||||||
|
|
|
@ -108,8 +108,13 @@
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="separator"></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'">
|
<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>
|
<span class="buttonicon buttonicon-history"></span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue