Removed ACE

This commit is contained in:
benweet 2014-03-20 00:24:56 +00:00
parent 0b6742873e
commit c410aa8eae
28 changed files with 125 additions and 3842 deletions

View File

@ -17,19 +17,13 @@
"stacktrace": "~0.5.3",
"requirejs-text": "~2.0.10",
"bootstrap-tour": "~0.7.1",
"ace": "https://github.com/benweet/ace.git#798a03b2f8b1315fa8ba2d867cee242b90960557",
"pagedown-ace": "https://github.com/benweet/pagedown-ace.git#84d5e1b7ff233a1c8cafa9716e825228d275120c",
"pagedown-extra": "https://github.com/jmcmanus/pagedown-extra.git#bd0870e3e871e15bde1fa5a427e3e10028a09789",
"crel": "https://github.com/KoryNunn/crel.git#8dbda04b129fc0aec01a2a080d1cab26816e11c1",
"waitForImages": "https://github.com/alexanderdickson/waitForImages.git#~1.4.2",
"to-markdown": "https://github.com/benweet/to-markdown.git#jquery",
"Typo.js": "https://github.com/cfinke/Typo.js.git",
"xregexp": "d06eff50f87d81d2dd3afc1e854784c38b17bcc4",
"yaml.js": "https://github.com/jeremyfa/yaml.js.git#~0.1.4",
"lz-string": "https://github.com/pieroxy/lz-string.git"
},
"resolutions": {
"jquery": "2.0.3",
"bootstrap": "v3.0.0"
"stackedit-pagedown": "https://github.com/benweet/stackedit-pagedown.git#d81b3689a99c84832d8885f607e6de860fb7d94a",
"prism": "gh-pages"
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
ᥢ䐪䀨ौްݜր娢ᠥ̠䨤桠ᓠ㎠䬡ء氢㠢瀾怭䂃FżθאĀƀҀ਀ڀ܀඀ༀ؂ప@䀼圸Ⱐᤠ愠ᄠ唠焠夠Ԡठ↜‚ŠòĊzĄⳋㆣ഼Ⲡȱバä഻ࠦಪ䅤悢傐碤䑔ቌ໌ᳶŠ叱ᥢ呁夁يጨ䈦ᄢ悇灐㣈汄Nㅽ`͡"゗㨡䰽ⱸ⪶弰妽䷫棵䊊疜ۆ䐭Ω䩢澸怡桀ú&ᨪ7‥⃢Ჾ乚ဠਬ∟㣃̑䐊瑡ဠ氠瘬"憙࢔ଧ〢⨆Ế涓ᷮ⎯⎔㱨㨠Ѓ楔梡䩆䠍»䏁ќ㴬ᔽ椕ᣖᯁ礃唂䟀ᬢ彰㰵լ昼佋䀸娰េ䦅Ჹ䞷摅᝚ၽᮓ㴞⪮㰐墇ᘫ䈈㨫ᥫ䌠ၣ嚸ܜ羘Ԣহ㘠ٰ͢₤㘴棕ⴰ໑溔桤㏝沔癆秚ۗ੸ᷗ沖฾畣溕㴡俀搖深珄ᾖᬁ䒛棔瓑咝ᡬ㶌ᯅᴕ匰㽆櫯୙篚ᅀର⒐᷒㐕䖙淉⡕嶇沒ᮽ玑氀栬㮄ᘠ縖Ш刉ぃ䗌㲗珮夢➼㵤ᔔ㸍⩫䆟〡璨叐琊ᔨƺ熊ᔇ價⁽⿇爓奷㫨ᘥݣᇏߤڟ徣ᗻ㷛湂ᔂ绿䋱Ề㧶⹵ೆ圁圑稶凴㸫䘓㹐∐䇟已ၴᘯۛ䢢Ƨ䋰夗劓廄⤭ۀ䁡♂ᰔ兮巳尠⠩Ɨ傥ᘼ⎐呣尒ᢞ岩稢㌒㹴஡弜⎑䐲═ᇠ㢨䀠ੰ➞ᕔ⑎煏ށ㕚▉㥏㠾濶㈰䁸撎㘦嬰獊䕞∲搹ਨ䏞ิ珱㯶ㆁ䡁搹䉀碙෾擶綩擙㝑♠⊬旾䠫晚呦寡୶ᑠ摑榰刮䉙杁厥ᣐᑅ㥔ᜅ睇棅䓲ص籐Թ㯷Ț棇毵㣕ㅹⓂ͕哚䓰X囙勂檕૎㤕淯嘅⛐ᚭ彈䞞圡嗭෭ቅ䗖摎咻❚巼㐭࠾㓕෌㔅绕㕑䡙㓭嫇殊卛箊㗝ᚰ廘瑭୾疽磊撥ៗ㟝懘䊍睿グ#杀ҟᶔ㝠㐬睰㸮曛暁絳撮㽑ᩢȍ吗㾄㋵⡬㑴燔㾮ਊ墬紳হ潊㋷尸㡻㽋ʭ᦭慡Э䶵䋶㋷姮㜧嬆㇆ᵞ㔦㘶垏旃⦿⍌媾Υ㌐椺瀰ಮ၌ۏᆪౡ䡍㻍疨Šල㱣植㺏ෳ㲍䡊䫚ⶬ完涪ଊ涺̍巂଎㷗ⴄ㷫ㅡ䠾嬌ᷣ㐼竴䘿ᇈ缌淸縌ϣタИ笏෷⚼䏴禎ᐂা琀熿⏝㤼௣㋢棚ɿ⮺䁀淪無弻㜙殦畼㠶燡寫㣿剫㵺Ⱆ無␻㕀篣㙀ΎШـ淎୤៫㕝ុ㞍䢕礍៊䇜Ǝ෣矞Ḃɽࡗ⿎ⶠցǂෝࡀณ㜏圥愷䒲羏䐥恫怜繖浹䷲浻忚ව筿֓宐๦爂恌üⰤ㳧䈠C叚ⶦӀ旕䢔ೡ䎈᳾恢㇢䇛䆠涱Ө㲑䠨䓁⨳ţ㧶䉘ਧᆻܰ㔬嬦м㘳㚼ᯣౄ䈯䮧桡砨匬䢦Ŏᤱᆶ淼ᥤ⊴㹧྿宐犕ゲ焀ㄥḭෝѐ㢴⎙࡙ݐ懐敨爖崎亶ᖼ燰Ძ兘淍Ҁ䷖悭๦㤡Dଢ㹚处ࠤђ㇁ᔢԄ杀㊮঍䋡澬አ

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -2,26 +2,12 @@ define([
"underscore",
"utils",
"storage",
"ace/range"
], function(_, utils, storage, range) {
var Range = range.Range;
], function(_, utils, storage) {
function FileDescriptor(fileIndex, title, syncLocations, publishLocations) {
this.fileIndex = fileIndex;
this._title = title || storage[fileIndex + ".title"];
this._editorScrollTop = parseInt(storage[fileIndex + ".editorScrollTop"]) || 0;
this._editorSelectRange = (function() {
try {
var rangeComponents = storage[fileIndex + ".editorSelectRange"].split(';');
rangeComponents = _.map(rangeComponents, function(component) {
return parseInt(component);
});
return new Range(rangeComponents[0], rangeComponents[1], rangeComponents[2], rangeComponents[3]);
}
catch(e) {
return new Range(0, 0, 0, 0);
}
})();
this._editorStart = parseInt(storage[fileIndex + ".editorEnd"]) || 0;
this._editorEnd = parseInt(storage[fileIndex + ".editorEnd"]) || 0;
this._previewScrollTop = parseInt(storage[fileIndex + ".previewScrollTop"]) || 0;
@ -72,20 +58,6 @@ define([
storage[this.fileIndex + ".editorEnd"] = editorEnd;
}
});
Object.defineProperty(this, 'editorSelectRange', {
get: function() {
return this._editorSelectRange;
},
set: function(range) {
this._editorSelectRange = range;
storage[this.fileIndex + ".editorSelectRange"] = [
range.start.row,
range.start.column,
range.end.row,
range.end.column
].join(';');
}
});
Object.defineProperty(this, 'previewScrollTop', {
get: function() {
return this._previewScrollTop;
@ -157,4 +129,4 @@ define([
};
return FileDescriptor;
});
});

View File

@ -3,7 +3,6 @@ define([
"jquery",
"underscore",
"crel",
"ace",
"editor",
"constants",
"utils",
@ -18,15 +17,8 @@ define([
"text!html/settingsUserCustomExtensionTooltip.html",
"storage",
"uilayout",
'pagedown-ace',
'pagedown-light',
'libs/ace_mode',
'ace/requirejs/text!ace/css/editor.css',
'ace/requirejs/text!ace/theme/textmate.css',
'ace/ext/spellcheck',
'ace/ext/searchbox'
], function($, _, crel, ace, editor, constants, utils, storage, settings, eventMgr, shortcutMgr, mousetrap, bodyIndexHTML, bodyViewerHTML, settingsTemplateTooltipHTML, settingsUserCustomExtensionTooltipHTML) {
'pagedown',
], function($, _, crel, editor, constants, utils, storage, settings, eventMgr, shortcutMgr, mousetrap, bodyIndexHTML, bodyViewerHTML, settingsTemplateTooltipHTML, settingsUserCustomExtensionTooltipHTML) {
var core = {};
@ -128,8 +120,8 @@ define([
utils.setInputValue("#input-settings-max-width", settings.maxWidth);
// Default content
utils.setInputValue("#textarea-settings-default-content", settings.defaultContent);
// Mode
utils.setInputRadio("radio-settings-mode", storage.mode || '_ace_');
// Edit mode
utils.setInputRadio("radio-settings-mode", settings.editMode);
// Commit message
utils.setInputValue("#input-settings-publish-commit-msg", settings.commitMsg);
// Gdrive multi-accounts
@ -174,8 +166,8 @@ define([
newSettings.maxWidth = utils.getInputIntValue("#input-settings-max-width", event, 1);
// Default content
newSettings.defaultContent = utils.getInputValue("#textarea-settings-default-content");
// Mode
var mode = utils.getInputRadio("radio-settings-mode");
// Edit mode
newSettings.editMode = utils.getInputRadio("radio-settings-mode");
// Commit message
newSettings.commitMsg = utils.getInputTextValue("#input-settings-publish-commit-msg", event);
// Gdrive multi-accounts
@ -209,7 +201,6 @@ define([
$.extend(settings, newSettings);
storage.settings = JSON.stringify(settings);
storage.themeV3 = theme;
storage.mode = mode;
}
}
@ -239,95 +230,6 @@ define([
}
}
// Create ACE editor
var aceEditor;
function createAceEditor() {
aceEditor = ace.edit("wmd-input");
aceEditor.setOption("spellcheck", true);
aceEditor.renderer.setShowGutter(false);
aceEditor.renderer.setPrintMarginColumn(false);
aceEditor.renderer.setPadding(constants.EDITOR_DEFAULT_PADDING);
aceEditor.session.setUseWrapMode(true);
aceEditor.session.setNewLineMode("unix");
aceEditor.session.setMode("libs/ace_mode");
aceEditor.session.$selectLongWords = true;
aceEditor.setShowPrintMargin(true);
aceEditor.setHighlightActiveLine(false);
aceEditor.setHighlightGutterLine(false);
aceEditor.setHighlightSelectedWord(false);
aceEditor.setDisplayIndentGuides(false);
aceEditor.setShowFoldWidgets(false);
aceEditor.setWrapBehavioursEnabled(false);
// Hack to disable bracket highlighting
aceEditor.$highlightBrackets = function() {};
// Hack to make bold titles
(function(self) {
function checkLine(currentLine) {
var line = self.lines[currentLine];
if(line.length !== 0) {
if(line[0].type.indexOf("markup.heading.multi") === 0) {
_.each(self.lines[currentLine - 1], function(previousLineObject) {
previousLineObject.type = "markup.heading.prev.multi";
});
}
}
}
function customWorker() {
// Duplicate from background_tokenizer.js
if(!self.running) {
return;
}
var workerStart = new Date();
var currentLine = self.currentLine;
var endLine = -1;
var doc = self.doc;
while (self.lines[currentLine]) {
currentLine++;
}
var startLine = currentLine;
var len = doc.getLength();
var processedLines = 0;
self.running = false;
while (currentLine < len) {
self.$tokenizeRow(currentLine);
endLine = currentLine;
do {
checkLine(currentLine); // benweet
currentLine++;
} while (self.lines[currentLine]);
// only check every 5 lines
processedLines++;
if((processedLines % 5 === 0) && (new Date() - workerStart) > 20) {
self.running = setTimeout(customWorker, 20); // benweet
self.currentLine = currentLine;
return;
}
}
self.currentLine = currentLine;
if(startLine <= endLine) {
self.fireUpdateEvent(startLine, endLine);
}
}
self.$worker = function() {
self.lines.splice(0, self.lines.length);
self.states.splice(0, self.states.length);
self.currentLine = 0;
customWorker();
};
})(aceEditor.session.bgTokenizer);
shortcutMgr.configureAce(aceEditor);
eventMgr.onAceCreated(aceEditor);
}
// Create the layout
var $editorButtonsElt;
var maxWidthMap = [
@ -395,22 +297,6 @@ define([
'padding-right': padding + 'px'
});
}
if(aceEditor !== undefined && paneName == 'center') {
aceEditor.resize();
var bottomMargin = (aceEditor.renderer.$size.scrollerHeight - aceEditor.renderer.lineHeight) / 2;
bottomMargin < 0 && (bottomMargin = 0);
aceEditor.renderer.setScrollMargin(0, bottomMargin, 0, 0);
setTimeout(function() {
var padding = (aceEditor.renderer.$size.scrollerWidth - getMaxWidth()) / 2;
if(padding < constants.EDITOR_DEFAULT_PADDING) {
padding = constants.EDITOR_DEFAULT_PADDING;
}
if(padding !== aceEditor.renderer.$padding) {
aceEditor.renderer.setPadding(padding);
aceEditor.resize(true);
}
}, 5);
}
eventMgr.onLayoutResize(paneName);
},
};
@ -498,7 +384,6 @@ define([
var $editorElt;
var fileDesc;
var documentContent;
var UndoManager = require("ace/undomanager").UndoManager;
core.initEditor = function(fileDescParam) {
if(fileDesc !== undefined) {
eventMgr.onFileClosed(fileDesc);
@ -507,43 +392,16 @@ define([
documentContent = undefined;
var initDocumentContent = fileDesc.content;
if(aceEditor !== undefined) {
aceEditor.setValue(initDocumentContent, -1);
aceEditor.getSession().setUndoManager(new UndoManager());
}
else {
//$editorElt.val(initDocumentContent);
}
if(pagedownEditor !== undefined) {
// If the editor is already created
$editorElt.val(initDocumentContent);
aceEditor && aceEditor.selection.setSelectionRange(fileDesc.editorSelectRange);
aceEditor || pagedownEditor.undoManager.reinit(initDocumentContent, fileDesc.editorStart, fileDesc.editorEnd, fileDesc.editorScrollTop);
aceEditor ? aceEditor.focus() : $editorElt.focus();
//pagedownEditor.refreshPreview();
pagedownEditor.undoManager.reinit(initDocumentContent, fileDesc.editorStart, fileDesc.editorEnd, fileDesc.editorScrollTop);
$editorElt.focus();
return;
}
var $previewContainerElt = $(".preview-container");
if(!window.lightMode) {
// Store editor scrollTop on scroll event
var saveScroll = _.debounce(function() {
if(documentContent !== undefined) {
fileDesc.editorScrollTop = aceEditor.renderer.getScrollTop();
}
}, 100);
aceEditor.session.on('changeScrollTop', saveScroll);
// Store editor selection on change
var saveSelection = _.debounce(function() {
if(documentContent !== undefined) {
fileDesc.editorSelectRange = aceEditor.getSelectionRange();
}
}, 100);
aceEditor.session.selection.on('changeSelection', saveSelection);
aceEditor.session.selection.on('changeCursor', saveSelection);
}
// Store preview scrollTop on scroll event
$previewContainerElt.scroll(function() {
if(documentContent !== undefined) {
@ -565,37 +423,6 @@ define([
};
converter.setOptions(options);
function checkDocumentChanges() {
var newDocumentContent = $editorElt.text();
if(aceEditor !== undefined) {
newDocumentContent = aceEditor.getValue();
}
if(documentContent == newDocumentContent) {
return false;
}
if(documentContent !== undefined) {
fileDesc.content = newDocumentContent;
eventMgr.onContentChanged(fileDesc);
}
else {
eventMgr.onFileOpen(fileDesc);
$previewContainerElt.scrollTop(fileDesc.previewScrollTop);
if(window.lightMode) {
$editorElt.scrollTop(fileDesc.editorScrollTop);
}
else {
_.defer(function() {
aceEditor.renderer.scrollToY(fileDesc.editorScrollTop);
});
}
}
documentContent = newDocumentContent;
return true;
}
var previewWrapper;
if(window.lightMode) {
pagedownEditor = new Markdown.EditorLight(converter);
}
@ -622,38 +449,12 @@ define([
return true;
});
if(settings.lazyRendering === true) {
previewWrapper = function(makePreview) {
var debouncedMakePreview = _.debounce(makePreview, 500);
return function() {
var debounce = documentContent !== undefined;
if(checkDocumentChanges()) {
debounce ? debouncedMakePreview() : makePreview();
}
};
};
}
else {
previewWrapper = function(makePreview) {
return function() {
checkDocumentChanges() && makePreview();
};
};
}
eventMgr.onPagedownConfigure(pagedownEditor);
pagedownEditor.hooks.chain("onPreviewRefresh", eventMgr.onAsyncPreview);
if(window.lightMode) {
pagedownEditor.run();
$editorElt.val(initDocumentContent);
pagedownEditor.undoManager.reinit(initDocumentContent, fileDesc.editorStart, fileDesc.editorEnd, fileDesc.editorScrollTop);
$editorElt.focus();
}
else {
pagedownEditor.run(aceEditor, previewWrapper);
aceEditor.selection.setSelectionRange(fileDesc.editorSelectRange);
aceEditor.focus();
}
pagedownEditor.run();
$editorElt.val(initDocumentContent);
pagedownEditor.undoManager.reinit(initDocumentContent, fileDesc.editorStart, fileDesc.editorEnd, fileDesc.editorScrollTop);
$editorElt.focus();
// Hide default buttons
$(".wmd-button-row li").addClass("btn btn-success").css("left", 0).find("span").hide();
@ -681,6 +482,9 @@ define([
var isDocumentPanelShown = false;
var isMenuPanelShown = false;
core.onReady = function() {
// Add RTL class
settings.editMode == 'rtl' && $(document.body).addClass('rtl');
if(window.viewerMode === true) {
document.body.innerHTML = bodyViewerHTML;
}
@ -788,7 +592,7 @@ define([
isMenuPanelShown = false;
menuPanelBackdropElt.removeBackdrop();
$menuPanelElt.removeClass('move-to-front');
aceEditor ? aceEditor.focus() : $editorElt.focus();
$editorElt.focus();
}
}).on('hidden.bs.collapse', function(e) {
if(e.target === $menuPanelElt[0]) {
@ -820,7 +624,7 @@ define([
isDocumentPanelShown = false;
documentPanelBackdropElt.removeBackdrop();
$documentPanelElt.removeClass('move-to-front');
aceEditor ? aceEditor.focus() : $editorElt.focus();
$editorElt.focus();
}
}).on('hidden.bs.collapse', function(e) {
if(e.target === $documentPanelElt[0]) {
@ -829,27 +633,14 @@ define([
}
});
// Create UI layout
createLayout();
// Editor
if(window.lightMode) {
// In pre mode, we replace ACE with an editable pre
$('#wmd-input').replaceWith(function() {
return $('<pre id="wmd-input">').addClass(this.className).addClass('form-control');
});
// Create UI layout after textarea
createLayout();
editor.init(document.querySelector('#wmd-input'), document.querySelector('.preview-container'));
}
else {
// Create UI layout before ACE editor
createLayout();
// ACE editor
createAceEditor();
}
$editorElt = $('#wmd-input');
editor.init(document.querySelector('#wmd-input'), document.querySelector('.preview-container'));
// Do periodic tasks
intervalId = window.setInterval(function() {
utils.updateCurrentTime();
@ -892,7 +683,7 @@ define([
}).on('hidden.bs.modal', function() {
// Focus on the editor when modal is gone
isModalShown = false;
aceEditor ? aceEditor.focus() : $editorElt.focus();
$editorElt.focus();
// Revert to current theme when settings modal is closed
applyTheme(window.theme);
}).keyup(function(e) {

View File

@ -29,14 +29,12 @@ define([
"extensions/mathJax",
"extensions/emailConverter",
"extensions/scrollLink",
"extensions/buttonFocusMode",
"extensions/buttonSync",
"extensions/buttonPublish",
"extensions/buttonStat",
"extensions/buttonHtmlCode",
"extensions/buttonViewer",
"extensions/welcomeTour",
"extensions/spellCheck",
"extensions/userCustom",
"bootstrap",
"jquery-waitforimages",
@ -211,12 +209,9 @@ define([
addEventHook("onSectionsCreated");
addEventHook("onMarkdownTrim");
// Operation on ACE
addEventHook("onAceCreated");
// Refresh twitter buttons
addEventHook("onTweet");
var onPreviewFinished = createEventHook("onPreviewFinished");
var onAsyncPreviewListenerList = getExtensionListenerList("onAsyncPreview");
@ -281,7 +276,7 @@ define([
}) : "");
}, "").value();
document.querySelector('.accordion-extensions').innerHTML = accordionHtml;
// Create extension buttons
logger.log("onCreateButton");
var onCreateButtonListenerList = getExtensionListenerList("onCreateButton");
@ -327,7 +322,7 @@ define([
});
});
});
// Call onReady listeners
onReady();
};
@ -335,4 +330,4 @@ define([
// For extensions that need to call other extensions
eventMgr.onEventMgrCreated(eventMgr);
return eventMgr;
});
});

View File

@ -1,42 +0,0 @@
define([
"jquery",
"underscore",
"crel",
"classes/Extension"
], function($, _, crel, Extension) {
var buttonFocusMode = new Extension("buttonFocusMode", 'Button "Focus Mode"', true, true);
buttonFocusMode.settingsBlock = "When typing, scrolls automatically the editor to always have the caret centered verticaly.";
var aceEditor;
buttonFocusMode.onAceCreated = function(aceEditorParam) {
aceEditor = aceEditorParam;
};
var isMouseActive = false;
function doFocusMode() {
if(aceEditor) {
if(isMouseActive === true) {
return;
}
var positionInDocument = aceEditor.selection.getCursor();
var positionInScreen = aceEditor.session.documentToScreenPosition(positionInDocument.row, positionInDocument.column);
aceEditor.session.setScrollTop((positionInScreen.row + 0.5) * aceEditor.renderer.lineHeight - aceEditor.renderer.$size.scrollerHeight / 2);
}
}
buttonFocusMode.onReady = function() {
if(aceEditor) {
aceEditor.getSession().selection.on('changeCursor', doFocusMode);
aceEditor.container.addEventListener('keydown', function() {
isMouseActive = false;
}, true);
aceEditor.container.addEventListener('mousedown', function() {
isMouseActive = true;
}, true);
return;
}
};
return buttonFocusMode;
});

View File

@ -29,11 +29,6 @@ define([
newConfig.shortcutNext = utils.getInputTextValue("#input-document-selector-shortcut-next", event);
};
var aceEditor;
documentSelector.onAceCreated = function(aceEditorParam) {
aceEditor = aceEditorParam;
};
var fileMgr;
documentSelector.onFileMgrCreated = function(fileMgrParameter) {
fileMgr = fileMgrParameter;
@ -74,9 +69,6 @@ define([
if(!$liElt.hasClass("disabled")) {
fileMgr.selectFile(fileDesc);
}
else if(aceEditor !== undefined) {
aceEditor.focus();
}
else {
$editorElt.focus();
}
@ -99,7 +91,7 @@ define([
documentSelector.onReady = function() {
$editorElt = $('#wmd-input');
if(documentSelector.config.orderBy == "title") {
sortFunction = function(fileDesc) {
return fileDesc.title.toLowerCase();
@ -172,4 +164,4 @@ define([
return documentSelector;
});
});

View File

@ -8,11 +8,6 @@ define([
var scrollLink = new Extension("scrollLink", "Scroll Link", true, true);
scrollLink.settingsBlock = scrollLinkSettingsBlockHTML;
var aceEditor;
scrollLink.onAceCreated = function(aceEditorParam) {
aceEditor = aceEditorParam;
};
var sectionList;
scrollLink.onSectionsCreated = function(sectionListParam) {
sectionList = sectionListParam;
@ -35,51 +30,31 @@ define([
}
mdSectionList = [];
var mdSectionOffset;
var firstSectionOffset = offsetBegin;
var scrollHeight;
if(window.lightMode) {
var editorScrollTop = $editorElt.scrollTop();
$editorElt.find(".wmd-input-section").each(function() {
if(mdSectionOffset === undefined) {
// Force start to 0 for the first section
mdSectionOffset = 0;
return;
}
var $delimiterElt = $(this.firstChild);
// Consider div scroll position
var newSectionOffset = $delimiterElt.position().top + editorScrollTop;
mdSectionList.push({
startOffset: mdSectionOffset,
endOffset: newSectionOffset,
height: newSectionOffset - mdSectionOffset
});
mdSectionOffset = newSectionOffset;
});
// Last section
scrollHeight = $editorElt.prop('scrollHeight');
var editorScrollTop = $editorElt.scrollTop();
$editorElt.find(".wmd-input-section").each(function() {
if(mdSectionOffset === undefined) {
// Force start to 0 for the first section
mdSectionOffset = 0;
return;
}
var $delimiterElt = $(this.firstChild);
// Consider div scroll position
var newSectionOffset = $delimiterElt.position().top + editorScrollTop;
mdSectionList.push({
startOffset: mdSectionOffset,
endOffset: scrollHeight,
height: scrollHeight - mdSectionOffset
endOffset: newSectionOffset,
height: newSectionOffset - mdSectionOffset
});
}
else {
var mdTextOffset = 0;
_.each(sectionList, function(section) {
mdTextOffset += section.text.length + firstSectionOffset;
firstSectionOffset = 0;
var documentPosition = aceEditor.session.doc.indexToPosition(mdTextOffset);
var screenPosition = aceEditor.session.documentToScreenPosition(documentPosition.row, documentPosition.column);
var newSectionOffset = screenPosition.row * aceEditor.renderer.lineHeight;
var sectionHeight = newSectionOffset - mdSectionOffset;
mdSectionList.push({
startOffset: mdSectionOffset,
endOffset: newSectionOffset,
height: sectionHeight
});
mdSectionOffset = newSectionOffset;
});
}
mdSectionOffset = newSectionOffset;
});
// Last section
scrollHeight = $editorElt.prop('scrollHeight');
mdSectionList.push({
startOffset: mdSectionOffset,
endOffset: scrollHeight,
height: scrollHeight - mdSectionOffset
});
// Find corresponding sections in the preview
htmlSectionList = [];
@ -124,7 +99,7 @@ define([
if(!isPreviewVisible || mdSectionList.length === 0 || mdSectionList.length !== htmlSectionList.length) {
return;
}
var editorScrollTop = window.lightMode ? $editorElt.scrollTop() : aceEditor.renderer.getScrollTop();
var editorScrollTop = $editorElt.scrollTop();
editorScrollTop < 0 && (editorScrollTop = 0);
var previewScrollTop = $previewElt.scrollTop();
function getDestScrollTop(srcScrollTop, srcSectionList, destSectionList) {
@ -188,20 +163,10 @@ define([
// Animate the editor
lastPreviewScrollTop = previewScrollTop;
destScrollTop = getDestScrollTop(previewScrollTop, htmlSectionList, mdSectionList);
if(window.lightMode) {
destScrollTop = _.min([
destScrollTop,
$editorElt.prop('scrollHeight') - $editorElt.outerHeight()
]);
}
else {
destScrollTop = _.min([
destScrollTop,
aceEditor.session.getScreenLength() * aceEditor.renderer.lineHeight + aceEditor.renderer.scrollMargin.bottom - aceEditor.renderer.$size.scrollerHeight
]);
// If negative, set it to zero
destScrollTop < 0 && (destScrollTop = 0);
}
destScrollTop = _.min([
destScrollTop,
$editorElt.prop('scrollHeight') - $editorElt.outerHeight()
]);
if(Math.abs(destScrollTop - editorScrollTop) <= 9) {
// Skip the animation if diff is <= 9
lastEditorScrollTop = editorScrollTop;
@ -216,12 +181,7 @@ define([
step: function(now) {
isEditorMoving = true;
lastEditorScrollTop = editorScrollTop + now;
if(window.lightMode) {
$editorElt.scrollTop(lastEditorScrollTop);
}
else {
aceEditor.session.setScrollTop(lastEditorScrollTop);
}
$editorElt.scrollTop(lastEditorScrollTop);
},
done: function() {
_.defer(function() {
@ -278,12 +238,7 @@ define([
doScrollLink();
}
};
if(window.lightMode) {
$editorElt.scroll(handleEditorScroll);
}
else {
aceEditor.session.on("changeScrollTop", handleEditorScroll);
}
$editorElt.scroll(handleEditorScroll);
};
var $previewContentsElt;

View File

@ -1,224 +0,0 @@
define([
"jquery",
"underscore",
"crel",
"utils",
"classes/Extension",
"xregexp",
"text!bower-libs/Typo.js/typo/typo.js",
"text!bower-libs/lz-string/libs/lz-string-1.3.3.js",
"text!workers/spellCheckWorker.js",
"text!html/spellCheckSettingsBlock.html",
], function($, _, crel, utils, Extension, XRegExp, typoJS, LZStringJS, spellCheckWorkerJS, spellCheckSettingsBlockHTML) {
var spellCheck = new Extension("spellCheck", "Spell Check", true, true, true);
spellCheck.settingsBlock = spellCheckSettingsBlockHTML;
spellCheck.defaultConfig = {
locale: "en_US",
};
spellCheck.onLoadSettings = function() {
utils.setInputValue("#select-spell-check-locale", spellCheck.config.locale);
};
spellCheck.onSaveSettings = function(newConfig) {
newConfig.locale = utils.getInputValue("#select-spell-check-locale");
};
var worker;
var isInited = false;
spellCheck.onInit = function() {
// Create a web worker
worker = new Worker('res/worker.js');
worker.postMessage(spellCheckWorkerJS);
require([
'text!../libs/dictionaries/' + spellCheck.config.locale + '.dic.lz',
'text!../libs/dictionaries/' + spellCheck.config.locale + '.aff.lz',
], function(dic, aff) {
worker.postMessage(JSON.stringify(['init', typoJS, LZStringJS, spellCheck.config.locale, aff, dic]));
isInited = true;
start();
});
};
var aceEditor;
var wordRegExp = XRegExp('\\p{L}+(?:\'\\p{L}+)*', 'g');
var markers = [];
var timeoutId;
var currentRowCheck;
function rowCheck(rowIndex) {
var tokens = aceEditor.session.getTokens(rowIndex).slice();
var tokenOffset = 0;
var self = this;
self.checkToken = function() {
if (tokens.length === 0) {
!timeoutId && (timeoutId = setTimeout(check, 5));
return;
}
var token = tokens.shift();
var words = [];
if (!/code|code_block|link|reference|string|keyword|tag|markup\.underline/.test(token.type)) {
token.value.replace(wordRegExp, function(word, offset) {
words.push({
value: word,
offset: offset + tokenOffset
});
});
}
tokenOffset += token.value.length;
if (words.length === 0) {
self.checkToken();
return;
}
worker.onmessage = function(e) {
var message = JSON.parse(e.data);
if (message[0] != 'check') {
return;
}
var checkedWords = message[1];
if (self.stopped) {
return;
}
var Range = require('ace/range').Range;
_.each(checkedWords, function(word) {
if (!word.check) {
var range = new Range(rowIndex, word.offset, rowIndex, word.offset + word.value.length);
var markerId = aceEditor.session.addMarker(range, "misspelled", "typo", true);
var marker = aceEditor.session.getMarkers(true)[markerId];
markers.push(marker);
}
});
self.checkToken();
};
worker.postMessage(JSON.stringify(['check', words]));
};
}
var rowIndex = 0;
function check() {
timeoutId = undefined;
currentRowCheck && (currentRowCheck.stopped = true);
currentRowCheck = new rowCheck(rowIndex++);
currentRowCheck.checkToken();
}
function stop() {
currentRowCheck && (currentRowCheck.stopped = true);
timeoutId && clearTimeout(timeoutId);
timeoutId = undefined;
}
function start() {
if(isInited === false || aceEditor === undefined) {
return;
}
var savedMarkers = [];
_.each(markers, function(marker) {
if (marker.range.start.row < rowIndex) {
savedMarkers.push(marker);
}
else {
aceEditor.session.removeMarker(marker.id);
}
});
markers = savedMarkers;
timeoutId = setTimeout(check, 2000);
}
/*
var dropdownElt;
var $dropdownElt;
var liEltTmpl = [
'<li>',
' <a href="#">',
' <%= suggestion %>',
' </a>',
'</li>'
].join('');
var currentWordSuggest = undefined;
function wordSuggest(marker) {
var word = aceEditor.session.getTextRange(marker.range);
var self = this;
self.run = function() {
worker.onmessage = function(e) {
var message = JSON.parse(e.data);
if (message[0] != 'suggest') {
return;
}
var suggestions = message[1];
if (self.stopped) {
return;
}
console.log(suggestions);
var liListHtml = _.reduce(suggestions, function(result, suggestion) {
return result + _.template(liEltTmpl, {
suggestion: suggestion,
});
}, '');
dropdownElt.innerHTML = liListHtml;
$(dropdownElt).dropdown('toggle');
};
worker.postMessage(JSON.stringify(['suggest', word]));
};
}
*/
var fileOpen = false;
spellCheck.onFileClose = function() {
stop();
fileOpen = false;
};
spellCheck.onFileOpen = function() {
fileOpen = true;
rowIndex = 0;
stop();
start();
};
spellCheck.onAceCreated = function(aceEditorParam) {
aceEditor = aceEditorParam;
aceEditor.session.on('change', function(e) {
if (fileOpen === true) {
var modifiedRowIndex = e.data.range.start.row;
if (modifiedRowIndex < rowIndex) {
rowIndex = modifiedRowIndex;
}
stop();
start();
}
});
// Suggestions are disabled. Too much CPU consumption.
/*
aceEditor.on("click", function(ev) {
var screenCoordinates = aceEditor.renderer.pixelToScreenCoordinates(ev.x, ev.y);
var documentPosition = aceEditor.session.screenToDocumentPosition(screenCoordinates.row, screenCoordinates.column);
_.each(markers, function(marker) {
if (marker.range.contains(documentPosition.row, documentPosition.column)) {
currentWordSuggest && (currentWordSuggest.stopped = true);
currentWordSuggest = new wordSuggest(marker);
currentWordSuggest.run();
}
});
});
};
spellCheck.onReady = function() {
dropdownElt = crel('ul', {
class: 'dropdown-menu dropdown-spell-checker'
});
document.querySelector('.ui-layout-resizer-north').appendChild(crel('div', crel('div', {
'data-toggle': 'dropdown'
}), dropdownElt));
$dropdownElt = $(dropdownElt).dropdown();
*/
};
return spellCheck;
});

View File

@ -98,7 +98,7 @@ define([
fileMgr.deleteFile = function(fileDesc) {
fileDesc = fileDesc || fileMgr.currentFile;
// Unassociate file from folder
if(fileDesc.folder) {
fileDesc.folder.removeFile(fileDesc);
@ -160,11 +160,6 @@ define([
});
};
var aceEditor;
eventMgr.addListener('onAceCreated', function(aceEditorParam) {
aceEditor = aceEditorParam;
});
eventMgr.addListener("onReady", function() {
var $editorElt = $("#wmd-input");
fileMgr.selectFile();
@ -204,7 +199,7 @@ define([
eventMgr.onTitleChanged(fileDesc);
}
$fileTitleInputElt.val(fileDesc.title);
aceEditor ? aceEditor.focus() : $editorElt.focus();
$editorElt.focus();
}
$fileTitleInputElt.blur(function() {
applyTitle();
@ -222,9 +217,6 @@ define([
});
$(".action-edit-document").click(function() {
var content = $editorElt.val();
if(aceEditor !== undefined) {
content = aceEditor.getValue();
}
var title = fileMgr.currentFile.title;
var fileDesc = fileMgr.createFile(title, content);
fileMgr.selectFile(fileDesc);

View File

@ -42,7 +42,7 @@
</ul>
</div>
</div>
<div id="wmd-input" class="ui-layout-center"></div>
<pre id="wmd-input" class="ui-layout-center form-control"></pre>
<div class="ui-layout-east preview-container"></div>
<div class="ui-layout-south preview-container"></div>
<div id="wmd-button-bar" class="hide"></div>

File diff suppressed because it is too large Load Diff

View File

@ -1,312 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2010, Ajax.org B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ***** END LICENSE BLOCK ***** */
define(function(require, exports, module) {
"use strict";
var lang = require("ace/lib/lang");
var config = require("ace/config");
var Range = require('ace/range').Range
function bindKey(win, mac) {
return {
win: win,
mac: mac
};
}
exports.commands = [{
name: "overwrite",
bindKey: "Insert",
exec: function(editor) { editor.toggleOverwrite(); },
readOnly: true
}, {
name: "selecttostart",
bindKey: bindKey("Ctrl-Shift-Home", "Command-Shift-Up"),
exec: function(editor) { editor.getSelection().selectFileStart(); },
multiSelectAction: "forEach",
readOnly: true
}, {
name: "gotostart",
bindKey: bindKey("Ctrl-Home", "Command-Home|Command-Up"),
exec: function(editor) { editor.navigateFileStart(); },
multiSelectAction: "forEach",
readOnly: true
}, {
name: "selectup",
bindKey: bindKey("Shift-Up", "Shift-Up"),
exec: function(editor) { editor.getSelection().selectUp(); },
multiSelectAction: "forEach",
readOnly: true
}, {
name: "golineup",
bindKey: bindKey("Up", "Up"),
exec: function(editor, args) { editor.navigateUp(args.times); },
multiSelectAction: "forEach",
readOnly: true
}, {
name: "selecttoend",
bindKey: bindKey("Ctrl-Shift-End", "Command-Shift-Down"),
exec: function(editor) { editor.getSelection().selectFileEnd(); },
multiSelectAction: "forEach",
readOnly: true
}, {
name: "gotoend",
bindKey: bindKey("Ctrl-End", "Command-End|Command-Down"),
exec: function(editor) { editor.navigateFileEnd(); },
multiSelectAction: "forEach",
readOnly: true
}, {
name: "selectdown",
bindKey: bindKey("Shift-Down", "Shift-Down"),
exec: function(editor) { editor.getSelection().selectDown(); },
multiSelectAction: "forEach",
readOnly: true
}, {
name: "golinedown",
bindKey: bindKey("Down", "Down"),
exec: function(editor, args) { editor.navigateDown(args.times); },
multiSelectAction: "forEach",
readOnly: true
}, {
name: "selectwordleft",
bindKey: bindKey("Ctrl-Shift-Left", "Option-Shift-Left"),
exec: function(editor) { editor.getSelection().selectWordLeft(); },
multiSelectAction: "forEach",
readOnly: true
}, {
name: "gotowordleft",
bindKey: bindKey("Ctrl-Left", "Option-Left"),
exec: function(editor) { editor.navigateWordLeft(); },
multiSelectAction: "forEach",
readOnly: true
}, {
name: "selecttolinestart",
bindKey: bindKey("Alt-Shift-Left", "Command-Shift-Left"),
exec: function(editor) { editor.getSelection().selectLineStart(); },
multiSelectAction: "forEach",
readOnly: true
}, {
name: "gotolinestart",
bindKey: bindKey("Alt-Left|Home", "Command-Left|Home"),
exec: function(editor) { editor.navigateLineStart(); },
multiSelectAction: "forEach",
readOnly: true
}, {
name: "selectleft",
bindKey: bindKey("Shift-Left", "Shift-Left"),
exec: function(editor) { editor.getSelection().selectLeft(); },
multiSelectAction: "forEach",
readOnly: true
}, {
name: "gotoleft",
bindKey: bindKey("Left", "Left"),
exec: function(editor, args) { editor.navigateLeft(args.times); },
multiSelectAction: "forEach",
readOnly: true
}, {
name: "selectwordright",
bindKey: bindKey("Ctrl-Shift-Right", "Option-Shift-Right"),
exec: function(editor) { editor.getSelection().selectWordRight(); },
multiSelectAction: "forEach",
readOnly: true
}, {
name: "gotowordright",
bindKey: bindKey("Ctrl-Right", "Option-Right"),
exec: function(editor) { editor.navigateWordRight(); },
multiSelectAction: "forEach",
readOnly: true
}, {
name: "selecttolineend",
bindKey: bindKey("Alt-Shift-Right", "Command-Shift-Right"),
exec: function(editor) { editor.getSelection().selectLineEnd(); },
multiSelectAction: "forEach",
readOnly: true
}, {
name: "gotolineend",
bindKey: bindKey("Alt-Right|End", "Command-Right|End"),
exec: function(editor) { editor.navigateLineEnd(); },
multiSelectAction: "forEach",
readOnly: true
}, {
name: "selectright",
bindKey: bindKey("Shift-Right", "Shift-Right"),
exec: function(editor) { editor.getSelection().selectRight(); },
multiSelectAction: "forEach",
readOnly: true
}, {
name: "gotoright",
bindKey: bindKey("Right", "Right"),
exec: function(editor, args) { editor.navigateRight(args.times); },
multiSelectAction: "forEach",
readOnly: true
}, {
name: "selectpagedown",
bindKey: "Shift-PageDown",
exec: function(editor) { editor.selectPageDown(); },
readOnly: true
}, {
name: "pagedown",
bindKey: bindKey(null, "Option-PageDown"),
exec: function(editor) { editor.scrollPageDown(); },
readOnly: true
}, {
name: "gotopagedown",
bindKey: bindKey("PageDown", "PageDown"),
exec: function(editor) { editor.gotoPageDown(); },
readOnly: true
}, {
name: "selectpageup",
bindKey: "Shift-PageUp",
exec: function(editor) { editor.selectPageUp(); },
readOnly: true
}, {
name: "pageup",
bindKey: bindKey(null, "Option-PageUp"),
exec: function(editor) { editor.scrollPageUp(); },
readOnly: true
}, {
name: "gotopageup",
bindKey: "PageUp",
exec: function(editor) { editor.gotoPageUp(); },
readOnly: true
}, {
name: "scrollup",
bindKey: bindKey("Ctrl-Up", null),
exec: function(e) { e.renderer.scrollBy(0, -2 * e.renderer.layerConfig.lineHeight); },
readOnly: true
}, {
name: "scrolldown",
bindKey: bindKey("Ctrl-Down", null),
exec: function(e) { e.renderer.scrollBy(0, 2 * e.renderer.layerConfig.lineHeight); },
readOnly: true
}, {
name: "selectlinestart",
bindKey: "Shift-Home",
exec: function(editor) { editor.getSelection().selectLineStart(); },
multiSelectAction: "forEach",
readOnly: true
}, {
name: "selectlineend",
bindKey: "Shift-End",
exec: function(editor) { editor.getSelection().selectLineEnd(); },
multiSelectAction: "forEach",
readOnly: true
},
// commands disabled in readOnly mode
{
name: "cut",
exec: function(editor) {
var range = editor.getSelectionRange();
editor._emit("cut", range);
if (!editor.selection.isEmpty()) {
editor.session.remove(range);
editor.clearSelection();
}
},
multiSelectAction: "forEach"
}, {
name: "undo",
bindKey: bindKey("Ctrl-Z", "Command-Z"),
exec: function(editor) { editor.undo(); }
}, {
name: "redo",
bindKey: bindKey("Ctrl-Shift-Z|Ctrl-Y", "Command-Shift-Z|Command-Y"),
exec: function(editor) { editor.redo(); }
}, {
name: "del",
bindKey: bindKey("Delete", "Delete|Ctrl-D"),
exec: function(editor) { editor.remove("right"); },
multiSelectAction: "forEach"
}, {
name: "backspace",
bindKey: bindKey(
"Command-Backspace|Option-Backspace|Shift-Backspace|Backspace",
"Ctrl-Backspace|Command-Backspace|Shift-Backspace|Backspace|Ctrl-H"
),
exec: function(editor) { editor.remove("left"); },
multiSelectAction: "forEach"
}, {
name: "removetolinestart",
bindKey: bindKey("Alt-Backspace", "Command-Backspace"),
exec: function(editor) { editor.removeToLineStart(); },
multiSelectAction: "forEach"
}, {
name: "removetolineend",
bindKey: bindKey("Alt-Delete", "Ctrl-K"),
exec: function(editor) { editor.removeToLineEnd(); },
multiSelectAction: "forEach"
}, {
name: "removewordleft",
bindKey: bindKey("Ctrl-Backspace", "Alt-Backspace|Ctrl-Alt-Backspace"),
exec: function(editor) { editor.removeWordLeft(); },
multiSelectAction: "forEach"
}, {
name: "removewordright",
bindKey: bindKey("Ctrl-Delete", "Alt-Delete"),
exec: function(editor) { editor.removeWordRight(); },
multiSelectAction: "forEach"
}, {
name: "outdent",
bindKey: bindKey("Shift-Tab", "Shift-Tab"),
exec: function(editor) { editor.blockOutdent(); },
multiSelectAction: "forEach"
}, {
name: "indent",
bindKey: bindKey("Tab", "Tab"),
exec: function(editor) {
// Perform block indent if the caret is at the begining of a list item
var selectionRange = editor.getSelectionRange();
var range = new Range(selectionRange.end.row, 0, selectionRange.end.row, selectionRange.end.column);
var startText = editor.session.getTextRange(range);
var token = editor.session.getTokenAt(selectionRange.end.row, selectionRange.end.column);
if(token && token.type == "markup.list" && /^\s*(?:[-+*]|\d+\.)\s+$/.test(startText)) {
editor.blockIndent();
}
else {
editor.indent();
}
},
multiSelectAction: "forEach"
}, {
name: "insertstring",
exec: function(editor, str) { editor.insert(str); },
multiSelectAction: "forEach"
}, {
name: "inserttext",
exec: function(editor, args) {
editor.insert(lang.stringRepeat(args.text || "", args.times || 1));
},
multiSelectAction: "forEach"
}];
});

View File

@ -1,96 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2010, Ajax.org B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ***** END LICENSE BLOCK ***** */
define(function(require, exports, module) {
"use strict";
var oop = require("ace/lib/oop");
var TextMode = require("ace/mode/text").Mode;
var Tokenizer = require("ace/tokenizer").Tokenizer;
var MarkdownHighlightRules = require("./ace_mode_highlight_rules").MarkdownHighlightRules;
var MarkdownFoldMode = require("ace/mode/folding/markdown").FoldMode;
var eventMgr = require('eventMgr');
var Range = require('ace/range').Range
var editor = undefined;
eventMgr.addListener('onAceCreated', function(editorParam) {
editor = editorParam;
});
var Mode = function() {
var highlighter = new MarkdownHighlightRules();
this.$tokenizer = new Tokenizer(highlighter.getRules());
this.$embeds = highlighter.getEmbeds();
//this.foldingRules = new MarkdownFoldMode();
};
oop.inherits(Mode, TextMode);
var isIndentingList = false;
(function() {
this.type = "text";
this.lineCommentStart = ">";
this.getNextLineIndent = function(state, line, tab) {
if(isIndentingList === true && (state == "listblock" || state == "listblock-start") && /^\s*(?:[-+*]|\d+\.)\s+$/.test(line)) {
// When hitting enter twice in a listblock, remove the previous line
var rows = editor.$getSelectedRows();
if (rows.last > 1) {
var range = new Range(
rows.last - 2, editor.session.getLine(rows.last - 2).length,
rows.last - 1, editor.session.getLine(rows.last - 1).length);
var previousLine = editor.session.getTextRange(range);
if(/^\s*(?:[-+*]|\d+\.)\s+$/.test(previousLine)) {
editor.session.remove(range);
}
}
isIndentingList = false;
return this.$getIndent(line);
}
isIndentingList = false;
if (state == "listblock") {
var match = /^(\s*)(?:([-+*])|(\d+)\.)(\s+)/.exec(line);
if (!match)
return "";
var marker = match[2];
if (!marker)
marker = parseInt(match[3], 10) + 1 + ".";
isIndentingList = true;
return match[1] + marker + match[4];
} else {
return this.$getIndent(line);
}
};
}).call(Mode.prototype);
exports.Mode = Mode;
});

View File

@ -1,239 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2010, Ajax.org B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ***** END LICENSE BLOCK ***** */
define(function(require, exports, module) {
"use strict";
var oop = require("ace/lib/oop");
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;
var HtmlHighlightRules = require("ace/mode/html_highlight_rules").HtmlHighlightRules;
var MarkdownHighlightRules = function() {
HtmlHighlightRules.call(this);
// regexp must not have capturing parentheses
// regexps are ordered -> the first match is used
this.$rules["start"].unshift({
token : "empty_line",
regex : '^$',
next: "allowBlock"
}, { // h1
token: "markup.heading.multi.1",
regex: "^=+(?=\\s*$)"
}, { // h2
token: "markup.heading.multi.2",
regex: "^\\-+(?=\\s*$)"
}, {
token : function(value) {
return "markup.heading." + value.length;
},
regex : /^#{1,6}(?=\s*[^ #]|\s+#.)/,
next : "header"
},
{ // Github style block
token : "constant.language.escape",
regex : "^```\\s*[a-zA-Z]*(?:{.*?\\})?\\s*$",
next : "githubblock"
}, { // block quote
token : ["constant.language.escape", "blockquote"],
regex : "(^\\s*>\\s*(?:[*+-]|\\d+\\.)?)(\\s+)",
next : "blockquote"
}, { // HR * - _
token : "constant",
regex : "^ {0,2}(?:(?: ?\\* ?){3,}|(?: ?\\- ?){3,}|(?: ?\\_ ?){3,})\\s*$",
next: "allowBlock"
}, { // list
token : ["constant.language.escape", "markup.list"],
regex : "(^\\s{0,3}(?:[*+-]|\\d+\\.))(\\s+)",
next : "listblock-start"
}, { // Math block
token : "constant.language.escape",
regex : "\\$\\$|\\\\\\\\\\[|\\\\\\\\\\\\\\\\\\(",
next : "mathblock"
}, { // LaTeX block
token : ["keyword", "text"],
regex : "(\\\\?\\\\begin)(\\{[a-z]*\\*?\\})",
next : "latexblock"
}, {
token : "doccomment",
regex : "<\\!---", next :
"doccomment"
}, {
include : "basic"
});
this.addRules({
"basic" : [{
token : "constant.language.escape",
regex : /\\[\\`*_{}\[\]()#+\-.!]/
}, { // Escaped $
token : "text",
regex : "\\\\\\$",
}, { // Math inline
token : ["constant.language.escape", "keyword", "constant.language.escape"],
regex : "(\\$)(.*?)(\\$)"
}, { // code span `
token : ["constant.language.escape", "code", "constant.language.escape"],
regex : "(`+)(.*?[^`])(\\1)"
}, { // reference
token : ["constant.language.escape", "reference", "constant.language.escape", "link", "description", "constant.language.escape"],
regex : "^([ ]{0,3}\\[)([^\\]]+)(\\]:\\s*)([^ ]+)(\\s*(?:[\"][^\"]+[\"])?(\\s*))$"
}, { // link by reference
token : ["constant.language.escape", "markup.underline", "constant.language.escape", "reference", "constant.language.escape"],
regex : "(\\[)((?:[[^\\]]*\\]|[^\\[\\]])*)(\\][ ]?(?:\\n[ ]*)?\\[)(.*?)(\\])"
}, { // link by url
token : ["constant.language.escape", "markup.underline", "constant.language.escape", "link", "description", "constant.language.escape"],
regex : "(\\[)"+
"(\\[[^\\]]*\\]|[^\\[\\]]*)"+
"(\\]\\([ \\t]*)"+
"(<?(?:(?:[^\\(]*?\\([^\\)]*?\\)\\S*?)|(?:.*?))>?)"+
"((?:[ \t]*\"(?:.*?)\"[ \\t]*)?)"+
"(\\))"
}, { // strong ** __
token : ["constant.language.escape", "strong", "constant.language.escape"],
regex : "([*]{2}|[_]{2}(?=\\S))(.*?\\S[*_]*)(\\1)"
}, { // emphasis * _
token : ["constant.language.escape", "emphasis", "constant.language.escape"],
regex : "([*]|[_](?=\\S))(.*?\\S[*_]*)(\\1)"
}, { //
token : ["text", "url", "text"],
regex : "(<)("+
"(?:https?|ftp|dict):[^'\">\\s]+"+
"|"+
"(?:mailto:)?[-.\\w]+\\@[-a-z0-9]+(?:\\.[-a-z0-9]+)*\\.[a-z]+"+
")(>)"
}],
// code block
"allowBlock": [
{token : ["text", "code_block"], regex : "^( {4}|\\t)(.+)", next : "allowBlock"},
{token : "empty", regex : "", next : "start"}
],
"header" : [{
regex: "$",
next : "start"
}, {
include: "basic"
}, {
defaultToken : "markup.heading"
} ],
"listblock-start" : [{
token : "checkbox",
regex : /(?:\[[ x]\])?/,
next : "listblock"
}],
"listblock" : [ { // Lists only escape on completely blank lines.
token : "empty_line",
regex : "^$",
next : "start"
}, { // list
token : ["constant.language.escape", "markup.list"],
regex : "(^\\s{0,3}(?:[*+-]|\\d+\\.))(\\s+)",
next : "listblock-start"
}, {
include : "basic", noEscape: true
}, {
defaultToken : "markup.list"
} ],
"blockquote" : [ { // BLockquotes only escape on blank lines.
token : "empty_line",
regex : "^\\s*$",
next : "start"
}, { // block quote
token : ["constant.language.escape", "blockquote"],
regex : "(^\\s*>\\s*(?:[*+-]|\\d+\\.)?)(\\s+)",
next : "blockquote"
}, {
include : "basic", noEscape: true
}, {
defaultToken : "blockquote"
} ],
"githubblock" : [ {
token : "constant.language.escape",
regex : "^```",
next : "start"
}, {
token : "code_block",
regex : ".+"
} ],
"mathblock" : [ {
token : "constant.language.escape",
regex : "\\$\\$|\\\\\\\\\\]|\\\\\\\\\\\\\\\\\\)",
next : "start"
}, {
include : "latex"
} ],
"latexblock" : [{
token : ["keyword", "text"],
regex : "(\\\\?\\\\end)(\\{[a-z]*\\*?\\})",
next : "start"
}, {
include : "latex"
}],
"latex" : [{
// A tex command e.g. \foo
token : "keyword",
regex : "\\\\(?:[^a-zA-Z]|[a-zA-Z]+)"
}, {
// Curly and square braces
token : "lparen",
regex : "[[({]"
}, {
// Curly and square braces
token : "rparen",
regex : "[\\])}]"
}, {
// A comment. Tex comments start with % and go to
// the end of the line
token : "comment",
regex : "%.*$"
}],
doccomment : [
{token : "doccomment", regex : "-->", next : "start"},
{defaultToken : "doccomment"}
],
});
this.normalizeRules();
};
oop.inherits(MarkdownHighlightRules, TextHighlightRules);
exports.MarkdownHighlightRules = MarkdownHighlightRules;
});

