Fix framework by removing some async and also fix media tags
This commit is contained in:
parent
90d00c10b1
commit
1c791b5b51
@ -66,20 +66,16 @@ define([
|
|||||||
var normalize = function (x) { return x; };
|
var normalize = function (x) { return x; };
|
||||||
|
|
||||||
var extractMetadata = function (content) {
|
var extractMetadata = function (content) {
|
||||||
var meta = {};
|
|
||||||
if (Array.isArray(content)) {
|
if (Array.isArray(content)) {
|
||||||
var m = content.pop();
|
var m = content[content.length - 1];
|
||||||
if (typeof(m.metadata) === 'object') {
|
if (typeof(m.metadata) === 'object') {
|
||||||
// pad
|
// pad
|
||||||
meta = m.metadata;
|
return m.metadata;
|
||||||
} else {
|
|
||||||
content.push(m);
|
|
||||||
}
|
}
|
||||||
} else if (typeof(content.metadata) === 'object') {
|
} else if (typeof(content.metadata) === 'object') {
|
||||||
meta = content.metadata;
|
return content.metadata;
|
||||||
delete content.metadata;
|
|
||||||
}
|
}
|
||||||
return meta;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
var stateChange = function (newState) {
|
var stateChange = function (newState) {
|
||||||
@ -94,7 +90,6 @@ define([
|
|||||||
} else {
|
} else {
|
||||||
state = newState;
|
state = newState;
|
||||||
}
|
}
|
||||||
console.log(state + ' ' + wasEditable);
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case STATE.DISCONNECTED:
|
case STATE.DISCONNECTED:
|
||||||
case STATE.INITIALIZING: {
|
case STATE.INITIALIZING: {
|
||||||
@ -108,7 +103,6 @@ define([
|
|||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
if (wasEditable !== (state === STATE.READY)) {
|
if (wasEditable !== (state === STATE.READY)) {
|
||||||
console.log("fire");
|
|
||||||
evEditableStateChange.fire(state === STATE.READY);
|
evEditableStateChange.fire(state === STATE.READY);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -119,9 +113,10 @@ define([
|
|||||||
var oldContent = normalize(contentGetter());
|
var oldContent = normalize(contentGetter());
|
||||||
var newContentStr = cpNfInner.chainpad.getUserDoc();
|
var newContentStr = cpNfInner.chainpad.getUserDoc();
|
||||||
|
|
||||||
var newContent = normalize(JSON.parse(newContentStr));
|
var newContent = JSON.parse(newContentStr);
|
||||||
var meta = extractMetadata(newContent);
|
var meta = extractMetadata(newContent);
|
||||||
cpNfInner.metadataMgr.updateMetadata(meta);
|
cpNfInner.metadataMgr.updateMetadata(meta);
|
||||||
|
newContent = normalize(newContent);
|
||||||
|
|
||||||
evContentUpdate.fire(newContent);
|
evContentUpdate.fire(newContent);
|
||||||
|
|
||||||
@ -209,8 +204,7 @@ define([
|
|||||||
|
|
||||||
if (!newPad) {
|
if (!newPad) {
|
||||||
var newContent = JSON.parse(newContentStr);
|
var newContent = JSON.parse(newContentStr);
|
||||||
var meta = extractMetadata(newContent);
|
cpNfInner.metadataMgr.updateMetadata(extractMetadata(newContent));
|
||||||
cpNfInner.metadataMgr.updateMetadata(meta);
|
|
||||||
newContent = normalize(newContent);
|
newContent = normalize(newContent);
|
||||||
evContentUpdate.fire(newContent);
|
evContentUpdate.fire(newContent);
|
||||||
|
|
||||||
@ -230,13 +224,13 @@ define([
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
title.updateTitle(Cryptpad.initialName || title.defaultTitle);
|
title.updateTitle(Cryptpad.initialName || title.defaultTitle);
|
||||||
|
evOnDefaultContentNeeded.fire();
|
||||||
}
|
}
|
||||||
|
stateChange(STATE.READY);
|
||||||
if (!readOnly) { onLocal(); }
|
if (!readOnly) { onLocal(); }
|
||||||
evOnReady.fire(newPad);
|
evOnReady.fire(newPad);
|
||||||
|
|
||||||
Cryptpad.removeLoadingScreen(emitResize);
|
Cryptpad.removeLoadingScreen(emitResize);
|
||||||
stateChange(STATE.READY);
|
|
||||||
|
|
||||||
if (newPad) {
|
if (newPad) {
|
||||||
common.openTemplatePicker();
|
common.openTemplatePicker();
|
||||||
@ -297,8 +291,8 @@ define([
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onRemote: function () { evStart.reg(onRemote); },
|
onRemote: onRemote,
|
||||||
onLocal: function () { evStart.reg(onLocal); },
|
onLocal: onLocal,
|
||||||
onInit: function () { stateChange(STATE.INITIALIZING); },
|
onInit: function () { stateChange(STATE.INITIALIZING); },
|
||||||
onReady: function () { evStart.reg(onReady); },
|
onReady: function () { evStart.reg(onReady); },
|
||||||
onConnectionChange: onConnectionChange
|
onConnectionChange: onConnectionChange
|
||||||
|
|||||||
@ -38,7 +38,6 @@ define([], function () {
|
|||||||
var queue = [];
|
var queue = [];
|
||||||
var messageFromInner = function (m, cb) { queue.push([ m, cb ]); };
|
var messageFromInner = function (m, cb) { queue.push([ m, cb ]); };
|
||||||
sframeChan.on('Q_RT_MESSAGE', function (message, cb) {
|
sframeChan.on('Q_RT_MESSAGE', function (message, cb) {
|
||||||
console.log(message);
|
|
||||||
messageFromInner(message, cb);
|
messageFromInner(message, cb);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -291,7 +291,48 @@ define([
|
|||||||
framework._.toolbar.$rightside.append($collapse);
|
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 andThen2 = function (editor, Ckeditor, framework) {
|
||||||
|
var mediaTagMap = {}
|
||||||
var $bar = $('#cke_1_toolbox');
|
var $bar = $('#cke_1_toolbox');
|
||||||
var $html = $bar.closest('html');
|
var $html = $bar.closest('html');
|
||||||
var $faLink = $html.find('head link[href*="/bower_components/components-font-awesome/css/font-awesome.min.css"]');
|
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 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!
|
// apply patches, and try not to lose the cursor in the process!
|
||||||
framework.onContentUpdate(function (hjson) {
|
framework.onContentUpdate(function (hjson) {
|
||||||
if (!Array.isArray(hjson)) {
|
if (!Array.isArray(hjson)) {
|
||||||
@ -416,10 +416,10 @@ define([
|
|||||||
userDocStateDom.setAttribute("contenteditable",
|
userDocStateDom.setAttribute("contenteditable",
|
||||||
inner.getAttribute('contenteditable'));
|
inner.getAttribute('contenteditable'));
|
||||||
|
|
||||||
restoreMediaTags(userDocStateDom);
|
restoreMediaTags(userDocStateDom, mediaTagMap);
|
||||||
var patch = (DD).diff(inner, userDocStateDom);
|
var patch = (DD).diff(inner, userDocStateDom);
|
||||||
(DD).apply(inner, patch);
|
(DD).apply(inner, patch);
|
||||||
displayMediaTags(inner);
|
displayMediaTags(framework, inner, mediaTagMap);
|
||||||
if (framework.isReadOnly()) {
|
if (framework.isReadOnly()) {
|
||||||
var $links = $(inner).find('a');
|
var $links = $(inner).find('a');
|
||||||
// off so that we don't end up with multiple identical handlers
|
// off so that we don't end up with multiple identical handlers
|
||||||
@ -428,6 +428,7 @@ define([
|
|||||||
});
|
});
|
||||||
|
|
||||||
framework.setContentGetter(function () {
|
framework.setContentGetter(function () {
|
||||||
|
displayMediaTags(framework, inner, mediaTagMap);
|
||||||
return Hyperjson.fromDOM(inner, isNotMagicLine, hjsonFilters);
|
return Hyperjson.fromDOM(inner, isNotMagicLine, hjsonFilters);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -452,6 +453,7 @@ define([
|
|||||||
} else if (framework.isReadOnly()) {
|
} else if (framework.isReadOnly()) {
|
||||||
cursor.setToStart();
|
cursor.setToStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
var fmConfig = {
|
var fmConfig = {
|
||||||
ckeditor: editor,
|
ckeditor: editor,
|
||||||
body: $('body'),
|
body: $('body'),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user