Repaired viewer

This commit is contained in:
benweet 2013-07-29 01:03:19 +01:00
parent f732b99d91
commit 55a1e0f1b2
7 changed files with 75 additions and 48 deletions

View File

@ -1,9 +1,10 @@
define(function() {
function Extension(extensionId, extensionName, isOptional) {
function Extension(extensionId, extensionName, isOptional, disableInViewer) {
this.extensionId = extensionId;
this.extensionName = extensionName;
this.isOptional = isOptional;
this.disableInViewer = disableInViewer;
}
return Extension;

View File

@ -82,6 +82,9 @@ define([
_.each(extensionList, function(extension) {
extension.config = _.extend({}, extension.defaultConfig, extensionSettings[extension.extensionId]);
extension.config.enabled = !extension.isOptional || extension.config.enabled === undefined || extension.config.enabled === true;
if(viewerMode === true && extension.disableInViewer) {
extension.config.enabled = false;
}
});
// Call every onInit callbacks
@ -157,17 +160,18 @@ define([
var previewContentsJQElt = undefined;
extensionMgr["onAsyncPreview"] = function() {
logger.log("onAsyncPreview");
logger.log("Conversion time: " + (new Date() - extensionMgr.previewStartTime));
// Call onPreviewFinished callbacks when all async preview are finished
var counter = 0;
function tryFinished() {
if(++counter === nbAsyncPreviewCallback) {
logger.log("Preview time: " + (new Date() - extensionMgr.previewStartTime));
_.defer(function() {
var html = "";
_.each(previewContentsElt.children, function(elt) {
html += elt.innerHTML;
});
onPreviewFinished(utils.trim(html));
logger.log("Preview time: " + (new Date() - extensionMgr.previewStartTime));
});
}
}

View File

@ -7,7 +7,7 @@ define([
"text!html/buttonHtmlCodeSettingsBlock.html",
], function($, _, utils, Extension, buttonHtmlCodeHTML, buttonHtmlCodeSettingsBlockHTML) {
var buttonHtmlCode = new Extension("buttonHtmlCode", 'Button "HTML code"', true);
var buttonHtmlCode = new Extension("buttonHtmlCode", 'Button "HTML code"', true, true);
buttonHtmlCode.settingsBlock = buttonHtmlCodeSettingsBlockHTML;
buttonHtmlCode.defaultConfig = {
template: "<%= documentHTML %>",
@ -21,6 +21,11 @@ define([
newConfig.template = utils.getInputValue("#textarea-html-code-template");
};
var extensionMgr = undefined;
buttonHtmlCode.onExtensionMgrCreated = function(extensionMgrParameter) {
extensionMgr = extensionMgrParameter;
};
buttonHtmlCode.onCreatePreviewButton = function() {
return $(buttonHtmlCodeHTML);
};

View File

@ -7,7 +7,7 @@ define([
"text!html/buttonStatSettingsBlock.html",
], function($, _, utils, Extension, buttonStatHTML, buttonStatSettingsBlockHTML) {
var buttonStat = new Extension("buttonStat", 'Button "Statistics"', true);
var buttonStat = new Extension("buttonStat", 'Button "Statistics"', true, true);
buttonStat.settingsBlock = buttonStatSettingsBlockHTML;
buttonStat.defaultConfig = {
name1: "Characters",

View File

@ -7,7 +7,7 @@ define([
"libs/jquery.mousewheel"
], function($, _, Extension, scrollLinkSettingsBlockHTML) {
var scrollLink = new Extension("scrollLink", "Scroll Link", true);
var scrollLink = new Extension("scrollLink", "Scroll Link", true, true);
scrollLink.settingsBlock = scrollLinkSettingsBlockHTML;
var sectionList = undefined;

View File

@ -245,14 +245,17 @@
Markdown.Extra.prototype.hashExtraBlock = function(block) {
return '\n<p>~X' + (this.hashBlocks.push(block) - 1) + 'X</p>\n';
};
Markdown.Extra.prototype.hashExtraInline = function(block) {
return '~X' + (this.hashBlocks.push(block) - 1) + 'X';
};
// Replace placeholder blocks in `text` with their corresponding
// html blocks in the hashBlocks array.
Markdown.Extra.prototype.unHashExtraBlocks = function(text) {
var self = this;
function recursiveUnHash() {
var hasHash = false;
text = text.replace(/<p>~X(\d+)X<\/p>/g, function(wholeMatch, m1) {
text = text.replace(/(?:<p>)?~X(\d+)X(?:<\/p>)?/g, function(wholeMatch, m1) {
hasHash = true;
var key = parseInt(m1, 10);
return self.hashBlocks[key];
@ -495,9 +498,10 @@
}
footnoteCounter++;
self.usedFootnotes.push(id);
return '<a href="#fn:' + id + '" id="fnref:' + id
+ '" title="See footnote" class="footnote">' + footnoteCounter
+ '</a>';
var html = '<a href="#fn:' + id + '" id="fnref:' + id
+ '" title="See footnote" class="footnote">' + footnoteCounter
+ '</a>';
return self.hashExtraInline(html);
});
return text;

View File

@ -2,7 +2,8 @@
<html manifest="cache.manifest">
<head>
<title>StackEdit Viewer</title>
<link rel="canonical" href="http://benweet.github.io/stackedit/viewer.html">
<link rel="canonical"
href="http://benweet.github.io/stackedit/viewer.html">
<link rel="icon" href="img/stackedit-32.ico" type="image/x-icon">
<link rel="shortcut icon" href="img/stackedit-32.ico"
type="image/x-icon">
@ -12,17 +13,22 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="msvalidate.01" content="5E47EE6F67B069C17E3CDD418351A612" />
<script>
// Use http://.../?debug to serve original CSS/JavaScript files instead of minified
var suffix = "";
if (!location.search.match(/(\?|&)debug/)) {
suffix = "-min";
}
document.write('<link href="css/main' + suffix + '.css" rel="stylesheet">');
var theme = localStorage.theme;
if(theme) {
// Use http://.../?debug to serve original CSS/JavaScript files instead of minified
var suffix = "";
if(!location.search.match(/(\?|&)debug/)) {
suffix = "-min";
}
document.write('<link href="css/main' + suffix + '.css" rel="stylesheet">');
var theme = localStorage.theme;
if(theme) {
document.write('<link href="themes/' + theme + '/' + theme + '.css" rel="stylesheet">');
}
var require = { baseUrl : "js", deps : [ "main" + suffix ] };
}
var require = {
baseUrl: "js",
deps: [
"main" + suffix
]
};
var viewerMode = true;
</script>
<script src="js/libs/require.js"></script>
@ -44,13 +50,14 @@
<i class="icon-download-alt"></i>
</button>
<ul class="dropdown-menu">
<li><a class="action-download-md" href="#"><i
class="icon-download-alt"></i> Save as Markdown</a></li>
<li><a class="action-download-html" href="#"><i
class="icon-download-alt"></i> Save as HTML</a></li>
<li><a class="action-download-template" href="#"><i
class="icon-download-alt"></i> Save using template</a></li>
</ul></li>
<li><a class="action-download-md" href="#"><i
class="icon-download-alt"></i> Save as Markdown</a></li>
<li><a class="action-download-html" href="#"><i
class="icon-download-alt"></i> Save as HTML</a></li>
<li><a class="action-download-template" href="#"><i
class="icon-download-alt"></i> Save using template</a></li>
</ul>
</li>
<li class="btn-group">
<button class="btn dropdown-toggle action-open-file"
data-toggle="dropdown" title="Open local document">
@ -63,10 +70,12 @@
type="text" id="file-search" class="span3">
</div>
</li>
</ul></li>
</ul>
</li>
<li class="btn-group"><button class="btn action-open-stackedit"
title="Open StackEdit"><i
class="icon-stackedit"></i></button></li>
title="Open StackEdit">
<i class="icon-stackedit"></i>
</button></li>
</ul>
<ul class="nav pull-right">
<li><i class="working-indicator icon-none"></i></li>
@ -76,23 +85,27 @@
</div>
<div id="wmd-button-bar" class="hide"></div>
<textarea id="wmd-input" class="hide"></textarea>
<div id="preview-container"></div>
<div class="preview-container">
<div id="preview-contents">
<div id="wmd-preview" class="preview-content"></div>
</div>
</div>
<div id="modal-non-unique" class="modal hide">
<div class="modal-header">
<h3>Ooops...</h3>
</div>
<div class="modal-body">
<p>StackEdit has stopped because another instance was running in
the same browser.</p>
<blockquote class="muted">If you want to reopen
StackEdit, click on "Reload".</blockquote>
</div>
<div class="modal-footer">
<a href="javascript:window.location.reload();"
class="btn btn-primary">Reload</a>
</div>
</div>
<div id="modal-non-unique" class="modal hide">
<div class="modal-header">
<h3>Ooops...</h3>
</div>
<div class="modal-body">
<p>StackEdit has stopped because another instance was running in
the same browser.</p>
<blockquote class="muted">If you want to reopen
StackEdit, click on "Reload".</blockquote>
</div>
<div class="modal-footer">
<a href="javascript:window.location.reload();"
class="btn btn-primary">Reload</a>
</div>
</div>
</body>
</html>