text: "use strict";define("composer",["taskbar","translator","composer/controls","composer/uploads","composer/formatting","composer/drafts","composer/tags","composer/categoryList","composer/preview","composer/resize","composer/autocomplete","scrollStop"],function(e,i,t,o,n,a,s,r,d,l,c,p){var f={active:undefined,posts:{},bsEnvironment:undefined,formatting:undefined};$(window).off("resize",m).on("resize",m);m();$(window).on("action:composer.topics.post",function(e,i){localStorage.removeItem("category:"+i.data.cid+":bookmark");localStorage.removeItem("category:"+i.data.cid+":bookmark:clicked")});$(window).on("popstate",function(){var e=f.bsEnvironment;if(f.active&&(e==="xs"||e==="sm")){if(!f.posts[f.active].modified){E(f.active);return}i.translate("[[modules:composer.discard]]",function(e){bootbox.confirm(e,function(e){if(e){E(f.active)}})})}});function u(){var e=f.bsEnvironment;if(ajaxify.data.template.compose===true||e==="xs"||e==="sm"){history.back()}}function m(){var e=utils.findBootstrapEnvironment();if(f.active!==undefined){l.reposition($("#cmp-uuid-"+f.active));if((e==="md"||e==="lg")&&window.location.pathname.startsWith("/compose")){history.back()}else if((e==="xs"||e==="sm")&&!window.location.pathname.startsWith("/compose")){w()}}f.bsEnvironment=e}function g(e){var i,t;if(e.hasOwnProperty("cid")){i="cid"}else if(e.hasOwnProperty("tid")){i="tid"}else if(e.hasOwnProperty("pid")){i="pid"}t=e[i];for(var o in f.posts){if(f.posts[o].hasOwnProperty(i)&&t===f.posts[o][i]){return o}}return false}function v(t){var o=utils.generateUUID(),n=g(t);if(n){e.updateActive(n);return f.load(n)}i.translate("[[topic:composer.new_topic]]",function(i){e.push("composer",o,{title:t.title?t.title:i})});if(0!==parseInt(app.user.uid,10)){if(t.hasOwnProperty("cid")){t.save_id=["composer",app.user.uid,"cid",t.cid].join(":")}else if(t.hasOwnProperty("tid")){t.save_id=["composer",app.user.uid,"tid",t.tid].join(":")}else if(t.hasOwnProperty("pid")){t.save_id=["composer",app.user.uid,"pid",t.pid].join(":")}}a.updateVisibility("available",t.save_id,true);a.updateVisibility("open",t.save_id,true);f.posts[o]=t;f.load(o)}function h(e,i){$("#cmp-uuid-"+e).find(".composer-submit").removeAttr("disabled");app.alert({type:"danger",timeout:3e3,title:"",message:i,alert_id:"post_error"})}f.findByTid=function(e){for(var i in f.posts){if(f.posts.hasOwnProperty(i)&&f.posts[i].hasOwnProperty("tid")&&parseInt(f.posts[i].tid,10)===parseInt(e,10)){return i}}return null};f.addButton=function(e,i,t){n.addButton(e,i,t)};f.newTopic=function(e){v({action:"topics.post",cid:e.cid,title:e.title||"",body:e.body||"",tags:e.tags||[],modified:false,isMain:true})};f.addQuote=function(e,t,o,n,a,s,r){r=r||f.active;var l=(n||"").replace(/([\\`*_{}\[\]()#+\-.!])/g,"\\$1").replace(/\[/g,"&#91;").replace(/\]/g,"&#93;").replace(/%/g,"&#37;").replace(/,/g,"&#44;");if(s){s="> "+s.replace(/\n/g,"\n> ")+"\n\n"}var c="["+l+"]("+config.relative_path+"/post/"+(o||t)+")";if(r===undefined){if(n&&(o||t)){f.newReply(e,t,n,"[[modules:composer.user_said_in, "+a+", "+c+"]]\n"+s)}else{f.newReply(e,t,n,"[[modules:composer.user_said, "+a+"]]\n"+s)}return}else if(r!==f.active){f.load(r)}var p=$("#cmp-uuid-"+r);var u=p.find("textarea");var m=u.val();if(n&&(o||t)){i.translate("[[modules:composer.user_said_in, "+a+", "+c+"]]\n",config.defaultLang,g)}else{i.translate("[[modules:composer.user_said, "+a+"]]\n",config.defaultLang,g)}function g(e){f.posts[r].body=(m.length?m+"\n\n":"")+e+s;u.val(f.posts[r].body);T(p);d.render(p)}};f.newReply=function(e,t,o,n){i.translate(n,config.defaultLang,function(i){v({action:"posts.reply",tid:e,toPid:t,title:o,body:i,modified:false,isMain:false})})};f.editPost=function(e){socket.emit("plugins.composer.push",e,function(i,t){if(i){return app.alertError(i.message)}v({action:"posts.edit",pid:e,uid:t.uid,handle:t.handle,title:t.title,body:t.body,modified:false,isMain:t.isMain,thumb:t.thumb,tags:t.tags})})};f.load=function(e){var i=$("#cmp-uuid-"+e);if(i.length){x(e);l.reposition(i);T(i);_()}else{if(f.formatting){b(e)}else{socket.emit("plugins.composer.getFormattingOptions",function(i,t){f.formatting=t;b(e)})}}};f.enhance=function(e,t,s){if(!t&&!s){t=utils.generateUUID();f.posts[t]=s=ajaxify.data;e.attr("id","cmp-uuid-"+t)}var l=e.find("textarea");var p=a.getDraft(s.save_id);var m=e.find(".composer-submit");r.init(e,f.posts[t]);n.addHandler(e);n.addComposerButtons();d.handleToggler(e);e.find(".img-upload-btn").removeClass("hide");e.find("#files.lt-ie9").removeClass("hide");if(config.allowFileUploads){e.find(".file-upload-btn").removeClass("hide");e.find("#files.lt-ie9").removeClass("hide")}o.initialize(t,ajaxify.data.cid);if(config.allowTopicsThumbnail&&s.isMain){o.toggleThumbEls(e,f.posts[t].thumb||"")}c.init(e);e.on("change","input, textarea",function(){f.posts[t].modified=true});m.on("click",function(e){e.preventDefault();e.stopPropagation();$(this).attr("disabled",true);P(t)});e.keypress(function(e){var i=e.which?e.which:e.keyCode;if((i===10||i==13)&&e.ctrlKey){m.attr("disabled",true);P(t);return false}return true});e.find(".composer-discard").on("click",function(e){e.preventDefault();if(!f.posts[t].modified){u();E(t);return}var o=$(this).prop("disabled",true);i.translate("[[modules:composer.discard]]",function(e){bootbox.confirm(e,function(e){if(e){u();E(t)}o.prop("disabled",false)})})});l.on("input propertychange",function(){d.render(e)});l.on("scroll",function(){d.matchScroll(e)});d.render(e,function(){d.matchScroll(e)});l.val(p?p:s.body);a.init(e,s);y(e);T(e);if(typeof screenfull!=="undefined"&&!screenfull.enabled){$('[data-format="zen"]').addClass("hidden")}$(window).trigger("action:composer.enhanced")};function b(i){var t=f.posts[i];var o=config.allowTopicsThumbnail&&t.isMain,n=t?t.hasOwnProperty("cid"):false,a=t?!!t.isMain:false,r=t?!!t.pid:false,d=t?parseInt(t.uid,10)===0:false;var c=t.title.replace(/%/g,"&#37;").replace(/,/g,"&#44;");var u={title:c,mobile:f.bsEnvironment==="xs"||f.bsEnvironment==="sm",resizable:true,allowTopicsThumbnail:o,isTopicOrMain:n||a,minimumTagLength:config.minimumTagLength,maximumTagLength:config.maximumTagLength,isTopic:n,isEditing:r,showHandleInput:config.allowGuestHandles&&(app.user.uid===0||r&&d&&app.user.isAdmin),handle:t?t.handle||"":undefined,formatting:f.formatting,tagWhitelist:ajaxify.data.tagWhitelist};if(u.mobile){w()}app.parseAndTranslate("composer",u,function(o){if($("#cmp-uuid-"+i).length){return}o=$(o);o.attr("id","cmp-uuid-"+i);$(document.body).append(o);var n=$(o[0]);l.reposition(n);f.enhance(n,i,t);s.init(n,f.posts[i]);x(i);n.on("click",function(){if(!e.isActive(i)){e.updateActive(i)}});l.handleResize(n);if(f.bsEnvironment==="xs"||f.bsEnvironment==="sm"){var a=n.find(".composer-submit"),r=n.find(".mobile-navbar .composer-submit"),d=n.find(".write"),c=d.attr("tabindex");a.removeAttr("tabindex");r.attr("tabindex",parseInt(c,10)+1);$(".category-name-container").on("click",function(){$(".category-selector").toggleClass("open")})}$(window).trigger("action:composer.loaded",{post_uuid:i,composerData:f.posts[i]});p.apply(n.find(".write"));T(n);_()})}function w(){var e="compose?p="+window.location.pathname,i=window.location.pathname.slice(1);if(i.startsWith(config.relative_path.slice(1))){i=i.slice(config.relative_path.length)}window.history.replaceState({url:null,returnPath:i},i,config.relative_path+"/"+i);window.history.pushState({url:e},e,config.relative_path+"/"+e)}function y(e){var i=e.find(".help");socket.emit("plugins.composer.renderHelp",function(e,t){if(!e&&t&&t.length>0){i.removeClass("hidden");i.on("click",function(){bootbox.alert(t)})}})}function x(e){if(f.active&&f.active!==e){f.minimize(f.active)}f.active=e}function T(e){setTimeout(function(){var i=e.find("input.title");if(i.length){i.focus()}else{e.find("textarea").focus().putCursorAtEnd()}},1)}function P(e){var i=f.posts[e];var t=$("#cmp-uuid-"+e);var n=t.find(".handle");var d=t.find(".title");var l=t.find("textarea");var c=t.find("input#topic-thumb-url");var p=i.hasOwnProperty("template")&&i.template.compose===true;d.val(d.val().trim());l.val(utils.rtrim(l.val()));if(c.length){c.val(c.val().trim())}var m=i.action;var g=(i.hasOwnProperty("cid")||parseInt(i.pid,10))&&t.find("input.title").length;var v=!g||g&&parseInt(i.cid,10);if(o.inProgress[e]&&o.inProgress[e].length){return h(e,"[[error:still-uploading]]")}else if(g&&d.val().length<parseInt(config.minimumTitleLength,10)){return h(e,"[[error:title-too-short, "+config.minimumTitleLength+"]]")}else if(g&&d.val().length>parseInt(config.maximumTitleLength,10)){return h(e,"[[error:title-too-long, "+config.maximumTitleLength+"]]")}else if(m==="topics.post"&&!v){return h(e,"[[error:category-not-selected]]")}else if(g&&s.getTags(e)&&s.getTags(e).length<parseInt(config.minimumTagsPerTopic,10)){return h(e,"[[error:not-enough-tags, "+config.minimumTagsPerTopic+"]]")}else if(l.val().length<parseInt(config.minimumPostLength,10)){return h(e,"[[error:content-too-short, "+config.minimumPostLength+"]]")}else if(l.val().length>parseInt(config.maximumPostLength,10)){return h(e,"[[error:content-too-long, "+config.maximumPostLength+"]]")}var b={};if(m==="topics.post"){b={handle:n?n.val():undefined,title:d.val(),content:l.val(),thumb:c.val()||"",cid:r.getSelectedCid(),tags:s.getTags(e)}}else if(m==="posts.reply"){b={tid:i.tid,handle:n?n.val():undefined,content:l.val(),toPid:i.toPid}}else if(m==="posts.edit"){b={pid:i.pid,handle:n?n.val():undefined,content:l.val(),title:d.val(),thumb:c.val()||"",tags:s.getTags(e)}}$(window).trigger("action:composer.submit",{composerEl:t,action:m,composerData:b});var w=$('#taskbar [data-uuid="'+e+'"] i');var y=t.find(".write");w.removeClass("fa-plus").addClass("fa-circle-o-notch fa-spin");f.minimize(e);y.prop("readonly",true);socket.emit(m,b,function(o,n){t.find(".composer-submit").removeAttr("disabled");if(o){if(o.message==="[[error:email-not-confirmed]]"){return app.showEmailConfirmWarning(o)}return app.alertError(o.message)}E(e);a.removeDraft(i.save_id);if(n.queued){app.alertSuccess(n.message)}else{if(m==="topics.post"){ajaxify.go("topic/"+n.slug,undefined,p||f.bsEnvironment==="xs"||f.bsEnvironment==="sm"?true:false)}else if(m==="posts.reply"){if(p||f.bsEnvironment==="xs"||f.bsEnvironment==="sm"){window.history.back()}else if(ajaxify.data.template.topic){if(parseInt(i.tid,10)!==parseInt(ajaxify.data.tid,10)){ajaxify.go("post/"+n.pid)}}else{ajaxify.go("post/"+n.pid)}}else{u()}}$(window).trigger("action:composer."+m,{composerData:b,data:n})})}function _(){$("html").addClass("composing")}function k(){$("body").css({paddingBottom:0});$("html").removeClass("composing")}function E(i){if(f.posts[i]){$("#cmp-uuid-"+i).remove();a.removeDraft(f.posts[i].save_id);delete f.posts[i];f.active=undefined;e.discard("composer",i);$('[data-action="post"]').removeAttr("disabled");$(window).trigger("action:composer.discard")}k()}f.minimize=function(i){var t=$("#cmp-uuid-"+i);t.css("visibility","hidden");f.active=undefined;e.minimize("composer",i);k()};return f});
  //# sourceMappingURL=node_modules/nodebb-plugin-composer-default/static/lib/composer.js.map