define(["require","exports","../shared/AntragsgruenEditor"],function(t,a,e){"use strict";var i=function(){function t(t){this.$form=t;var a=t.data("multi-paragraph-mode");if("undefined"==typeof a)throw"data-multi-paragraph-mode needs to be set";this.lang=$("html").attr("lang"),this.initEditorialOpener(),a?this.initMultiParagraphMode():this.spmInit()}return t.prototype.initEditorialOpener=function(){var t=$(".editorialChange .opener");$(".input-group.date").datetimepicker({locale:this.lang,format:"L"}),t.click(function(t){t.preventDefault();var a=$(".editorialChange"),i=a.find(".texteditor");$(t.target).addClass("hidden"),$("#section_holder_editorial").removeClass("hidden");var n=new e.AntragsgruenEditor("amendmentEditorial_wysiwyg");i.parents("form").submit(function(){i.parent().find("textarea.raw").val(n.getEditor().getData())})}),""!=$("#amendmentEditorial").val()&&t.click()},t.prototype.initMultiParagraphMode=function(){$(".wysiwyg-textarea:not(#section_holder_editorial)").each(function(t,a){var i=$(a),n=i.find(".texteditor"),r=new e.AntragsgruenEditor(n.attr("id")),d=r.getEditor();n.parents("form").submit(function(){n.parent().find("textarea.raw").val(d.getData()),"undefined"!=typeof d.plugins.lite&&(d.plugins.lite.findPlugin(d).acceptAll(),n.parent().find("textarea.consolidated").val(d.getData()))})})},t.prototype.spmSetModifyable=function(){var t=this.$spmParagraphs.filter(".modified");0==t.length?this.$spmParagraphs.addClass("modifyable"):(this.$spmParagraphs.removeClass("modifyable"),$("input[name=modifiedParagraphNo]").val(t.data("paragraph-no")),$("input[name=modifiedSectionId]").val(t.parents(".texteditorBox").data("section-id")))},t.prototype.spmOnParaClick=function(t){var a=$(t.currentTarget);if(a.hasClass("modifyable")){a.addClass("modified"),this.spmSetModifyable();var i,n=a.find(".texteditor");i="undefined"!=typeof CKEDITOR.instances[n.attr("id")]?CKEDITOR.instances[n.attr("id")]:new e.AntragsgruenEditor(n.attr("id")).getEditor(),n.attr("contenteditable","true"),n.parents("form").submit(function(){n.parent().find("textarea.raw").val(i.getData()),"undefined"!=typeof i.plugins.lite&&(i.plugins.lite.findPlugin(i).acceptAll(),n.parent().find("textarea.consolidated").val(i.getData()))}),n.focus()}},t.prototype.spmRevert=function(t){t.preventDefault(),t.stopPropagation();var a=$(t.target).parents(".wysiwyg-textarea"),e=a.find(".texteditor"),i=e.attr("id");$("#"+i).attr("contenteditable","false"),e.html(a.data("original")),a.removeClass("modified"),this.spmSetModifyable()},t.prototype.spmInitNonSingleParas=function(t,a){var i=$(a),n=i.find(".texteditor");if(!i.hasClass("hidden")){var r=new e.AntragsgruenEditor(n.attr("id")).getEditor();n.parents("form").submit(function(){n.parent().find("textarea.raw").val(r.getData()),"undefined"!=typeof r.plugins.lite&&(r.plugins.lite.findPlugin(r).acceptAll(),n.parent().find("textarea.consolidated").val(r.getData()))})}},t.prototype.spmInit=function(){this.$spmParagraphs=$(".wysiwyg-textarea.single-paragraph"),this.$spmParagraphs.click(this.spmOnParaClick.bind(this)),this.$spmParagraphs.find(".modifiedActions .revert").click(this.spmRevert.bind(this)),this.spmSetModifyable(),$(".wysiwyg-textarea").filter(":not(.single-paragraph)").each(this.spmInitNonSingleParas.bind(this)),$(".texteditorBox").each(function(t,a){var e=$(a),i=e.data("section-id"),n=e.data("changed-para-no");n>-1&&$("#section_holder_"+i+"_"+n).click()})},t}();a.AmendmentEdit=i});
//# sourceMappingURL=AmendmentEdit.js.map