View File

@ -1,11 +0,0 @@
(function() {
define(function (require, exports, module) {
"use strict";
exports.load = function (name, req, onLoad, config) {
onLoad('', 'utf8');
};
});
})();

View File

@ -3,11 +3,6 @@
requirejs.config({
waitSeconds: 0,
packages: [
{
name: 'ace',
location: 'bower-libs/ace/lib/ace',
main: 'ace'
},
{
name: 'css',
location: 'bower-libs/require-css',
@ -48,24 +43,18 @@ requirejs.config({
'bootstrap-tour': 'bower-libs/bootstrap-tour/build/js/bootstrap-tour',
css_browser_selector: 'bower-libs/css_browser_selector/css_browser_selector',
'jquery-mousewheel': 'bower-libs/jquery-mousewheel/jquery.mousewheel',
'pagedown-ace': 'bower-libs/pagedown-ace/Markdown.Editor',
'pagedown-light': 'libs/Markdown.Editor.light',
'pagedown-extra': 'bower-libs/pagedown-extra/Markdown.Extra',
'ace/requirejs/text': 'libs/ace_text',
'ace/commands/default_commands': 'libs/ace_commands',
'pagedown': 'bower-libs/stackedit-pagedown/Markdown.Editor',
'require-css': 'bower-libs/require-css/css',
xregexp: 'bower-libs/xregexp/xregexp-all',
yaml: 'bower-libs/yaml.js',
'yaml.js': 'bower-libs/yaml.js',
'yaml-js': 'bower-libs/yaml.js/bin/yaml',
Typo: 'bower-libs/Typo.js',
'Typo.js': 'bower-libs/Typo.js',
css: 'bower-libs/require-css/css',
'css-builder': 'bower-libs/require-css/css-builder',
normalize: 'bower-libs/require-css/normalize',
prism: 'bower-libs/prism/prism',
'prism-core': 'bower-libs/prism/components/prism-core',
caret: 'bower-libs/caret.js/src/jquery.caret'
'prism-core': 'bower-libs/prism/components/prism-core'
},
shim: {
underscore: {
@ -126,9 +115,6 @@ requirejs.config({
bootstrap: [
'jquery'
],
'caret': [
'jquery'
],
'jquery-waitforimages': [
'jquery'
],
@ -156,15 +142,12 @@ requirejs.config({
'jquery-ui-core': [
'jquery'
],
'pagedown': [
'bower-libs/stackedit-pagedown/Markdown.Converter'
],
'pagedown-extra': [
'pagedown-ace'
'bower-libs/stackedit-pagedown/Markdown.Converter'
],
'pagedown-ace': [
'bower-libs/pagedown-ace/Markdown.Converter'
],
'pagedown-light': [
'bower-libs/pagedown-ace/Markdown.Converter'
]
}
});
@ -187,13 +170,6 @@ catch (e) {
// Viewer mode is deduced from the body class
window.viewerMode = /(^| )viewer($| )/.test(document.body.className);
// Light mode is for mobile or viewer
window.lightMode = window.viewerMode || /_light_/.test(localStorage.mode) || /(\?|&)light($|&)/.test(location.search) || (function(a) {
if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino|android|ipad|playbook|silk/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) {
return true;
}
})(navigator.userAgent || navigator.vendor || window.opera);
// Keep the theme in a global variable
window.theme = localStorage.themeV3 || 'default';
var themeModule = "less!themes/" + window.theme;
@ -205,15 +181,12 @@ if (window.baseDir.indexOf('-min') !== -1) {
// media-importer, we are actually loading all the modules
require(["jquery", "core", "eventMgr", "synchronizer", "publisher", "mediaImporter", "css",
themeModule, ], function($, core, eventMgr) {
if(window.noStart) {
return;
}
$(function() {
// Add RTL class
/_rtl_/.test(localStorage.mode) && $(document.body).addClass('rtl');
// Here, all the modules are loaded and the DOM is ready
core.onReady();

View File

@ -14,21 +14,21 @@ define([
"text!html/dialogExportGdrive.html",
"text!html/dialogAutoSyncGdrive.html",
], function($, _, constants, utils, storage, logger, Provider, settings, eventMgr, fileMgr, googleHelper, dialogExportGdriveHTML, dialogAutoSyncGdriveHTML) {
return function(providerId, providerName, accountIndex) {
var accountId = 'google.gdrive' + accountIndex;
var gdriveProvider = new Provider(providerId, providerName);
gdriveProvider.defaultPublishFormat = "template";
gdriveProvider.exportPreferencesInputIds = [
providerId + "-parentid",
providerId + "-realtime",
];
function createSyncIndex(id) {
return "sync." + providerId + "." + id;
}
function createSyncAttributes(id, etag, content, title) {
var syncAttributes = {};
syncAttributes.provider = gdriveProvider;
@ -39,7 +39,7 @@ define([
syncAttributes.syncIndex = createSyncIndex(id);
return syncAttributes;
}
function importFilesFromIds(ids) {
googleHelper.downloadMetadata(ids, accountId, function(error, result) {
if(error) {
@ -66,7 +66,7 @@ define([
});
});
}
gdriveProvider.importFiles = function() {
googleHelper.picker(function(error, docs) {
if(error || docs.length === 0) {
@ -85,7 +85,7 @@ define([
importFilesFromIds(importIds);
}, 'doc', accountId);
};
gdriveProvider.exportFile = function(event, title, content, callback) {
var fileId = utils.getInputTextValue('#input-sync-export-' + providerId + '-fileid');
if(fileId) {
@ -109,7 +109,7 @@ define([
callback(undefined, syncAttributes);
});
};
gdriveProvider.exportRealtimeFile = function(event, title, content, callback) {
var parentId = utils.getInputTextValue('#input-sync-export-' + providerId + '-parentid');
googleHelper.createRealtimeFile(parentId, title, accountId, function(error, result) {
@ -121,7 +121,7 @@ define([
callback(undefined, syncAttributes);
});
};
gdriveProvider.syncUp = function(uploadContent, uploadContentCRC, uploadTitle, uploadTitleCRC, syncAttributes, callback) {
// Skip if CRC has not changed
if(uploadContentCRC == syncAttributes.contentCRC && uploadTitleCRC == syncAttributes.titleCRC) {
@ -139,7 +139,7 @@ define([
callback(undefined, true);
});
};
gdriveProvider.syncUpRealtime = function(uploadContent, uploadContentCRC, uploadTitle, uploadTitleCRC, syncAttributes, callback) {
// Skip if title CRC has not changed
if(uploadTitleCRC == syncAttributes.titleCRC) {
@ -156,7 +156,7 @@ define([
callback(undefined, true);
});
};
gdriveProvider.syncDown = function(callback) {
var lastChangeId = parseInt(storage[accountId + ".gdrive.lastChangeId"], 10);
googleHelper.checkChanges(lastChangeId, accountId, function(error, changes, newChangeId) {
@ -251,7 +251,7 @@ define([
});
});
};
gdriveProvider.publish = function(publishAttributes, frontMatter, title, content, callback) {
var contentType = publishAttributes.format != "markdown" ? 'text/html' : undefined;
googleHelper.upload(publishAttributes.id, undefined, publishAttributes.fileName || title, content, contentType, undefined, accountId, function(error, result) {
@ -263,7 +263,7 @@ define([
callback();
});
};
gdriveProvider.newPublishAttributes = function(event) {
var publishAttributes = {};
publishAttributes.id = utils.getInputTextValue('#input-publish-' + providerId + '-fileid');
@ -273,7 +273,7 @@ define([
}
return publishAttributes;
};
// Keep a link to the Pagedown editor
var pagedownEditor;
var undoExecute;
@ -282,22 +282,8 @@ define([
eventMgr.addListener("onPagedownConfigure", function(pagedownEditorParam) {
pagedownEditor = pagedownEditorParam;
});
// Keep a link to the ACE editor
var realtimeContext;
var aceEditor;
var isAceUpToDate = true;
eventMgr.addListener('onAceCreated', function(aceEditorParam) {
aceEditor = aceEditorParam;
// Listen to editor's changes
aceEditor.session.on('change', function() {
// Update the real time model if any
realtimeContext && realtimeContext.string && realtimeContext.string.setText(aceEditor.getValue());
});
});
// Start realtime synchronization
var Range = require('ace/range').Range;
gdriveProvider.startRealtimeSync = function(fileDesc, syncAttributes) {
var localContext = {};
realtimeContext = localContext;
@ -305,27 +291,27 @@ define([
if(err || !doc) {
return;
}
// If user just switched to another document or file has just been
// reselected
if(localContext.isStopped === true) {
doc.close();
return;
}
logger.log("Starting Google Drive realtime synchronization");
localContext.document = doc;
var model = doc.getModel();
var realtimeString = model.getRoot().get('content');
// Saves model content checksum
function updateContentState() {
syncAttributes.contentCRC = utils.crc32(realtimeString.getText());
utils.storeAttributes(syncAttributes);
}
var debouncedRefreshPreview = _.debounce(pagedownEditor.refreshPreview, 100);
// Listen to insert text events
realtimeString.addEventListener(gapi.drive.realtime.EventType.TEXT_INSERTED, function(e) {
if(aceEditor !== undefined && (isAceUpToDate === false || e.isLocal === false)) {
@ -365,7 +351,7 @@ define([
updateContentState();
}
});
// Try to merge offline modifications
var localContent = fileDesc.content;
var localContentChanged = syncAttributes.contentCRC != utils.crc32(localContent);
@ -384,12 +370,12 @@ define([
realtimeString.setText(localContent);
}
}
if(aceEditor === undefined) {
// Binds model with textarea
localContext.binding = gapi.drive.realtime.databinding.bindString(realtimeString, document.getElementById("wmd-input"));
}
// Update content state according to collaborators changes
if(remoteContentChanged === true) {
logger.log("Google Drive realtime document updated from server");
@ -397,17 +383,17 @@ define([
updateContentState();
aceEditor === undefined && debouncedRefreshPreview();
}
if(aceEditor !== undefined) {
// Tell ACE to update realtime string on each change
localContext.string = realtimeString;
}
// Save undo/redo buttons default actions
undoExecute = pagedownEditor.uiManager.buttons.undo.execute;
redoExecute = pagedownEditor.uiManager.buttons.redo.execute;
setUndoRedoButtonStates = pagedownEditor.uiManager.setUndoRedoButtonStates;
// Set temporary actions for undo/redo buttons
pagedownEditor.uiManager.buttons.undo.execute = function() {
if(model.canUndo) {
@ -425,7 +411,7 @@ define([
model.redo();
}
};
// Add event handler for model's UndoRedoStateChanged events
pagedownEditor.uiManager.setUndoRedoButtonStates = function() {
setTimeout(function() {
@ -437,7 +423,7 @@ define([
model.addEventListener(gapi.drive.realtime.EventType.UNDO_REDO_STATE_CHANGED, function() {
pagedownEditor.uiManager.setUndoRedoButtonStates();
});
}, function(err) {
console.error(err);
if(err.type == "token_refresh_required") {
@ -455,7 +441,7 @@ define([
}
});
};
// Stop realtime synchronization
gdriveProvider.stopRealtimeSync = function() {
logger.log("Stopping Google Drive realtime synchronization");
@ -465,7 +451,7 @@ define([
realtimeContext.document && realtimeContext.document.close();
realtimeContext = undefined;
}
if(setUndoRedoButtonStates !== undefined) {
// Set back original undo/redo actions
pagedownEditor.uiManager.buttons.undo.execute = undoExecute;
@ -474,14 +460,14 @@ define([
pagedownEditor.uiManager.setUndoRedoButtonStates();
}
};
// Initialize the AutoSync dialog fields
gdriveProvider.setAutosyncDialogConfig = function() {
var config = gdriveProvider.autosyncConfig;
utils.setInputChecked('#input-autosync-' + providerId + '-enabled', config.enabled);
utils.setInputValue('#input-autosync-' + providerId + '-parentid', config.parentId);
};
// Retrieve the AutoSync dialog fields
gdriveProvider.getAutosyncDialogConfig = function() {
var config = {};
@ -489,7 +475,7 @@ define([
config.parentId = utils.getInputTextValue('#input-autosync-' + providerId + '-parentid');
return config;
};
// Perform AutoSync
gdriveProvider.autosyncFile = function(title, content, config, callback) {
var parentId = config.parentId;
@ -502,10 +488,10 @@ define([
callback(undefined, syncAttributes);
});
};
// Disable publish on optional multi-account
gdriveProvider.isPublishEnabled = settings.gdriveMultiAccount > accountIndex;
eventMgr.addListener("onReady", function() {
// Hide optional multi-account sub-menus
$('.submenu-sync-' + providerId).toggle(settings.gdriveMultiAccount > accountIndex);
@ -516,14 +502,14 @@ define([
providerId: providerId,
providerName: providerName
}));
// Create autosync dialog
var modalAutosyncElt = document.querySelector('.modal-autosync-' + providerId);
modalAutosyncElt && (modalAutosyncElt.innerHTML = _.template(dialogAutoSyncGdriveHTML, {
providerId: providerId,
providerName: providerName
}));
// Choose folder button in export modal
$('.action-export-' + providerId + '-choose-folder').click(function() {
googleHelper.picker(function(error, docs) {
@ -536,7 +522,7 @@ define([
utils.setInputValue('#input-sync-export-' + providerId + '-parentid', docs[0].id);
}, 'folder', accountId);
});
// Choose folder button in autosync modal
$('.action-autosync-' + providerId + '-choose-folder').click(function() {
googleHelper.picker(function(error, docs) {
@ -549,14 +535,14 @@ define([
utils.setInputValue('#input-autosync-' + providerId + '-parentid', docs[0].id);
}, 'folder', accountId);
});
// On export, disable file ID input if realtime is checked
var $realtimeCheckboxElt = $('#input-sync-export-' + providerId + '-realtime');
var $fileIdInputElt = $('#input-sync-export-' + providerId + '-fileid');
$('#input-sync-export-' + providerId + '-realtime').change(function() {
$fileIdInputElt.prop('disabled', $realtimeCheckboxElt.prop('checked'));
});
// Skip gdrive action if provider is not enabled in the settings
if(accountIndex >= settings.gdriveMultiAccount) {
return;
@ -595,7 +581,7 @@ define([
importFilesFromIds(importIds);
}
});
return gdriveProvider;
};
});
});

View File

@ -6,6 +6,7 @@ define([
var settings = {
layoutOrientation: "horizontal",
mode: 'ltr',
lazyRendering: true,
editorFontFamily: 'Menlo, Consolas, "Courier New", Courier, monospace',
editorFontSize: 13,
@ -65,4 +66,4 @@ define([
}
return settings;
});
});

View File

@ -2,7 +2,7 @@
define([
"underscore"
], function(_) {
function retrieveIndexArray(storeIndex) {
try {
return _.compact(localStorage[storeIndex].split(";"));
@ -246,12 +246,18 @@ define([
});
version = "v17";
}
if(version == "v17") {
localStorage.removeItem('focusMode');
localStorage.removeItem('mode');
_.each(_.keys(localStorage), function(key) {
if(key.match(/file\.\S+\.editorSelectRange/)); {
localStorage.removeItem(key);
}
});
version = "v18";
}
localStorage.version = version;
return localStorage;
});
});

View File

@ -1,7 +1,4 @@
@import "base.less";
@import (less) "../bower-libs/ace/lib/ace/css/editor.css";
@import (less) "../bower-libs/ace/lib/ace/ext/searchbox.css";
@import (less) "../bower-libs/ace/lib/ace/theme/textmate.css";
@import "../bower-libs/bootstrap-tour/src/less/bootstrap-tour.less";
@import (less) "jquery.jgrowl.css";
@ -1013,192 +1010,6 @@ a {
* Editor
*****************************/
.ace_editor {
color: @tertiary-color-dark;
}
.ace-tm {
background-color: @tertiary-bg;
.ace_text-input {
box-sizing: initial;
}
.ace_cursor {
color: darken(@primary-desaturated, 30%);
}
.ace_print-margin-layer {
display: none;
}
.ace_marker-layer .ace_bracket {
display: none;
}
.ace_markup.ace_heading {
color: @tertiary-color-darker;
font-weight: bold;
}
.ace_markup.ace_list {
color: @tertiary-color;
}
.ace_constant.ace_language {
color: @tertiary-color-light;
font-weight: normal;
}
.ace_meta.ace_tag {
color: @tertiary-color-darker;
font-weight: bold;
}
.ace_keyword.ace_operator {
color: @tertiary-color-dark;
background-color: transparent;
}
.ace_storage, .ace_keyword {
color: @tertiary-color-darker;
font-weight: bold;
}
.ace_entity.ace_name.ace_function {
color: @tertiary-color-darker;
font-weight: bold;
}
.ace_string {
color: @tertiary-color-darker;
font-weight: bold;
}
.ace_invalid {
color: inherit;
background: inherit;
}
.ace_strong {
color: @tertiary-color-dark;
font-weight: bold;
}
.ace_emphasis {
color: @tertiary-color-darker;
font-style: italic;
}
.ace_blockquote {
color: @tertiary-color;
}
.ace_code {
color: @tertiary-color-darker;
background-color: @code-bg;
}
.ace_code_block {
color: @tertiary-color-darker;
font-weight: bold;
}
.ace_link {
color: @tertiary-color;
background-color: @code-bg;
}
.ace_description {
color: @tertiary-color;
}
.ace_constant {
color: @tertiary-color-dark;
}
.ace_comment {
color: @tertiary-color-light;
font-style: italic;
}
.ace_doccomment {
color: fade(@state-danger-text, 90%);
font-style: italic;
font-weight: bold;
}
.ace_marker-layer .misspelled {
position: absolute;
z-index: -2;
border-bottom: 1px dotted red;
margin-bottom: -1px;
}
}
.ace_search {
background-color: @secondary-bg-light;
border: 1px solid @secondary-border-color-light;
border-top: 0;
padding: 10px 15px 5px;
font-family: @font-family-base;
min-width: 318px;
.ace_search_form, .ace_replace_form {
border-color: @input-border;
margin-bottom: 10px;
}
.ace_search_field {
width: 185px;
}
.ace_search_field, .ace_searchbtn, .ace_replacebtn {
height: @input-height-small;
padding: 0 @padding-base-horizontal;
font-size: @font-size-base;
line-height: @line-height-base;
color: @input-color;
vertical-align: middle;
background-color: @secondary-bg-lighter;
border-color: @input-border;
.box-shadow(~"@{form-control-inset-shadow}");
}
.ace_searchbtn {
background-image: none;
font-family: "fontello";
width: auto;
font-size: 16px;
&.next:before {
content: '\e880';
}
&.prev:before {
content: '\e87f';
}
}
.ace_replacebtn {
padding: 0 4px;
}
.ace_searchbtn_close {
background: transparent;
margin: 0;
font-size: (@font-size-base * 1.5);
font-weight: @close-font-weight;
text-shadow: @close-text-shadow;
.opacity(.3);
&:before {
content: '\d7';
}
&:hover,
&:focus {
color: @close-color;
text-decoration: none;
cursor: pointer;
.opacity(.5);
background: transparent;
}
}
}
@font-face {
font-family: 'PT Sans';
font-style: normal;
@ -1224,7 +1035,6 @@ a {
src: local('PT Sans Bold Italic'), local('PTSans-BoldItalic'), url("../font/PTSans-BoldItalic-webfont.woff") format('woff');
}
#wmd-input {
font-family: @font-family-monospace;
letter-spacing: normal;