define(["exports"], function (exports) { "use strict"; var _extends = function (child, parent) { child.prototype = Object.create(parent.prototype, { constructor: { value: child, enumerable: false, writable: true, configurable: true } }); child.__proto__ = parent; }; /* global View */ /* global esprima */ /* global html_beautify */ var editViewTemplate = "\n \n \n \n

Edit

\n \n
\n \n HTML\n Script\n Properties\n \n
\n \n
\n
\n
\n \n
\n
\n \n
\n
"; var EditView = (function (View) { var EditView = function EditView(options) { View.call(this, options); this.el.className = "fxos-customizer-edit-view"; this.render(); }; _extends(EditView, View); EditView.prototype.init = function (controller) { var _this = this; View.prototype.init.call(this, controller); this.modal = this.$("gaia-modal"); this.header = this.$("gaia-header"); this.tabs = this.$("gaia-tabs"); this.htmlCodeEditor = this.$("section[data-id=\"html\"] > fxos-code-editor"); this.scriptCodeEditor = this.$("section[data-id=\"script\"] > fxos-code-editor"); this.propertyInspector = this.$("section[data-id=\"properties\"] > fxos-inspector"); this.scriptErrors = this.$("section[data-id=\"script\"] > .errors"); this.tabPanes = [].slice.apply(this.$$(".tab-pane")); this.on("click", "button[data-action=\"cancel\"]", function () { _this.controller.close(); }); this.on("click", "button[data-action=\"save\"]", function () { _this.controller.save(); }); this.tabs.addEventListener("change", function () { _this.tabPanes.forEach(function (tabPane, index) { if (index === _this.tabs.selected) { tabPane.classList.add("active"); } else { tabPane.classList.remove("active"); } }); }); this.htmlCodeEditor.addEventListener("change", function () { _this.controller.changes.innerHTML = _this.htmlCodeEditor.value; }); this.scriptCodeEditor.addEventListener("change", function () { _this.controller.changes.script = _this.scriptCodeEditor.value; clearTimeout(_this.validateScriptTimeout); _this.validateScriptTimeout = setTimeout(_this.validateScript.bind(_this), 2000); }); this.scriptCodeEditor.addEventListener("touchstart", function () { clearTimeout(_this.validateScriptTimeout); }); this.scriptCodeEditor.addEventListener("touchend", function () { clearTimeout(_this.validateScriptTimeout); _this.validateScriptTimeout = setTimeout(_this.validateScript.bind(_this), 2000); }); this.propertyInspector.addEventListener("createattribute", function (evt) { var detail = JSON.parse(evt.detail); _this.controller.changes.createAttributes = _this.controller.changes.createAttributes || {}; _this.controller.changes.createAttributes[detail.expression] = detail.name; }); this.propertyInspector.addEventListener("removeattribute", function (evt) { var detail = JSON.parse(evt.detail); _this.controller.changes.removeAttributes = _this.controller.changes.removeAttributes || {}; _this.controller.changes.removeAttributes[detail.expression] = detail.name; }); this.propertyInspector.addEventListener("save", function (evt) { var detail = JSON.parse(evt.detail); _this.controller.changes.properties = _this.controller.changes.properties || {}; _this.controller.changes.properties[detail.expression] = detail.value; }); this.el.addEventListener("contextmenu", function (evt) { evt.stopPropagation(); }); }; EditView.prototype.template = function () { return editViewTemplate; }; EditView.prototype.open = function () { this.modal.open(); }; EditView.prototype.close = function () { this.modal.close(); }; EditView.prototype.setTarget = function (target) { var _this2 = this; var clonedTarget = target.cloneNode(true); var html = clonedTarget.innerHTML.trim(); this.htmlCodeEditor.value = "Loading..."; setTimeout(function () { html = html_beautify(html, { indent_size: 2 }); _this2.htmlCodeEditor.value = html; }, 1); this.scriptCodeEditor.value = "/**\n * You can edit a script to be inserted\n * in the generated add-on here.\n *\n * Globals:\n * selector [String]\n * el [HTMLElement]\n * mo [MutationObserver]\n */\n\n//el.addEventListener('click', function(evt) {\n// alert('Clicked!');\n//});\n"; this.propertyInspector.setRootTarget(clonedTarget); }; EditView.prototype.validateScript = function () { var error; try { var syntax = esprima.parse(this.controller.changes.script); if (syntax.errors && syntax.errors.length > 0) { error = syntax.errors[0]; } } catch (e) { error = e; } if (error) { this.scriptErrors.textContent = error.message; this.scriptErrors.classList.add("active"); } else { this.scriptErrors.textContent = ""; this.scriptErrors.classList.remove("active"); } }; return EditView; })(View); exports["default"] = EditView; });