Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert ES6 JS files to ES5 #901

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 15 additions & 11 deletions app/assets/javascripts/comfy/admin/cms/base.js
@@ -1,24 +1,26 @@
(() => {
if (!window.CMS) window.CMS = {};
const CMS = window.CMS;
"use strict";

// TODO(glebm): Use the battle-tested universal onPageLoad code and enable Turbolinks+async in the demo app.
(function () {
if (!window.CMS) window.CMS = {};
var CMS = window.CMS; // TODO(glebm): Use the battle-tested universal onPageLoad code and enable Turbolinks+async in the demo app.
// See: https://gist.github.com/glebm/2496daf445877055447a6fac46509d9a
const isTurbolinks = 'Turbolinks' in window && window.Turbolinks.supported;

var isTurbolinks = 'Turbolinks' in window && window.Turbolinks.supported;

if (isTurbolinks) {
document.addEventListener('turbolinks:load', () => {
document.addEventListener('turbolinks:load', function () {
window.CMS.init();
});
document.addEventListener('turbolinks:before-cache', () => {
document.addEventListener('turbolinks:before-cache', function () {
window.CMS.dispose();
});
} else {
document.addEventListener('DOMContentLoaded', () => {
document.addEventListener('DOMContentLoaded', function () {
window.CMS.init();
});
}

CMS.init = () => {
CMS.init = function () {
CMS.current_path = window.location.pathname;
CMS.slugify();
CMS.codemirror.init();
Expand All @@ -33,7 +35,7 @@
CMS.diff();
};

CMS.dispose = () => {
CMS.dispose = function () {
CMS.codemirror.dispose();
CMS.wysiwyg.dispose();
CMS.files.dispose();
Expand All @@ -42,5 +44,7 @@
CMS.timepicker.dispose();
};

CMS.getLocale = () => document.querySelector('meta[name="cms-locale"]').content;
CMS.getLocale = function () {
return document.querySelector('meta[name="cms-locale"]').content;
};
})();
18 changes: 10 additions & 8 deletions app/assets/javascripts/comfy/admin/cms/categories.js
@@ -1,17 +1,19 @@
(() => {
window.CMS.categories = (root = document) => {
const widget = root.querySelector('.categories-widget');
"use strict";

(function () {
window.CMS.categories = function () {
var root = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document;
var widget = root.querySelector('.categories-widget');
if (widget === null) return;
const readSection = widget.querySelector('.read');
const editSection = widget.querySelector('.editable');
widget.querySelector('.read button.toggle-cat-edit').addEventListener('click', () => {
var readSection = widget.querySelector('.read');
var editSection = widget.querySelector('.editable');
widget.querySelector('.read button.toggle-cat-edit').addEventListener('click', function () {
readSection.style.display = 'none';
editSection.style.display = 'block';
});
widget.querySelector('.editable button.toggle-cat-edit').addEventListener('click', () => {
widget.querySelector('.editable button.toggle-cat-edit').addEventListener('click', function () {
editSection.style.display = 'none';
readSection.style.display = 'block';
});
};
})();

106 changes: 85 additions & 21 deletions app/assets/javascripts/comfy/admin/cms/codemirror.js
@@ -1,31 +1,95 @@
(() => {
const codeMirrorInstances = [];
"use strict";

(function () {
var codeMirrorInstances = [];
window.CMS.codemirror = {
init(root = document) {
for (const textarea of root.querySelectorAll('textarea[data-cms-cm-mode]')) {
const codemirror = CodeMirror.fromTextArea(textarea, {
mode: textarea.dataset.cmsCmMode,
tabSize: 2,
lineWrapping: true,
autoCloseTags: true,
lineNumbers: true,
viewportMargin: Infinity
});
codeMirrorInstances.push(codemirror);
init: function init() {
var root = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document;
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;

try {
for (var _iterator = root.querySelectorAll('textarea[data-cms-cm-mode]')[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var textarea = _step.value;
var codemirror = CodeMirror.fromTextArea(textarea, {
mode: textarea.dataset.cmsCmMode,
tabSize: 2,
lineWrapping: true,
autoCloseTags: true,
lineNumbers: true,
viewportMargin: Infinity
});
codeMirrorInstances.push(codemirror);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}

const tabsRoot = root.id === 'form-fragments' ? root : root.querySelector('#form-fragments');
jQuery(tabsRoot).find('a[data-toggle="tab"]').on('shown.bs.tab', () => {
for (const codemirror of codeMirrorInstances) {
codemirror.refresh();
var tabsRoot = root.id === 'form-fragments' ? root : root.querySelector('#form-fragments');
jQuery(tabsRoot).find('a[data-toggle="tab"]').on('shown.bs.tab', function () {
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;

try {
for (var _iterator2 = codeMirrorInstances[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var codemirror = _step2.value;
codemirror.refresh();
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
});
},
dispose() {
for (const codemirror of codeMirrorInstances) {
codemirror.toTextArea();
dispose: function dispose() {
var _iteratorNormalCompletion3 = true;
var _didIteratorError3 = false;
var _iteratorError3 = undefined;

try {
for (var _iterator3 = codeMirrorInstances[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var codemirror = _step3.value;
codemirror.toTextArea();
}
} catch (err) {
_didIteratorError3 = true;
_iteratorError3 = err;
} finally {
try {
if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
_iterator3.return();
}
} finally {
if (_didIteratorError3) {
throw _iteratorError3;
}
}
}

codeMirrorInstances.length = 0;
}
}
};
})();
10 changes: 6 additions & 4 deletions app/assets/javascripts/comfy/admin/cms/diff.js
@@ -1,10 +1,12 @@
(() => {
window.CMS.diff = () => {
"use strict";

(function () {
window.CMS.diff = function () {
jQuery('.revision').prettyTextDiff({
cleanup: true,
originalContainer: '.original',
changedContainer: '.current',
diffContainer: '.diff .content',
diffContainer: '.diff .content'
});
}
};
})();
129 changes: 87 additions & 42 deletions app/assets/javascripts/comfy/admin/cms/file_link.js
@@ -1,13 +1,28 @@
(() => {
const isFirefox = /\bFirefox\//.test(navigator.userAgent);
"use strict";

function _instanceof(left, right) { if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) { return !!right[Symbol.hasInstance](left); } else { return left instanceof right; } }

function _classCallCheck(instance, Constructor) { if (!_instanceof(instance, Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

(function () {
var isFirefox = /\bFirefox\//.test(navigator.userAgent);

var FileLink =
/*#__PURE__*/
function () {
function FileLink(link) {
var _this = this;

_classCallCheck(this, FileLink);

class FileLink {
constructor(link) {
this.link = link;
this.isImage = !!link.dataset.cmsFileThumbUrl;

link.addEventListener('dragstart', (evt) => {
evt.dataTransfer.setData('text/plain', this.link.dataset.cmsFileLinkTag);
link.addEventListener('dragstart', function (evt) {
evt.dataTransfer.setData('text/plain', _this.link.dataset.cmsFileLinkTag);
});

if (this.isImage) {
Expand All @@ -18,50 +33,80 @@
content: this.buildFileThumbnail(),
html: true
});
link.addEventListener('dragstart', function (evt) {
evt.dataTransfer.setDragImage(_this.buildFileThumbnail(), 4, 2);

link.addEventListener('dragstart', (evt) => {
evt.dataTransfer.setDragImage(this.buildFileThumbnail(), 4, 2);
this.getPopover().hide();
_this.getPopover().hide();
});

this.workAroundFirefoxPopoverGlitch();
}
}

buildFileThumbnail() {
const img = new Image();
img.src = this.link.dataset.cmsFileThumbUrl;
return img;
}
_createClass(FileLink, [{
key: "buildFileThumbnail",
value: function buildFileThumbnail() {
var img = new Image();
img.src = this.link.dataset.cmsFileThumbUrl;
return img;
} // To work around a Firefox bug causing the popover to re-appear after the drop:
// https://github.com/comfy/comfortable-mexican-sofa/pull/799#issuecomment-369124161
//
// Possibly related to:
// https://bugzilla.mozilla.org/show_bug.cgi?id=505521

// To work around a Firefox bug causing the popover to re-appear after the drop:
// https://github.com/comfy/comfortable-mexican-sofa/pull/799#issuecomment-369124161
//
// Possibly related to:
// https://bugzilla.mozilla.org/show_bug.cgi?id=505521
workAroundFirefoxPopoverGlitch() {
if (!isFirefox) return;
this.link.addEventListener('dragstart', () => {
this.getPopover().disable();
});
this.link.addEventListener('dragend', () => {
setTimeout(() => {
const popover = this.getPopover();
popover.enable();
popover.hide();
}, 300);
});
}
}, {
key: "workAroundFirefoxPopoverGlitch",
value: function workAroundFirefoxPopoverGlitch() {
var _this2 = this;

// We can't keep a reference to the Popover object, because Bootstrap re-creates it internally.
getPopover() {
return jQuery(this.link).data(bootstrap.Popover.DATA_KEY);
}
}
if (!isFirefox) return;
this.link.addEventListener('dragstart', function () {
_this2.getPopover().disable();
});
this.link.addEventListener('dragend', function () {
setTimeout(function () {
var popover = _this2.getPopover();

window.CMS.fileLinks = (root = document) => {
for (const link of root.querySelectorAll('[data-cms-file-link-tag]')) {
new FileLink(link);
popover.enable();
popover.hide();
}, 300);
});
} // We can't keep a reference to the Popover object, because Bootstrap re-creates it internally.

}, {
key: "getPopover",
value: function getPopover() {
return jQuery(this.link).data(bootstrap.Popover.DATA_KEY);
}
}]);

return FileLink;
}();

window.CMS.fileLinks = function () {
var root = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document;
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;

try {
for (var _iterator = root.querySelectorAll('[data-cms-file-link-tag]')[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var link = _step.value;
new FileLink(link);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
};
})();