Fix framework by removing some async and also fix media tags

pull/1/head
Caleb James DeLisle 7 years ago
parent 90d00c10b1
commit 1c791b5b51

@ -66,20 +66,16 @@ define([
var normalize = function (x) { return x; };
var extractMetadata = function (content) {
var meta = {};
if (Array.isArray(content)) {
var m = content.pop();
var m = content[content.length - 1];
if (typeof(m.metadata) === 'object') {
// pad
meta = m.metadata;
} else {
content.push(m);
return m.metadata;
}
} else if (typeof(content.metadata) === 'object') {
meta = content.metadata;
delete content.metadata;
return content.metadata;
}
return meta;
return;
};
var stateChange = function (newState) {
@ -94,7 +90,6 @@ define([
} else {
state = newState;
}
console.log(state + ' ' + wasEditable);
switch (state) {
case STATE.DISCONNECTED:
case STATE.INITIALIZING: {
@ -108,7 +103,6 @@ define([
default:
}
if (wasEditable !== (state === STATE.READY)) {
console.log("fire");
evEditableStateChange.fire(state === STATE.READY);
}
};
@ -119,9 +113,10 @@ define([
var oldContent = normalize(contentGetter());
var newContentStr = cpNfInner.chainpad.getUserDoc();
var newContent = normalize(JSON.parse(newContentStr));
var newContent = JSON.parse(newContentStr);
var meta = extractMetadata(newContent);
cpNfInner.metadataMgr.updateMetadata(meta);
newContent = normalize(newContent);
evContentUpdate.fire(newContent);
@ -209,8 +204,7 @@ define([
if (!newPad) {
var newContent = JSON.parse(newContentStr);
var meta = extractMetadata(newContent);
cpNfInner.metadataMgr.updateMetadata(meta);
cpNfInner.metadataMgr.updateMetadata(extractMetadata(newContent));
newContent = normalize(newContent);
evContentUpdate.fire(newContent);
@ -230,13 +224,13 @@ define([
}
} else {
title.updateTitle(Cryptpad.initialName || title.defaultTitle);
evOnDefaultContentNeeded.fire();
}
stateChange(STATE.READY);
if (!readOnly) { onLocal(); }
evOnReady.fire(newPad);
Cryptpad.removeLoadingScreen(emitResize);
stateChange(STATE.READY);
if (newPad) {
common.openTemplatePicker();
@ -297,8 +291,8 @@ define([
return false;
}
},
onRemote: function () { evStart.reg(onRemote); },
onLocal: function () { evStart.reg(onLocal); },
onRemote: onRemote,
onLocal: onLocal,
onInit: function () { stateChange(STATE.INITIALIZING); },
onReady: function () { evStart.reg(onReady); },
onConnectionChange: onConnectionChange

@ -38,7 +38,6 @@ define([], function () {
var queue = [];
var messageFromInner = function (m, cb) { queue.push([ m, cb ]); };
sframeChan.on('Q_RT_MESSAGE', function (message, cb) {
console.log(message);
messageFromInner(message, cb);
});

@ -291,7 +291,48 @@ define([
framework._.toolbar.$rightside.append($collapse);
};
var displayMediaTags = function (framework, dom, mediaTagMap) {
setTimeout(function () { // Just in case
var tags = dom.querySelectorAll('media-tag:empty');
Array.prototype.slice.call(tags).forEach(function (el) {
MediaTag(el);
$(el).on('keydown', function (e) {
if ([8,46].indexOf(e.which) !== -1) {
$(el).remove();
framework.localChange();
}
});
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.type === 'childList') {
var list_values = [].slice.call(el.children);
mediaTagMap[el.getAttribute('src')] = list_values;
}
});
});
observer.observe(el, {
attributes: false,
childList: true,
characterData: false
});
});
});
};
var restoreMediaTags = function (tempDom, mediaTagMap) {
var tags = tempDom.querySelectorAll('media-tag:empty');
Array.prototype.slice.call(tags).forEach(function (tag) {
var src = tag.getAttribute('src');
if (mediaTagMap[src]) {
mediaTagMap[src].forEach(function (n) {
tag.appendChild(n);
});
}
});
};
var andThen2 = function (editor, Ckeditor, framework) {
var mediaTagMap = {}
var $bar = $('#cke_1_toolbox');
var $html = $bar.closest('html');
var $faLink = $html.find('head link[href*="/bower_components/components-font-awesome/css/font-awesome.min.css"]');
@ -363,47 +404,6 @@ define([
var DD = new DiffDom(mkDiffOptions(cursor, framework.isReadOnly()));
var mediaMap = {};
var restoreMediaTags = function (tempDom) {
var tags = tempDom.querySelectorAll('media-tag:empty');
Array.prototype.slice.call(tags).forEach(function (tag) {
var src = tag.getAttribute('src');
if (mediaMap[src]) {
mediaMap[src].forEach(function (n) {
tag.appendChild(n);
});
}
});
};
var displayMediaTags = function (dom) {
setTimeout(function () { // Just in case
var tags = dom.querySelectorAll('media-tag:empty');
console.log(Array.prototype.slice.call(tags));
Array.prototype.slice.call(tags).forEach(function (el) {
MediaTag(el);
$(el).on('keydown', function (e) {
if ([8,46].indexOf(e.which) !== -1) {
$(el).remove();
framework.localChange();
}
});
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.type === 'childList') {
var list_values = [].slice.call(el.children);
mediaMap[el.getAttribute('src')] = list_values;
}
});
});
observer.observe(el, {
attributes: false,
childList: true,
characterData: false
});
});
});
};
// apply patches, and try not to lose the cursor in the process!
framework.onContentUpdate(function (hjson) {
if (!Array.isArray(hjson)) {
@ -416,10 +416,10 @@ define([
userDocStateDom.setAttribute("contenteditable",
inner.getAttribute('contenteditable'));
restoreMediaTags(userDocStateDom);
restoreMediaTags(userDocStateDom, mediaTagMap);
var patch = (DD).diff(inner, userDocStateDom);
(DD).apply(inner, patch);
displayMediaTags(inner);
displayMediaTags(framework, inner, mediaTagMap);
if (framework.isReadOnly()) {
var $links = $(inner).find('a');
// off so that we don't end up with multiple identical handlers
@ -428,6 +428,7 @@ define([
});
framework.setContentGetter(function () {
displayMediaTags(framework, inner, mediaTagMap);
return Hyperjson.fromDOM(inner, isNotMagicLine, hjsonFilters);
});
@ -452,6 +453,7 @@ define([
} else if (framework.isReadOnly()) {
cursor.setToStart();
}
var fmConfig = {
ckeditor: editor,
body: $('body'),

Loading…
Cancel
Save