|
|
@ -1,7 +1,7 @@
|
|
|
|
require(['/api/config'], function (ApiConfig) {
|
|
|
|
require(['/api/config'], function(ApiConfig) {
|
|
|
|
// see ckeditor_base.js getUrl()
|
|
|
|
// see ckeditor_base.js getUrl()
|
|
|
|
window.CKEDITOR_GETURL = function (resource) {
|
|
|
|
window.CKEDITOR_GETURL = function(resource) {
|
|
|
|
if (resource.indexOf( '/' ) === 0) {
|
|
|
|
if (resource.indexOf('/') === 0) {
|
|
|
|
resource = window.CKEDITOR.basePath.replace(/\/bower_components\/.*/, '') + resource;
|
|
|
|
resource = window.CKEDITOR.basePath.replace(/\/bower_components\/.*/, '') + resource;
|
|
|
|
} else if (resource.indexOf(':/') === -1) {
|
|
|
|
} else if (resource.indexOf(':/') === -1) {
|
|
|
|
resource = window.CKEDITOR.basePath + resource;
|
|
|
|
resource = window.CKEDITOR.basePath + resource;
|
|
|
@ -44,7 +44,7 @@ define([
|
|
|
|
'css!/bower_components/bootstrap/dist/css/bootstrap.min.css',
|
|
|
|
'css!/bower_components/bootstrap/dist/css/bootstrap.min.css',
|
|
|
|
'css!/bower_components/components-font-awesome/css/font-awesome.min.css',
|
|
|
|
'css!/bower_components/components-font-awesome/css/font-awesome.min.css',
|
|
|
|
'less!/pad/app-pad.less'
|
|
|
|
'less!/pad/app-pad.less'
|
|
|
|
], function (
|
|
|
|
], function(
|
|
|
|
$,
|
|
|
|
$,
|
|
|
|
Hyperjson,
|
|
|
|
Hyperjson,
|
|
|
|
Framework,
|
|
|
|
Framework,
|
|
|
@ -65,16 +65,15 @@ define([
|
|
|
|
ChainPad,
|
|
|
|
ChainPad,
|
|
|
|
AppConfig,
|
|
|
|
AppConfig,
|
|
|
|
Test
|
|
|
|
Test
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
{
|
|
|
|
|
|
|
|
var DiffDom = window.diffDOM;
|
|
|
|
var DiffDom = window.diffDOM;
|
|
|
|
|
|
|
|
|
|
|
|
var slice = function (coll) {
|
|
|
|
var slice = function(coll) {
|
|
|
|
return Array.prototype.slice.call(coll);
|
|
|
|
return Array.prototype.slice.call(coll);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var removeListeners = function (root) {
|
|
|
|
var removeListeners = function(root) {
|
|
|
|
slice(root.attributes).map(function (attr) {
|
|
|
|
slice(root.attributes).map(function(attr) {
|
|
|
|
if (/^on/.test(attr.name)) {
|
|
|
|
if (/^on/.test(attr.name)) {
|
|
|
|
root.attributes.removeNamedItem(attr.name);
|
|
|
|
root.attributes.removeNamedItem(attr.name);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -82,7 +81,7 @@ define([
|
|
|
|
slice(root.children).forEach(removeListeners);
|
|
|
|
slice(root.children).forEach(removeListeners);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var hjsonToDom = function (H) {
|
|
|
|
var hjsonToDom = function(H) {
|
|
|
|
var dom = Hyperjson.toDOM(H);
|
|
|
|
var dom = Hyperjson.toDOM(H);
|
|
|
|
removeListeners(dom);
|
|
|
|
removeListeners(dom);
|
|
|
|
return dom;
|
|
|
|
return dom;
|
|
|
@ -97,17 +96,17 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
// MEDIATAG: Filter elements to serialize
|
|
|
|
// MEDIATAG: Filter elements to serialize
|
|
|
|
// * Remove the drag&drop and resizers from the hyperjson
|
|
|
|
// * Remove the drag&drop and resizers from the hyperjson
|
|
|
|
var isWidget = function (el) {
|
|
|
|
var isWidget = function(el) {
|
|
|
|
return typeof (el.getAttribute) === "function" &&
|
|
|
|
return typeof(el.getAttribute) === "function" &&
|
|
|
|
(el.getAttribute('data-cke-hidden-sel') ||
|
|
|
|
(el.getAttribute('data-cke-hidden-sel') ||
|
|
|
|
(el.getAttribute('class') &&
|
|
|
|
(el.getAttribute('class') &&
|
|
|
|
(/cke_widget_drag/.test(el.getAttribute('class')) ||
|
|
|
|
(/cke_widget_drag/.test(el.getAttribute('class')) ||
|
|
|
|
/cke_image_resizer/.test(el.getAttribute('class')))
|
|
|
|
/cke_image_resizer/.test(el.getAttribute('class')))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var isNotMagicLine = function (el) {
|
|
|
|
var isNotMagicLine = function(el) {
|
|
|
|
return !(el && typeof(el.getAttribute) === 'function' &&
|
|
|
|
return !(el && typeof(el.getAttribute) === 'function' &&
|
|
|
|
el.getAttribute('class') &&
|
|
|
|
el.getAttribute('class') &&
|
|
|
|
el.getAttribute('class').split(' ').indexOf('non-realtime') !== -1);
|
|
|
|
el.getAttribute('class').split(' ').indexOf('non-realtime') !== -1);
|
|
|
@ -115,12 +114,12 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
var isCursor = Cursors.isCursor;
|
|
|
|
var isCursor = Cursors.isCursor;
|
|
|
|
|
|
|
|
|
|
|
|
var shouldSerialize = function (el) {
|
|
|
|
var shouldSerialize = function(el) {
|
|
|
|
return isNotMagicLine(el) && !isWidget(el) && !isCursor(el);
|
|
|
|
return isNotMagicLine(el) && !isWidget(el) && !isCursor(el);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// MEDIATAG: Filter attributes in the serialized elements
|
|
|
|
// MEDIATAG: Filter attributes in the serialized elements
|
|
|
|
var widgetFilter = function (hj) {
|
|
|
|
var widgetFilter = function(hj) {
|
|
|
|
// Send a widget ID == 0 to avoid a fight between browsers and
|
|
|
|
// Send a widget ID == 0 to avoid a fight between browsers and
|
|
|
|
// prevent the container from having the "selected" class (blue border)
|
|
|
|
// prevent the container from having the "selected" class (blue border)
|
|
|
|
if (hj[1].class) {
|
|
|
|
if (hj[1].class) {
|
|
|
@ -137,7 +136,7 @@ define([
|
|
|
|
//hj[1]['data-cke-widget-id'] = "0";
|
|
|
|
//hj[1]['data-cke-widget-id'] = "0";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Remove the title attribute of the drag&drop icons (translation conflicts)
|
|
|
|
// Remove the title attribute of the drag&drop icons (translation conflicts)
|
|
|
|
if (split.indexOf('cke_widget_drag_handler') !== -1 ||
|
|
|
|
if (split.indexOf('cke_widget_drag_handler') !== -1 ||
|
|
|
|
split.indexOf('cke_image_resizer') !== -1) {
|
|
|
|
split.indexOf('cke_image_resizer') !== -1) {
|
|
|
|
hj[1].title = undefined;
|
|
|
|
hj[1].title = undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -145,18 +144,18 @@ define([
|
|
|
|
return hj;
|
|
|
|
return hj;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var hjsonFilters = function (hj) {
|
|
|
|
var hjsonFilters = function(hj) {
|
|
|
|
/* catch `type="_moz"` before it goes over the wire */
|
|
|
|
/* catch `type="_moz"` before it goes over the wire */
|
|
|
|
var brFilter = function (hj) {
|
|
|
|
var brFilter = function(hj) {
|
|
|
|
if (hj[1].type === '_moz') { hj[1].type = undefined; }
|
|
|
|
if (hj[1].type === '_moz') { hj[1].type = undefined; }
|
|
|
|
return hj;
|
|
|
|
return hj;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
var mediatagContentFilter = function (hj) {
|
|
|
|
var mediatagContentFilter = function(hj) {
|
|
|
|
if (hj[0] === 'MEDIA-TAG') { hj[2] = []; }
|
|
|
|
if (hj[0] === 'MEDIA-TAG') { hj[2] = []; }
|
|
|
|
return hj;
|
|
|
|
return hj;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
var commentActiveFilter = function (hj) {
|
|
|
|
var commentActiveFilter = function(hj) {
|
|
|
|
if (hj[0] === 'COMMENT') { delete (hj[1] || {}).class; }
|
|
|
|
if (hj[0] === 'COMMENT') { delete(hj[1] || {}).class; }
|
|
|
|
return hj;
|
|
|
|
return hj;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
brFilter(hj);
|
|
|
|
brFilter(hj);
|
|
|
@ -166,7 +165,7 @@ define([
|
|
|
|
return hj;
|
|
|
|
return hj;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var domFromHTML = function (html) {
|
|
|
|
var domFromHTML = function(html) {
|
|
|
|
return new DOMParser().parseFromString(html, 'text/html');
|
|
|
|
return new DOMParser().parseFromString(html, 'text/html');
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -180,22 +179,22 @@ define([
|
|
|
|
];
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
var CKEDITOR_CHECK_INTERVAL = 100;
|
|
|
|
var CKEDITOR_CHECK_INTERVAL = 100;
|
|
|
|
var ckEditorAvailable = function (cb) {
|
|
|
|
var ckEditorAvailable = function(cb) {
|
|
|
|
var intr;
|
|
|
|
var intr;
|
|
|
|
var check = function () {
|
|
|
|
var check = function() {
|
|
|
|
if (window.CKEDITOR) {
|
|
|
|
if (window.CKEDITOR) {
|
|
|
|
clearTimeout(intr);
|
|
|
|
clearTimeout(intr);
|
|
|
|
cb(window.CKEDITOR);
|
|
|
|
cb(window.CKEDITOR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
intr = setInterval(function () {
|
|
|
|
intr = setInterval(function() {
|
|
|
|
console.log("Ckeditor was not defined. Trying again in %sms", CKEDITOR_CHECK_INTERVAL);
|
|
|
|
console.log("Ckeditor was not defined. Trying again in %sms", CKEDITOR_CHECK_INTERVAL);
|
|
|
|
check();
|
|
|
|
check();
|
|
|
|
}, CKEDITOR_CHECK_INTERVAL);
|
|
|
|
}, CKEDITOR_CHECK_INTERVAL);
|
|
|
|
check();
|
|
|
|
check();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var mkHelpMenu = function (framework) {
|
|
|
|
var mkHelpMenu = function(framework) {
|
|
|
|
var $toolbarContainer = $('.cke_toolbox_main');
|
|
|
|
var $toolbarContainer = $('.cke_toolbox_main');
|
|
|
|
$toolbarContainer.before(framework._.sfCommon.getBurnAfterReadingWarning());
|
|
|
|
$toolbarContainer.before(framework._.sfCommon.getBurnAfterReadingWarning());
|
|
|
|
var helpMenu = framework._.sfCommon.createHelpMenu(['text', 'pad']);
|
|
|
|
var helpMenu = framework._.sfCommon.createHelpMenu(['text', 'pad']);
|
|
|
@ -204,9 +203,9 @@ define([
|
|
|
|
framework._.toolbar.$drawer.append(helpMenu.button);
|
|
|
|
framework._.toolbar.$drawer.append(helpMenu.button);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var mkDiffOptions = function (cursor, readOnly) {
|
|
|
|
var mkDiffOptions = function(cursor, readOnly) {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
preDiffApply: function (info) {
|
|
|
|
preDiffApply: function(info) {
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
Don't accept attributes that begin with 'on'
|
|
|
|
Don't accept attributes that begin with 'on'
|
|
|
|
these are probably listeners, and we don't want to
|
|
|
|
these are probably listeners, and we don't want to
|
|
|
@ -257,15 +256,15 @@ define([
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// CkEditor drag&drop icon container
|
|
|
|
// CkEditor drag&drop icon container
|
|
|
|
if (info.node && info.node.tagName === 'SPAN' &&
|
|
|
|
if (info.node && info.node.tagName === 'SPAN' &&
|
|
|
|
info.node.getAttribute('class') &&
|
|
|
|
info.node.getAttribute('class') &&
|
|
|
|
info.node.getAttribute('class').split(' ').indexOf('cke_widget_drag_handler_container') !== -1) {
|
|
|
|
info.node.getAttribute('class').split(' ').indexOf('cke_widget_drag_handler_container') !== -1) {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// CkEditor drag&drop title (language fight)
|
|
|
|
// CkEditor drag&drop title (language fight)
|
|
|
|
if (info.node && info.node.getAttribute &&
|
|
|
|
if (info.node && info.node.getAttribute &&
|
|
|
|
info.node.getAttribute('class') &&
|
|
|
|
info.node.getAttribute('class') &&
|
|
|
|
(info.node.getAttribute('class').split(' ').indexOf('cke_widget_drag_handler') !== -1 ||
|
|
|
|
(info.node.getAttribute('class').split(' ').indexOf('cke_widget_drag_handler') !== -1 ||
|
|
|
|
info.node.getAttribute('class').split(' ').indexOf('cke_image_resizer') !== -1 ) ) {
|
|
|
|
info.node.getAttribute('class').split(' ').indexOf('cke_image_resizer') !== -1)) {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -287,15 +286,13 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
// Don't remote the "active" class of our comments
|
|
|
|
// Don't remote the "active" class of our comments
|
|
|
|
if (info.node && info.node.tagName === 'COMMENT') {
|
|
|
|
if (info.node && info.node.tagName === 'COMMENT') {
|
|
|
|
if (info.diff.action === 'removeAttribute' &&
|
|
|
|
if (info.diff.action === 'removeAttribute' && ['class'].indexOf(info.diff.name) !== -1) {
|
|
|
|
['class'].indexOf(info.diff.name) !== -1) {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (info.node && info.node.tagName === 'BODY') {
|
|
|
|
if (info.node && info.node.tagName === 'BODY') {
|
|
|
|
if (info.diff.action === 'removeAttribute' &&
|
|
|
|
if (info.diff.action === 'removeAttribute' && ['class', 'spellcheck'].indexOf(info.diff.name) !== -1) {
|
|
|
|
['class', 'spellcheck'].indexOf(info.diff.name) !== -1) {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -343,50 +340,50 @@ define([
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
cursor.update();
|
|
|
|
cursor.update();
|
|
|
|
|
|
|
|
|
|
|
|
// no use trying to recover the cursor if it doesn't exist
|
|
|
|
// no use trying to recover the cursor if it doesn't exist
|
|
|
|
if (!cursor.exists()) { return; }
|
|
|
|
if (!cursor.exists()) { return; }
|
|
|
|
|
|
|
|
|
|
|
|
/* frame is either 0, 1, 2, or 3, depending on which
|
|
|
|
/* frame is either 0, 1, 2, or 3, depending on which
|
|
|
|
cursor frames were affected: none, first, last, or both
|
|
|
|
cursor frames were affected: none, first, last, or both
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
var frame = info.frame = cursor.inNode(info.node);
|
|
|
|
var frame = info.frame = cursor.inNode(info.node);
|
|
|
|
|
|
|
|
|
|
|
|
if (!frame) { return; }
|
|
|
|
if (!frame) { return; }
|
|
|
|
|
|
|
|
|
|
|
|
if (frame && typeof info.diff.oldValue === 'string' && typeof info.diff.newValue === 'string') {
|
|
|
|
if (frame && typeof info.diff.oldValue === 'string' && typeof info.diff.newValue === 'string') {
|
|
|
|
//var pushes = cursor.pushDelta(info.diff.oldValue, info.diff.newValue);
|
|
|
|
//var pushes = cursor.pushDelta(info.diff.oldValue, info.diff.newValue);
|
|
|
|
var ops = ChainPad.Diff.diff(info.diff.oldValue, info.diff.newValue);
|
|
|
|
var ops = ChainPad.Diff.diff(info.diff.oldValue, info.diff.newValue);
|
|
|
|
|
|
|
|
|
|
|
|
if (frame & 1) {
|
|
|
|
if (frame & 1) {
|
|
|
|
// push cursor start if necessary
|
|
|
|
// push cursor start if necessary
|
|
|
|
cursor.transformRange(cursor.Range.start, ops);
|
|
|
|
cursor.transformRange(cursor.Range.start, ops);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (frame & 2) {
|
|
|
|
if (frame & 2) {
|
|
|
|
// push cursor end if necessary
|
|
|
|
// push cursor end if necessary
|
|
|
|
cursor.transformRange(cursor.Range.end, ops);
|
|
|
|
cursor.transformRange(cursor.Range.end, ops);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
},
|
|
|
|
},
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
postDiffApply: function (info) {
|
|
|
|
postDiffApply: function (info) {
|
|
|
|
if (info.frame) {
|
|
|
|
if (info.frame) {
|
|
|
|
if (info.node) {
|
|
|
|
if (info.node) {
|
|
|
|
if (info.frame & 1) { cursor.fixStart(info.node); }
|
|
|
|
if (info.frame & 1) { cursor.fixStart(info.node); }
|
|
|
|
if (info.frame & 2) { cursor.fixEnd(info.node); }
|
|
|
|
if (info.frame & 2) { cursor.fixEnd(info.node); }
|
|
|
|
} else { console.error("info.node did not exist"); }
|
|
|
|
} else { console.error("info.node did not exist"); }
|
|
|
|
|
|
|
|
|
|
|
|
var sel = cursor.makeSelection();
|
|
|
|
var sel = cursor.makeSelection();
|
|
|
|
var range = cursor.makeRange();
|
|
|
|
var range = cursor.makeRange();
|
|
|
|
|
|
|
|
|
|
|
|
cursor.fixSelection(sel, range);
|
|
|
|
cursor.fixSelection(sel, range);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -394,30 +391,29 @@ define([
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
var addToolbarHideBtn = function (framework, $bar) {
|
|
|
|
var addToolbarHideBtn = function(framework, $bar) {
|
|
|
|
// Expand / collapse the toolbar
|
|
|
|
// Expand / collapse the toolbar
|
|
|
|
var cfg = {
|
|
|
|
var cfg = {
|
|
|
|
element: $bar
|
|
|
|
element: $bar
|
|
|
|
};
|
|
|
|
};
|
|
|
|
var onClick = function (visible) {
|
|
|
|
var onClick = function(visible) {
|
|
|
|
framework._.sfCommon.setAttribute(['pad', 'showToolbar'], visible);
|
|
|
|
framework._.sfCommon.setAttribute(['pad', 'showToolbar'], visible);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
framework._.sfCommon.getAttribute(['pad', 'showToolbar'], function (err, data) {
|
|
|
|
framework._.sfCommon.getAttribute(['pad', 'showToolbar'], function(err, data) {
|
|
|
|
if (($(window).height() >= 800 || $(window).width() >= 800) &&
|
|
|
|
if (($(window).height() >= 800 || $(window).width() >= 800) &&
|
|
|
|
(typeof(data) === "undefined" || data)) { $('.cke_toolbox_main').show(); }
|
|
|
|
(typeof(data) === "undefined" || data)) { $('.cke_toolbox_main').show(); } else { $('.cke_toolbox_main').hide(); }
|
|
|
|
else { $('.cke_toolbox_main').hide(); }
|
|
|
|
|
|
|
|
var $collapse = framework._.sfCommon.createButton('toggle', true, cfg, onClick);
|
|
|
|
var $collapse = framework._.sfCommon.createButton('toggle', true, cfg, onClick);
|
|
|
|
framework._.toolbar.$rightside.append($collapse);
|
|
|
|
framework._.toolbar.$rightside.append($collapse);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var displayMediaTags = function (framework, dom, mediaTagMap) {
|
|
|
|
var displayMediaTags = function(framework, dom, mediaTagMap) {
|
|
|
|
setTimeout(function () { // Just in case
|
|
|
|
setTimeout(function() { // Just in case
|
|
|
|
var tags = dom.querySelectorAll('media-tag:empty');
|
|
|
|
var tags = dom.querySelectorAll('media-tag:empty');
|
|
|
|
Array.prototype.slice.call(tags).forEach(function (el) {
|
|
|
|
Array.prototype.slice.call(tags).forEach(function(el) {
|
|
|
|
MediaTag(el);
|
|
|
|
MediaTag(el);
|
|
|
|
$(el).on('keydown', function (e) {
|
|
|
|
$(el).on('keydown', function(e) {
|
|
|
|
if ([8,46].indexOf(e.which) !== -1) {
|
|
|
|
if ([8, 46].indexOf(e.which) !== -1) {
|
|
|
|
$(el).remove();
|
|
|
|
$(el).remove();
|
|
|
|
framework.localChange();
|
|
|
|
framework.localChange();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -439,19 +435,19 @@ define([
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var restoreMediaTags = function (tempDom, mediaTagMap) {
|
|
|
|
var restoreMediaTags = function(tempDom, mediaTagMap) {
|
|
|
|
var tags = tempDom.querySelectorAll('media-tag:empty');
|
|
|
|
var tags = tempDom.querySelectorAll('media-tag:empty');
|
|
|
|
Array.prototype.slice.call(tags).forEach(function (tag) {
|
|
|
|
Array.prototype.slice.call(tags).forEach(function(tag) {
|
|
|
|
var src = tag.getAttribute('src');
|
|
|
|
var src = tag.getAttribute('src');
|
|
|
|
if (mediaTagMap[src]) {
|
|
|
|
if (mediaTagMap[src]) {
|
|
|
|
mediaTagMap[src].forEach(function (n) {
|
|
|
|
mediaTagMap[src].forEach(function(n) {
|
|
|
|
tag.appendChild(n.cloneNode());
|
|
|
|
tag.appendChild(n.cloneNode());
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var andThen2 = function (editor, Ckeditor, framework) {
|
|
|
|
var andThen2 = function(editor, Ckeditor, framework) {
|
|
|
|
var mediaTagMap = {};
|
|
|
|
var mediaTagMap = {};
|
|
|
|
var $contentContainer = $('#cke_1_contents');
|
|
|
|
var $contentContainer = $('#cke_1_contents');
|
|
|
|
var $html = $('html');
|
|
|
|
var $html = $('html');
|
|
|
@ -461,7 +457,7 @@ define([
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var ml = editor._.magiclineBackdoor.that.line.$;
|
|
|
|
var ml = editor._.magiclineBackdoor.that.line.$;
|
|
|
|
[ml, ml.parentElement].forEach(function (el) {
|
|
|
|
[ml, ml.parentElement].forEach(function(el) {
|
|
|
|
el.setAttribute('class', 'non-realtime');
|
|
|
|
el.setAttribute('class', 'non-realtime');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
@ -479,14 +475,14 @@ define([
|
|
|
|
var inner = window.inner = documentBody;
|
|
|
|
var inner = window.inner = documentBody;
|
|
|
|
var $inner = $(inner);
|
|
|
|
var $inner = $(inner);
|
|
|
|
|
|
|
|
|
|
|
|
var observer = new MutationObserver(function (muts) {
|
|
|
|
var observer = new MutationObserver(function(muts) {
|
|
|
|
muts.forEach(function (mut) {
|
|
|
|
muts.forEach(function(mut) {
|
|
|
|
if (mut.type === 'childList') {
|
|
|
|
if (mut.type === 'childList') {
|
|
|
|
var $a;
|
|
|
|
var $a;
|
|
|
|
for (var i = 0; i < mut.addedNodes.length; i++) {
|
|
|
|
for (var i = 0; i < mut.addedNodes.length; i++) {
|
|
|
|
$a = $(mut.addedNodes[i]);
|
|
|
|
$a = $(mut.addedNodes[i]);
|
|
|
|
if ($a.is('p') && $a.find('> span:empty').length
|
|
|
|
if ($a.is('p') && $a.find('> span:empty').length &&
|
|
|
|
&& $a.find('> br').length && $a.children().length === 2) {
|
|
|
|
$a.find('> br').length && $a.children().length === 2) {
|
|
|
|
$a.find('> span').append($a.find('> br'));
|
|
|
|
$a.find('> span').append($a.find('> br'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -519,7 +515,7 @@ define([
|
|
|
|
// Display other users cursor
|
|
|
|
// Display other users cursor
|
|
|
|
var cursors = Cursors.create(inner, hjsonToDom, cursor);
|
|
|
|
var cursors = Cursors.create(inner, hjsonToDom, cursor);
|
|
|
|
|
|
|
|
|
|
|
|
var openLink = function (e) {
|
|
|
|
var openLink = function(e) {
|
|
|
|
var el = e.currentTarget;
|
|
|
|
var el = e.currentTarget;
|
|
|
|
if (!el || el.nodeName !== 'A') { return; }
|
|
|
|
if (!el || el.nodeName !== 'A') { return; }
|
|
|
|
var href = el.getAttribute('href');
|
|
|
|
var href = el.getAttribute('href');
|
|
|
@ -530,7 +526,7 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
mkHelpMenu(framework);
|
|
|
|
mkHelpMenu(framework);
|
|
|
|
|
|
|
|
|
|
|
|
framework._.sfCommon.getAttribute(['pad', 'width'], function (err, data) {
|
|
|
|
framework._.sfCommon.getAttribute(['pad', 'width'], function(err, data) {
|
|
|
|
var active = data || typeof(data) === "undefined";
|
|
|
|
var active = data || typeof(data) === "undefined";
|
|
|
|
if (active) {
|
|
|
|
if (active) {
|
|
|
|
$contentContainer.addClass('cke_body_width');
|
|
|
|
$contentContainer.addClass('cke_body_width');
|
|
|
@ -539,50 +535,50 @@ define([
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
framework.onEditableChange(function (unlocked) {
|
|
|
|
framework.onEditableChange(function(unlocked) {
|
|
|
|
if (!framework.isReadOnly()) {
|
|
|
|
if (!framework.isReadOnly()) {
|
|
|
|
$inner.attr('contenteditable', '' + Boolean(unlocked));
|
|
|
|
$inner.attr('contenteditable', '' + Boolean(unlocked));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$inner.css({ background: unlocked ? '#fff' : '#eee' });
|
|
|
|
$inner.css({ background: unlocked ? '#fff' : '#eee' });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
framework.setMediaTagEmbedder(function ($mt) {
|
|
|
|
framework.setMediaTagEmbedder(function($mt) {
|
|
|
|
$mt.attr('contenteditable', 'false');
|
|
|
|
$mt.attr('contenteditable', 'false');
|
|
|
|
//$mt.attr('tabindex', '1');
|
|
|
|
//$mt.attr('tabindex', '1');
|
|
|
|
//MEDIATAG
|
|
|
|
//MEDIATAG
|
|
|
|
var element = new window.CKEDITOR.dom.element($mt[0]);
|
|
|
|
var element = new window.CKEDITOR.dom.element($mt[0]);
|
|
|
|
editor.insertElement(element);
|
|
|
|
editor.insertElement(element);
|
|
|
|
editor.widgets.initOn( element, 'mediatag' );
|
|
|
|
editor.widgets.initOn(element, 'mediatag');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
framework.setTitleRecommender(function () {
|
|
|
|
framework.setTitleRecommender(function() {
|
|
|
|
var text;
|
|
|
|
var text;
|
|
|
|
if (['h1', 'h2', 'h3'].some(function (t) {
|
|
|
|
if (['h1', 'h2', 'h3'].some(function(t) {
|
|
|
|
var $header = $inner.find(t + ':first-of-type');
|
|
|
|
var $header = $inner.find(t + ':first-of-type');
|
|
|
|
if ($header.length && $header.text()) {
|
|
|
|
if ($header.length && $header.text()) {
|
|
|
|
text = $header.text();
|
|
|
|
text = $header.text();
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})) { return text; }
|
|
|
|
})) { return text; }
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var DD = new DiffDom(mkDiffOptions(cursor, framework.isReadOnly()));
|
|
|
|
var DD = new DiffDom(mkDiffOptions(cursor, framework.isReadOnly()));
|
|
|
|
|
|
|
|
|
|
|
|
var cursorStopped = false;
|
|
|
|
var cursorStopped = false;
|
|
|
|
var cursorTo;
|
|
|
|
var cursorTo;
|
|
|
|
var updateCursor = function () {
|
|
|
|
var updateCursor = function() {
|
|
|
|
if (cursorTo) { clearTimeout(cursorTo); }
|
|
|
|
if (cursorTo) { clearTimeout(cursorTo); }
|
|
|
|
|
|
|
|
|
|
|
|
// If we're receiving content
|
|
|
|
// If we're receiving content
|
|
|
|
if (cursorStopped) { return void setTimeout(updateCursor, 100); }
|
|
|
|
if (cursorStopped) { return void setTimeout(updateCursor, 100); }
|
|
|
|
|
|
|
|
|
|
|
|
cursorTo = setTimeout(function () {
|
|
|
|
cursorTo = setTimeout(function() {
|
|
|
|
framework.updateCursor();
|
|
|
|
framework.updateCursor();
|
|
|
|
}, 500); // 500ms to make sure it is sent after chainpad sync
|
|
|
|
}, 500); // 500ms to make sure it is sent after chainpad sync
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 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)) { throw new Error(Messages.typeError); }
|
|
|
|
if (!Array.isArray(hjson)) { throw new Error(Messages.typeError); }
|
|
|
|
var userDocStateDom = hjsonToDom(hjson);
|
|
|
|
var userDocStateDom = hjsonToDom(hjson);
|
|
|
|
cursorStopped = true;
|
|
|
|
cursorStopped = true;
|
|
|
@ -598,7 +594,7 @@ define([
|
|
|
|
userDocStateDom.normalize();
|
|
|
|
userDocStateDom.normalize();
|
|
|
|
inner.normalize();
|
|
|
|
inner.normalize();
|
|
|
|
|
|
|
|
|
|
|
|
$(userDocStateDom).find('span[data-cke-display-name="media-tag"]:empty').each(function (i, el) {
|
|
|
|
$(userDocStateDom).find('span[data-cke-display-name="media-tag"]:empty').each(function(i, el) {
|
|
|
|
$(el).remove();
|
|
|
|
$(el).remove();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
@ -617,15 +613,15 @@ define([
|
|
|
|
var ops = ChainPad.Diff.diff(oldText, newText);
|
|
|
|
var ops = ChainPad.Diff.diff(oldText, newText);
|
|
|
|
cursor.restoreOffset(ops);
|
|
|
|
cursor.restoreOffset(ops);
|
|
|
|
|
|
|
|
|
|
|
|
setTimeout(function () {
|
|
|
|
setTimeout(function() {
|
|
|
|
cursorStopped = false;
|
|
|
|
cursorStopped = false;
|
|
|
|
updateCursor();
|
|
|
|
updateCursor();
|
|
|
|
}, 200);
|
|
|
|
}, 200);
|
|
|
|
|
|
|
|
|
|
|
|
// MEDIATAG: Migrate old mediatags to the widget system
|
|
|
|
// MEDIATAG: Migrate old mediatags to the widget system
|
|
|
|
$inner.find('media-tag:not(.cke_widget_element)').each(function (i, el) {
|
|
|
|
$inner.find('media-tag:not(.cke_widget_element)').each(function(i, el) {
|
|
|
|
var element = new window.CKEDITOR.dom.element(el);
|
|
|
|
var element = new window.CKEDITOR.dom.element(el);
|
|
|
|
editor.widgets.initOn( element, 'mediatag' );
|
|
|
|
editor.widgets.initOn(element, 'mediatag');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
displayMediaTags(framework, inner, mediaTagMap);
|
|
|
|
displayMediaTags(framework, inner, mediaTagMap);
|
|
|
@ -642,19 +638,19 @@ define([
|
|
|
|
comments.onContentUpdate();
|
|
|
|
comments.onContentUpdate();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
framework.setTextContentGetter(function () {
|
|
|
|
framework.setTextContentGetter(function() {
|
|
|
|
var innerCopy = inner.cloneNode(true);
|
|
|
|
var innerCopy = inner.cloneNode(true);
|
|
|
|
displayMediaTags(framework, innerCopy, mediaTagMap);
|
|
|
|
displayMediaTags(framework, innerCopy, mediaTagMap);
|
|
|
|
innerCopy.normalize();
|
|
|
|
innerCopy.normalize();
|
|
|
|
$(innerCopy).find('*').each(function (i, el) {
|
|
|
|
$(innerCopy).find('*').each(function(i, el) {
|
|
|
|
$(el).append(' ');
|
|
|
|
$(el).append(' ');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
var str = $(innerCopy).text();
|
|
|
|
var str = $(innerCopy).text();
|
|
|
|
str = str.replace(/\s\s+/g, ' ');
|
|
|
|
str = str.replace(/\s\s+/g, ' ');
|
|
|
|
return str;
|
|
|
|
return str;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
framework.setContentGetter(function () {
|
|
|
|
framework.setContentGetter(function() {
|
|
|
|
$inner.find('span[data-cke-display-name="media-tag"]:empty').each(function (i, el) {
|
|
|
|
$inner.find('span[data-cke-display-name="media-tag"]:empty').each(function(i, el) {
|
|
|
|
$(el).remove();
|
|
|
|
$(el).remove();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
@ -677,7 +673,7 @@ define([
|
|
|
|
$('.cke_toolbox_main').hide();
|
|
|
|
$('.cke_toolbox_main').hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
framework.onReady(function (newPad) {
|
|
|
|
framework.onReady(function(newPad) {
|
|
|
|
editor.focus();
|
|
|
|
editor.focus();
|
|
|
|
|
|
|
|
|
|
|
|
if (!module.isMaximized) {
|
|
|
|
if (!module.isMaximized) {
|
|
|
@ -700,7 +696,7 @@ define([
|
|
|
|
var fmConfig = {
|
|
|
|
var fmConfig = {
|
|
|
|
ckeditor: editor,
|
|
|
|
ckeditor: editor,
|
|
|
|
body: $('body'),
|
|
|
|
body: $('body'),
|
|
|
|
onUploaded: function (ev, data) {
|
|
|
|
onUploaded: function(ev, data) {
|
|
|
|
var parsed = Hash.parsePadUrl(data.url);
|
|
|
|
var parsed = Hash.parsePadUrl(data.url);
|
|
|
|
var secret = Hash.getSecrets('file', parsed.hash, data.password);
|
|
|
|
var secret = Hash.getSecrets('file', parsed.hash, data.password);
|
|
|
|
var fileHost = privateData.fileHost || privateData.origin;
|
|
|
|
var fileHost = privateData.fileHost || privateData.origin;
|
|
|
@ -714,39 +710,39 @@ define([
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
editor.insertElement(element);
|
|
|
|
editor.insertElement(element);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
editor.widgets.initOn( element, 'mediatag' );
|
|
|
|
editor.widgets.initOn(element, 'mediatag');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
window.APP.FM = framework._.sfCommon.createFileManager(fmConfig);
|
|
|
|
window.APP.FM = framework._.sfCommon.createFileManager(fmConfig);
|
|
|
|
|
|
|
|
|
|
|
|
framework._.sfCommon.getAttribute(['pad', 'spellcheck'], function (err, data) {
|
|
|
|
framework._.sfCommon.getAttribute(['pad', 'spellcheck'], function(err, data) {
|
|
|
|
if (framework.isReadOnly()) { return; }
|
|
|
|
if (framework.isReadOnly()) { return; }
|
|
|
|
if (data) {
|
|
|
|
if (data) {
|
|
|
|
$iframe.find('body').attr('spellcheck', true);
|
|
|
|
$iframe.find('body').attr('spellcheck', true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
framework._.sfCommon.isPadStored(function (err, val) {
|
|
|
|
framework._.sfCommon.isPadStored(function(err, val) {
|
|
|
|
if (!val) { return; }
|
|
|
|
if (!val) { return; }
|
|
|
|
var b64images = $inner.find('img[src^="data:image"]:not(.cke_reset)');
|
|
|
|
var b64images = $inner.find('img[src^="data:image"]:not(.cke_reset)');
|
|
|
|
if (b64images.length && framework._.sfCommon.isLoggedIn()) {
|
|
|
|
if (b64images.length && framework._.sfCommon.isLoggedIn()) {
|
|
|
|
var no = h('button.cp-corner-cancel', Messages.cancel);
|
|
|
|
var no = h('button.cp-corner-cancel', Messages.cancel);
|
|
|
|
var yes = h('button.cp-corner-primary', Messages.ok);
|
|
|
|
var yes = h('button.cp-corner-primary', Messages.ok);
|
|
|
|
var actions = h('div', [no, yes]);
|
|
|
|
var actions = h('div', [no, yes]);
|
|
|
|
var modal = UI.cornerPopup(Messages.pad_base64, actions, '', {big: true});
|
|
|
|
var modal = UI.cornerPopup(Messages.pad_base64, actions, '', { big: true });
|
|
|
|
$(no).click(function () {
|
|
|
|
$(no).click(function() {
|
|
|
|
modal.delete();
|
|
|
|
modal.delete();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
$(yes).click(function () {
|
|
|
|
$(yes).click(function() {
|
|
|
|
modal.delete();
|
|
|
|
modal.delete();
|
|
|
|
b64images.each(function (i, el) {
|
|
|
|
b64images.each(function(i, el) {
|
|
|
|
var src = $(el).attr('src');
|
|
|
|
var src = $(el).attr('src');
|
|
|
|
var blob = Util.dataURIToBlob(src);
|
|
|
|
var blob = Util.dataURIToBlob(src);
|
|
|
|
var ext = '.' + (blob.type.split('/')[1] || 'png');
|
|
|
|
var ext = '.' + (blob.type.split('/')[1] || 'png');
|
|
|
|
var name = (framework._.title.getTitle() || 'Pad')+'_image';
|
|
|
|
var name = (framework._.title.getTitle() || 'Pad') + '_image';
|
|
|
|
blob.name = name + ext;
|
|
|
|
blob.name = name + ext;
|
|
|
|
var ev = {
|
|
|
|
var ev = {
|
|
|
|
insertElement: function (newEl) {
|
|
|
|
insertElement: function(newEl) {
|
|
|
|
var element = new window.CKEDITOR.dom.element(el);
|
|
|
|
var element = new window.CKEDITOR.dom.element(el);
|
|
|
|
newEl.replace(element);
|
|
|
|
newEl.replace(element);
|
|
|
|
setTimeout(framework.localChange);
|
|
|
|
setTimeout(framework.localChange);
|
|
|
@ -769,34 +765,34 @@ define([
|
|
|
|
});*/
|
|
|
|
});*/
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
framework.onDefaultContentNeeded(function () {
|
|
|
|
framework.onDefaultContentNeeded(function() {
|
|
|
|
inner.innerHTML = '<p></p>';
|
|
|
|
inner.innerHTML = '<p></p>';
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var importMediaTags = function (dom, cb) {
|
|
|
|
var importMediaTags = function(dom, cb) {
|
|
|
|
var $dom = $(dom);
|
|
|
|
var $dom = $(dom);
|
|
|
|
$dom.find('media-tag').each(function (i, el) {
|
|
|
|
$dom.find('media-tag').each(function(i, el) {
|
|
|
|
$(el).empty();
|
|
|
|
$(el).empty();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
cb($dom[0]);
|
|
|
|
cb($dom[0]);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
framework.setFileImporter({ accept: 'text/html' }, function (content, f, cb) {
|
|
|
|
framework.setFileImporter({ accept: 'text/html' }, function(content, f, cb) {
|
|
|
|
importMediaTags(domFromHTML(content).body, function (dom) {
|
|
|
|
importMediaTags(domFromHTML(content).body, function(dom) {
|
|
|
|
cb(Hyperjson.fromDOM(dom));
|
|
|
|
cb(Hyperjson.fromDOM(dom));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}, true);
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
|
|
|
|
framework.setFileExporter(Exporter.ext, function (cb) {
|
|
|
|
framework.setFileExporter(Exporter.ext, function(cb) {
|
|
|
|
Exporter.main(inner, cb);
|
|
|
|
Exporter.main(inner, cb);
|
|
|
|
}, true);
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
|
|
|
|
framework.setNormalizer(function (hjson) {
|
|
|
|
framework.setNormalizer(function(hjson) {
|
|
|
|
return [
|
|
|
|
return [
|
|
|
|
'BODY',
|
|
|
|
'BODY',
|
|
|
|
{
|
|
|
|
{
|
|
|
|
"class": "cke_editable cke_editable_themed cke_contents_ltr cke_show_borders",
|
|
|
|
"class": "cke_editable cke_editable_themed cke_contents_ltr cke_show_borders",
|
|
|
|
"contenteditable": "true",
|
|
|
|
"contenteditable": "true",
|
|
|
|
"spellcheck":"false"
|
|
|
|
"spellcheck": "false"
|
|
|
|
},
|
|
|
|
},
|
|
|
|
hjson[2]
|
|
|
|
hjson[2]
|
|
|
|
];
|
|
|
|
];
|
|
|
@ -829,7 +825,7 @@ define([
|
|
|
|
The solution is the "input" event, triggered by the browser as soon as the
|
|
|
|
The solution is the "input" event, triggered by the browser as soon as the
|
|
|
|
character is inserted.
|
|
|
|
character is inserted.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
inner.addEventListener('input', function () {
|
|
|
|
inner.addEventListener('input', function() {
|
|
|
|
framework.localChange();
|
|
|
|
framework.localChange();
|
|
|
|
updateCursor();
|
|
|
|
updateCursor();
|
|
|
|
editor.fire('cp-wc'); // Update word count
|
|
|
|
editor.fire('cp-wc'); // Update word count
|
|
|
@ -838,8 +834,8 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
var wordCount = h('span.cp-app-pad-wordCount');
|
|
|
|
var wordCount = h('span.cp-app-pad-wordCount');
|
|
|
|
$('.cke_toolbox_main').append(wordCount);
|
|
|
|
$('.cke_toolbox_main').append(wordCount);
|
|
|
|
editor.on('cp-wc-update', function () {
|
|
|
|
editor.on('cp-wc-update', function() {
|
|
|
|
if (!editor.wordCount || typeof (editor.wordCount.wordCount) === "undefined") {
|
|
|
|
if (!editor.wordCount || typeof(editor.wordCount.wordCount) === "undefined") {
|
|
|
|
wordCount.innerText = '';
|
|
|
|
wordCount.innerText = '';
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -849,7 +845,7 @@ define([
|
|
|
|
// export the typing tests to the window.
|
|
|
|
// export the typing tests to the window.
|
|
|
|
// call like `test = easyTest()`
|
|
|
|
// call like `test = easyTest()`
|
|
|
|
// terminate the test like `test.cancel()`
|
|
|
|
// terminate the test like `test.cancel()`
|
|
|
|
window.easyTest = function () {
|
|
|
|
window.easyTest = function() {
|
|
|
|
cursor.update();
|
|
|
|
cursor.update();
|
|
|
|
//var start = cursor.Range.start;
|
|
|
|
//var start = cursor.Range.start;
|
|
|
|
//var test = TypingTest.testInput(inner, start.el, start.offset, framework.localChange);
|
|
|
|
//var test = TypingTest.testInput(inner, start.el, start.offset, framework.localChange);
|
|
|
@ -861,18 +857,18 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
// Fix the scrollbar if it's reset when clicking on a button (firefox only?)
|
|
|
|
// Fix the scrollbar if it's reset when clicking on a button (firefox only?)
|
|
|
|
var buttonScrollTop;
|
|
|
|
var buttonScrollTop;
|
|
|
|
$('.cke_toolbox_main').find('.cke_button, .cke_combo_button').mousedown(function () {
|
|
|
|
$('.cke_toolbox_main').find('.cke_button, .cke_combo_button').mousedown(function() {
|
|
|
|
buttonScrollTop = $('iframe').contents().scrollTop();
|
|
|
|
buttonScrollTop = $('iframe').contents().scrollTop();
|
|
|
|
setTimeout(function () {
|
|
|
|
setTimeout(function() {
|
|
|
|
$('iframe').contents().scrollTop(buttonScrollTop);
|
|
|
|
$('iframe').contents().scrollTop(buttonScrollTop);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$('.cke_toolbox_main').find('.cke_button').click(function () {
|
|
|
|
$('.cke_toolbox_main').find('.cke_button').click(function() {
|
|
|
|
var e = this;
|
|
|
|
var e = this;
|
|
|
|
var classString = e.getAttribute('class');
|
|
|
|
var classString = e.getAttribute('class');
|
|
|
|
var classes = classString.split(' ').filter(function (c) {
|
|
|
|
var classes = classString.split(' ').filter(function(c) {
|
|
|
|
return /cke_button__/.test(c);
|
|
|
|
return /cke_button__/.test(c);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
@ -885,12 +881,12 @@ define([
|
|
|
|
framework.start();
|
|
|
|
framework.start();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var main = function () {
|
|
|
|
var main = function() {
|
|
|
|
var Ckeditor;
|
|
|
|
var Ckeditor;
|
|
|
|
var editor;
|
|
|
|
var editor;
|
|
|
|
var framework;
|
|
|
|
var framework;
|
|
|
|
|
|
|
|
|
|
|
|
nThen(function (waitFor) {
|
|
|
|
nThen(function(waitFor) {
|
|
|
|
Framework.create({
|
|
|
|
Framework.create({
|
|
|
|
toolbarContainer: '#cp-app-pad-toolbar',
|
|
|
|
toolbarContainer: '#cp-app-pad-toolbar',
|
|
|
|
contentContainer: '#cp-app-pad-editor',
|
|
|
|
contentContainer: '#cp-app-pad-editor',
|
|
|
@ -917,15 +913,15 @@ define([
|
|
|
|
module.cursor.fixSelection(sel, range);
|
|
|
|
module.cursor.fixSelection(sel, range);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
}*/
|
|
|
|
}, waitFor(function (fw) { window.APP.framework = framework = fw; }));
|
|
|
|
}, waitFor(function(fw) { window.APP.framework = framework = fw; }));
|
|
|
|
|
|
|
|
|
|
|
|
nThen(function (waitFor) {
|
|
|
|
nThen(function(waitFor) {
|
|
|
|
ckEditorAvailable(waitFor(function (ck) {
|
|
|
|
ckEditorAvailable(waitFor(function(ck) {
|
|
|
|
Ckeditor = ck;
|
|
|
|
Ckeditor = ck;
|
|
|
|
require(['/pad/wysiwygarea-plugin.js'], waitFor());
|
|
|
|
require(['/pad/wysiwygarea-plugin.js'], waitFor());
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
$(waitFor());
|
|
|
|
$(waitFor());
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
}).nThen(function(waitFor) {
|
|
|
|
Ckeditor.config.toolbarCanCollapse = true;
|
|
|
|
Ckeditor.config.toolbarCanCollapse = true;
|
|
|
|
if (screen.height < 800) {
|
|
|
|
if (screen.height < 800) {
|
|
|
|
Ckeditor.config.toolbarStartupExpanded = false;
|
|
|
|
Ckeditor.config.toolbarStartupExpanded = false;
|
|
|
@ -947,20 +943,19 @@ define([
|
|
|
|
'import': Messages.pad_mediatagImport,
|
|
|
|
'import': Messages.pad_mediatagImport,
|
|
|
|
options: Messages.pad_mediatagOptions
|
|
|
|
options: Messages.pad_mediatagOptions
|
|
|
|
};
|
|
|
|
};
|
|
|
|
Messages.comments_comment = "COMMENT"; // XXX
|
|
|
|
|
|
|
|
Ckeditor._commentsTranslations = {
|
|
|
|
Ckeditor._commentsTranslations = {
|
|
|
|
comment: Messages.comments_comment,
|
|
|
|
comment: Messages.comments_comment,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
Ckeditor.plugins.addExternal('mediatag','/pad/', 'mediatag-plugin.js');
|
|
|
|
Ckeditor.plugins.addExternal('mediatag', '/pad/', 'mediatag-plugin.js');
|
|
|
|
Ckeditor.plugins.addExternal('blockbase64','/pad/', 'disable-base64.js');
|
|
|
|
Ckeditor.plugins.addExternal('blockbase64', '/pad/', 'disable-base64.js');
|
|
|
|
Ckeditor.plugins.addExternal('comments','/pad/', 'comment.js');
|
|
|
|
Ckeditor.plugins.addExternal('comments', '/pad/', 'comment.js');
|
|
|
|
Ckeditor.plugins.addExternal('wordcount','/pad/wordcount/', 'plugin.js');
|
|
|
|
Ckeditor.plugins.addExternal('wordcount', '/pad/wordcount/', 'plugin.js');
|
|
|
|
module.ckeditor = editor = Ckeditor.replace('editor1', {
|
|
|
|
module.ckeditor = editor = Ckeditor.replace('editor1', {
|
|
|
|
customConfig: '/customize/ckeditor-config.js',
|
|
|
|
customConfig: '/customize/ckeditor-config.js',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
editor.addCommand('pagemode', {
|
|
|
|
editor.addCommand('pagemode', {
|
|
|
|
exec: function () {
|
|
|
|
exec: function() {
|
|
|
|
if (!framework) { return; }
|
|
|
|
if (!framework) { return; }
|
|
|
|
var $contentContainer = $('#cke_1_contents');
|
|
|
|
var $contentContainer = $('#cke_1_contents');
|
|
|
|
var $button = $('.cke_button__pagemode');
|
|
|
|
var $button = $('.cke_button__pagemode');
|
|
|
@ -983,12 +978,12 @@ define([
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
editor.on('instanceReady', waitFor());
|
|
|
|
editor.on('instanceReady', waitFor());
|
|
|
|
}).nThen(function () {
|
|
|
|
}).nThen(function() {
|
|
|
|
editor.plugins.mediatag.import = function ($mt) {
|
|
|
|
editor.plugins.mediatag.import = function($mt) {
|
|
|
|
framework._.sfCommon.importMediaTag($mt);
|
|
|
|
framework._.sfCommon.importMediaTag($mt);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
Links.init(Ckeditor, editor);
|
|
|
|
Links.init(Ckeditor, editor);
|
|
|
|
}).nThen(function () {
|
|
|
|
}).nThen(function() {
|
|
|
|
// Move ckeditor parts to have a structure like the other apps
|
|
|
|
// Move ckeditor parts to have a structure like the other apps
|
|
|
|
var $contentContainer = $('#cke_1_contents');
|
|
|
|
var $contentContainer = $('#cke_1_contents');
|
|
|
|
var $mainContainer = $('#cke_editor1 > .cke_inner');
|
|
|
|
var $mainContainer = $('#cke_editor1 > .cke_inner');
|
|
|
@ -998,19 +993,19 @@ define([
|
|
|
|
$ckeToolbar.find('.cke_button__image_icon').parent().hide();
|
|
|
|
$ckeToolbar.find('.cke_button__image_icon').parent().hide();
|
|
|
|
}).nThen(waitFor());
|
|
|
|
}).nThen(waitFor());
|
|
|
|
|
|
|
|
|
|
|
|
}).nThen(function (/*waitFor*/) {
|
|
|
|
}).nThen(function( /*waitFor*/ ) {
|
|
|
|
function launchAnchorTest(test) {
|
|
|
|
function launchAnchorTest(test) {
|
|
|
|
// -------- anchor test: make sure the exported anchor contains <a name="..."> -------
|
|
|
|
// -------- anchor test: make sure the exported anchor contains <a name="..."> -------
|
|
|
|
console.log('---- anchor test: make sure the exported anchor contains <a name="..."> -----.');
|
|
|
|
console.log('---- anchor test: make sure the exported anchor contains <a name="..."> -----.');
|
|
|
|
|
|
|
|
|
|
|
|
function tryAndTestExport() {
|
|
|
|
function tryAndTestExport() {
|
|
|
|
console.log("Starting tryAndTestExport.");
|
|
|
|
console.log("Starting tryAndTestExport.");
|
|
|
|
editor.on( 'dialogShow', function( evt ) {
|
|
|
|
editor.on('dialogShow', function(evt) {
|
|
|
|
console.log("Anchor dialog detected.");
|
|
|
|
console.log("Anchor dialog detected.");
|
|
|
|
var dialog = evt.data;
|
|
|
|
var dialog = evt.data;
|
|
|
|
$(dialog.parts.contents.$).find("input").val('xx-' + Math.round(Math.random()*1000));
|
|
|
|
$(dialog.parts.contents.$).find("input").val('xx-' + Math.round(Math.random() * 1000));
|
|
|
|
dialog.click(window.CKEDITOR.dialog.okButton(editor).id);
|
|
|
|
dialog.click(window.CKEDITOR.dialog.okButton(editor).id);
|
|
|
|
} );
|
|
|
|
});
|
|
|
|
var existingText = editor.getData();
|
|
|
|
var existingText = editor.getData();
|
|
|
|
editor.insertText("A bit of text");
|
|
|
|
editor.insertText("A bit of text");
|
|
|
|
console.log("Launching anchor command.");
|
|
|
|
console.log("Launching anchor command.");
|
|
|
@ -1020,46 +1015,45 @@ define([
|
|
|
|
var waitH = window.setInterval(function() {
|
|
|
|
var waitH = window.setInterval(function() {
|
|
|
|
console.log("Waited 2s for the dialog to appear");
|
|
|
|
console.log("Waited 2s for the dialog to appear");
|
|
|
|
var anchors = window.CKEDITOR.plugins["link"].getEditorAnchors(editor);
|
|
|
|
var anchors = window.CKEDITOR.plugins["link"].getEditorAnchors(editor);
|
|
|
|
if(!anchors || anchors.length===0) {
|
|
|
|
if (!anchors || anchors.length === 0) {
|
|
|
|
test.fail("No anchors found. Please adjust document");
|
|
|
|
test.fail("No anchors found. Please adjust document");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
console.log(anchors.length + " anchors found.");
|
|
|
|
console.log(anchors.length + " anchors found.");
|
|
|
|
var exported = Exporter.getHTML(window.inner);
|
|
|
|
var exported = Exporter.getHTML(window.inner);
|
|
|
|
console.log("Obtained exported: " + exported);
|
|
|
|
console.log("Obtained exported: " + exported);
|
|
|
|
var allFound = true;
|
|
|
|
var allFound = true;
|
|
|
|
for(var i=0; i<anchors.length; i++) {
|
|
|
|
for (var i = 0; i < anchors.length; i++) {
|
|
|
|
var anchor = anchors[i];
|
|
|
|
var anchor = anchors[i];
|
|
|
|
console.log("Anchor " + anchor.name);
|
|
|
|
console.log("Anchor " + anchor.name);
|
|
|
|
var expected = "<a id=\"" + anchor.id + "\" name=\"" + anchor.name + "\" ";
|
|
|
|
var expected = "<a id=\"" + anchor.id + "\" name=\"" + anchor.name + "\" ";
|
|
|
|
var found = exported.indexOf(expected)>=0;
|
|
|
|
var found = exported.indexOf(expected) >= 0;
|
|
|
|
console.log("Found " + expected + " " + found + ".");
|
|
|
|
console.log("Found " + expected + " " + found + ".");
|
|
|
|
allFound = allFound && found;
|
|
|
|
allFound = allFound && found;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
console.log("Cleaning up.");
|
|
|
|
console.log("Cleaning up.");
|
|
|
|
if(allFound) {
|
|
|
|
if (allFound) {
|
|
|
|
// clean-up
|
|
|
|
// clean-up
|
|
|
|
editor.execCommand('undo');
|
|
|
|
editor.execCommand('undo');
|
|
|
|
editor.execCommand('undo');
|
|
|
|
editor.execCommand('undo');
|
|
|
|
var nint = window.setInterval(function(){
|
|
|
|
var nint = window.setInterval(function() {
|
|
|
|
console.log("Waiting for undo to yield same result.");
|
|
|
|
console.log("Waiting for undo to yield same result.");
|
|
|
|
if(existingText === editor.getData()) {
|
|
|
|
if (existingText === editor.getData()) {
|
|
|
|
window.clearInterval(nint);
|
|
|
|
window.clearInterval(nint);
|
|
|
|
test.pass();
|
|
|
|
test.pass();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 500);
|
|
|
|
}, 500);
|
|
|
|
} else
|
|
|
|
} else {
|
|
|
|
{
|
|
|
|
|
|
|
|
test.fail("Not all expected a elements found for document at " + window.top.location + ".");
|
|
|
|
test.fail("Not all expected a elements found for document at " + window.top.location + ".");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
window.clearInterval(waitH);
|
|
|
|
window.clearInterval(waitH);
|
|
|
|
},2000);
|
|
|
|
}, 2000);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var intervalHandle = window.setInterval(function() {
|
|
|
|
var intervalHandle = window.setInterval(function() {
|
|
|
|
if(editor.status==="ready") {
|
|
|
|
if (editor.status === "ready") {
|
|
|
|
window.clearInterval(intervalHandle);
|
|
|
|
window.clearInterval(intervalHandle);
|
|
|
|
console.log("Editor is ready.");
|
|
|
|
console.log("Editor is ready.");
|
|
|
|
tryAndTestExport();
|
|
|
|
tryAndTestExport();
|
|
|
@ -1076,4 +1070,4 @@ define([
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
main();
|
|
|
|
main();
|
|
|
|
});
|
|
|
|
});
|