New extension pattern

This commit is contained in:
benweet 2013-05-27 23:13:41 +01:00
parent d636e80646
commit 68f8aea79c
12 changed files with 64 additions and 48 deletions

View File

@ -230,32 +230,34 @@ define([
return true;
});
var firstChange = true;
var previewWrapper = function(makePreview) {
return function() {
if(firstChange !== true) {
onTextChange();
}
makePreview();
};
};
var documentContent = undefined;
function checkDocumentChanges() {
var newDocumentContent = $("#wmd-input").val();
if(documentContent !== undefined && documentContent != newDocumentContent) {
onTextChange();
}
documentContent = newDocumentContent;
}
var previewWrapper = undefined;
if(settings.lazyRendering === true) {
var lastRefresh = 0;
previewWrapper = function(makePreview) {
//var debouncedMakePreview = _.debounce(makePreview, 500);
var debouncedMakePreview = _.debounce(makePreview, 500);
return function() {
if(firstChange === true) {
if(documentContent === undefined) {
makePreview();
}
else {
onTextChange();
var currentDate = new Date().getTime();
if(currentDate - lastRefresh > 500) {
makePreview();
lastRefresh = currentDate;
}
//debouncedMakePreview();
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() {
// Load theme list

View File

@ -14,7 +14,7 @@ define([
var uploadPending = false;
var isOffline = false;
// Enable/disable the button
function updateButtonState() {
var updateButtonState = function() {
if(syncRunning === true || uploadPending === false || isOffline) {
$(".action-force-sync").addClass("disabled");
}
@ -39,6 +39,8 @@ define([
updateButtonState();
};
buttonSync.onReady = updateButtonState;
// Check that a file has synchronized locations
var checkSynchronization = function(fileDesc) {
if(_.size(fileDesc.syncLocations) !== 0) {

View File

@ -45,7 +45,7 @@ define([
return fileDesc.title.toLowerCase();
}).each(function(fileDesc) {
var a = $('<a href="#">').html(composeTitle(fileDesc)).click(function() {
if(liMap[fileDesc.fileIndex].is(".disabled")) {
if(!liMap[fileDesc.fileIndex].is(".disabled")) {
fileMgr.selectFile(fileDesc);
}
});

View File

@ -43,7 +43,7 @@ define([
}
var publishDesc = JSON.stringify(publishAttributes).replace(/{|}|"/g, "");
var lineElement = $(_.template(lineTemplate, {
provider: providerMap[publishAttributes.provider],
provider: publishAttributes.provider,
publishDesc: publishDesc
}));
lineElement.append($(removeButtonTemplate).click(function() {

View File

@ -39,7 +39,7 @@ define([
_.each(syncAttributesList, function(syncAttributes) {
var syncDesc = syncAttributes.id || syncAttributes.path;
var lineElement = $(_.template(lineTemplate, {
provider: providerMap[syncAttributes.provider],
provider: syncAttributes.provider,
syncDesc: syncDesc
}));
lineElement.append($(removeButtonTemplate).click(function() {

View File

@ -8,7 +8,7 @@ define([
extensionId: "toc",
extensionName: "Table Of Content",
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

View File

@ -194,7 +194,7 @@ define([
fileMgr.hasSync = function(provider) {
return _.some(fileSystem, function(fileDesc) {
return _.some(fileDesc.syncLocations, function(syncAttributes) {
syncAttributes.provider == provider.providerId;
return syncAttributes.provider === provider;
});
});
};

View File

@ -204,7 +204,7 @@ else
text = _UnescapeSpecialChars(text);
text = pluginHooks.postConversion(text);
text = pluginHooks.postConversion(text); // benweet
// attacklab: Restore dollar signs
text = text.replace(/~D/g, "$$");
@ -939,7 +939,7 @@ else
// Recursion for sub-lists:
item = _DoLists(_Outdent(item), /* isInsideParagraphlessListItem= */ true);
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);
}
last_item_had_a_double_newline = ends_with_double_newline;
@ -1231,7 +1231,12 @@ else
text = text.replace(/\\([`*_{}\[\]()>#+-.!])/g, escapeCharacters_callback);
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) {
if (lookbehind)
return wholeMatch;
@ -1258,10 +1263,16 @@ else
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;
}
function _DoAutoLinks(text) {
// note that at this point, all other URL in the text are already hyperlinked as <a href=""></a>
@ -1271,7 +1282,7 @@ else
// 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
// 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>

View File

@ -111,20 +111,20 @@
* 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.
*/
hooks.addFalse("insertLinkDialog");
hooks.addFalse("insertLinkDialog"); // benweet
this.getConverter = function () { return markdownConverter; }
var that = this,
panels;
this.run = function (previewWrapper) {
this.run = function (previewWrapper) { // benweet
if (panels)
return; // already initialized
panels = new PanelCollection(idPostfix);
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;
if (!/\?noundo/.test(doc.location.href)) {
@ -821,7 +821,7 @@
this.init();
};
function PreviewManager(converter, panels, previewRefreshCallback, previewWrapper) {
function PreviewManager(converter, panels, previewRefreshCallback, previewWrapper) { // benweet
var managerObj = this;
var timeout;
@ -869,7 +869,7 @@
var text = panels.input.value;
if (text !== undefined && text == oldInputText) {
if (text && text == oldInputText) {
return; // Input text hasn't changed.
}
else {
@ -887,7 +887,7 @@
pushPreviewHtml(text);
};
if(previewWrapper !== undefined) {
if(previewWrapper !== undefined) { // benweet
makePreviewHtml = previewWrapper(makePreviewHtml);
}
@ -1416,12 +1416,12 @@
return false;
}
}
button.className = button.className.replace(/ disabled/g, "");
button.className = button.className.replace(/ disabled/g, ""); // benweet
}
else {
image.style.backgroundPosition = button.XShift + " " + disabledYShift;
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);
}
else {
if (!this.hooks.insertLinkDialog(linkEnteredCallback))
if (!this.hooks.insertLinkDialog(linkEnteredCallback)) // benweet
ui.prompt(this.getString("linkdialog"), linkDefaultText, linkEnteredCallback);
}
return true;

View File

@ -8,15 +8,15 @@ requirejs.config({
"lib/MathJax": '../lib/MathJax/MathJax.js?config=TeX-AMS_HTML'
},
shim: {
'lib/underscore': {
'underscore': {
exports: '_'
},
'lib/jgrowl': {
deps: ['lib/jquery'],
'jgrowl': {
deps: ['jquery'],
exports: 'jQuery.jGrowl'
},
'lib/jquery-ui': ['lib/jquery'],
'lib/bootstrap': ['lib/jquery'],
'lib/jquery-ui': ['jquery'],
'lib/bootstrap': ['jquery'],
'lib/layout': ['lib/jquery-ui'],
'lib/Markdown.Extra': ['lib/Markdown.Converter', 'lib/prettify'],
'lib/Markdown.Editor': ['lib/Markdown.Converter']

View File

@ -1,5 +1,6 @@
define([
"underscore"
"underscore",
"config"
], function(_) {
var settings = {

View File

@ -112,7 +112,7 @@ define([
if(uploadCycle === true) {
// New upload cycle
uploadCycle = false;
uploadFileList = fileMgr.getFileList();
uploadFileList = _.values(fileSystem);
fileUp(callback);
}
else {