Skip to content

Commit

Permalink
removing ajax call on editor load
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorybesson committed Aug 31, 2016
1 parent 7bb71ed commit 7daa3b0
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 21 deletions.
36 changes: 23 additions & 13 deletions dist/server/public/scripts/modules/EditorReload.js
Expand Up @@ -69,9 +69,31 @@ var Reload = function () {
}
return script;
}
}, {
key: 'inject',
value: function inject(str) {
var iframe = document.querySelector('#page-template');
var iframeBody = (0, _iframe.IframeDocument)('#page-template').body;
var scrollTop = iframeBody.scrollTop;

var doc = iframe.contentWindow.document;
str = str.replace(/<\/head>/, '<base href="/" /></head>');
doc.open();
doc.write(str);
doc.close();

setTimeout(function () {
var iframeDoc = (0, _iframe.IframeDocument)('#page-template');
if (typeof iframeDoc !== 'undefined' && iframeDoc !== null && typeof iframeDoc.body !== 'undefined' && iframeDoc.body !== null) {
iframeDoc.body.scrollTop = scrollTop;
}
}, 1000);
}
}, {
key: 'reload',
value: function reload() {
var _this = this;

var iframe = document.querySelector('#page-template');
var iframeBody = (0, _iframe.IframeDocument)('#page-template').body;
var scrollTop = iframeBody.scrollTop;
Expand All @@ -88,19 +110,7 @@ var Reload = function () {
method: 'post'
}, function (code, responseText, request) {
if (typeof responseText !== 'undefined' && responseText !== null) {
var str = responseText;
var doc = iframe.contentWindow.document;
str = str.replace(/<\/head>/, '<base href="/" /></head>');
doc.open();
doc.write(str);
doc.close();

setTimeout(function () {
var iframeDoc = (0, _iframe.IframeDocument)('#page-template');
if (typeof iframeDoc !== 'undefined' && iframeDoc !== null && typeof iframeDoc.body !== 'undefined' && iframeDoc.body !== null) {
iframeDoc.body.scrollTop = scrollTop;
}
}, 1000);
_this.inject(responseText);
}

return;
Expand Down
6 changes: 3 additions & 3 deletions dist/server/public/scripts/template-engine-compiled.js

Large diffs are not rendered by default.

32 changes: 28 additions & 4 deletions dist/server/public/scripts/template-engine.js
Expand Up @@ -87,9 +87,33 @@ var Engine = function () {
}

_createClass(Engine, [{
key: 'loadIframe',
value: function loadIframe() {
_EditorReload2.default.instance.reload();
key: 'inject',
value: function inject() {
var findComments = function findComments(el) {
var arr = [];
for (var i = 0; i < el.childNodes.length; i++) {
var node = el.childNodes[i];
if (node.nodeType === 8) {
arr.push(node);
} else {
arr.push.apply(arr, findComments(node));
}
}
return arr;
};

var commentNodes = findComments(document);

Array.prototype.forEach.call(commentNodes, function (comment) {
if (comment.nodeValue.indexOf('[pageHTML]') > -1) {
var base = comment.data;
if (typeof base !== 'undefined' && base !== null) {
base = base.replace(/\[pageHTML\]/g, '');
base = base.replace(/-- >/g, '-->');
_EditorReload2.default.instance.inject(base);
}
}
});
}
}, {
key: '_bindEvents',
Expand Down Expand Up @@ -139,5 +163,5 @@ window.abe = {
};

document.addEventListener("DOMContentLoaded", function (event) {
if (document.querySelector('#page-template')) engine.loadIframe();
if (document.querySelector('#page-template')) engine.inject();
});
8 changes: 8 additions & 0 deletions dist/server/routes/get-main.js
Expand Up @@ -184,7 +184,15 @@ var route = function route(req, res, next) {
_filePath = '/' + _filePath.replace(/^\/+/, '');
}

var pageHtml = '';
if (typeof _json !== 'undefined' && _json !== null && typeof _json.abe_meta !== 'undefined' && _json.abe_meta !== null) {
var text = (0, _cli.getTemplate)(_json.abe_meta.template);
var page = new _cli.Page(req.params[0], text, _json, false);
pageHtml = page.html.replace(/"/g, '\"').replace(/'/g, "\'");
}

var EditorVariables = {
pageHtml: pageHtml,
isHome: isHome,
abeUrl: '/abe/',
test: JSON.stringify(_abeLocale2.default),
Expand Down
3 changes: 3 additions & 0 deletions dist/server/views/template-engine.html
Expand Up @@ -31,5 +31,8 @@
<script type="text/javascript" src="/scripts/admin-compiled.js"></script>

{{abeImport 'body' manager.config this}}
<!-- [pageHTML]
{{pageHtml}}
[pageHTML] -->
</body>
</html>
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -76,14 +76,14 @@
"xss": "^0.2.10"
},
"devDependencies": {
"node-sass": "3.6.0",
"babel": "^6.3.26",
"babel-cli": "^6.3.17",
"babel-preset-es2015": "^6.3.13",
"babel-preset-stage-0": "^6.3.13",
"babelify": "^7.2.0",
"browserify": "^13.0.0",
"mkdirp": "^0.5.1",
"node-sass": "^3.6.0",
"nodemon": "^1.8.1",
"parallelshell": "^2.0.0",
"watchify": "^3.4.0"
Expand Down

0 comments on commit 7daa3b0

Please sign in to comment.