New extension pattern
This commit is contained in:
parent
d636e80646
commit
68f8aea79c
42
js/core.js
42
js/core.js
@ -230,32 +230,34 @@ define([
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
var firstChange = true;
|
var documentContent = undefined;
|
||||||
var previewWrapper = function(makePreview) {
|
function checkDocumentChanges() {
|
||||||
return function() {
|
var newDocumentContent = $("#wmd-input").val();
|
||||||
if(firstChange !== true) {
|
if(documentContent !== undefined && documentContent != newDocumentContent) {
|
||||||
onTextChange();
|
onTextChange();
|
||||||
}
|
}
|
||||||
makePreview();
|
documentContent = newDocumentContent;
|
||||||
};
|
}
|
||||||
};
|
var previewWrapper = undefined;
|
||||||
if(settings.lazyRendering === true) {
|
if(settings.lazyRendering === true) {
|
||||||
var lastRefresh = 0;
|
|
||||||
previewWrapper = function(makePreview) {
|
previewWrapper = function(makePreview) {
|
||||||
//var debouncedMakePreview = _.debounce(makePreview, 500);
|
var debouncedMakePreview = _.debounce(makePreview, 500);
|
||||||
return function() {
|
return function() {
|
||||||
if(firstChange === true) {
|
if(documentContent === undefined) {
|
||||||
makePreview();
|
makePreview();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
onTextChange();
|
debouncedMakePreview();
|
||||||
var currentDate = new Date().getTime();
|
|
||||||
if(currentDate - lastRefresh > 500) {
|
|
||||||
makePreview();
|
|
||||||
lastRefresh = currentDate;
|
|
||||||
}
|
|
||||||
//debouncedMakePreview();
|
|
||||||
}
|
}
|
||||||
|
checkDocumentChanges();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
previewWrapper = function(makePreview) {
|
||||||
|
return function() {
|
||||||
|
checkDocumentChanges();
|
||||||
|
makePreview();
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -313,7 +315,7 @@ define([
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
core.onReady(extensionManager.onReady);
|
core.onReady(extensionMgr.onReady);
|
||||||
core.onReady(function() {
|
core.onReady(function() {
|
||||||
|
|
||||||
// Load theme list
|
// Load theme list
|
||||||
|
@ -14,7 +14,7 @@ define([
|
|||||||
var uploadPending = false;
|
var uploadPending = false;
|
||||||
var isOffline = false;
|
var isOffline = false;
|
||||||
// Enable/disable the button
|
// Enable/disable the button
|
||||||
function updateButtonState() {
|
var updateButtonState = function() {
|
||||||
if(syncRunning === true || uploadPending === false || isOffline) {
|
if(syncRunning === true || uploadPending === false || isOffline) {
|
||||||
$(".action-force-sync").addClass("disabled");
|
$(".action-force-sync").addClass("disabled");
|
||||||
}
|
}
|
||||||
@ -39,6 +39,8 @@ define([
|
|||||||
updateButtonState();
|
updateButtonState();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
buttonSync.onReady = updateButtonState;
|
||||||
|
|
||||||
// Check that a file has synchronized locations
|
// Check that a file has synchronized locations
|
||||||
var checkSynchronization = function(fileDesc) {
|
var checkSynchronization = function(fileDesc) {
|
||||||
if(_.size(fileDesc.syncLocations) !== 0) {
|
if(_.size(fileDesc.syncLocations) !== 0) {
|
||||||
|
@ -45,7 +45,7 @@ define([
|
|||||||
return fileDesc.title.toLowerCase();
|
return fileDesc.title.toLowerCase();
|
||||||
}).each(function(fileDesc) {
|
}).each(function(fileDesc) {
|
||||||
var a = $('<a href="#">').html(composeTitle(fileDesc)).click(function() {
|
var a = $('<a href="#">').html(composeTitle(fileDesc)).click(function() {
|
||||||
if(liMap[fileDesc.fileIndex].is(".disabled")) {
|
if(!liMap[fileDesc.fileIndex].is(".disabled")) {
|
||||||
fileMgr.selectFile(fileDesc);
|
fileMgr.selectFile(fileDesc);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -43,7 +43,7 @@ define([
|
|||||||
}
|
}
|
||||||
var publishDesc = JSON.stringify(publishAttributes).replace(/{|}|"/g, "");
|
var publishDesc = JSON.stringify(publishAttributes).replace(/{|}|"/g, "");
|
||||||
var lineElement = $(_.template(lineTemplate, {
|
var lineElement = $(_.template(lineTemplate, {
|
||||||
provider: providerMap[publishAttributes.provider],
|
provider: publishAttributes.provider,
|
||||||
publishDesc: publishDesc
|
publishDesc: publishDesc
|
||||||
}));
|
}));
|
||||||
lineElement.append($(removeButtonTemplate).click(function() {
|
lineElement.append($(removeButtonTemplate).click(function() {
|
||||||
|
@ -39,7 +39,7 @@ define([
|
|||||||
_.each(syncAttributesList, function(syncAttributes) {
|
_.each(syncAttributesList, function(syncAttributes) {
|
||||||
var syncDesc = syncAttributes.id || syncAttributes.path;
|
var syncDesc = syncAttributes.id || syncAttributes.path;
|
||||||
var lineElement = $(_.template(lineTemplate, {
|
var lineElement = $(_.template(lineTemplate, {
|
||||||
provider: providerMap[syncAttributes.provider],
|
provider: syncAttributes.provider,
|
||||||
syncDesc: syncDesc
|
syncDesc: syncDesc
|
||||||
}));
|
}));
|
||||||
lineElement.append($(removeButtonTemplate).click(function() {
|
lineElement.append($(removeButtonTemplate).click(function() {
|
||||||
|
@ -8,7 +8,7 @@ define([
|
|||||||
extensionId: "toc",
|
extensionId: "toc",
|
||||||
extensionName: "Table Of Content",
|
extensionName: "Table Of Content",
|
||||||
optional: true,
|
optional: true,
|
||||||
settingsBloc: '<p>Generates tables of content using the marker [TOC].</p>'
|
settingsBloc: '<p>Generates a table of content and include it in your document using the marker [TOC].</p>'
|
||||||
};
|
};
|
||||||
|
|
||||||
// TOC element description
|
// TOC element description
|
||||||
|
@ -194,7 +194,7 @@ define([
|
|||||||
fileMgr.hasSync = function(provider) {
|
fileMgr.hasSync = function(provider) {
|
||||||
return _.some(fileSystem, function(fileDesc) {
|
return _.some(fileSystem, function(fileDesc) {
|
||||||
return _.some(fileDesc.syncLocations, function(syncAttributes) {
|
return _.some(fileDesc.syncLocations, function(syncAttributes) {
|
||||||
syncAttributes.provider == provider.providerId;
|
return syncAttributes.provider === provider;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -204,7 +204,7 @@ else
|
|||||||
|
|
||||||
text = _UnescapeSpecialChars(text);
|
text = _UnescapeSpecialChars(text);
|
||||||
|
|
||||||
text = pluginHooks.postConversion(text);
|
text = pluginHooks.postConversion(text); // benweet
|
||||||
|
|
||||||
// attacklab: Restore dollar signs
|
// attacklab: Restore dollar signs
|
||||||
text = text.replace(/~D/g, "$$");
|
text = text.replace(/~D/g, "$$");
|
||||||
@ -939,7 +939,7 @@ else
|
|||||||
// Recursion for sub-lists:
|
// Recursion for sub-lists:
|
||||||
item = _DoLists(_Outdent(item), /* isInsideParagraphlessListItem= */ true);
|
item = _DoLists(_Outdent(item), /* isInsideParagraphlessListItem= */ true);
|
||||||
item = item.replace(/\n$/, ""); // chomp(item)
|
item = item.replace(/\n$/, ""); // chomp(item)
|
||||||
if (!isInsideParagraphlessListItem)
|
if (!isInsideParagraphlessListItem) // only the outer-most item should run this, otherwise it's run multiple times for the inner ones
|
||||||
item = _RunSpanGamut(item);
|
item = _RunSpanGamut(item);
|
||||||
}
|
}
|
||||||
last_item_had_a_double_newline = ends_with_double_newline;
|
last_item_had_a_double_newline = ends_with_double_newline;
|
||||||
@ -1232,6 +1232,11 @@ else
|
|||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var charInsideUrl = "[-A-Z0-9+&@#/%?=~_|[\\]()!:,.;]",
|
||||||
|
charEndingUrl = "[-A-Z0-9+&@#/%=~_|[\\])]",
|
||||||
|
autoLinkRegex = new RegExp("(=\"|<)?\\b(https?|ftp)(://" + charInsideUrl + "*" + charEndingUrl + ")(?=$|\\W)", "gi"),
|
||||||
|
endCharRegex = new RegExp(charEndingUrl, "i");
|
||||||
|
|
||||||
function handleTrailingParens(wholeMatch, lookbehind, protocol, link) {
|
function handleTrailingParens(wholeMatch, lookbehind, protocol, link) {
|
||||||
if (lookbehind)
|
if (lookbehind)
|
||||||
return wholeMatch;
|
return wholeMatch;
|
||||||
@ -1258,7 +1263,13 @@ else
|
|||||||
return "";
|
return "";
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (tail) {
|
||||||
|
var lastChar = link.charAt(link.length - 1);
|
||||||
|
if (!endCharRegex.test(lastChar)) {
|
||||||
|
tail = lastChar + tail;
|
||||||
|
link = link.substr(0, link.length - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
return "<" + protocol + link + ">" + tail;
|
return "<" + protocol + link + ">" + tail;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1271,7 +1282,7 @@ else
|
|||||||
// must be preceded by a non-word character (and not by =" or <) and followed by non-word/EOF character
|
// must be preceded by a non-word character (and not by =" or <) and followed by non-word/EOF character
|
||||||
// simulating the lookbehind in a consuming way is okay here, since a URL can neither and with a " nor
|
// simulating the lookbehind in a consuming way is okay here, since a URL can neither and with a " nor
|
||||||
// with a <, so there is no risk of overlapping matches.
|
// with a <, so there is no risk of overlapping matches.
|
||||||
text = text.replace(/(="|<)?\b(https?|ftp)(:\/\/[-A-Z0-9+&@#\/%?=~_|\[\]\(\)!:,\.;]*[-A-Z0-9+&@#\/%=~_|\[\])])(?=$|\W)/gi, handleTrailingParens);
|
text = text.replace(autoLinkRegex, handleTrailingParens);
|
||||||
|
|
||||||
// autolink anything like <http://example.com>
|
// autolink anything like <http://example.com>
|
||||||
|
|
||||||
|
@ -111,20 +111,20 @@
|
|||||||
* its own image insertion dialog, this hook should return true, and the callback should be called with the chosen
|
* its own image insertion dialog, this hook should return true, and the callback should be called with the chosen
|
||||||
* image url (or null if the user cancelled). If this hook returns false, the default dialog will be used.
|
* image url (or null if the user cancelled). If this hook returns false, the default dialog will be used.
|
||||||
*/
|
*/
|
||||||
hooks.addFalse("insertLinkDialog");
|
hooks.addFalse("insertLinkDialog"); // benweet
|
||||||
|
|
||||||
this.getConverter = function () { return markdownConverter; }
|
this.getConverter = function () { return markdownConverter; }
|
||||||
|
|
||||||
var that = this,
|
var that = this,
|
||||||
panels;
|
panels;
|
||||||
|
|
||||||
this.run = function (previewWrapper) {
|
this.run = function (previewWrapper) { // benweet
|
||||||
if (panels)
|
if (panels)
|
||||||
return; // already initialized
|
return; // already initialized
|
||||||
|
|
||||||
panels = new PanelCollection(idPostfix);
|
panels = new PanelCollection(idPostfix);
|
||||||
var commandManager = new CommandManager(hooks, getString);
|
var commandManager = new CommandManager(hooks, getString);
|
||||||
var previewManager = new PreviewManager(markdownConverter, panels, function () { hooks.onPreviewRefresh(); }, previewWrapper);
|
var previewManager = new PreviewManager(markdownConverter, panels, function () { hooks.onPreviewRefresh(); }, previewWrapper); // benweet
|
||||||
var undoManager, uiManager;
|
var undoManager, uiManager;
|
||||||
|
|
||||||
if (!/\?noundo/.test(doc.location.href)) {
|
if (!/\?noundo/.test(doc.location.href)) {
|
||||||
@ -821,7 +821,7 @@
|
|||||||
this.init();
|
this.init();
|
||||||
};
|
};
|
||||||
|
|
||||||
function PreviewManager(converter, panels, previewRefreshCallback, previewWrapper) {
|
function PreviewManager(converter, panels, previewRefreshCallback, previewWrapper) { // benweet
|
||||||
|
|
||||||
var managerObj = this;
|
var managerObj = this;
|
||||||
var timeout;
|
var timeout;
|
||||||
@ -869,7 +869,7 @@
|
|||||||
|
|
||||||
|
|
||||||
var text = panels.input.value;
|
var text = panels.input.value;
|
||||||
if (text !== undefined && text == oldInputText) {
|
if (text && text == oldInputText) {
|
||||||
return; // Input text hasn't changed.
|
return; // Input text hasn't changed.
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -887,7 +887,7 @@
|
|||||||
|
|
||||||
pushPreviewHtml(text);
|
pushPreviewHtml(text);
|
||||||
};
|
};
|
||||||
if(previewWrapper !== undefined) {
|
if(previewWrapper !== undefined) { // benweet
|
||||||
makePreviewHtml = previewWrapper(makePreviewHtml);
|
makePreviewHtml = previewWrapper(makePreviewHtml);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1416,12 +1416,12 @@
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
button.className = button.className.replace(/ disabled/g, "");
|
button.className = button.className.replace(/ disabled/g, ""); // benweet
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
image.style.backgroundPosition = button.XShift + " " + disabledYShift;
|
image.style.backgroundPosition = button.XShift + " " + disabledYShift;
|
||||||
button.onmouseover = button.onmouseout = button.onclick = function () { };
|
button.onmouseover = button.onmouseout = button.onclick = function () { };
|
||||||
button.className += " disabled";
|
button.className += " disabled"; // benweet
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1786,7 +1786,7 @@
|
|||||||
ui.prompt(this.getString("imagedialog"), imageDefaultText, linkEnteredCallback);
|
ui.prompt(this.getString("imagedialog"), imageDefaultText, linkEnteredCallback);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!this.hooks.insertLinkDialog(linkEnteredCallback))
|
if (!this.hooks.insertLinkDialog(linkEnteredCallback)) // benweet
|
||||||
ui.prompt(this.getString("linkdialog"), linkDefaultText, linkEnteredCallback);
|
ui.prompt(this.getString("linkdialog"), linkDefaultText, linkEnteredCallback);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
10
js/main.js
10
js/main.js
@ -8,15 +8,15 @@ requirejs.config({
|
|||||||
"lib/MathJax": '../lib/MathJax/MathJax.js?config=TeX-AMS_HTML'
|
"lib/MathJax": '../lib/MathJax/MathJax.js?config=TeX-AMS_HTML'
|
||||||
},
|
},
|
||||||
shim: {
|
shim: {
|
||||||
'lib/underscore': {
|
'underscore': {
|
||||||
exports: '_'
|
exports: '_'
|
||||||
},
|
},
|
||||||
'lib/jgrowl': {
|
'jgrowl': {
|
||||||
deps: ['lib/jquery'],
|
deps: ['jquery'],
|
||||||
exports: 'jQuery.jGrowl'
|
exports: 'jQuery.jGrowl'
|
||||||
},
|
},
|
||||||
'lib/jquery-ui': ['lib/jquery'],
|
'lib/jquery-ui': ['jquery'],
|
||||||
'lib/bootstrap': ['lib/jquery'],
|
'lib/bootstrap': ['jquery'],
|
||||||
'lib/layout': ['lib/jquery-ui'],
|
'lib/layout': ['lib/jquery-ui'],
|
||||||
'lib/Markdown.Extra': ['lib/Markdown.Converter', 'lib/prettify'],
|
'lib/Markdown.Extra': ['lib/Markdown.Converter', 'lib/prettify'],
|
||||||
'lib/Markdown.Editor': ['lib/Markdown.Converter']
|
'lib/Markdown.Editor': ['lib/Markdown.Converter']
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
define([
|
define([
|
||||||
"underscore"
|
"underscore",
|
||||||
|
"config"
|
||||||
], function(_) {
|
], function(_) {
|
||||||
|
|
||||||
var settings = {
|
var settings = {
|
||||||
|
@ -112,7 +112,7 @@ define([
|
|||||||
if(uploadCycle === true) {
|
if(uploadCycle === true) {
|
||||||
// New upload cycle
|
// New upload cycle
|
||||||
uploadCycle = false;
|
uploadCycle = false;
|
||||||
uploadFileList = fileMgr.getFileList();
|
uploadFileList = _.values(fileSystem);
|
||||||
fileUp(callback);
|
fileUp(callback);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Loading…
Reference in New Issue
Block a user